From b32a44053259392dcf2dfcc8ddff58aa154cbe0e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 17 Aug 2020 14:49:24 +0200 Subject: [PATCH] Fix display power control Fix display power control (#9114) --- tasmota/xdrv_13_display.ino | 24 +++++++++--------------- tasmota/xdsp_01_lcd.ino | 9 +++------ tasmota/xdsp_04_ili9341.ino | 18 +++++------------- tasmota/xdsp_11_sevenseg.ino | 7 +++---- tasmota/xdsp_interface.ino | 1 - 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 1b1013340..dd794e657 100644 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -71,7 +71,7 @@ enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_E FUNC_DISPLAY_DRAW_HLINE, FUNC_DISPLAY_DRAW_VLINE, FUNC_DISPLAY_DRAW_LINE, FUNC_DISPLAY_DRAW_CIRCLE, FUNC_DISPLAY_FILL_CIRCLE, FUNC_DISPLAY_DRAW_RECTANGLE, FUNC_DISPLAY_FILL_RECTANGLE, - FUNC_DISPLAY_TEXT_SIZE, FUNC_DISPLAY_FONT_SIZE, FUNC_DISPLAY_ROTATION, FUNC_DISPLAY_DRAW_STRING, FUNC_DISPLAY_ONOFF }; + FUNC_DISPLAY_TEXT_SIZE, FUNC_DISPLAY_FONT_SIZE, FUNC_DISPLAY_ROTATION, FUNC_DISPLAY_DRAW_STRING }; enum DisplayInitModes { DISPLAY_INIT_MODE, DISPLAY_INIT_PARTIAL, DISPLAY_INIT_FULL }; @@ -241,8 +241,7 @@ void DisplayDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint void DisplayOnOff(uint8_t on) { - dsp_on = on; - XdspCall(FUNC_DISPLAY_ONOFF); + ExecuteCommandPower(disp_device, on, SRC_DISPLAY); } /*-------------------------------------------------------------------------------------------*/ @@ -435,18 +434,10 @@ void DisplayText(void) DisplayInit(DISPLAY_INIT_FULL); break; case 'o': - if (!renderer) { - DisplayOnOff(0); - } else { - renderer->DisplayOnff(0); - } + DisplayOnOff(0); break; case 'O': - if (!renderer) { - DisplayOnOff(1); - } else { - renderer->DisplayOnff(1); - } + DisplayOnOff(1); break; case 'x': // set disp_xpos @@ -1268,8 +1259,11 @@ void DisplayInitDriver(void) // AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings.display_model); if (Settings.display_model) { - if (!light_type) { - devices_present++; // If no PWM channel for backlight then use "normal" power control + devices_present++; + if (!PinUsed(GPIO_BACKLIGHT)) { + if (light_type && (4 == Settings.display_model)) { + devices_present--; // Assume PWM channel is used for backlight + } } disp_device = devices_present; diff --git a/tasmota/xdsp_01_lcd.ino b/tasmota/xdsp_01_lcd.ino index 4a700488a..4afc0b47e 100644 --- a/tasmota/xdsp_01_lcd.ino +++ b/tasmota/xdsp_01_lcd.ino @@ -93,9 +93,9 @@ void LcdDrawStringAt(void) lcd->print(dsp_str); } -void LcdDisplayOnOff(uint8_t on) +void LcdDisplayOnOff() { - if (on) { + if (disp_power) { lcd->backlight(); } else { lcd->noBacklight(); @@ -212,7 +212,7 @@ bool Xdsp01(uint8_t function) LcdInit(dsp_init); break; case FUNC_DISPLAY_POWER: - LcdDisplayOnOff(disp_power); + LcdDisplayOnOff(); break; case FUNC_DISPLAY_CLEAR: lcd->clear(); @@ -238,9 +238,6 @@ bool Xdsp01(uint8_t function) case FUNC_DISPLAY_DRAW_STRING: LcdDrawStringAt(); break; - case FUNC_DISPLAY_ONOFF: - LcdDisplayOnOff(dsp_on); - break; // case FUNC_DISPLAY_ROTATION: // break; #ifdef USE_DISPLAY_MODES1TO5 diff --git a/tasmota/xdsp_04_ili9341.ino b/tasmota/xdsp_04_ili9341.ino index 191c074bb..68be6a73a 100644 --- a/tasmota/xdsp_04_ili9341.ino +++ b/tasmota/xdsp_04_ili9341.ino @@ -145,21 +145,16 @@ void Ili9341DrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint tft->println(str); } -void Ili9341DisplayOnOff(uint8_t on) +void Ili9341DisplayOnOff() { -// tft->showDisplay(on); -// tft->invertDisplay(on); +// tft->showDisplay(disp_power); +// tft->invertDisplay(disp_power); if (PinUsed(GPIO_BACKLIGHT)) { pinMode(Pin(GPIO_BACKLIGHT), OUTPUT); - digitalWrite(Pin(GPIO_BACKLIGHT), on); + digitalWrite(Pin(GPIO_BACKLIGHT), disp_power); } } -void Ili9341OnOff(void) -{ - Ili9341DisplayOnOff(disp_power); -} - /*********************************************************************************************/ #ifdef USE_DISPLAY_MODES1TO5 @@ -277,7 +272,7 @@ bool Xdsp04(uint8_t function) Ili9341Init(dsp_init); break; case FUNC_DISPLAY_POWER: - Ili9341OnOff(); + Ili9341DisplayOnOff(); break; case FUNC_DISPLAY_CLEAR: Ili9341Clear(); @@ -315,9 +310,6 @@ bool Xdsp04(uint8_t function) case FUNC_DISPLAY_DRAW_STRING: Ili9341DrawStringAt(dsp_x, dsp_y, dsp_str, dsp_color, dsp_flag); break; - case FUNC_DISPLAY_ONOFF: - Ili9341DisplayOnOff(dsp_on); - break; case FUNC_DISPLAY_ROTATION: tft->setRotation(Settings.display_rotate); break; diff --git a/tasmota/xdsp_11_sevenseg.ino b/tasmota/xdsp_11_sevenseg.ino index 1db043ef2..314e31a04 100644 --- a/tasmota/xdsp_11_sevenseg.ino +++ b/tasmota/xdsp_11_sevenseg.ino @@ -91,7 +91,7 @@ void SevensegInitDriver(void) break; } } - + Settings.display_width = 4; Settings.display_height = sevensegs; @@ -127,7 +127,7 @@ void SevensegDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uin // Some combinations won't make sense. // Reference: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-led-backpack.pdf // This code has been tested on 1.2" and 0.56" 7-Segment LED displays, but should mostly work for others. - // + // // Prefixes: // x upcoming decimal integer number displayed as hex // : turn on middle colon @@ -138,7 +138,7 @@ void SevensegDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uin // z clear this display // f upcoming number is floating point // r raw segment based on bitmap of upcoming integer number (see reference document above) - // + // // Some sample valid combinations: // 787 -> 787 // x47 -> 2F @@ -364,7 +364,6 @@ bool Xdsp11(uint8_t function) SevensegRefresh(); break; #endif // USE_DISPLAY_MODES1TO5 - case FUNC_DISPLAY_ONOFF: case FUNC_DISPLAY_POWER: SevensegOnOff(); break; diff --git a/tasmota/xdsp_interface.ino b/tasmota/xdsp_interface.ino index c92d6eceb..44e72a001 100644 --- a/tasmota/xdsp_interface.ino +++ b/tasmota/xdsp_interface.ino @@ -112,7 +112,6 @@ const uint8_t xdsp_present = sizeof(xdsp_func_ptr) / sizeof(xdsp_func_ptr[0]); * FUNC_DISPLAY_FONT_SIZE * FUNC_DISPLAY_ROTATION * FUNC_DISPLAY_DRAW_STRING - * FUNC_DISPLAY_ONOFF \*********************************************************************************************/ uint8_t XdspPresent(void)