Rename inertia timer to distinguish timers.
Rename timer member and relevant functions for the purpose they used, in order to distinguish between timers.
This commit is contained in:
@@ -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);
|
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)) {
|
if (esp_timer_is_active(relay_chn->inertia_timer)) {
|
||||||
return esp_timer_stop(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;
|
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
|
// 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);
|
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_STATE_FORWARD_PENDING : RELAY_CHN_STATE_REVERSE_PENDING;
|
||||||
relay_chn_update_state(relay_chn, new_state);
|
relay_chn_update_state(relay_chn, new_state);
|
||||||
// If the time passed is less than the opposite inertia time, wait for the remaining time
|
// 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 {
|
else {
|
||||||
// If the time passed is more than the opposite inertia time, run the command immediately
|
// 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_t new_state = cmd == RELAY_CHN_CMD_FORWARD
|
||||||
? RELAY_CHN_STATE_FORWARD_PENDING : RELAY_CHN_STATE_REVERSE_PENDING;
|
? RELAY_CHN_STATE_FORWARD_PENDING : RELAY_CHN_STATE_REVERSE_PENDING;
|
||||||
relay_chn_update_state(relay_chn, new_state);
|
relay_chn_update_state(relay_chn, new_state);
|
||||||
|
<<<<<<< HEAD
|
||||||
relay_chn_start_timer(relay_chn, RELAY_CHN_OPPOSITE_INERTIA_MS);
|
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;
|
break;
|
||||||
|
|
||||||
default: ESP_LOGD(TAG, "relay_chn_evaluate: Unknown relay channel state!");
|
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
|
// 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;
|
relay_chn->pending_cmd = RELAY_CHN_CMD_NONE;
|
||||||
// Invalidate the channel's timer if it is active
|
// 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
|
// 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;
|
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;
|
relay_chn->run_info.last_run_cmd_time_ms = esp_timer_get_time() / 1000;
|
||||||
// Schedule a free command for the channel
|
// Schedule a free command for the channel
|
||||||
relay_chn->pending_cmd = RELAY_CHN_CMD_FREE;
|
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 {
|
} else {
|
||||||
// If the channel was not running, issue a free command immediately
|
// If the channel was not running, issue a free command immediately
|
||||||
relay_chn_dispatch_cmd(relay_chn, RELAY_CHN_CMD_FREE);
|
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;
|
: RELAY_CHN_DIRECTION_DEFAULT;
|
||||||
// Set an inertia on the channel to prevent any immediate movement
|
// Set an inertia on the channel to prevent any immediate movement
|
||||||
relay_chn->pending_cmd = RELAY_CHN_CMD_FREE;
|
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)
|
void relay_chn_execute_free(relay_chn_t *relay_chn)
|
||||||
{
|
{
|
||||||
relay_chn->pending_cmd = RELAY_CHN_CMD_NONE;
|
relay_chn->pending_cmd = RELAY_CHN_CMD_NONE;
|
||||||
// Invalidate the channel's timer if it is active
|
// Invalidate the channel's timer if it is active
|
||||||
|
<<<<<<< HEAD
|
||||||
relay_chn_invalidate_timer(relay_chn);
|
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);
|
relay_chn_update_state(relay_chn, RELAY_CHN_STATE_FREE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user