@@ -63,17 +63,17 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
6363 @returns True if initialized successfully, False otherwise.
6464 */
6565 bool begin () {
66+ WS_DEBUG_PRINT (" New SSD1306 with height: " );
67+ WS_DEBUG_PRINT (_height);
68+ WS_DEBUG_PRINT (" width: " );
69+ WS_DEBUG_PRINT (_width);
70+ WS_DEBUG_PRINT (" text size: " );
71+ WS_DEBUG_PRINT (_text_sz);
6672 _display = new Adafruit_SSD1306 (_width, _height, _i2c);
67- bool did_begin = _display->begin (
68- SSD1306_SWITCHCAPVCC,
69- 0x3C ); // TODO: Note that this is hardcoded, not sure why not init'd yet
73+ // TODO: Use _sensorAddress instead of 0x3C hardcode!
74+ bool did_begin = _display->begin (SSD1306_SWITCHCAPVCC, 0x3C );
7075 if (!did_begin)
71- return false ;
72-
73- // Show initial display buffer contents on the screen --
74- // the library initializes this with an Adafruit splash screen.
75- _display->display ();
76- delay (1000 );
76+ return false ;
7777 // Clear the buffer
7878 _display->clearDisplay ();
7979 // Configure the text size and color
@@ -82,7 +82,7 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
8282 // Reset the cursor position
8383 _display->setCursor (0 , 0 );
8484 _display->display ();
85- return true ;
85+ return did_begin ;
8686 }
8787
8888 /* !
@@ -118,21 +118,27 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
118118 WS_DEBUG_PRINTLN (line_height);
119119
120120 int16_t y_idx = 0 ;
121+ uint16_t c_idx = 0 ;
121122 _display->setCursor (0 , y_idx);
122- for (int i = 0 ; message[i] != ' \0 ' ; i++) {
123- if (message[i] == ' \n ' ) {
123+ for (int i = 0 ; i < strlen (message); i++) {
124+ char c = message[c_idx];
125+ if (c == ' \\ ' && message[c_idx + 1 ] == ' n' ) {
124126 WS_DEBUG_PRINTLN (" New line detected!" );
127+ // Skip the '\n' character in the buffer
128+ c_idx += 2 ;
129+ // Move the cursor to the next line
125130 y_idx += line_height;
126131 _display->setCursor (0 , y_idx);
127132 } else {
128133 WS_DEBUG_PRINT (" Printing char: " );
129- WS_DEBUG_PRINT (message[i ]);
134+ WS_DEBUG_PRINT (message[c_idx ]);
130135 WS_DEBUG_PRINT (" at y: " );
131136 WS_DEBUG_PRINTLN (y_idx);
132- _display->print (message[i]);
137+ _display->print (message[c_idx]);
138+ _display->display ();
139+ c_idx++;
133140 }
134141 }
135- _display->display ();
136142 }
137143
138144protected:
0 commit comments