Enhance relay command handling
- `TILT_STOP` command is prioritized in `relay_chn_tilt_issue_cmd()` because it should override any other tilt commands. - The debug logs are cleaned up. Fixes #1088 Refs #1085
This commit is contained in:
@@ -93,6 +93,16 @@ static uint32_t relay_chn_tilt_get_required_timing_before_tilting(relay_chn_tilt
|
|||||||
// Issue a tilt command to a specific relay channel.
|
// Issue a tilt command to a specific relay channel.
|
||||||
static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_tilt_cmd_t cmd)
|
static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_tilt_cmd_t cmd)
|
||||||
{
|
{
|
||||||
|
// TILT_STOP is safe and high priority
|
||||||
|
if (cmd == RELAY_CHN_TILT_CMD_STOP) {
|
||||||
|
if (tilt_ctl->chn_ctl->state == RELAY_CHN_STATE_STOPPED) {
|
||||||
|
return; // Do nothing if already stopped
|
||||||
|
}
|
||||||
|
// If the command is TILT_STOP, issue it immediately
|
||||||
|
relay_chn_tilt_dispatch_cmd(tilt_ctl, cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (relay_chn_run_info_get_last_run_cmd(tilt_ctl->chn_ctl->run_info) == RELAY_CHN_CMD_NONE) {
|
if (relay_chn_run_info_get_last_run_cmd(tilt_ctl->chn_ctl->run_info) == RELAY_CHN_CMD_NONE) {
|
||||||
// Do not tilt if the channel hasn't been run before
|
// Do not tilt if the channel hasn't been run before
|
||||||
ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: Tilt will not be executed since the channel hasn't been run yet");
|
ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: Tilt will not be executed since the channel hasn't been run yet");
|
||||||
@@ -106,7 +116,6 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t
|
|||||||
|
|
||||||
// Set the command that will be processed
|
// Set the command that will be processed
|
||||||
tilt_ctl->cmd = cmd;
|
tilt_ctl->cmd = cmd;
|
||||||
ESP_LOGI(TAG, "relay_chn_tilt_issue_cmd: Command-chn: %d-%d", cmd, tilt_ctl->chn_ctl->id); // TODO delete
|
|
||||||
switch (tilt_ctl->chn_ctl->state) {
|
switch (tilt_ctl->chn_ctl->state) {
|
||||||
case RELAY_CHN_STATE_IDLE:
|
case RELAY_CHN_STATE_IDLE:
|
||||||
// Relay channel is free, tilt can be issued immediately
|
// Relay channel is free, tilt can be issued immediately
|
||||||
@@ -183,7 +192,6 @@ static void relay_chn_tilt_issue_cmd_on_all_channels(relay_chn_tilt_cmd_t cmd)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||||
relay_chn_tilt_ctl_t* tilt_ctl = &tilt_ctls[i];
|
relay_chn_tilt_ctl_t* tilt_ctl = &tilt_ctls[i];
|
||||||
ESP_LOGI(TAG, "issue_cmd_on_all_channels: Command|chn|ctl.id: %d|%d|%d", cmd, i, tilt_ctl->chn_ctl->id); // TODO delete
|
|
||||||
relay_chn_tilt_issue_cmd(tilt_ctl, cmd);
|
relay_chn_tilt_issue_cmd(tilt_ctl, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,7 +498,7 @@ static void relay_chn_tilt_execute_stop(relay_chn_tilt_ctl_t *tilt_ctl)
|
|||||||
if (relay_chn_output_stop(tilt_ctl->chn_ctl->output) != ESP_OK) {
|
if (relay_chn_output_stop(tilt_ctl->chn_ctl->output) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "relay_chn_tilt_execute_stop: Failed to output stop for relay channel #%d!", tilt_ctl->chn_ctl->id);
|
ESP_LOGE(TAG, "relay_chn_tilt_execute_stop: Failed to output stop for relay channel #%d!", tilt_ctl->chn_ctl->id);
|
||||||
}
|
}
|
||||||
relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP);
|
relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_IDLE);
|
||||||
|
|
||||||
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
||||||
// Start the flush debounce timer
|
// Start the flush debounce timer
|
||||||
@@ -553,7 +561,6 @@ static void relay_chn_tilt_execute_pause(relay_chn_tilt_ctl_t *tilt_ctl)
|
|||||||
esp_err_t relay_chn_tilt_dispatch_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_tilt_cmd_t cmd)
|
esp_err_t relay_chn_tilt_dispatch_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_tilt_cmd_t cmd)
|
||||||
{
|
{
|
||||||
ESP_LOGD(TAG, "relay_chn_tilt_dispatch_cmd: Command: %d", cmd);
|
ESP_LOGD(TAG, "relay_chn_tilt_dispatch_cmd: Command: %d", cmd);
|
||||||
ESP_LOGI(TAG, "tilt_dispatch_cmd: Command-chn: %d-%d", cmd, tilt_ctl->chn_ctl->id); // TODO delete
|
|
||||||
|
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case RELAY_CHN_TILT_CMD_STOP:
|
case RELAY_CHN_TILT_CMD_STOP:
|
||||||
|
|||||||
Reference in New Issue
Block a user