From c7894181b75086ee50c25d3bc253447fb45f9dac Mon Sep 17 00:00:00 2001 From: stefanbode Date: Sun, 18 Feb 2024 12:36:03 +0100 Subject: [PATCH] fix issue on inverted shutters with commands comming with shutterposition (#20752) * fix INVERTED bug fix shutterposition xxx commands do not work on inverted shutter * fix INVERTED bug * fix INVERTED bug shutterposition UP/DOWN/... commands did not work as expected on inverted shutter --- .../xdrv_27_esp32_shutter.ino | 22 ++++++++++--------- .../tasmota_xdrv_driver/xdrv_27_shutter.ino | 19 ++++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index d8d90fdef..47b956ee6 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -1,7 +1,7 @@ /* xdrv_27_esp32_shutter.ino - Shutter/Blind support for Tasmota - Copyright (C) 2023 Stefan Bode + Copyright (C) 2024 Stefan Bode This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1824,13 +1824,15 @@ void CmndShutterPosition(void) } } + // special handling fo UP,DOWN,TOGGLE,STOP and similar commands command + // + if ( XdrvMailbox.data_len > 0 ) { + // set len to 0 to avoid loop + uint32_t data_len_save = XdrvMailbox.data_len; + int32_t payload_save = XdrvMailbox.payload; + XdrvMailbox.data_len = 0; + XdrvMailbox.payload = -99; - // value 0 with data_len > 0 can mean Open - // special handling fo UP,DOWN,TOGGLE,STOP command comming with payload -99 - // STOP will come with payload 0 because predefined value in TASMOTA - if ((XdrvMailbox.data_len > 3) && (XdrvMailbox.payload <= 0)) { - // set len to 0 to avoid loop on close where payload is 0 - XdrvMailbox.data_len = 0; if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_UP) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_OPEN) || ((Shutter[index].direction==0) && !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPOPEN))) { CmndShutterOpen(); return; @@ -1848,12 +1850,12 @@ void CmndShutterPosition(void) return; } if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOP) || ((Shutter[index].direction) && (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPOPEN) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPCLOSE)))) { - // Back to normal: all -99 if not a clear position - XdrvMailbox.payload = -99; CmndShutterStop(); return; } - + // restore values + XdrvMailbox.payload = payload_save; + XdrvMailbox.data_len = data_len_save; } int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index dfba0caab..c09284573 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -1297,11 +1297,15 @@ void CmndShutterPosition(void) } // value 0 with data_len > 0 can mean Open - // special handling fo UP,DOWN,TOGGLE,STOP command comming with payload -99 - // STOP will come with payload 0 because predefined value in TASMOTA - if ((XdrvMailbox.data_len > 3) && (XdrvMailbox.payload <= 0)) { - // set len to 0 to avoid loop on close where payload is 0 - XdrvMailbox.data_len = 0; + // special handling fo UP,DOWN,TOGGLE,STOP and similar commands command + // + if ( XdrvMailbox.data_len > 0 ) { + // set len to 0 to avoid loop + uint32_t data_len_save = XdrvMailbox.data_len; + int32_t payload_save = XdrvMailbox.payload; + XdrvMailbox.data_len = 0; + XdrvMailbox.payload = -99; + if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_UP) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_OPEN) || ((Shutter[index].direction==0) && !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPOPEN))) { CmndShutterOpen(); return; @@ -1319,11 +1323,12 @@ void CmndShutterPosition(void) return; } if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOP) || ((Shutter[index].direction) && (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPOPEN) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPCLOSE)))) { - // Back to normal: all -99 if not a clear position - XdrvMailbox.payload = -99; CmndShutterStop(); return; } + // restore values + XdrvMailbox.payload = payload_save; + XdrvMailbox.data_len = data_len_save; } int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload);