clear on ctor dtor

This commit is contained in:
brentru 2025-06-05 14:59:13 -04:00
parent 964760ad96
commit eed66c7984
2 changed files with 9 additions and 2 deletions

View file

@ -881,6 +881,10 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
} else if (strcmp("oled128x32default", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x32large", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x64default", msgDeviceInitReq->i2c_device_name) ==
0 ||
strcmp("oled128x64large", msgDeviceInitReq->i2c_device_name) ==
0) {
WS_DEBUG_PRINTLN("SSD1306 display detected!");
_ssd1306 = new WipperSnapper_I2C_Driver_Out_Ssd1306(this->_i2c, i2cAddress);

View file

@ -53,6 +53,8 @@ public:
*/
~WipperSnapper_I2C_Driver_Out_Ssd1306() {
if (_display != nullptr) {
_display->clearDisplay();
_display->display();
_display->ssd1306_command(SSD1306_DISPLAYOFF);
delete _display;
_display = nullptr;
@ -68,13 +70,14 @@ public:
_display = new Adafruit_SSD1306(_width, _height, _i2c);
if (!_display->begin(SSD1306_SWITCHCAPVCC, _sensorAddress))
return false;
// Clear the buffer
_display->clearDisplay();
// Configure the text size and color
_display->setTextSize(_text_sz);
_display->setTextColor(SSD1306_WHITE);
// Use full 256 char 'Code Page 437' font
_display->cp437(true);
// Clear the buffer
_display->clearDisplay();
_display->display();
return true;
}