@@ -63,17 +63,17 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
63
63
@returns True if initialized successfully, False otherwise.
64
64
*/
65
65
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);
66
72
_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 );
70
75
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 ;
77
77
// Clear the buffer
78
78
_display->clearDisplay ();
79
79
// Configure the text size and color
@@ -82,7 +82,7 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
82
82
// Reset the cursor position
83
83
_display->setCursor (0 , 0 );
84
84
_display->display ();
85
- return true ;
85
+ return did_begin ;
86
86
}
87
87
88
88
/* !
@@ -118,21 +118,27 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
118
118
WS_DEBUG_PRINTLN (line_height);
119
119
120
120
int16_t y_idx = 0 ;
121
+ uint16_t c_idx = 0 ;
121
122
_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' ) {
124
126
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
125
130
y_idx += line_height;
126
131
_display->setCursor (0 , y_idx);
127
132
} else {
128
133
WS_DEBUG_PRINT (" Printing char: " );
129
- WS_DEBUG_PRINT (message[i ]);
134
+ WS_DEBUG_PRINT (message[c_idx ]);
130
135
WS_DEBUG_PRINT (" at y: " );
131
136
WS_DEBUG_PRINTLN (y_idx);
132
- _display->print (message[i]);
137
+ _display->print (message[c_idx]);
138
+ _display->display ();
139
+ c_idx++;
133
140
}
134
141
}
135
- _display->display ();
136
142
}
137
143
138
144
protected:
0 commit comments