Fix STOP command does not interrupt

An if statement has been added to handle the STOP command properly
when the `previous_state` is one of the `*PENDING` states.

Fixes #1093
This commit is contained in:
2025-08-27 17:02:02 +03:00
parent 71b632737e
commit 7d597f3725

View File

@@ -454,13 +454,20 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl)
// If there is any pending command, cancel it since the STOP command is issued right after it // If there is any pending command, cancel it since the STOP command is issued right after it
chn_ctl->pending_cmd = RELAY_CHN_CMD_NONE; chn_ctl->pending_cmd = RELAY_CHN_CMD_NONE;
// Invalidate the channel's timer if it is active
esp_timer_stop(chn_ctl->inertia_timer);
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT #if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
esp_timer_stop(chn_ctl->run_limit_timer); esp_timer_stop(chn_ctl->run_limit_timer);
#endif #endif
if (previous_state == RELAY_CHN_STATE_FORWARD_PENDING || previous_state == RELAY_CHN_STATE_REVERSE_PENDING) {
chn_ctl->pending_cmd = RELAY_CHN_CMD_IDLE;
// Do nothing more and let the timer set channel idle when it expires
return;
}
// Invalidate the channel's timer if it is active
esp_timer_stop(chn_ctl->inertia_timer);
// Save the last run time only if the previous state was either STATE FORWARD // Save the last run time only if the previous state was either STATE FORWARD
// or STATE_REVERSE. Then schedule a free command. // or STATE_REVERSE. Then schedule a free command.
if (previous_state == RELAY_CHN_STATE_FORWARD || previous_state == RELAY_CHN_STATE_REVERSE) { if (previous_state == RELAY_CHN_STATE_FORWARD || previous_state == RELAY_CHN_STATE_REVERSE) {
@@ -474,7 +481,6 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl)
// relay_chn_dispatch_cmd(chn_ctl, RELAY_CHN_CMD_IDLE); // relay_chn_dispatch_cmd(chn_ctl, RELAY_CHN_CMD_IDLE);
relay_chn_execute_idle(chn_ctl); relay_chn_execute_idle(chn_ctl);
} }
ESP_LOGI(TAG, "execute_stop: #%d, state: %d", chn_ctl->id, chn_ctl->state); // TODO delete
} }
static void relay_chn_execute_forward(relay_chn_ctl_t *chn_ctl) static void relay_chn_execute_forward(relay_chn_ctl_t *chn_ctl)