2222
2323#define DEFAULT_WIDTH 128
2424#define DEFAULT_HEIGHT 64
25- #define DEFAULT_ADDR 0x3C
26- #define PIN_OLED_RESET -1
2725
2826/* !
2927 @brief Class that provides a driver interface for a SSD1306
@@ -42,8 +40,7 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
4240 7-bit device address.
4341 */
4442 /* ******************************************************************************/
45- WipperSnapper_I2C_Driver_Out_Ssd1306 (TwoWire *i2c,
46- uint16_t sensorAddress)
43+ WipperSnapper_I2C_Driver_Out_Ssd1306 (TwoWire *i2c, uint16_t sensorAddress)
4744 : WipperSnapper_I2C_Driver_Out(i2c, sensorAddress) {
4845 _i2c = i2c;
4946 _sensorAddress = sensorAddress;
@@ -66,9 +63,9 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
6663 @returns True if initialized successfully, False otherwise.
6764 */
6865 bool begin () {
69- _display = new Adafruit_SSD1306 (_width, _height, & _i2c, PIN_OLED_RESET );
70- bool did_begin = _display->begin (SSD1306_SWITCHCAPVCC, DEFAULT_ADDR );
71- if (! did_begin)
66+ _display = new Adafruit_SSD1306 (_width, _height, _i2c);
67+ bool did_begin = _display->begin (SSD1306_SWITCHCAPVCC, _sensorAddress );
68+ if (!did_begin)
7269 return false ;
7370
7471 // Show initial display buffer contents on the screen --
@@ -77,14 +74,42 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
7774 delay (2000 );
7875 // Clear the buffer
7976 _display->clearDisplay ();
80- // Set the text size
81-
77+ // Configure the text size and color
78+ _display->setTextSize (_text_sz);
79+ _display->setTextColor (SSD1306_WHITE);
80+ // Reset the cursor position
81+ _display->setCursor (0 , 0 );
8282 return true ;
8383 }
8484
85+ /* !
86+ @brief Configures a SSD1306 OLED display. Must be called before driver
87+ begin()
88+ @param width
89+ The width of the display in pixels.
90+ @param height
91+ The height of the display in pixels.
92+ @param i2c_address
93+ The I2C address of the display.
94+ */
95+ void ConfigureSSD1306 (uint8_t width, uint8_t height, uint8_t text_size) {
96+ _width = width;
97+ _height = height;
98+ _text_sz = text_size;
99+ }
100+
101+ /* !
102+ @brief Writes a message to the SSD1306 display.
103+ @param message
104+ The message to be displayed.
105+ */
106+ void WriteMessageSSD1306 (const char *message) {
107+ // noop
108+ }
85109
86110protected:
87- Adafruit_SSD1306 *_display = nullptr ; // /< Pointer to the Adafruit_SSD1306 object
111+ Adafruit_SSD1306 *_display =
112+ nullptr ; // /< Pointer to the Adafruit_SSD1306 object
88113 uint8_t _width, _height, _text_sz; // /< Width and height of the display
89114};
90115
0 commit comments