From 7d597f37250a2310c6b50d731af038b7a0f61182 Mon Sep 17 00:00:00 2001 From: ismail Date: Wed, 27 Aug 2025 17:02:02 +0300 Subject: [PATCH] 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 --- src/relay_chn_core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/relay_chn_core.c b/src/relay_chn_core.c index a1ae5a4..be24eb0 100644 --- a/src/relay_chn_core.c +++ b/src/relay_chn_core.c @@ -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 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 esp_timer_stop(chn_ctl->run_limit_timer); #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 // or STATE_REVERSE. Then schedule a free command. 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_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)