From 043d80809b5bd633dfe5a6d5bc3a500b646ff0e3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:09:07 +0100 Subject: [PATCH] Fix shutter slider user control --- .../xdrv_01_9_webserver.ino | 56 +++++++++++++------ .../xdrv_27_esp32_shutter.ino | 6 -- .../tasmota_xdrv_driver/xdrv_27_shutter.ino | 6 -- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index e3736dbd7..4efe0b3f1 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -266,6 +266,13 @@ const char HTTP_HEAD_STYLE3[] PROGMEM = "

%s

" // Module name "

%s

"; // Device name +const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM = + "" + "
%s" + "" + "
" + ""; + const char HTTP_MSG_SLIDER_GRADIENT[] PROGMEM = "" "
" @@ -467,6 +474,11 @@ struct WEB { uint32_t upload_size = 0; uint32_t slider_update_time = 0; int slider[LST_MAX]; +#ifdef ESP8266 + int8_t shutter_slider[MAX_SHUTTERS]; +#else // ESP32 + int8_t shutter_slider[MAX_SHUTTERS_ESP32]; +#endif // ESP8266 uint16_t upload_error = 0; uint8_t state = HTTP_OFF; uint8_t upload_file_type; @@ -605,6 +617,9 @@ void StartWebserver(int type) for (uint32_t i = 0; i < LST_MAX; i++) { Web.slider[i] = -1; } + for (uint32_t i = 0; i < sizeof(Web.shutter_slider); i++) { + Web.shutter_slider[i] = -1; + } if (!Webserver) { Webserver = new ESP8266WebServer((HTTP_MANAGER == type || HTTP_MANAGER_RESET_ONLY == type) ? 80 : WEB_PORT); @@ -1168,13 +1183,6 @@ void WebSliderColdWarm(void) { } #endif // USE_LIGHT -const char HTTP_MSG_SLIDER_SHUTTERT[] PROGMEM = - "" - "
%s" - "" - "
" - ""; - void HandleRoot(void) { #ifndef NO_CAPTIVE_PORTAL if (CaptivePortal()) { return; } // If captive portal redirect instead of displaying the page. @@ -1332,10 +1340,12 @@ void HandleRoot(void) { shutter_button_idx--; // Right button is previous button (up) bool set_button = ((shutter_button_idx <= MAX_BUTTON_TEXT) && strlen(GetWebButton(shutter_button_idx -1))); snprintf_P(stemp, sizeof(stemp), PSTR("Shutter %d"), shutter_idx +1); - WSContentSend_P(HTTP_MSG_SLIDER_SHUTTERT, + uint32_t shutter_real_to_percent_position = ShutterRealToPercentPosition(-9999, shutter_idx); + Web.shutter_slider[shutter_idx] = (ShutterGetOptions(shutter_idx) & 1) ? (100 - shutter_real_to_percent_position) : shutter_real_to_percent_position; + WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, (set_button) ? HtmlEscape(GetWebButton(shutter_button_idx -1)).c_str() : stemp, shutter_idx +1, - (ShutterGetOptions(shutter_idx) & 1) ? (100 - ShutterRealToPercentPosition(-9999, shutter_idx)) : ShutterRealToPercentPosition(-9999, shutter_idx), + Web.shutter_slider[shutter_idx], shutter_idx +1); } WSContentSend_P(PSTR("")); @@ -1687,14 +1697,27 @@ bool HandleRootStatusRefresh(void) } } + uint32_t slider_update_time = millis(); #ifdef USE_SHUTTER - if (!msg_exec_javascript) { - WSContentSend_P(HTTP_MSG_EXEC_JAVASCRIPT); // "web_refresh; // Allow other users to sync screen + } + else if (slider_update_time > Web.slider_update_time) { + Web.slider_update_time = 1; // Allow multiple updates + Web.shutter_slider[i] = current_value; + } + if (!msg_exec_javascript) { + WSContentSend_P(HTTP_MSG_EXEC_JAVASCRIPT); // "flag3.pwm_multi_channels) { // SetOption68 0 - Enable multi-channels PWM instead of Color PWM @@ -1741,10 +1763,10 @@ bool HandleRootStatusRefresh(void) } } } +#endif // USE_LIGHT if (1 == Web.slider_update_time) { Web.slider_update_time = 0; } -#endif // USE_LIGHT if (msg_exec_javascript) { WSContentSend_P(PSTR("\">")); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index d166f4460..2be8c6f9d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -45,12 +45,6 @@ #define D_ERROR_FILESYSTEM_NOT_READY "SHT: ERROR File system not enabled" #define D_ERROR_FILE_NOT_FOUND "SHT: ERROR File system not ready or file not found" -const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM = - "" - "
%s%s
" - "
" - "{e}"; - const uint16_t SHUTTER_VERSION = 0x0100; // Latest driver version (See settings deltas below) typedef struct { // depreciated 2023-04-28 diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index 642d78154..da7c7a138 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -54,12 +54,6 @@ int32_t current_real_position = 0; int32_t current_pwm_velocity = 0; bool sensor_data_reported = false; -const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM = - "" - "
%s%s
" - "
" - "{e}"; - const uint8_t MAX_MODES = 8; enum Shutterposition_mode {SHT_UNDEF, SHT_TIME, SHT_TIME_UP_DOWN, SHT_TIME_GARAGE, SHT_COUNTER, SHT_PWM_VALUE, SHT_PWM_TIME,SHT_AUTOCONFIG}; enum Shutterswitch_mode {SHT_SWITCH, SHT_PULSE,};