From 6fbf8c58f72ed22bfe46d42505f2eb7da4cb0866 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Sun, 15 Dec 2024 12:33:43 +0100
Subject: [PATCH] Fix GUI timing related divide by zero exception
---
CHANGELOG.md | 1 +
.../xdrv_01_9_webserver.ino | 36 +++++++++----------
.../tasmota_xdrv_driver/xdrv_13_display.ino | 18 +++-------
3 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e705f0533..f2885de68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
- MCP23xxx, PCF8574 and Shift595 power control when a display is configured regression from v14.3.0.7
- Display DisplayMode adds a display device while not configured
- GUI intermittent exception on screen updates due to flash access
+- GUI timing related divide by zero exception
### Removed
diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
index 5c9f55e5a..cf32f4e76 100644
--- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
+++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
@@ -1885,21 +1885,23 @@ bool HandleRootStatusRefresh(void) {
XsnsXdrvCall(FUNC_WEB_SENSOR);
WSContentSend_P(PSTR(""));
- if (!Settings->flag6.gui_no_state_text && // SetOption161 - (GUI) Disable display of state text (1)
- TasmotaGlobal.devices_present) {
+ if (!Settings->flag6.gui_no_state_text) { // SetOption161 - (GUI) Disable display of state text (1)
+ if (!Web.buttons_non_light_non_shutter) { // Might still be zero on restart so chk if we have at least one
+ WebGetDeviceCounts();
+ }
+ if ((Web.buttons_non_light_non_shutter > 0) &&
+ ( Web.buttons_non_light_non_shutter <= 8)) { // We need at least one non light AND non shutter button
#ifdef USE_SONOFF_IFAN
- if (IsModuleIfan()) {
- WSContentSend_P(PSTR("{t}
"));
- WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(TasmotaGlobal.power, 0)) ? PSTR("bold") : PSTR("normal"), 54, GetStateText(bitRead(TasmotaGlobal.power, 0)));
- uint32_t fanspeed = GetFanspeed();
- snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
- WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? PSTR("bold") : PSTR("normal"), 54, (fanspeed) ? svalue : GetStateText(0));
- WSContentSend_P(PSTR("
"));
- } else {
+ if (IsModuleIfan()) {
+ WSContentSend_P(PSTR("{t}"));
+ WSContentSend_P(HTTP_DEVICE_STATE, 36, (bitRead(TasmotaGlobal.power, 0)) ? PSTR("bold") : PSTR("normal"), 54, GetStateText(bitRead(TasmotaGlobal.power, 0)));
+ uint32_t fanspeed = GetFanspeed();
+ snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
+ WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? PSTR("bold") : PSTR("normal"), 54, (fanspeed) ? svalue : GetStateText(0));
+ WSContentSend_P(PSTR("
"));
+ } else {
#endif // USE_SONOFF_IFAN
-
- if (Web.buttons_non_light_non_shutter <= 8) { // Any non light AND non shutter button
WSContentSend_P(PSTR("{t}"));
uint32_t cols = Web.buttons_non_light_non_shutter;
uint32_t fontsize = (cols < 5) ? 70 - (cols * 8) : 32;
@@ -1908,17 +1910,15 @@ bool HandleRootStatusRefresh(void) {
if (bitRead(Web.light_shutter_button_mask, button_idx -1)) { continue; } // Skip non-sequential shutter button
bool power_state = bitRead(TasmotaGlobal.power, button_idx -1);
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), power_state);
- WSContentSend_P(HTTP_DEVICE_STATE, 100 / cols, (power_state) ? "bold" : "normal", fontsize, (cols < 5) ? GetStateText(power_state) : svalue);
+ WSContentSend_P(HTTP_DEVICE_STATE, 100 / cols, (power_state) ? PSTR("bold") : PSTR("normal"), fontsize, (cols < 5) ? GetStateText(power_state) : svalue);
button_ptr++;
- if (button_ptr == Web.buttons_non_light_non_shutter) { break; }
+ if (button_ptr >= Web.buttons_non_light_non_shutter) { break; }
}
WSContentSend_P(PSTR("
"));
- }
-
#ifdef USE_SONOFF_IFAN
- }
+ }
#endif // USE_SONOFF_IFAN
-
+ }
}
if (1 == Web.slider_update_time) {
diff --git a/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino b/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino
index a6ebf1e6f..732586d65 100644
--- a/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino
+++ b/tasmota/tasmota_xdrv_driver/xdrv_13_display.ino
@@ -1852,11 +1852,12 @@ void DisplayLocalSensor(void)
\*********************************************************************************************/
void DisplayInitDriver(void) {
- Settings->display_model = 0;
+ uint32_t display_model = Settings->display_model;
+ Settings->display_model = 0; // Test if any display_model is available
XdspCall(FUNC_DISPLAY_INIT_DRIVER);
-
-// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings->display_model);
-
+ if (Settings->display_model) { // If model found keep using user configured one for backward compatibility
+ Settings->display_model = display_model;
+ }
if (!Settings->display_model) { return; }
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("DSP: Model %d"), Settings->display_model);
@@ -1891,15 +1892,6 @@ void DisplayInitDriver(void) {
#endif
UpdateDevicesPresent(1);
- if (!PinUsed(GPIO_BACKLIGHT)) {
- if ((LT_PWM1 == TasmotaGlobal.light_type) && // Single PWM light channel
- (4 == Settings->display_model) // ILI9341 legacy
-// ((4 == Settings->display_model) || // ILI9341 legacy
-// (17 == Settings->display_model)) // Universal - Too invasive in case displays have no backlight pin
- ) {
- UpdateDevicesPresent(-1); // Assume PWM channel is used for backlight
- }
- }
disp_device = TasmotaGlobal.devices_present;
#ifndef USE_DISPLAY_MODES1TO5