From 6572f0ed395714474757cdb66af50a395e48f826 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 3 Aug 2023 11:55:20 +0200 Subject: [PATCH] Fixing SHUTTERINVERT issues (#19243) * fix wrong inverted shutter * fix inverted shutter for esp32 --- .../xdrv_27_esp32_shutter.ino | 16 ++++++++-------- tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino | 15 +++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index f09370ed6..9ff0807c0 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -460,8 +460,6 @@ void ShutterRtc50mS(void) int32_t ShutterPercentToRealPosition(int16_t percent, uint32_t index) { - // if inverted recalculate the percentposition - percent = (ShutterSettings.shutter_options[index] & 1) ? 100 - percent : percent; if (ShutterSettings.shutter_set50percent[index] != 50) { return (percent <= 5) ? ShutterSettings.shuttercoeff[2][index] * percent*10 : (ShutterSettings.shuttercoeff[1][index] * percent + (ShutterSettings.shuttercoeff[0][index]*10))*10; } else { @@ -523,9 +521,8 @@ uint8_t ShutterRealToPercentPosition(int32_t realpos, uint32_t index) } } } - realpercent = realpercent < 0 ? 0 : realpercent; - // if inverted recalculate the percentposition - return (ShutterSettings.shutter_options[index] & 1) ? 100 - realpercent : realpercent; + realpercent = realpercent < 0 ? 0 : realpercent; + return realpercent; } void ShutterInit(void) @@ -1321,7 +1318,7 @@ void ShutterToggle(bool dir) void ShutterShow(){ for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) { - WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, (ShutterSettings.shutter_options[i] & 1) ? D_OPEN : D_CLOSE,(ShutterSettings.shutter_options[i] & 1) ? D_CLOSE : D_OPEN, ShutterRealToPercentPosition(-9999, i), i+1); + WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, (Settings->shutter_options[i] & 1) ? D_OPEN : D_CLOSE,(Settings->shutter_options[i] & 1) ? D_CLOSE : D_OPEN, (Settings->shutter_options[i] & 1) ? (100 - ShutterRealToPercentPosition(-9999, i)) : ShutterRealToPercentPosition(-9999, i), i+1); } } /*********************************************************************************************\ @@ -1516,8 +1513,11 @@ void CmndShutterPosition(void) } int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload); - // webgui still send also on inverted shutter the native position. - target_pos_percent = ((ShutterSettings.shutter_options[index] & 1) && (SRC_WEBGUI == TasmotaGlobal.last_source)) ? 100 - target_pos_percent : target_pos_percent; + target_pos_percent = ((Settings->shutter_options[index] & 1) && ((SRC_MQTT != TasmotaGlobal.last_source) + || (SRC_SERIAL != TasmotaGlobal.last_source) + || (SRC_WEBCOMMAND != TasmotaGlobal.last_source) + )) ? 100 - target_pos_percent : target_pos_percent; + if (XdrvMailbox.payload != -99) { Shutter[index].target_position = ShutterPercentToRealPosition(target_pos_percent, index); //Shutter[i].accelerator[index] = ShutterGlobal.open_velocity_max / ((Shutter[i].motordelay[index] > 0) ? Shutter[i].motordelay[index] : 1); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index f6fe28a40..e49c1b633 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -252,8 +252,6 @@ void ShutterRtc50mS(void) int32_t ShutterPercentToRealPosition(int16_t percent, uint32_t index) { - // if inverted recalculate the percentposition - percent = (Settings->shutter_options[index] & 1) ? 100 - percent : percent; if (Settings->shutter_set50percent[index] != 50) { return (percent <= 5) ? Settings->shuttercoeff[2][index] * percent*10 : (Settings->shuttercoeff[1][index] * percent + (Settings->shuttercoeff[0][index]*10))*10; } else { @@ -315,9 +313,8 @@ uint8_t ShutterRealToPercentPosition(int32_t realpos, uint32_t index) } } } - realpercent = realpercent < 0 ? 0 : realpercent; - // if inverted recalculate the percentposition - return (Settings->shutter_options[index] & 1) ? 100 - realpercent : realpercent; + realpercent = realpercent < 0 ? 0 : realpercent; + return realpercent; } void ShutterInit(void) @@ -1144,7 +1141,7 @@ void ShutterToggle(bool dir) void ShutterShow(){ for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) { - WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, (Settings->shutter_options[i] & 1) ? D_OPEN : D_CLOSE,(Settings->shutter_options[i] & 1) ? D_CLOSE : D_OPEN, ShutterRealToPercentPosition(-9999, i), i+1); + WSContentSend_P(HTTP_MSG_SLIDER_SHUTTER, (Settings->shutter_options[i] & 1) ? D_OPEN : D_CLOSE,(Settings->shutter_options[i] & 1) ? D_CLOSE : D_OPEN, (Settings->shutter_options[i] & 1) ? (100 - ShutterRealToPercentPosition(-9999, i)) : ShutterRealToPercentPosition(-9999, i), i+1); } } @@ -1338,8 +1335,10 @@ void CmndShutterPosition(void) } int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload); - // webgui still send also on inverted shutter the native position. - target_pos_percent = ((Settings->shutter_options[index] & 1) && (SRC_WEBGUI != TasmotaGlobal.last_source)) ? 100 - target_pos_percent : target_pos_percent; + target_pos_percent = ((Settings->shutter_options[index] & 1) && ((SRC_MQTT != TasmotaGlobal.last_source) + || (SRC_SERIAL != TasmotaGlobal.last_source) + || (SRC_WEBCOMMAND != TasmotaGlobal.last_source) + )) ? 100 - target_pos_percent : target_pos_percent; if (XdrvMailbox.payload != -99) { //target_pos_percent = (Settings->shutter_options[index] & 1) ? 100 - target_pos_percent : target_pos_percent; Shutter[index].target_position = ShutterPercentToRealPosition(target_pos_percent, index);