From afd22b5b42d9c04e397b0ea2920de2fd2ab60126 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 5 Apr 2023 13:47:12 +0200 Subject: [PATCH] fix #18331 (Wrong discovery on ESP32_shutter (#18334) * fix ESP32_shutter wrong discovery * fix wrong discovers on ESP32 shutter * fix wrong discovers on ESP32_shutter * Update xdrv_12_discovery.ino --- .../tasmota_xdrv_driver/xdrv_12_discovery.ino | 18 +++++++++--------- .../xdrv_27_esp32_shutter.ino | 4 ++++ .../tasmota_xdrv_driver/xdrv_27_shutter.ino | 4 ++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino b/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino index cd5bcb71b..2a6d8411a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_12_discovery.ino @@ -114,11 +114,11 @@ void TasDiscoverMessage(void) { #ifdef USE_SHUTTER if (Settings->flag3.shutter_mode) { - for (uint32_t k = 0; k < MAX_SHUTTERS; k++) { - if (Settings->shutter_startrelay[k] > 0) { - Shutter[Settings->shutter_startrelay[k]-1] = Shutter[Settings->shutter_startrelay[k]] = 1; + for (uint32_t k = 0; k < TasmotaGlobal.shutters_present; k++) { + if (ShutterGetStartRelay(k) > 0) { + Shutter[ShutterGetStartRelay(k)-1] = Shutter[ShutterGetStartRelay(k)] = 1; } else { - // terminate loop at first INVALID Settings->shutter_startrelay[i]. + // terminate loop at first INVALID ShutterGetStartRelay(k). break; } } @@ -199,7 +199,7 @@ void TasDiscoverMessage(void) { light_controller_isCTRGBLinked, light_subtype); - for (uint32_t i = 0; i < MAX_SHUTTERS; i++) { + for (uint32_t i = 0; i < tmax(TasmotaGlobal.shutters_present,MAX_SHUTTERS); i++) { #ifdef USE_SHUTTER ResponseAppend_P(PSTR("%s%d"), (i > 0 ? "," : ""), Settings->shutter_options[i]); #else @@ -209,12 +209,12 @@ void TasDiscoverMessage(void) { ResponseAppend_P(PSTR("]," // Shutter Options (end) "\"sht\":[")); // Shutter Tilt (start) - for (uint32_t i = 0; i < MAX_SHUTTERS; i++) { + for (uint32_t i = 0; i < tmax(TasmotaGlobal.shutters_present,MAX_SHUTTERS); i++) { #ifdef USE_SHUTTER ResponseAppend_P(PSTR("%s[%d,%d,%d]"), (i > 0 ? "," : ""), - Settings->shutter_tilt_config[0][i], - Settings->shutter_tilt_config[1][i], - Settings->shutter_tilt_config[2][i]); + ShutterGetTiltConfig(0,i), + ShutterGetTiltConfig(1,i), + ShutterGetTiltConfig(2,i)); #else ResponseAppend_P(PSTR("%s[0,0,0]"), (i > 0 ? "," : "")); #endif // USE_SHUTTER diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index 893f37eff..ee3a0b961 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -351,6 +351,10 @@ uint8_t ShutterGetStartRelay(uint8_t index) { return ShutterSettings.shutter_startrelay[index]; } +int8_t ShutterGetTiltConfig(uint8_t config_idx,uint8_t index) { + return Shutter[index].tilt_config[config_idx]; +} + void ExecuteCommandPowerShutter(uint32_t device, uint32_t state, uint32_t source) { // first implementation for virtual relays. Avoid switching relay numbers that do not exist. diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index 81ede1e77..a763e51e1 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -189,6 +189,10 @@ uint8_t ShutterGetStartRelay(uint8_t index) { return Settings->shutter_startrelay[index]; } +int8_t ShutterGetTiltConfig(uint8_t config_idx,uint8_t index) { + return Shutter[index].tilt_config[config_idx]; +} + void ExecuteCommandPowerShutter(uint32_t device, uint32_t state, uint32_t source) { // first implementation for virtual relays. Avoid switching relay numbers that do not exist.