General code and comment cleanup
This commit is contained in:
@@ -28,8 +28,8 @@ static const char *TAG = "RELAY_CHN_CORE";
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
|
||||
/*
|
||||
* Run limit timer callback immediately dispatches a STOP command for the
|
||||
/*
|
||||
* Run limit timer callback immediately dispatches a STOP command for the
|
||||
* relevant channel as soon as the run limit time times out
|
||||
*/
|
||||
static void relay_chn_run_limit_timer_cb(void* arg)
|
||||
@@ -195,17 +195,17 @@ static void relay_chn_stop_prv(relay_chn_ctl_t *chn_ctl)
|
||||
|
||||
/**
|
||||
* @brief The command issuer function.
|
||||
*
|
||||
* This function is the deciding logic for issuing a command to a relay channel. It evaluates
|
||||
*
|
||||
* This function is the deciding logic for issuing a command to a relay channel. It evaluates
|
||||
* the current state of the channel before issuing the command. Then it decides whether to run
|
||||
* the command immediately or wait for the opposite inertia time.
|
||||
*
|
||||
*
|
||||
* The STOP command is an exception, it is always run immediately since it is safe in any case.
|
||||
*
|
||||
*
|
||||
* Another special consideration is the FLIP command. If the channel is running, the FLIP command
|
||||
* is issued after the channel is stopped. If the channel is stopped, the FLIP command is issued
|
||||
* immediately.
|
||||
*
|
||||
*
|
||||
* @param chn_ctl The relay channel to issue the command to.
|
||||
* @param cmd The command to issue.
|
||||
*/
|
||||
@@ -214,7 +214,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
if (cmd == RELAY_CHN_CMD_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (cmd == RELAY_CHN_CMD_STOP) {
|
||||
if (chn_ctl->state == RELAY_CHN_STATE_STOPPED) {
|
||||
return; // Do nothing if already stopped
|
||||
@@ -232,7 +232,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
// If the channel is idle, run the command immediately
|
||||
relay_chn_dispatch_cmd(chn_ctl, cmd);
|
||||
break;
|
||||
|
||||
|
||||
case RELAY_CHN_STATE_FORWARD_PENDING:
|
||||
case RELAY_CHN_STATE_REVERSE_PENDING:
|
||||
// The channel is already waiting for the opposite inertia time,
|
||||
@@ -241,7 +241,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
relay_chn_dispatch_cmd(chn_ctl, cmd);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case RELAY_CHN_STATE_STOPPED:
|
||||
if (last_run_cmd == cmd || last_run_cmd == RELAY_CHN_CMD_NONE) {
|
||||
// Since the state is STOPPED, the inertia timer should be running and must be invalidated
|
||||
@@ -254,7 +254,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
relay_chn_dispatch_cmd(chn_ctl, cmd);
|
||||
}
|
||||
else {
|
||||
// If the last run command is different from the current command, calculate the time passed
|
||||
// If the last run command is different from the current command, calculate the time passed
|
||||
// since the last run command stopped and decide whether to run the command immediately or wait
|
||||
uint32_t last_run_cmd_time_ms = relay_chn_run_info_get_last_run_cmd_time_ms(chn_ctl->run_info);
|
||||
uint32_t current_time_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
@@ -281,7 +281,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case RELAY_CHN_STATE_FORWARD:
|
||||
case RELAY_CHN_STATE_REVERSE:
|
||||
if (cmd == RELAY_CHN_CMD_FLIP) {
|
||||
@@ -290,18 +290,18 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
|
||||
relay_chn_dispatch_cmd(chn_ctl, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (last_run_cmd == cmd) {
|
||||
// If the last run command is the same as the current command, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Stop the channel first before the schedule
|
||||
relay_chn_stop_prv(chn_ctl);
|
||||
|
||||
// If the last run command is different from the current command, wait for the opposite inertia time
|
||||
chn_ctl->pending_cmd = 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_update_state(chn_ctl, new_state);
|
||||
relay_chn_start_timer_or_idle(chn_ctl, chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS, "inertia");
|
||||
@@ -366,9 +366,6 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl)
|
||||
{
|
||||
relay_chn_stop_prv(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;
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
|
||||
esp_timer_stop(chn_ctl->run_limit_timer);
|
||||
#endif
|
||||
@@ -382,8 +379,7 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl)
|
||||
chn_ctl->pending_cmd = RELAY_CHN_CMD_IDLE;
|
||||
relay_chn_start_timer_or_idle(chn_ctl, chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS, "idle");
|
||||
} else {
|
||||
// If the channel was not running one of the run or fwd, issue a free command immediately
|
||||
// relay_chn_dispatch_cmd(chn_ctl, RELAY_CHN_CMD_IDLE);
|
||||
// If the channel was not running forward or reverse, issue a free command immediately
|
||||
relay_chn_execute_idle(chn_ctl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user