Skip to content

Commit

Permalink
Fixing SHUTTERINVERT issues (#19243)
Browse files Browse the repository at this point in the history
* fix wrong inverted shutter

* fix inverted shutter for esp32
  • Loading branch information
stefanbode authored Aug 3, 2023
1 parent 5e591ef commit 6572f0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
16 changes: 8 additions & 8 deletions tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
/*********************************************************************************************\
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6572f0e

Please sign in to comment.