From 9bf1bd93c049dbe511ba74d7c2c749ecd64c85cd Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 5 Feb 2023 12:52:21 +0100 Subject: [PATCH] Add some display safeguards fixing power issues at restart --- .../tasmota_xdrv_driver/xdrv_13_display.ino | 22 ++++++++++++------- .../xdsp_17_universal.ino | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino b/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino index 05bc7db16..5c4ce996e 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino @@ -237,7 +237,7 @@ uint16_t dsp_rad; uint16_t dsp_color; int16_t dsp_len; -uint8_t disp_power = 0; +int8_t disp_power = -1; uint8_t disp_device = 0; uint8_t disp_refresh = 1; uint8_t disp_autodraw = 1; @@ -293,9 +293,10 @@ void DisplayDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint XdspCall(FUNC_DISPLAY_DRAW_STRING); } -void DisplayOnOff(uint8_t on) -{ - ExecuteCommandPower(disp_device, on, SRC_DISPLAY); +void DisplayOnOff(uint8_t on) { + if (disp_device) { + ExecuteCommandPower(disp_device, on, SRC_DISPLAY); + } } /*-------------------------------------------------------------------------------------------*/ @@ -1838,8 +1839,10 @@ void DisplayLocalSensor(void) * Public \*********************************************************************************************/ -void DisplayInitDriver(void) -{ +void DisplayInitDriver(void) { + + + XdspCall(FUNC_DISPLAY_INIT_DRIVER); // AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings->display_model); @@ -1890,8 +1893,9 @@ void DisplayInitDriver(void) } } -void DisplaySetPower(void) -{ +void DisplaySetPower(void) { + if (!disp_device) { return; } // Not initialized yet + disp_power = bitRead(XdrvMailbox.index, disp_device -1); //AddLog(LOG_LEVEL_DEBUG, PSTR("DSP: Power %d"), disp_power); @@ -1995,6 +1999,8 @@ void CmndDisplayMode(void) { // Apply the current display dimmer void ApplyDisplayDimmer(void) { + if ((disp_power < 0) || !disp_device) { return; } // Not initialized yet + uint8_t dimmer8 = changeUIntScale(GetDisplayDimmer(), 0, 100, 0, 255); uint16_t dimmer10_gamma = ledGamma10(dimmer8); if (dimmer8 && !(disp_power)) { diff --git a/tasmota/tasmota_xdsp_display/xdsp_17_universal.ino b/tasmota/tasmota_xdsp_display/xdsp_17_universal.ino index 68dd09af1..c3154cd60 100644 --- a/tasmota/tasmota_xdsp_display/xdsp_17_universal.ino +++ b/tasmota/tasmota_xdsp_display/xdsp_17_universal.ino @@ -436,7 +436,7 @@ int8_t cs; Settings->display_width = renderer->width(); Settings->display_height = renderer->height(); -// ApplyDisplayDimmer(); // Not allowed here. Way too early in initi sequence. IE power state has not even been set at this point in time + ApplyDisplayDimmer(); #ifdef SHOW_SPLASH if (!Settings->flag5.display_no_splash) {