From bd04c5296f913b3ed8adc286eebf11f37721ea07 Mon Sep 17 00:00:00 2001 From: Coscolin Date: Sun, 19 May 2024 14:39:45 +0200 Subject: [PATCH 1/4] Turn off/on display on S3 and T-Displays for battery safe --- CO2_Gadget.ino | 37 +++++++++++--------- CO2_Gadget_Buttons.h | 16 ++++----- CO2_Gadget_OLED.h | 80 ++++++++++++++++++++++++-------------------- CO2_Gadget_TFT.h | 24 ++++++++++++- 4 files changed, 96 insertions(+), 61 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 551207ba..e9fec96c 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -76,6 +76,7 @@ bool activeOTA = false; bool mustInitMenu = false; bool menuInitialized = false; uint16_t DisplayBrightness = 100; +bool displayOn = true; bool displayReverse = false; bool showFahrenheit = false; bool displayShowTemperature = true; @@ -299,11 +300,12 @@ static int64_t lastReadingsCommunicationTime = 0; static int startCheckingAfterUs = 1900000; void wakeUpDisplay() { - if (actualDisplayBrightness == 0) { + if (!displayOn) { #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) - setDisplayBrightness(DisplayBrightness); - // publishMQTTLogData("Display woken up. Setting display brightness to " + String(DisplayBrightness)); - // Serial.println("-->[MAIN] Display woken up. Setting display brightness to " + String(DisplayBrightness)); + turnOnDisplay(); +// setDisplayBrightness(DisplayBrightness); +// publishMQTTLogData("Display woken up. Setting display brightness to " + String(DisplayBrightness)); +// Serial.println("-->[MAIN] Display woken up. Setting display brightness to " + String(DisplayBrightness)); #endif lastTimeButtonPressed = millis(); } @@ -446,17 +448,21 @@ void adjustBrightnessLoop() { } if (inMenu) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); return; } // Display backlight IS sleeping - if ((actualDisplayBrightness == 0) && (actualDisplayBrightness != DisplayBrightness)) { + // if ((actualDisplayBrightness == 0) && (actualDisplayBrightness != DisplayBrightness)) { + if (!displayOn) { if ((!displayOffOnExternalPower) && (workingOnExternalPower)) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); } if (timeToDisplayOff == 0) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); } return; } @@ -469,18 +475,19 @@ void adjustBrightnessLoop() { // If configured not to turn off the display on external power and it's working on external power, do nothing and return (except if DisplayBrightness is 0, then turn on display)) if ((workingOnExternalPower) && (!displayOffOnExternalPower)) { - if (actualDisplayBrightness == 0) { - setDisplayBrightness(DisplayBrightness); // Exception: When USB connected (just connected) & TFT is OFF -> Turn Display ON - // publishMQTTLogData("Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); - // Serial.println("-->[MAIN] Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); - // delay(10); - } + wakeUpDisplay(); + // if (actualDisplayBrightness == 0) { + // setDisplayBrightness(DisplayBrightness); // Exception: When USB connected (just connected) & TFT is OFF -> Turn Display ON + // publishMQTTLogData("Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); + // Serial.println("-->[MAIN] Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); + // delay(10); + //} return; } if (timeToDisplayOff == 0) return; // If timeToDisplayOff is 0, don't turn off the display - if ((actualDisplayBrightness != 0) && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) { + if (displayOn && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) { if ((workingOnExternalPower) && (displayOffOnExternalPower)) { Serial.println("-->[MAIN] Turning off display on external power to save power. Actual brightness: " + String(actualDisplayBrightness)); turnOffDisplay(); diff --git a/CO2_Gadget_Buttons.h b/CO2_Gadget_Buttons.h index ef532963..59ecac1f 100644 --- a/CO2_Gadget_Buttons.h +++ b/CO2_Gadget_Buttons.h @@ -8,7 +8,7 @@ Button2 btnUp(BTN_UP); // Initialize the up button Button2 btnDwn(BTN_DWN); // Initialize the down button void IRAM_ATTR buttonUpISR() { - if (actualDisplayBrightness == 0) { // Turn on the display only if it's OFF + if (!displayOn) { // Turn on the display only if it's OFF shouldWakeUpDisplay = true; lastTimeButtonPressed = millis(); } @@ -19,7 +19,7 @@ void IRAM_ATTR buttonUpISR() { } void IRAM_ATTR buttonDownISR() { - if (actualDisplayBrightness == 0) { // Turn on the display only if it's OFF + if (!displayOn) { // Turn on the display only if it's OFF shouldWakeUpDisplay = true; lastTimeButtonPressed = millis(); } @@ -35,13 +35,13 @@ void IRAM_ATTR buttonDownISR() { // } void initButtons() { - // Set Interrupt Service Routine to turn on the display on button UP or DOWN press (nothing to do with the button functionality for the menu itself) - #if BTN_UP != -1 +// Set Interrupt Service Routine to turn on the display on button UP or DOWN press (nothing to do with the button functionality for the menu itself) +#if BTN_UP != -1 attachInterrupt(BTN_UP, buttonUpISR, RISING); - #endif - #if BTN_DWN != -1 - // attachInterrupt(BTN_DWN, buttonUpISR, RISING); // Conflicts with Improv because of GPIO 0 - #endif +#endif +#if BTN_DWN != -1 +// attachInterrupt(BTN_DWN, buttonUpISR, RISING); // Conflicts with Improv because of GPIO 0 +#endif btnUp.setLongClickTime(LONGCLICK_TIME_MS); btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); }); diff --git a/CO2_Gadget_OLED.h b/CO2_Gadget_OLED.h index 2e50ced4..2bd1ce4d 100644 --- a/CO2_Gadget_OLED.h +++ b/CO2_Gadget_OLED.h @@ -13,6 +13,7 @@ // clang-format on // #include #include + #include "bootlogo.h" #include "icons.h" U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE); // Frame Buffer: clearBuffer/sendBuffer. More RAM usage, Faster @@ -25,25 +26,30 @@ int displayHeight = 64; #define MENUFONT u8g2_font_5x8_mf void setDisplayBrightness(uint32_t newBrightness) { - Serial.printf("-->[OLED] Setting display brightness value at %d\n", newBrightness); - u8g2.setContrast(newBrightness); - actualDisplayBrightness = newBrightness; + Serial.printf("-->[OLED] Setting display brightness value at %d\n", newBrightness); + u8g2.setContrast(newBrightness); + actualDisplayBrightness = newBrightness; } void turnOffDisplay() { - setDisplayBrightness(0); // Turn off the display + setDisplayBrightness(0); // Turn off the display + displayOn = false; +} +void turnOnDisplay() { + setDisplayBrightness(DisplayBrightness); // Turn off the display + displayOn = true; } void displaySplashScreen() { - u8g2.clearDisplay(); - u8g2.firstPage(); - do { - // u8g2.drawXBMP(30, 0, 59, 20, eMarieteLogo); - // u8g2.drawXBM(7, 23, 46, 36, CO2Logo); - // u8g2.drawXBM(60, 32, 61, 23, GadgetLogo); - u8g2.drawXBM(0, 0, 128, 64, splash); - } while (u8g2.nextPage()); - u8g2.setFont(MENUFONT); + u8g2.clearDisplay(); + u8g2.firstPage(); + do { + // u8g2.drawXBMP(30, 0, 59, 20, eMarieteLogo); + // u8g2.drawXBM(7, 23, 46, 36, CO2Logo); + // u8g2.drawXBM(60, 32, 61, 23, GadgetLogo); + u8g2.drawXBM(0, 0, 128, 64, splash); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); } /*************************************************************************************** @@ -54,37 +60,37 @@ void displaySplashScreen() { // notificationText = string to display. // notificationTypes one of enum notificationTypes notifyNothing, notifyInfo, notifyWarning, notifyError bool displayNotification(String notificationText, notificationTypes notificationType) { - uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; - return true; + uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; + return true; } bool displayNotification(String notificationText, String notificationText2, notificationTypes notificationType) { - uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; - return true; + uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; + return true; } -void initDisplay(bool fastMode = false) { // fastMode not used in OLED display. Just for compatibility with TFT and other displays. - Serial.printf("-->[OLED] Initialized: \t#%s#\n", - ((u8g2.begin()) ? "OK" : "Failed")); - u8g2.firstPage(); - do { - u8g2.setFont(u8g2_font_ncenB12_tr); - u8g2.drawStr(0, 15, " eMariete.com"); - u8g2.drawStr(0, 33, " CO2 Gadget"); - u8g2.drawStr(0, 51, " Air Quality"); - } while (u8g2.nextPage()); - u8g2.setFont(MENUFONT); - if (displayReverse) { - u8g2.setDisplayRotation(U8G2_R2); - } else { - u8g2.setDisplayRotation(U8G2_R0); - } - setDisplayBrightness(DisplayBrightness); - displaySplashScreen(); - delay(1000); +void initDisplay(bool fastMode = false) { // fastMode not used in OLED display. Just for compatibility with TFT and other displays. + Serial.printf("-->[OLED] Initialized: \t#%s#\n", + ((u8g2.begin()) ? "OK" : "Failed")); + u8g2.firstPage(); + do { + u8g2.setFont(u8g2_font_ncenB12_tr); + u8g2.drawStr(0, 15, " eMariete.com"); + u8g2.drawStr(0, 33, " CO2 Gadget"); + u8g2.drawStr(0, 51, " Air Quality"); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); + if (displayReverse) { + u8g2.setDisplayRotation(U8G2_R2); + } else { + u8g2.setDisplayRotation(U8G2_R0); + } + setDisplayBrightness(DisplayBrightness); + displaySplashScreen(); + delay(1000); } -void displayShowValues(bool forceRedraw = false) { +void displayShowValues(bool forceRedraw = false) { if ((co2 == 0) || (co2 > 9999)) return; String co2Str = String(co2); if (co2Str.length() < 4) { diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 8575d7fd..ae357b4c 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -225,7 +225,29 @@ void setDisplayBrightness(uint16_t newBrightness) { } void turnOffDisplay() { - setDisplayBrightness(0); // Turn off the display + tft.writecommand(TFT_DISPOFF); // Comando para apagar la pantalla + tft.writecommand(TFT_SLPIN); + digitalWrite(TFT_BACKLIGHT, LOW); // turn of lcd backlight +#ifdef TTGO_TDISPLAY + setDisplayBrightness(0); +#endif + displayOn = false; +} + +void turnOnDisplay() { + // tft.init(); + tft.writecommand(TFT_SLPOUT); + delay(120); + tft.writecommand(TFT_DISPON); // turn on display + digitalWrite(TFT_BACKLIGHT, HIGH); // turn on lcd backlight +#ifdef TTGO_TDISPLAY + setDisplayBrightness(DisplayBrightness); +#endif +#ifdef ARDUINO_LILYGO_T_DISPLAY_S3 + actualDisplayBrightness = 16; // At the beginning brightness is at maximum level +#endif + setDisplayBrightness(DisplayBrightness); + displayOn = true; } void displaySplashScreen() { From 78ba9bd0fd0c43a28a6007ec5129295b01591bfb Mon Sep 17 00:00:00 2001 From: Coscolin Date: Sun, 19 May 2024 14:41:38 +0200 Subject: [PATCH 2/4] Turn off/on display on S3 and T-Displays for battery safe --- CO2_Gadget.ino | 37 +++++++++++--------- CO2_Gadget_Buttons.h | 16 ++++----- CO2_Gadget_OLED.h | 80 ++++++++++++++++++++++++-------------------- CO2_Gadget_TFT.h | 24 ++++++++++++- 4 files changed, 96 insertions(+), 61 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 551207ba..e9fec96c 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -76,6 +76,7 @@ bool activeOTA = false; bool mustInitMenu = false; bool menuInitialized = false; uint16_t DisplayBrightness = 100; +bool displayOn = true; bool displayReverse = false; bool showFahrenheit = false; bool displayShowTemperature = true; @@ -299,11 +300,12 @@ static int64_t lastReadingsCommunicationTime = 0; static int startCheckingAfterUs = 1900000; void wakeUpDisplay() { - if (actualDisplayBrightness == 0) { + if (!displayOn) { #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) - setDisplayBrightness(DisplayBrightness); - // publishMQTTLogData("Display woken up. Setting display brightness to " + String(DisplayBrightness)); - // Serial.println("-->[MAIN] Display woken up. Setting display brightness to " + String(DisplayBrightness)); + turnOnDisplay(); +// setDisplayBrightness(DisplayBrightness); +// publishMQTTLogData("Display woken up. Setting display brightness to " + String(DisplayBrightness)); +// Serial.println("-->[MAIN] Display woken up. Setting display brightness to " + String(DisplayBrightness)); #endif lastTimeButtonPressed = millis(); } @@ -446,17 +448,21 @@ void adjustBrightnessLoop() { } if (inMenu) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); return; } // Display backlight IS sleeping - if ((actualDisplayBrightness == 0) && (actualDisplayBrightness != DisplayBrightness)) { + // if ((actualDisplayBrightness == 0) && (actualDisplayBrightness != DisplayBrightness)) { + if (!displayOn) { if ((!displayOffOnExternalPower) && (workingOnExternalPower)) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); } if (timeToDisplayOff == 0) { - setDisplayBrightness(DisplayBrightness); + wakeUpDisplay(); + // setDisplayBrightness(DisplayBrightness); } return; } @@ -469,18 +475,19 @@ void adjustBrightnessLoop() { // If configured not to turn off the display on external power and it's working on external power, do nothing and return (except if DisplayBrightness is 0, then turn on display)) if ((workingOnExternalPower) && (!displayOffOnExternalPower)) { - if (actualDisplayBrightness == 0) { - setDisplayBrightness(DisplayBrightness); // Exception: When USB connected (just connected) & TFT is OFF -> Turn Display ON - // publishMQTTLogData("Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); - // Serial.println("-->[MAIN] Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); - // delay(10); - } + wakeUpDisplay(); + // if (actualDisplayBrightness == 0) { + // setDisplayBrightness(DisplayBrightness); // Exception: When USB connected (just connected) & TFT is OFF -> Turn Display ON + // publishMQTTLogData("Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); + // Serial.println("-->[MAIN] Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); + // delay(10); + //} return; } if (timeToDisplayOff == 0) return; // If timeToDisplayOff is 0, don't turn off the display - if ((actualDisplayBrightness != 0) && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) { + if (displayOn && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) { if ((workingOnExternalPower) && (displayOffOnExternalPower)) { Serial.println("-->[MAIN] Turning off display on external power to save power. Actual brightness: " + String(actualDisplayBrightness)); turnOffDisplay(); diff --git a/CO2_Gadget_Buttons.h b/CO2_Gadget_Buttons.h index ef532963..59ecac1f 100644 --- a/CO2_Gadget_Buttons.h +++ b/CO2_Gadget_Buttons.h @@ -8,7 +8,7 @@ Button2 btnUp(BTN_UP); // Initialize the up button Button2 btnDwn(BTN_DWN); // Initialize the down button void IRAM_ATTR buttonUpISR() { - if (actualDisplayBrightness == 0) { // Turn on the display only if it's OFF + if (!displayOn) { // Turn on the display only if it's OFF shouldWakeUpDisplay = true; lastTimeButtonPressed = millis(); } @@ -19,7 +19,7 @@ void IRAM_ATTR buttonUpISR() { } void IRAM_ATTR buttonDownISR() { - if (actualDisplayBrightness == 0) { // Turn on the display only if it's OFF + if (!displayOn) { // Turn on the display only if it's OFF shouldWakeUpDisplay = true; lastTimeButtonPressed = millis(); } @@ -35,13 +35,13 @@ void IRAM_ATTR buttonDownISR() { // } void initButtons() { - // Set Interrupt Service Routine to turn on the display on button UP or DOWN press (nothing to do with the button functionality for the menu itself) - #if BTN_UP != -1 +// Set Interrupt Service Routine to turn on the display on button UP or DOWN press (nothing to do with the button functionality for the menu itself) +#if BTN_UP != -1 attachInterrupt(BTN_UP, buttonUpISR, RISING); - #endif - #if BTN_DWN != -1 - // attachInterrupt(BTN_DWN, buttonUpISR, RISING); // Conflicts with Improv because of GPIO 0 - #endif +#endif +#if BTN_DWN != -1 +// attachInterrupt(BTN_DWN, buttonUpISR, RISING); // Conflicts with Improv because of GPIO 0 +#endif btnUp.setLongClickTime(LONGCLICK_TIME_MS); btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); }); diff --git a/CO2_Gadget_OLED.h b/CO2_Gadget_OLED.h index 2e50ced4..2bd1ce4d 100644 --- a/CO2_Gadget_OLED.h +++ b/CO2_Gadget_OLED.h @@ -13,6 +13,7 @@ // clang-format on // #include #include + #include "bootlogo.h" #include "icons.h" U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE); // Frame Buffer: clearBuffer/sendBuffer. More RAM usage, Faster @@ -25,25 +26,30 @@ int displayHeight = 64; #define MENUFONT u8g2_font_5x8_mf void setDisplayBrightness(uint32_t newBrightness) { - Serial.printf("-->[OLED] Setting display brightness value at %d\n", newBrightness); - u8g2.setContrast(newBrightness); - actualDisplayBrightness = newBrightness; + Serial.printf("-->[OLED] Setting display brightness value at %d\n", newBrightness); + u8g2.setContrast(newBrightness); + actualDisplayBrightness = newBrightness; } void turnOffDisplay() { - setDisplayBrightness(0); // Turn off the display + setDisplayBrightness(0); // Turn off the display + displayOn = false; +} +void turnOnDisplay() { + setDisplayBrightness(DisplayBrightness); // Turn off the display + displayOn = true; } void displaySplashScreen() { - u8g2.clearDisplay(); - u8g2.firstPage(); - do { - // u8g2.drawXBMP(30, 0, 59, 20, eMarieteLogo); - // u8g2.drawXBM(7, 23, 46, 36, CO2Logo); - // u8g2.drawXBM(60, 32, 61, 23, GadgetLogo); - u8g2.drawXBM(0, 0, 128, 64, splash); - } while (u8g2.nextPage()); - u8g2.setFont(MENUFONT); + u8g2.clearDisplay(); + u8g2.firstPage(); + do { + // u8g2.drawXBMP(30, 0, 59, 20, eMarieteLogo); + // u8g2.drawXBM(7, 23, 46, 36, CO2Logo); + // u8g2.drawXBM(60, 32, 61, 23, GadgetLogo); + u8g2.drawXBM(0, 0, 128, 64, splash); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); } /*************************************************************************************** @@ -54,37 +60,37 @@ void displaySplashScreen() { // notificationText = string to display. // notificationTypes one of enum notificationTypes notifyNothing, notifyInfo, notifyWarning, notifyError bool displayNotification(String notificationText, notificationTypes notificationType) { - uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; - return true; + uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; + return true; } bool displayNotification(String notificationText, String notificationText2, notificationTypes notificationType) { - uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; - return true; + uint16_t textColor, boxColor, backgroundColor, boxMarging = 15; + return true; } -void initDisplay(bool fastMode = false) { // fastMode not used in OLED display. Just for compatibility with TFT and other displays. - Serial.printf("-->[OLED] Initialized: \t#%s#\n", - ((u8g2.begin()) ? "OK" : "Failed")); - u8g2.firstPage(); - do { - u8g2.setFont(u8g2_font_ncenB12_tr); - u8g2.drawStr(0, 15, " eMariete.com"); - u8g2.drawStr(0, 33, " CO2 Gadget"); - u8g2.drawStr(0, 51, " Air Quality"); - } while (u8g2.nextPage()); - u8g2.setFont(MENUFONT); - if (displayReverse) { - u8g2.setDisplayRotation(U8G2_R2); - } else { - u8g2.setDisplayRotation(U8G2_R0); - } - setDisplayBrightness(DisplayBrightness); - displaySplashScreen(); - delay(1000); +void initDisplay(bool fastMode = false) { // fastMode not used in OLED display. Just for compatibility with TFT and other displays. + Serial.printf("-->[OLED] Initialized: \t#%s#\n", + ((u8g2.begin()) ? "OK" : "Failed")); + u8g2.firstPage(); + do { + u8g2.setFont(u8g2_font_ncenB12_tr); + u8g2.drawStr(0, 15, " eMariete.com"); + u8g2.drawStr(0, 33, " CO2 Gadget"); + u8g2.drawStr(0, 51, " Air Quality"); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); + if (displayReverse) { + u8g2.setDisplayRotation(U8G2_R2); + } else { + u8g2.setDisplayRotation(U8G2_R0); + } + setDisplayBrightness(DisplayBrightness); + displaySplashScreen(); + delay(1000); } -void displayShowValues(bool forceRedraw = false) { +void displayShowValues(bool forceRedraw = false) { if ((co2 == 0) || (co2 > 9999)) return; String co2Str = String(co2); if (co2Str.length() < 4) { diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 8575d7fd..ae357b4c 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -225,7 +225,29 @@ void setDisplayBrightness(uint16_t newBrightness) { } void turnOffDisplay() { - setDisplayBrightness(0); // Turn off the display + tft.writecommand(TFT_DISPOFF); // Comando para apagar la pantalla + tft.writecommand(TFT_SLPIN); + digitalWrite(TFT_BACKLIGHT, LOW); // turn of lcd backlight +#ifdef TTGO_TDISPLAY + setDisplayBrightness(0); +#endif + displayOn = false; +} + +void turnOnDisplay() { + // tft.init(); + tft.writecommand(TFT_SLPOUT); + delay(120); + tft.writecommand(TFT_DISPON); // turn on display + digitalWrite(TFT_BACKLIGHT, HIGH); // turn on lcd backlight +#ifdef TTGO_TDISPLAY + setDisplayBrightness(DisplayBrightness); +#endif +#ifdef ARDUINO_LILYGO_T_DISPLAY_S3 + actualDisplayBrightness = 16; // At the beginning brightness is at maximum level +#endif + setDisplayBrightness(DisplayBrightness); + displayOn = true; } void displaySplashScreen() { From e0c3b2766f2b0f220f6b18ba2722db776d32fbdc Mon Sep 17 00:00:00 2001 From: Coscolin Date: Sun, 19 May 2024 14:43:17 +0200 Subject: [PATCH 3/4] Remove setDisplayBrightness duplicated --- CO2_Gadget_TFT.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index ae357b4c..0801c8b1 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -240,9 +240,6 @@ void turnOnDisplay() { delay(120); tft.writecommand(TFT_DISPON); // turn on display digitalWrite(TFT_BACKLIGHT, HIGH); // turn on lcd backlight -#ifdef TTGO_TDISPLAY - setDisplayBrightness(DisplayBrightness); -#endif #ifdef ARDUINO_LILYGO_T_DISPLAY_S3 actualDisplayBrightness = 16; // At the beginning brightness is at maximum level #endif From 6c3437b7cc0f9025be1a566eba7f0664791849a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Coscol=C3=ADn?= Date: Sun, 19 May 2024 16:47:41 +0200 Subject: [PATCH 4/4] Actualizar CO2_Gadget_TFT.h Remove conditional setDisplayBrightness() so is executed later --- CO2_Gadget_TFT.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index ae357b4c..0801c8b1 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -240,9 +240,6 @@ void turnOnDisplay() { delay(120); tft.writecommand(TFT_DISPON); // turn on display digitalWrite(TFT_BACKLIGHT, HIGH); // turn on lcd backlight -#ifdef TTGO_TDISPLAY - setDisplayBrightness(DisplayBrightness); -#endif #ifdef ARDUINO_LILYGO_T_DISPLAY_S3 actualDisplayBrightness = 16; // At the beginning brightness is at maximum level #endif