Skip to content

Commit

Permalink
fix #19911 tilt position is not restored with command: shutterpositio…
Browse files Browse the repository at this point in the history
…n 0,-45 (#19916)

* fix shutterposition 0,-45 does not keep tilt

allow , on different config settings

* fix shutterposition 0,-45 does not maintain tilt

allow , on different config settings.
  • Loading branch information
stefanbode authored Nov 3, 2023
1 parent dab1a53 commit b835169
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
20 changes: 10 additions & 10 deletions tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ void CmndShutterButton(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < (1+4+4+1); str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < (1+4+4+1); str = strtok_r(nullptr, " ,", &str_ptr), i++) {
int field = -1;
int tilt = -128;
int pos_incrdecr = 0;
Expand Down Expand Up @@ -1647,7 +1647,7 @@ void CmndShutterCalibration(void)
char data_copy[strlen(XdrvMailbox.data) + 1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 5; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 5; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
int field = atoi(str);
// The fields in a data string can only range from 1-30000.
// and following value must be higher than previous one
Expand Down Expand Up @@ -1851,12 +1851,6 @@ void CmndShutterPosition(void)

}

//override tiltposition if explicit set (shutterbutton)
if (Shutter[index].tilt_target_pos_override != -128) {
Shutter[index].tilt_target_pos = tmin(tmax( Shutter[index].tilt_config[0],Shutter[index].tilt_target_pos_override ), Shutter[index].tilt_config[1]);
Shutter[index].tilt_target_pos_override = -128;
}

int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload);
target_pos_percent = ((ShutterSettings.shutter_options[index] & 1) && ((SRC_MQTT != TasmotaGlobal.last_source) // 1
&& (SRC_SERIAL != TasmotaGlobal.last_source) // 6
Expand All @@ -1868,6 +1862,12 @@ void CmndShutterPosition(void)
if (target_pos_percent == 0 && ShutterRealToPercentPosition(Shutter[index].real_position, index) > 0 ) {Shutter[index].tilt_target_pos = Shutter[index].tilt_config[4];}
if (target_pos_percent == 100 && ShutterRealToPercentPosition(Shutter[index].real_position, index) < 100) {Shutter[index].tilt_target_pos = Shutter[index].tilt_config[3];}

//override tiltposition if explicit set (shutterbutton)
if (Shutter[index].tilt_target_pos_override != -128) {
Shutter[index].tilt_target_pos = tmin(tmax( Shutter[index].tilt_config[0],Shutter[index].tilt_target_pos_override ), Shutter[index].tilt_config[1]);
Shutter[index].tilt_target_pos_override = -128;
}

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);
Expand Down Expand Up @@ -1966,7 +1966,7 @@ void CmndShutterPwmRange(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 2; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 2; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
uint16_t field = atoi(str);
// The fields in a data string can only range from 1-30000.
// and following value must be higher than previous one
Expand Down Expand Up @@ -2224,7 +2224,7 @@ void CmndShutterTiltConfig(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 6; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 6; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
Shutter[XdrvMailbox.index -1].tilt_config[i] = ShutterSettings.shutter_tilt_config[i][XdrvMailbox.index -1] = atoi(str);
}
// avoid negative runtime
Expand Down
23 changes: 12 additions & 11 deletions tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void ShutterInit(void)
break;
}
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d min realpos_chg: %d, min tilt_chg %d"), i+1, Shutter[i].min_realPositionChange, Shutter[i].min_TiltChange);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Openvel %d, Closevel: %d"), i+1, ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d Openvel %d, Closevel: %d"), i+1, ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d Init. Pos %d, Inv %d, Locked %d, Endstop enab %d, webButt inv %d, Motordel: %d"),
i+1, Shutter[i].real_position,
(Settings->shutter_options[i] & 1) ? 1 : 0, (Settings->shutter_options[i] & 2) ? 1 : 0, (Settings->shutter_options[i] & 4) ? 1 : 0, (Settings->shutter_options[i] & 8) ? 1 : 0, Shutter[i].motordelay);
Expand Down Expand Up @@ -1323,12 +1323,6 @@ void CmndShutterPosition(void)
}
}

// manual override of tiltposition
if (Shutter[index].tilt_target_pos_override != -128) {
Shutter[index].tilt_target_pos = tmin(tmax( Shutter[index].tilt_config[0],Shutter[index].tilt_target_pos_override ), Shutter[index].tilt_config[1]);
Shutter[index].tilt_target_pos_override = -128;
}

int8_t target_pos_percent = (XdrvMailbox.payload < 0) ? (XdrvMailbox.payload == -99 ? ShutterRealToPercentPosition(Shutter[index].real_position, index) : 0) : ((XdrvMailbox.payload > 100) ? 100 : XdrvMailbox.payload);
target_pos_percent = ((Settings->shutter_options[index] & 1) && ((SRC_MQTT != TasmotaGlobal.last_source)
&& (SRC_SERIAL != TasmotaGlobal.last_source)
Expand All @@ -1339,7 +1333,14 @@ void CmndShutterPosition(void)
// if position is either 0 or 100 reset the tilt to avoid tilt moving at the end
if (target_pos_percent == 0 && ShutterRealToPercentPosition(Shutter[index].real_position, index) > 0 ) {Shutter[index].tilt_target_pos = Shutter[index].tilt_config[4];}
if (target_pos_percent == 100 && ShutterRealToPercentPosition(Shutter[index].real_position, index) < 100) {Shutter[index].tilt_target_pos = Shutter[index].tilt_config[3];}


// manual override of tiltposition
if (Shutter[index].tilt_target_pos_override != -128) {
Shutter[index].tilt_target_pos = tmin(tmax( Shutter[index].tilt_config[0],Shutter[index].tilt_target_pos_override ), Shutter[index].tilt_config[1]);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Override tilt set: %d --> %d"),Shutter[index].tilt_target_pos_override, Shutter[index].tilt_target_pos);
Shutter[index].tilt_target_pos_override = -128;
}

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);
Expand Down Expand Up @@ -1727,7 +1728,7 @@ void CmndShutterPwmRange(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 2; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 2; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
uint16_t field = atoi(str);
// The fields in a data string can only range from 1-30000.
// and following value must be higher than previous one
Expand Down Expand Up @@ -1757,7 +1758,7 @@ void CmndShutterCalibration(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 5; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 5; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
int field = atoi(str);
// The fields in a data string can only range from 1-30000.
// and following value must be higher than previous one
Expand Down Expand Up @@ -1842,7 +1843,7 @@ void CmndShutterTiltConfig(void)
char data_copy[strlen(XdrvMailbox.data) +1];
strncpy(data_copy, XdrvMailbox.data, sizeof(data_copy)); // Duplicate data as strtok_r will modify it.
// Loop through the data string, splitting on ' ' seperators.
for (char *str = strtok_r(data_copy, " ", &str_ptr); str && i < 6; str = strtok_r(nullptr, " ", &str_ptr), i++) {
for (char *str = strtok_r(data_copy, " ,", &str_ptr); str && i < 6; str = strtok_r(nullptr, " ,", &str_ptr), i++) {
Shutter[XdrvMailbox.index -1].tilt_config[i] = Settings->shutter_tilt_config[i][XdrvMailbox.index -1] = atoi(str);
}
// avoid negative runtime
Expand Down

0 comments on commit b835169

Please sign in to comment.