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
This commit is contained in:
stefanbode 2024-02-18 12:36:03 +01:00 committed by GitHub
parent 30f650ebb2
commit c7894181b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 17 deletions

View File

@ -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);

View File

@ -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);