From 069363205a49320b336e8242a1bd1914752c645c Mon Sep 17 00:00:00 2001 From: ismail Date: Fri, 14 Feb 2025 14:50:35 +0300 Subject: [PATCH] Rename inertia timer to distinguish timers. Rename timer member and relevant functions for the purpose they used, in order to distinguish between timers. --- src/relay_chn.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/relay_chn.c b/src/relay_chn.c index fea062f..347d04e 100644 --- a/src/relay_chn.c +++ b/src/relay_chn.c @@ -363,7 +363,7 @@ static void relay_chn_dispatch_cmd(relay_chn_t *relay_chn, relay_chn_cmd_t cmd) sizeof(relay_chn->id), portMAX_DELAY); } -static esp_err_t relay_chn_invalidate_timer(relay_chn_t *relay_chn) +static esp_err_t relay_chn_invalidate_inertia_timer(relay_chn_t *relay_chn) { if (esp_timer_is_active(relay_chn->inertia_timer)) { return esp_timer_stop(relay_chn->inertia_timer); @@ -371,10 +371,10 @@ static esp_err_t relay_chn_invalidate_timer(relay_chn_t *relay_chn) return ESP_OK; } -static esp_err_t relay_chn_start_timer(relay_chn_t *relay_chn, uint32_t time_ms) +static esp_err_t relay_chn_start_inertia_timer(relay_chn_t *relay_chn, uint32_t time_ms) { // Invalidate the channel's timer if it is active - relay_chn_invalidate_timer(relay_chn); + relay_chn_invalidate_inertia_timer(relay_chn); return esp_timer_start_once(relay_chn->inertia_timer, time_ms * 1000); } @@ -457,7 +457,7 @@ static void relay_chn_issue_cmd(relay_chn_t* relay_chn, relay_chn_cmd_t cmd) ? RELAY_CHN_STATE_FORWARD_PENDING : RELAY_CHN_STATE_REVERSE_PENDING; relay_chn_update_state(relay_chn, new_state); // If the time passed is less than the opposite inertia time, wait for the remaining time - relay_chn_start_timer(relay_chn, inertia_time_ms); + relay_chn_start_inertia_timer(relay_chn, inertia_time_ms); } else { // If the time passed is more than the opposite inertia time, run the command immediately @@ -485,7 +485,11 @@ static void relay_chn_issue_cmd(relay_chn_t* relay_chn, relay_chn_cmd_t cmd) relay_chn_state_t new_state = cmd == RELAY_CHN_CMD_FORWARD ? RELAY_CHN_STATE_FORWARD_PENDING : RELAY_CHN_STATE_REVERSE_PENDING; relay_chn_update_state(relay_chn, new_state); +<<<<<<< HEAD relay_chn_start_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); +======= + relay_chn_start_inertia_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); +>>>>>>> 99c5f66 (Rename inertia timer to distinguish timers.) break; default: ESP_LOGD(TAG, "relay_chn_evaluate: Unknown relay channel state!"); @@ -587,7 +591,7 @@ static void relay_chn_execute_stop(relay_chn_t *relay_chn) // If there is any pending command, cancel it since the STOP command is issued right after it relay_chn->pending_cmd = RELAY_CHN_CMD_NONE; // Invalidate the channel's timer if it is active - relay_chn_invalidate_timer(relay_chn); + relay_chn_invalidate_inertia_timer(relay_chn); // If the channel was running, schedule a free command for the channel relay_chn_cmd_t last_run_cmd = relay_chn->run_info.last_run_cmd; @@ -596,7 +600,7 @@ static void relay_chn_execute_stop(relay_chn_t *relay_chn) relay_chn->run_info.last_run_cmd_time_ms = esp_timer_get_time() / 1000; // Schedule a free command for the channel relay_chn->pending_cmd = RELAY_CHN_CMD_FREE; - relay_chn_start_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_inertia_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); } else { // If the channel was not running, issue a free command immediately relay_chn_dispatch_cmd(relay_chn, RELAY_CHN_CMD_FREE); @@ -631,14 +635,18 @@ static void relay_chn_execute_flip(relay_chn_t *relay_chn) : RELAY_CHN_DIRECTION_DEFAULT; // Set an inertia on the channel to prevent any immediate movement relay_chn->pending_cmd = RELAY_CHN_CMD_FREE; - relay_chn_start_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_inertia_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS); } void relay_chn_execute_free(relay_chn_t *relay_chn) { relay_chn->pending_cmd = RELAY_CHN_CMD_NONE; // Invalidate the channel's timer if it is active +<<<<<<< HEAD relay_chn_invalidate_timer(relay_chn); +======= + relay_chn_invalidate_inertia_timer(relay_chn); +>>>>>>> 99c5f66 (Rename inertia timer to distinguish timers.) relay_chn_update_state(relay_chn, RELAY_CHN_STATE_FREE); }