diff --git a/relay_chn/src/relay_chn.c b/relay_chn/src/relay_chn.c index dc26ad7..124ff18 100644 --- a/relay_chn/src/relay_chn.c +++ b/relay_chn/src/relay_chn.c @@ -174,6 +174,7 @@ typedef struct relay_chn_type { static esp_err_t relay_chn_init_tilt_control(relay_chn_t *relay_chn); static esp_err_t relay_chn_tilt_init(void); static void relay_chn_tilt_count_reset(relay_chn_t *relay_chn); +static esp_err_t relay_chn_dispatch_tilt_cmd(relay_chn_t *relay_chn, relay_chn_tilt_cmd_t cmd); #endif // RELAY_CHN_ENABLE_TILTING @@ -609,6 +610,37 @@ static void relay_chn_issue_cmd(relay_chn_t* relay_chn, relay_chn_cmd_t cmd) relay_chn_start_esp_timer_once(relay_chn->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); break; +#if RELAY_CHN_ENABLE_TILTING == 1 + case RELAY_CHN_STATE_TILT_FORWARD: + // Terminate tilting first + relay_chn_dispatch_tilt_cmd(relay_chn, RELAY_CHN_TILT_CMD_STOP); + if (cmd == RELAY_CHN_CMD_FORWARD) { + // Schedule for running forward + relay_chn->pending_cmd = cmd; + relay_chn_update_state(relay_chn, RELAY_CHN_STATE_FORWARD_PENDING); + relay_chn_start_esp_timer_once(relay_chn->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + } else if (cmd == RELAY_CHN_CMD_REVERSE) { + // Run directly since it is the same direction + relay_chn_dispatch_cmd(relay_chn, cmd); + relay_chn_update_state(relay_chn, RELAY_CHN_STATE_REVERSE); + } + break; + case RELAY_CHN_STATE_TILT_REVERSE: + // Terminate tilting first + relay_chn_dispatch_tilt_cmd(relay_chn, RELAY_CHN_TILT_CMD_STOP); + if (cmd == RELAY_CHN_CMD_FORWARD) { + // Run directly since it is the same direction + relay_chn_dispatch_cmd(relay_chn, cmd); + relay_chn_update_state(relay_chn, RELAY_CHN_STATE_FORWARD); + } else if (cmd == RELAY_CHN_CMD_REVERSE) { + // Schedule for running reverse + relay_chn->pending_cmd = cmd; + relay_chn_update_state(relay_chn, RELAY_CHN_STATE_REVERSE_PENDING); + relay_chn_start_esp_timer_once(relay_chn->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + } + break; +#endif + default: ESP_LOGD(TAG, "relay_chn_evaluate: Unknown relay channel state!"); } }