From a5b320c152d5224056557534e344f8e6ae3bb7d6 Mon Sep 17 00:00:00 2001 From: ismail Date: Tue, 9 Sep 2025 10:53:56 +0300 Subject: [PATCH] Add state to string API function Added a state to string public API function. There was already a private function (`relay_chn_state_str`) that provides this functionality. So this function has been renamed to `relay_chn_state_to_str` and made publicly available. Refs #1104, #1105 and closes #1108. --- include/relay_chn.h | 8 ++++++++ private_include/relay_chn_core.h | 8 -------- src/relay_chn_core.c | 2 +- src/relay_chn_ctl_multi.c | 5 +++-- src/relay_chn_ctl_single.c | 3 ++- src/relay_chn_tilt.c | 3 ++- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/relay_chn.h b/include/relay_chn.h index 1ed03a1..d69f1f7 100644 --- a/include/relay_chn.h +++ b/include/relay_chn.h @@ -63,6 +63,14 @@ esp_err_t relay_chn_register_listener(relay_chn_state_listener_t listener); */ void relay_chn_unregister_listener(relay_chn_state_listener_t listener); +/** + * @brief Return the text presentation of an state. + * + * @param state A state with type of relay_chn_state_t. + * @return char* The text presentation of the state. "UNKNOWN" if the state is not known. + */ +char *relay_chn_state_to_str(relay_chn_state_t state); + #if CONFIG_RELAY_CHN_ENABLE_TILTING /** * @brief Get the default tilting sensitivity for the relay channel. diff --git a/private_include/relay_chn_core.h b/private_include/relay_chn_core.h index 1649099..86c704a 100644 --- a/private_include/relay_chn_core.h +++ b/private_include/relay_chn_core.h @@ -93,14 +93,6 @@ esp_err_t relay_chn_start_esp_timer_once(esp_timer_handle_t esp_timer, uint32_t */ void relay_chn_update_state(relay_chn_ctl_t *chn_ctl, relay_chn_state_t new_state); -/** - * @brief Return the text presentation of an state. - * - * @param state A state with type of relay_chn_state_t. - * @return char* The text presentation of the state. "UNKNOWN" if the state is not known. - */ -char *relay_chn_state_str(relay_chn_state_t state); - #if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Check if the provided channel ID is valid. diff --git a/src/relay_chn_core.c b/src/relay_chn_core.c index 2d8fba8..8d3aeb9 100644 --- a/src/relay_chn_core.c +++ b/src/relay_chn_core.c @@ -471,7 +471,7 @@ char *relay_chn_cmd_str(relay_chn_cmd_t cmd) } } -char *relay_chn_state_str(relay_chn_state_t state) +char *relay_chn_state_to_str(relay_chn_state_t state) { switch (state) { case RELAY_CHN_STATE_IDLE: diff --git a/src/relay_chn_ctl_multi.c b/src/relay_chn_ctl_multi.c index d433fd5..4289836 100644 --- a/src/relay_chn_ctl_multi.c +++ b/src/relay_chn_ctl_multi.c @@ -5,6 +5,7 @@ */ #include "esp_check.h" +#include "relay_chn.h" #include "relay_chn_priv_types.h" #include "relay_chn_core.h" #include "relay_chn_ctl.h" @@ -92,8 +93,8 @@ esp_err_t relay_chn_ctl_get_state_all(relay_chn_state_t *states) char *relay_chn_ctl_get_state_str(uint8_t chn_id) { return relay_chn_is_channel_id_valid(chn_id) - ? relay_chn_state_str(s_chn_ctls[chn_id].state) - : relay_chn_state_str(RELAY_CHN_STATE_UNDEFINED); + ? relay_chn_state_to_str(s_chn_ctls[chn_id].state) + : relay_chn_state_to_str(RELAY_CHN_STATE_UNDEFINED); } diff --git a/src/relay_chn_ctl_single.c b/src/relay_chn_ctl_single.c index e242030..dcb3ac7 100644 --- a/src/relay_chn_ctl_single.c +++ b/src/relay_chn_ctl_single.c @@ -5,6 +5,7 @@ */ #include "esp_check.h" +#include "relay_chn.h" #include "relay_chn_priv_types.h" #include "relay_chn_core.h" #include "relay_chn_ctl.h" @@ -65,7 +66,7 @@ relay_chn_state_t relay_chn_ctl_get_state() char *relay_chn_ctl_get_state_str() { - return relay_chn_state_str(s_chn_ctl.state); + return relay_chn_state_to_str(s_chn_ctl.state); } void relay_chn_ctl_run_forward() diff --git a/src/relay_chn_tilt.c b/src/relay_chn_tilt.c index c9552ad..acb6c47 100644 --- a/src/relay_chn_tilt.c +++ b/src/relay_chn_tilt.c @@ -5,6 +5,7 @@ */ #include "esp_check.h" +#include "relay_chn.h" #include "relay_chn_core.h" #include "relay_chn_output.h" #include "relay_chn_run_info.h" @@ -184,7 +185,7 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t break; default: - ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: Unexpected relay channel state: %s!", relay_chn_state_str(tilt_ctl->chn_ctl->state)); + ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: Unexpected relay channel state: %s!", relay_chn_state_to_str(tilt_ctl->chn_ctl->state)); } }