From 5afefc4dc040bde515328f4af60a576978fc3e7f Mon Sep 17 00:00:00 2001 From: ismail Date: Mon, 25 Aug 2025 10:24:13 +0300 Subject: [PATCH] Use original names for config parameters The config parameter names defined in the relay_chn_defs.h file have been changed back to their original names (with the CONFIG_ prefix), so that they are not confused with application-level defines. Refs #1085 --- include/relay_chn.h | 14 ++-- include/relay_chn_adapter.h | 14 ++-- include/relay_chn_defs.h | 21 ------ private_include/relay_chn_core.h | 8 +-- private_include/relay_chn_ctl.h | 4 +- private_include/relay_chn_nvs.h | 8 +-- private_include/relay_chn_output.h | 4 +- private_include/relay_chn_priv_types.h | 6 +- private_include/relay_chn_run_info.h | 4 +- src/relay_chn_core.c | 50 ++++++------- src/relay_chn_ctl_multi.c | 30 ++++---- src/relay_chn_ctl_single.c | 22 +++--- src/relay_chn_nvs.c | 30 ++++---- src/relay_chn_output.c | 40 +++++------ src/relay_chn_run_info.c | 12 ++-- src/relay_chn_tilt.c | 80 ++++++++++----------- test_apps/main/test_app_main.c | 14 ++-- test_apps/main/test_relay_chn_core_multi.c | 2 +- test_apps/main/test_relay_chn_core_single.c | 2 +- test_apps/main/test_relay_chn_nvs_multi.c | 20 +++--- test_apps/main/test_relay_chn_nvs_single.c | 8 +-- 21 files changed, 186 insertions(+), 207 deletions(-) diff --git a/include/relay_chn.h b/include/relay_chn.h index de3b94c..5f4d0be 100644 --- a/include/relay_chn.h +++ b/include/relay_chn.h @@ -64,7 +64,7 @@ esp_err_t relay_chn_register_listener(relay_chn_state_listener_t listener); */ void relay_chn_unregister_listener(relay_chn_state_listener_t listener); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the state of the specified relay channel. * @@ -143,7 +143,7 @@ void relay_chn_flip_direction(uint8_t chn_id); */ relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Get the run limit for the specified channel * @@ -168,7 +168,7 @@ uint16_t relay_chn_get_run_limit(uint8_t chn_id); * @param time_sec The run limit time in seconds. */ void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec); -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 #if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 @@ -239,7 +239,7 @@ esp_err_t relay_chn_tilt_get_sensitivity(uint8_t chn_id, uint8_t *sensitivity, s #endif // CONFIG_RELAY_CHN_ENABLE_TILTING -#else // RELAY_CHN_COUNT > 1 +#else // CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the state of the relay channel. @@ -299,7 +299,7 @@ void relay_chn_flip_direction(void); */ relay_chn_direction_t relay_chn_get_direction(void); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Get the run limit for the channel * @@ -320,7 +320,7 @@ uint16_t relay_chn_get_run_limit(void); * @param time_sec The run limit time in seconds. */ void relay_chn_set_run_limit(uint16_t time_sec); -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 #if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 @@ -377,7 +377,7 @@ uint8_t relay_chn_tilt_get_sensitivity(void); #endif // CONFIG_RELAY_CHN_ENABLE_TILTING -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 #ifdef __cplusplus } diff --git a/include/relay_chn_adapter.h b/include/relay_chn_adapter.h index 9db6196..d14abc0 100644 --- a/include/relay_chn_adapter.h +++ b/include/relay_chn_adapter.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT * * An adapter header to expose the appropriate API functions to the public API - * depending on the RELAY_CHN_COUNT value which determines single or multi mode. + * depending on the CONFIG_RELAY_CHN_COUNT value which determines single or multi mode. */ #pragma once @@ -13,7 +13,7 @@ extern "C" { #endif -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the current state of a relay channel. * @@ -101,7 +101,7 @@ static inline relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id) return relay_chn_ctl_get_direction(chn_id); } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Get the run limit for the specified channel * @@ -129,7 +129,7 @@ static inline void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec) { relay_chn_ctl_set_run_limit(chn_id, time_sec); } -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 #else @@ -209,7 +209,7 @@ static inline relay_chn_direction_t relay_chn_get_direction(void) return relay_chn_ctl_get_direction(); } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Get the run limit for the channel * @@ -233,9 +233,9 @@ static inline void relay_chn_set_run_limit(uint16_t time_sec) { relay_chn_ctl_set_run_limit(time_sec); } -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 #ifdef __cplusplus } diff --git a/include/relay_chn_defs.h b/include/relay_chn_defs.h index 9c52236..b044f8f 100644 --- a/include/relay_chn_defs.h +++ b/include/relay_chn_defs.h @@ -10,31 +10,10 @@ extern "C" { #endif -/* Config defines for covenient writing */ -#define RELAY_CHN_OPPOSITE_INERTIA_MS CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS -#define RELAY_CHN_COUNT CONFIG_RELAY_CHN_COUNT -#define RELAY_CHN_ENABLE_TILTING CONFIG_RELAY_CHN_ENABLE_TILTING -#define RELAY_CHN_ENABLE_NVS CONFIG_RELAY_CHN_ENABLE_NVS -#define RELAY_CHN_ENABLE_RUN_LIMIT CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT - -#if RELAY_CHN_ENABLE_NVS == 1 -#define RELAY_CHN_NVS_NAMESPACE CONFIG_RELAY_CHN_NVS_NAMESPACE -#define RELAY_CHN_NVS_CUSTOM_PARTITION CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION -#if RELAY_CHN_NVS_CUSTOM_PARTITION == 1 -#define RELAY_CHN_NVS_CUSTOM_PARTITION_NAME CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME -#endif -#endif - #if RELAY_CHN_COUNT > 1 #define RELAY_CHN_ID_ALL RELAY_CHN_COUNT /*!< Special ID to address all channels */ #endif -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 -#define RELAY_CHN_RUN_LIMIT_MIN_SEC CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC -#define RELAY_CHN_RUN_LIMIT_MAX_SEC CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC -#define RELAY_CHN_RUN_LIMIT_DEFAULT_SEC CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC -#endif - #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/private_include/relay_chn_core.h b/private_include/relay_chn_core.h index 3577b91..6a0a621 100644 --- a/private_include/relay_chn_core.h +++ b/private_include/relay_chn_core.h @@ -28,7 +28,7 @@ extern "C" { */ esp_err_t relay_chn_init_timer(relay_chn_ctl_t *chn_ctl); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Initializes the relay channel run limit timer. * @@ -40,7 +40,7 @@ esp_err_t relay_chn_init_timer(relay_chn_ctl_t *chn_ctl); * @return esp_err_t ESP_OK on success, or an error code on failure. */ esp_err_t relay_chn_init_run_limit_timer(relay_chn_ctl_t *chn_ctl); -#endif // RELAY_CHN_ENABLE_RUN_LIMIT +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT /** * @brief Issues a command to the relay channel. @@ -102,7 +102,7 @@ void relay_chn_update_state(relay_chn_ctl_t *chn_ctl, relay_chn_state_t new_stat */ char *relay_chn_state_str(relay_chn_state_t state); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Check if the provided channel ID is valid. * @@ -111,7 +111,7 @@ char *relay_chn_state_str(relay_chn_state_t state); * @return false Channel ID is invalid. */ bool relay_chn_is_channel_id_valid(uint8_t chn_id); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 #ifdef __cplusplus } diff --git a/private_include/relay_chn_ctl.h b/private_include/relay_chn_ctl.h index 8f89a11..ba9b98c 100644 --- a/private_include/relay_chn_ctl.h +++ b/private_include/relay_chn_ctl.h @@ -31,7 +31,7 @@ esp_err_t relay_chn_ctl_init(relay_chn_output_t *output, relay_chn_run_info_t *r */ void relay_chn_ctl_deinit(void); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the control structure for a specific relay channel. * @@ -49,7 +49,7 @@ relay_chn_ctl_t *relay_chn_ctl_get(uint8_t chn_id); relay_chn_ctl_t *relay_chn_ctl_get_all(void); #else relay_chn_ctl_t *relay_chn_ctl_get(void); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 #ifdef __cplusplus } diff --git a/private_include/relay_chn_nvs.h b/private_include/relay_chn_nvs.h index 09f84f2..043a4b2 100644 --- a/private_include/relay_chn_nvs.h +++ b/private_include/relay_chn_nvs.h @@ -45,7 +45,7 @@ esp_err_t relay_chn_nvs_set_direction(uint8_t ch, relay_chn_direction_t directio */ esp_err_t relay_chn_nvs_get_direction(uint8_t ch, relay_chn_direction_t *direction); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /** * @brief Store relay channel run limit in NVS. * @@ -63,9 +63,9 @@ esp_err_t relay_chn_nvs_set_run_limit(uint8_t ch, uint16_t time_sec); * @return ESP_OK on success, error code otherwise. */ esp_err_t relay_chn_nvs_get_run_limit(uint8_t ch, uint16_t *time_sec); -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING /** * @brief Store tilt sensitivity in NVS. * @@ -101,7 +101,7 @@ esp_err_t relay_chn_nvs_set_tilt_count(uint8_t ch, uint16_t tilt_count); * @return ESP_OK on success, error code otherwise. */ esp_err_t relay_chn_nvs_get_tilt_count(uint8_t ch, uint16_t *tilt_count); -#endif // RELAY_CHN_ENABLE_TILTING +#endif // CONFIG_RELAY_CHN_ENABLE_TILTING /** * @brief Erase all keys in the NVS namespace. diff --git a/private_include/relay_chn_output.h b/private_include/relay_chn_output.h index 27a8de9..d504fbf 100644 --- a/private_include/relay_chn_output.h +++ b/private_include/relay_chn_output.h @@ -36,7 +36,7 @@ esp_err_t relay_chn_output_init(const uint8_t* gpio_map, uint8_t gpio_count); */ void relay_chn_output_deinit(void); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the relay channel output object for a specific channel. * @@ -59,7 +59,7 @@ relay_chn_output_t *relay_chn_output_get_all(void); * @return Pointer to relay channel output object. */ relay_chn_output_t *relay_chn_output_get(void); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Stop the relay channel output. diff --git a/private_include/relay_chn_priv_types.h b/private_include/relay_chn_priv_types.h index c62a6f0..1b7b5de 100644 --- a/private_include/relay_chn_priv_types.h +++ b/private_include/relay_chn_priv_types.h @@ -45,7 +45,7 @@ typedef struct { uint32_t last_run_cmd_time_ms; /*!< The time in milliseconds when the last run command was issued */ } relay_chn_run_info_t; -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 /// @brief Tilt commands. typedef enum { RELAY_CHN_TILT_CMD_NONE, /*!< No command */ @@ -68,11 +68,11 @@ typedef struct { relay_chn_output_t *output; /*!< Output configuration of the relay channel */ relay_chn_cmd_t pending_cmd; /*!< The command that is pending to be issued */ esp_timer_handle_t inertia_timer; /*!< Timer to handle the opposite direction inertia time */ -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 esp_timer_handle_t run_limit_timer; /*!< Timer to handle the run limit */ uint16_t run_limit_sec; /*!< Run limit in seconds */ #endif -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 relay_chn_tilt_ctl_t *tilt_ctl; /*!< Pointer to the tilt control structure if tilting is enabled */ #endif } relay_chn_ctl_t; diff --git a/private_include/relay_chn_run_info.h b/private_include/relay_chn_run_info.h index 0b14296..b3f9188 100644 --- a/private_include/relay_chn_run_info.h +++ b/private_include/relay_chn_run_info.h @@ -21,7 +21,7 @@ extern "C" { */ void relay_chn_run_info_init(void); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get run information object for a specific relay channel. * @@ -43,7 +43,7 @@ relay_chn_run_info_t *relay_chn_run_info_get_all(void); * @return Pointer to run information structure. */ relay_chn_run_info_t *relay_chn_run_info_get(void); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 /** * @brief Get the last run command for a relay channel. diff --git a/src/relay_chn_core.c b/src/relay_chn_core.c index 48a6321..66c0f34 100644 --- a/src/relay_chn_core.c +++ b/src/relay_chn_core.c @@ -12,11 +12,11 @@ #include "relay_chn_run_info.h" #include "relay_chn_ctl.h" -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 #include "relay_chn_tilt.h" #endif -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "relay_chn_nvs.h" #endif @@ -35,7 +35,7 @@ typedef struct relay_chn_listener_entry_type { // The list that holds references to the registered listeners. static List_t relay_chn_listener_list; -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 /* * Run limit timer callback immediately dispatches a STOP command for the * relevant channel as soon as the run limit time times out @@ -90,7 +90,7 @@ esp_err_t relay_chn_create(const uint8_t* gpio_map, uint8_t gpio_count) ESP_RETURN_ON_FALSE(gpio_map != NULL, ESP_ERR_INVALID_ARG, TAG, "gpio_map cannot be NULL"); esp_err_t ret; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 ret = relay_chn_nvs_init(); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize NVS for relay channel"); #endif @@ -102,7 +102,7 @@ esp_err_t relay_chn_create(const uint8_t* gpio_map, uint8_t gpio_count) // Initialize the run info relay_chn_run_info_init(); -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_output_t *outputs = relay_chn_output_get_all(); relay_chn_run_info_t *run_infos = relay_chn_run_info_get_all(); #else @@ -114,13 +114,13 @@ esp_err_t relay_chn_create(const uint8_t* gpio_map, uint8_t gpio_count) ret = relay_chn_ctl_init(outputs, run_infos); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize relay channel control"); -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 // Initialize the tilt feature -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_ctl_t *chn_ctls = relay_chn_ctl_get_all(); #else relay_chn_ctl_t *chn_ctls = relay_chn_ctl_get(); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 ret = relay_chn_tilt_init(chn_ctls); // Initialize tilt feature ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize tilt feature"); #endif @@ -133,13 +133,13 @@ esp_err_t relay_chn_create(const uint8_t* gpio_map, uint8_t gpio_count) void relay_chn_destroy(void) { -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 relay_chn_tilt_deinit(); #endif relay_chn_ctl_deinit(); relay_chn_output_deinit(); -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 relay_chn_nvs_deinit(); #endif @@ -328,7 +328,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd) // 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 inertia_time_passed_ms = (uint32_t) (esp_timer_get_time() / 1000) - last_run_cmd_time_ms; - uint32_t inertia_time_ms = RELAY_CHN_OPPOSITE_INERTIA_MS - inertia_time_passed_ms; + uint32_t inertia_time_ms = CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS - inertia_time_passed_ms; if (inertia_time_ms > 0) { chn_ctl->pending_cmd = cmd; relay_chn_state_t new_state = cmd == RELAY_CHN_CMD_FORWARD @@ -366,10 +366,10 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd) 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_esp_timer_once(chn_ctl->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); break; -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 case RELAY_CHN_STATE_TILT_FORWARD: // Terminate tilting first relay_chn_tilt_dispatch_cmd(chn_ctl->tilt_ctl, RELAY_CHN_TILT_CMD_STOP); @@ -377,7 +377,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd) // Schedule for running forward chn_ctl->pending_cmd = cmd; relay_chn_update_state(chn_ctl, RELAY_CHN_STATE_FORWARD_PENDING); - relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } else if (cmd == RELAY_CHN_CMD_REVERSE) { // Run directly since it is the same direction relay_chn_dispatch_cmd(chn_ctl, cmd); @@ -395,7 +395,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd) // Schedule for running reverse chn_ctl->pending_cmd = cmd; relay_chn_update_state(chn_ctl, RELAY_CHN_STATE_REVERSE_PENDING); - relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } break; #endif @@ -404,16 +404,16 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd) } } -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 bool relay_chn_is_channel_id_valid(uint8_t chn_id) { - bool valid = (chn_id < RELAY_CHN_COUNT) || chn_id == RELAY_CHN_ID_ALL; + bool valid = (chn_id < CONFIG_RELAY_CHN_COUNT) || chn_id == RELAY_CHN_ID_ALL; if (!valid) { ESP_LOGE(TAG, "Invalid channel ID: %d", chn_id); } return valid; } -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 static void relay_chn_execute_idle(relay_chn_ctl_t *chn_ctl) @@ -437,7 +437,7 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl) // Invalidate the channel's timer if it is active esp_timer_stop(chn_ctl->inertia_timer); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 esp_timer_stop(chn_ctl->run_limit_timer); #endif @@ -448,7 +448,7 @@ static void relay_chn_execute_stop(relay_chn_ctl_t *chn_ctl) relay_chn_run_info_set_last_run_cmd_time_ms(chn_ctl->run_info, (uint32_t)(esp_timer_get_time() / 1000)); // Schedule a free command for the channel chn_ctl->pending_cmd = RELAY_CHN_CMD_IDLE; - relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } 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); @@ -465,7 +465,7 @@ static void relay_chn_execute_forward(relay_chn_ctl_t *chn_ctl) relay_chn_run_info_set_last_run_cmd(chn_ctl->run_info, RELAY_CHN_CMD_FORWARD); relay_chn_update_state(chn_ctl, RELAY_CHN_STATE_FORWARD); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 relay_chn_start_esp_timer_once(chn_ctl->run_limit_timer, chn_ctl->run_limit_sec * 1000); #endif } @@ -479,7 +479,7 @@ static void relay_chn_execute_reverse(relay_chn_ctl_t *chn_ctl) relay_chn_run_info_set_last_run_cmd(chn_ctl->run_info, RELAY_CHN_CMD_REVERSE); relay_chn_update_state(chn_ctl, RELAY_CHN_STATE_REVERSE); -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 relay_chn_start_esp_timer_once(chn_ctl->run_limit_timer, chn_ctl->run_limit_sec * 1000); #endif } @@ -489,7 +489,7 @@ static void relay_chn_execute_flip(relay_chn_ctl_t *chn_ctl) relay_chn_output_flip(chn_ctl->output); // Set an inertia on the channel to prevent any immediate movement chn_ctl->pending_cmd = RELAY_CHN_CMD_IDLE; - relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } // Dispatch relay channel command @@ -516,7 +516,7 @@ void relay_chn_dispatch_cmd(relay_chn_ctl_t *chn_ctl, relay_chn_cmd_t cmd) { ESP_LOGD(TAG, "Unknown relay channel command!"); } -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 // Reset the tilt counter when the command is either FORWARD or REVERSE if (cmd == RELAY_CHN_CMD_FORWARD || cmd == RELAY_CHN_CMD_REVERSE) { relay_chn_tilt_reset_count(chn_ctl->tilt_ctl); @@ -557,7 +557,7 @@ char *relay_chn_state_str(relay_chn_state_t state) return "FORWARD_PENDING"; case RELAY_CHN_STATE_REVERSE_PENDING: return "REVERSE_PENDING"; -#if RELAY_CHN_ENABLE_TILTING == 1 +#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1 case RELAY_CHN_STATE_TILT_FORWARD: return "TILT_FORWARD"; case RELAY_CHN_STATE_TILT_REVERSE: diff --git a/src/relay_chn_ctl_multi.c b/src/relay_chn_ctl_multi.c index 336c5f9..b18e58a 100644 --- a/src/relay_chn_ctl_multi.c +++ b/src/relay_chn_ctl_multi.c @@ -10,20 +10,20 @@ #include "relay_chn_ctl.h" #include "relay_chn_output.h" -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "relay_chn_nvs.h" #endif static const char *TAG = "RELAY_CHN_CTL"; -static relay_chn_ctl_t chn_ctls[RELAY_CHN_COUNT]; +static relay_chn_ctl_t chn_ctls[CONFIG_RELAY_CHN_COUNT]; esp_err_t relay_chn_ctl_init(relay_chn_output_t *outputs, relay_chn_run_info_t *run_infos) { // Initialize all relay channels esp_err_t ret; - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_ctl_t* chn_ctl = &chn_ctls[i]; relay_chn_output_t* output = &outputs[i]; relay_chn_run_info_t* run_info = &run_infos[i]; @@ -34,9 +34,9 @@ esp_err_t relay_chn_ctl_init(relay_chn_output_t *outputs, relay_chn_run_info_t * chn_ctl->output = output; chn_ctl->run_info = run_info; -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 - uint16_t run_limit_sec = RELAY_CHN_RUN_LIMIT_DEFAULT_SEC; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 + uint16_t run_limit_sec = CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC; +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // Load run limit value from NVS ret = relay_chn_nvs_get_run_limit(chn_ctl->id, &run_limit_sec); if (ret != ESP_OK && ret != ESP_ERR_NVS_NOT_FOUND) { @@ -55,13 +55,13 @@ esp_err_t relay_chn_ctl_init(relay_chn_output_t *outputs, relay_chn_run_info_t * void relay_chn_ctl_deinit() { - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_ctl_t* chn_ctl = &chn_ctls[i]; if (chn_ctl->inertia_timer != NULL) { esp_timer_delete(chn_ctl->inertia_timer); chn_ctl->inertia_timer = NULL; } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 if (chn_ctl->run_limit_timer != NULL) { esp_timer_delete(chn_ctl->run_limit_timer); chn_ctl->run_limit_timer = NULL; @@ -88,7 +88,7 @@ char *relay_chn_ctl_get_state_str(uint8_t chn_id) static void relay_chn_ctl_issue_cmd_on_all_channels(relay_chn_cmd_t cmd) { - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_issue_cmd(&chn_ctls[i], cmd); } } @@ -146,7 +146,7 @@ relay_chn_direction_t relay_chn_ctl_get_direction(uint8_t chn_id) return relay_chn_output_get_direction(chn_ctl->output); } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 uint16_t relay_chn_ctl_get_run_limit(uint8_t chn_id) { if (!relay_chn_is_channel_id_valid(chn_id) || chn_id == RELAY_CHN_ID_ALL) { @@ -164,14 +164,14 @@ void relay_chn_ctl_set_run_limit(uint8_t chn_id, uint16_t time_sec) } // Check for boundaries - if (time_sec > RELAY_CHN_RUN_LIMIT_MAX_SEC) - time_sec = RELAY_CHN_RUN_LIMIT_MAX_SEC; - else if (time_sec < RELAY_CHN_RUN_LIMIT_MIN_SEC) - time_sec = RELAY_CHN_RUN_LIMIT_MIN_SEC; + if (time_sec > CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC) + time_sec = CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC; + else if (time_sec < CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC) + time_sec = CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC; chn_ctls[chn_id].run_limit_sec = time_sec; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 relay_chn_nvs_set_run_limit(chn_id, time_sec); #endif } diff --git a/src/relay_chn_ctl_single.c b/src/relay_chn_ctl_single.c index a56f226..94ca732 100644 --- a/src/relay_chn_ctl_single.c +++ b/src/relay_chn_ctl_single.c @@ -10,7 +10,7 @@ #include "relay_chn_ctl.h" #include "relay_chn_output.h" -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "relay_chn_nvs.h" #endif @@ -27,10 +27,10 @@ esp_err_t relay_chn_ctl_init(relay_chn_output_t *output, relay_chn_run_info_t *r chn_ctl.pending_cmd = RELAY_CHN_CMD_NONE; chn_ctl.output = output; chn_ctl.run_info = run_info; -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 - uint16_t run_limit_sec = RELAY_CHN_RUN_LIMIT_DEFAULT_SEC; +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 + uint16_t run_limit_sec = CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC; esp_err_t ret; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // Load run limit value from NVS ret = relay_chn_nvs_get_run_limit(chn_ctl.id, &run_limit_sec); if (ret != ESP_OK && ret != ESP_ERR_NVS_NOT_FOUND) { @@ -51,7 +51,7 @@ void relay_chn_ctl_deinit() esp_timer_delete(chn_ctl.inertia_timer); chn_ctl.inertia_timer = NULL; } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 if (chn_ctl.run_limit_timer != NULL) { esp_timer_delete(chn_ctl.run_limit_timer); chn_ctl.run_limit_timer = NULL; @@ -95,7 +95,7 @@ relay_chn_direction_t relay_chn_ctl_get_direction() return relay_chn_output_get_direction(chn_ctl.output); } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 uint16_t relay_chn_ctl_get_run_limit() { return chn_ctl.run_limit_sec; @@ -104,14 +104,14 @@ uint16_t relay_chn_ctl_get_run_limit() void relay_chn_ctl_set_run_limit(uint16_t time_sec) { // Check for boundaries - if (time_sec > RELAY_CHN_RUN_LIMIT_MAX_SEC) - time_sec = RELAY_CHN_RUN_LIMIT_MAX_SEC; - else if (time_sec < RELAY_CHN_RUN_LIMIT_MIN_SEC) - time_sec = RELAY_CHN_RUN_LIMIT_MIN_SEC; + if (time_sec > CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC) + time_sec = CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC; + else if (time_sec < CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC) + time_sec = CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC; chn_ctl.run_limit_sec = time_sec; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 relay_chn_nvs_set_run_limit(chn_ctl.id, time_sec); #endif } diff --git a/src/relay_chn_nvs.c b/src/relay_chn_nvs.c index 04ec8df..eff7332 100644 --- a/src/relay_chn_nvs.c +++ b/src/relay_chn_nvs.c @@ -8,10 +8,10 @@ #include "relay_chn_nvs.h" #define RELAY_CHN_KEY_DIR "dir" /*!< Direction key */ -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 #define RELAY_CHN_KEY_RLIM(ch) "rlim_%d" /*!< Run limit key */ #endif -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING #define RELAY_CHN_KEY_TSENS(ch) "tsens_%d" /*!< Tilt sensitivity key */ #define RELAY_CHN_KEY_TCNT(ch) "tcnt_%d" /*!< Tilt count key */ #endif @@ -23,22 +23,22 @@ static nvs_handle_t relay_chn_nvs; esp_err_t relay_chn_nvs_init() { esp_err_t ret; -#if RELAY_CHN_NVS_CUSTOM_PARTITION == 1 - ret = nvs_open_from_partition(RELAY_CHN_NVS_CUSTOM_PARTITION_NAME, - RELAY_CHN_NVS_NAMESPACE, +#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1 + ret = nvs_open_from_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME, + CONFIG_RELAY_CHN_NVS_NAMESPACE, NVS_READWRITE, &relay_chn_nvs); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to open NVS namespace '%s' from partition '%s' with error %s", - RELAY_CHN_NVS_NAMESPACE, - RELAY_CHN_NVS_CUSTOM_PARTITION_NAME, + CONFIG_RELAY_CHN_NVS_NAMESPACE, + CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME, esp_err_to_name(ret)); #else - ret = nvs_open(RELAY_CHN_NVS_NAMESPACE, NVS_READWRITE, &relay_chn_nvs); - ESP_RETURN_ON_ERROR(ret, TAG, "Failed to open NVS namespace '%s'", RELAY_CHN_NVS_NAMESPACE); -#endif // RELAY_CHN_NVS_CUSTOM_PARTITION + ret = nvs_open(CONFIG_RELAY_CHN_NVS_NAMESPACE, NVS_READWRITE, &relay_chn_nvs); + ESP_RETURN_ON_ERROR(ret, TAG, "Failed to open NVS namespace '%s'", CONFIG_RELAY_CHN_NVS_NAMESPACE); +#endif // CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION return ESP_OK; } @@ -72,7 +72,7 @@ esp_err_t relay_chn_nvs_get_direction(uint8_t ch, relay_chn_direction_t *directi return ESP_OK; } -#if RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 esp_err_t relay_chn_nvs_set_run_limit(uint8_t ch, uint16_t time_sec) { esp_err_t ret = nvs_set_u16(relay_chn_nvs, RELAY_CHN_KEY_RLIM(ch), time_sec); @@ -86,9 +86,9 @@ esp_err_t relay_chn_nvs_get_run_limit(uint8_t ch, uint16_t *time_sec) return nvs_get_u16(relay_chn_nvs, RELAY_CHN_KEY_RLIM(ch), time_sec); } -#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1 -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING esp_err_t relay_chn_nvs_set_tilt_sensitivity(uint8_t ch, uint8_t sensitivity) { esp_err_t ret = nvs_set_u8(relay_chn_nvs, RELAY_CHN_KEY_TSENS(ch), sensitivity); @@ -117,13 +117,13 @@ esp_err_t relay_chn_nvs_get_tilt_count(uint8_t ch, uint16_t *tilt_count) ESP_ERR_INVALID_ARG, TAG, "Counter pointers are NULL"); return nvs_get_u16(relay_chn_nvs, RELAY_CHN_KEY_TCNT(ch), tilt_count); } -#endif // RELAY_CHN_ENABLE_TILTING +#endif // CONFIG_RELAY_CHN_ENABLE_TILTING esp_err_t relay_chn_nvs_erase_all() { // Erase all key-value pairs in the relay_chn NVS namespace esp_err_t ret = nvs_erase_all(relay_chn_nvs); - ESP_RETURN_ON_ERROR(ret, TAG, "Failed to erase all keys in NVS namespace '%s'", RELAY_CHN_NVS_NAMESPACE); + ESP_RETURN_ON_ERROR(ret, TAG, "Failed to erase all keys in NVS namespace '%s'", CONFIG_RELAY_CHN_NVS_NAMESPACE); // Commit the changes return nvs_commit(relay_chn_nvs); diff --git a/src/relay_chn_output.c b/src/relay_chn_output.c index 44c1465..828ad0a 100644 --- a/src/relay_chn_output.c +++ b/src/relay_chn_output.c @@ -10,15 +10,15 @@ #include "relay_chn_output.h" #include "relay_chn_core.h" -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "relay_chn_nvs.h" #endif static const char *TAG = "RELAY_CHN_OUTPUT"; -#if RELAY_CHN_COUNT > 1 -static relay_chn_output_t outputs[RELAY_CHN_COUNT]; +#if CONFIG_RELAY_CHN_COUNT > 1 +static relay_chn_output_t outputs[CONFIG_RELAY_CHN_COUNT]; #else static relay_chn_output_t output; #endif @@ -27,16 +27,16 @@ static relay_chn_output_t output; static esp_err_t relay_chn_output_check_gpio_capabilities(uint8_t gpio_count) { // Check if the device's GPIOs are enough for the number of channels - if (RELAY_CHN_COUNT > (GPIO_PIN_COUNT / 2)) { + if (CONFIG_RELAY_CHN_COUNT > (GPIO_PIN_COUNT / 2)) { ESP_LOGE(TAG, "Not enough GPIOs for the number of channels!"); - ESP_LOGE(TAG, "Max available num of channels: %d, requested channels: %d", GPIO_PIN_COUNT / 2, RELAY_CHN_COUNT); + ESP_LOGE(TAG, "Max available num of channels: %d, requested channels: %d", GPIO_PIN_COUNT / 2, CONFIG_RELAY_CHN_COUNT); return ESP_ERR_INVALID_ARG; } // Check if the provided GPIOs correspond to the number of channels - if (gpio_count != RELAY_CHN_COUNT * 2) { + if (gpio_count != CONFIG_RELAY_CHN_COUNT * 2) { ESP_LOGE(TAG, "Invalid number of GPIOs provided: %d", gpio_count); - ESP_LOGE(TAG, "Expected number of GPIOs: %d", RELAY_CHN_COUNT * 2); + ESP_LOGE(TAG, "Expected number of GPIOs: %d", CONFIG_RELAY_CHN_COUNT * 2); return ESP_ERR_INVALID_ARG; } return ESP_OK; @@ -73,7 +73,7 @@ static esp_err_t relay_chn_output_ctl_init(relay_chn_output_t *output, return ESP_OK; } -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 static esp_err_t relay_chn_output_load_direction(uint8_t ch, relay_chn_direction_t *direction) { esp_err_t ret = relay_chn_nvs_get_direction(ch, direction); @@ -93,15 +93,15 @@ esp_err_t relay_chn_output_init(const uint8_t* gpio_map, uint8_t gpio_count) ret = relay_chn_output_check_gpio_capabilities(gpio_count); ESP_RETURN_ON_ERROR(ret, TAG, "Device does not support the provided GPIOs"); -#if RELAY_CHN_COUNT > 1 - for (int i = 0; i < RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_COUNT > 1 + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_output_t* output = &outputs[i]; int gpio_index = i << 1; // gpio_index = i * 2 gpio_num_t forward_pin = (gpio_num_t) gpio_map[gpio_index]; gpio_num_t reverse_pin = (gpio_num_t) gpio_map[gpio_index + 1]; relay_chn_direction_t direction = RELAY_CHN_DIRECTION_DEFAULT; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // If NVS storage is enabled, retrieve the direction from storage ret = relay_chn_output_load_direction(i, &direction); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load direction from storage for channel %d", i); @@ -111,7 +111,7 @@ esp_err_t relay_chn_output_init(const uint8_t* gpio_map, uint8_t gpio_count) } #else relay_chn_direction_t direction = RELAY_CHN_DIRECTION_DEFAULT; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // If NVS storage is enabled, retrieve the direction from storage ret = relay_chn_output_load_direction(0, &direction); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load direction from storage for channel %d", 0); @@ -130,16 +130,16 @@ static void relay_chn_output_ctl_deinit(relay_chn_output_t *output) void relay_chn_output_deinit() { -#if RELAY_CHN_COUNT > 1 - for (int i = 0; i < RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_COUNT > 1 + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_output_ctl_deinit(&outputs[i]); } #else relay_chn_output_ctl_deinit(&output); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 } -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_output_t *relay_chn_output_get(uint8_t chn_id) { if (!relay_chn_is_channel_id_valid(chn_id)) { @@ -157,7 +157,7 @@ relay_chn_output_t *relay_chn_output_get(void) { return &output; } -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 esp_err_t relay_chn_output_stop(relay_chn_output_t *output) { @@ -194,10 +194,10 @@ void relay_chn_output_flip(relay_chn_output_t *output) ? RELAY_CHN_DIRECTION_FLIPPED : RELAY_CHN_DIRECTION_DEFAULT; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 uint8_t ch = 0; -#if RELAY_CHN_COUNT > 1 - for (uint8_t i = 0; i < RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_COUNT > 1 + for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { if (output == &outputs[i]) { ch = i; break; diff --git a/src/relay_chn_run_info.c b/src/relay_chn_run_info.c index e021023..9a21f47 100644 --- a/src/relay_chn_run_info.c +++ b/src/relay_chn_run_info.c @@ -8,16 +8,16 @@ #include "relay_chn_run_info.h" -#if RELAY_CHN_COUNT > 1 -static relay_chn_run_info_t run_infos[RELAY_CHN_COUNT]; +#if CONFIG_RELAY_CHN_COUNT > 1 +static relay_chn_run_info_t run_infos[CONFIG_RELAY_CHN_COUNT]; #else static relay_chn_run_info_t run_info; #endif void relay_chn_run_info_init() { -#if RELAY_CHN_COUNT > 1 - for (int i = 0; i < RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_COUNT > 1 + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { run_infos[i].last_run_cmd = RELAY_CHN_CMD_NONE; run_infos[i].last_run_cmd_time_ms = 0; } @@ -27,7 +27,7 @@ void relay_chn_run_info_init() #endif } -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_run_info_t *relay_chn_run_info_get(uint8_t chn_id) { if (!relay_chn_is_channel_id_valid(chn_id)) { @@ -45,7 +45,7 @@ relay_chn_run_info_t *relay_chn_run_info_get() { return &run_info; } -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 relay_chn_cmd_t relay_chn_run_info_get_last_run_cmd(relay_chn_run_info_t *run_info) { diff --git a/src/relay_chn_tilt.c b/src/relay_chn_tilt.c index 826c352..e99dea0 100644 --- a/src/relay_chn_tilt.c +++ b/src/relay_chn_tilt.c @@ -10,7 +10,7 @@ #include "relay_chn_run_info.h" #include "relay_chn_tilt.h" -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "relay_chn_nvs.h" #define RELAY_CHN_TILT_FLUSH_DEBOUNCE_MS 3000 @@ -63,14 +63,14 @@ typedef struct relay_chn_tilt_ctl { relay_chn_tilt_timing_t tilt_timing; /*!< Tilt timing structure */ uint16_t tilt_count; /*!< Tilt count to manage forward and reverse tilts */ esp_timer_handle_t tilt_timer; /*!< Tilt timer handle */ -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 esp_timer_handle_t flush_timer; /*!< Flush timer to avoid frequent write of tilt counters */ #endif } relay_chn_tilt_ctl_t; -#if RELAY_CHN_COUNT > 1 -static relay_chn_tilt_ctl_t tilt_ctls[RELAY_CHN_COUNT]; +#if CONFIG_RELAY_CHN_COUNT > 1 +static relay_chn_tilt_ctl_t tilt_ctls[CONFIG_RELAY_CHN_COUNT]; #else static relay_chn_tilt_ctl_t tilt_ctl; #endif @@ -87,7 +87,7 @@ static uint32_t relay_chn_tilt_get_required_timing_before_tilting(relay_chn_tilt uint32_t last_run_cmd_time_ms = relay_chn_run_info_get_last_run_cmd_time_ms(tilt_ctl->chn_ctl->run_info); uint32_t inertia_time_passed_ms = (uint32_t) (esp_timer_get_time() / 1000) - last_run_cmd_time_ms; - return RELAY_CHN_OPPOSITE_INERTIA_MS - inertia_time_passed_ms; + return CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS - inertia_time_passed_ms; } // Issue a tilt command to a specific relay channel. @@ -136,7 +136,7 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP); // Schedule for tilting tilt_ctl->step = RELAY_CHN_TILT_STEP_PENDING; - relay_chn_start_esp_timer_once(tilt_ctl->tilt_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(tilt_ctl->tilt_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } else if (cmd == RELAY_CHN_TILT_CMD_REVERSE) { // Stop the running channel first relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP); @@ -151,7 +151,7 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP); // Schedule for tilting tilt_ctl->step = RELAY_CHN_TILT_STEP_PENDING; - relay_chn_start_esp_timer_once(tilt_ctl->tilt_timer, RELAY_CHN_OPPOSITE_INERTIA_MS); + relay_chn_start_esp_timer_once(tilt_ctl->tilt_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS); } else if (cmd == RELAY_CHN_TILT_CMD_FORWARD) { // Stop the running channel first relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP); @@ -176,7 +176,7 @@ static void relay_chn_tilt_issue_auto(relay_chn_tilt_ctl_t *tilt_ctl) } } -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 void relay_chn_tilt_auto(uint8_t chn_id) { if (!relay_chn_is_channel_id_valid(chn_id)) { @@ -185,7 +185,7 @@ void relay_chn_tilt_auto(uint8_t chn_id) // Execute for all channels if (chn_id == RELAY_CHN_ID_ALL) { - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_tilt_issue_auto(&tilt_ctls[i]); } } @@ -198,7 +198,7 @@ void relay_chn_tilt_auto(uint8_t chn_id) static void relay_chn_tilt_issue_cmd_on_all_channels(relay_chn_tilt_cmd_t cmd) { - for (int i = 0; i < 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_issue_cmd(tilt_ctl, cmd); } @@ -239,7 +239,7 @@ void relay_chn_tilt_stop(uint8_t chn_id) } if (chn_id == RELAY_CHN_ID_ALL) { - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_tilt_dispatch_cmd(&tilt_ctls[i], RELAY_CHN_TILT_CMD_STOP); } } @@ -248,7 +248,7 @@ void relay_chn_tilt_stop(uint8_t chn_id) } } -#else // RELAY_CHN_COUNT > 1 +#else // CONFIG_RELAY_CHN_COUNT > 1 void relay_chn_tilt_auto() { @@ -269,7 +269,7 @@ void relay_chn_tilt_stop() { relay_chn_tilt_dispatch_cmd(&tilt_ctl, RELAY_CHN_TILT_CMD_STOP); } -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 static void relay_chn_tilt_set_timing_values(relay_chn_tilt_timing_t *tilt_timing, uint8_t sensitivity, @@ -314,7 +314,7 @@ static void relay_chn_tilt_compute_set_sensitivity(relay_chn_tilt_ctl_t *tilt_ct } } -#if RELAY_CHN_COUNT > 1 +#if CONFIG_RELAY_CHN_COUNT > 1 void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity) { if (!relay_chn_is_channel_id_valid(chn_id)) { @@ -322,7 +322,7 @@ void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity) } if (chn_id == RELAY_CHN_ID_ALL) { - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_tilt_compute_set_sensitivity(&tilt_ctls[i], sensitivity); } } @@ -330,9 +330,9 @@ void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity) relay_chn_tilt_compute_set_sensitivity(&tilt_ctls[chn_id], sensitivity); } -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 relay_chn_nvs_set_tilt_sensitivity(chn_id, sensitivity); -#endif // RELAY_CHN_ENABLE_NVS +#endif // CONFIG_RELAY_CHN_ENABLE_NVS } esp_err_t relay_chn_tilt_get_sensitivity(uint8_t chn_id, uint8_t *sensitivity, size_t length) @@ -345,12 +345,12 @@ esp_err_t relay_chn_tilt_get_sensitivity(uint8_t chn_id, uint8_t *sensitivity, s return ESP_ERR_INVALID_ARG; } if (chn_id == RELAY_CHN_ID_ALL) { - if (length < RELAY_CHN_COUNT) { + if (length < CONFIG_RELAY_CHN_COUNT) { ESP_LOGD(TAG, "relay_chn_tilt_get_sensitivity: length is too short to store all sensitivity values"); return ESP_ERR_INVALID_ARG; } - for (int i = 0; i < RELAY_CHN_COUNT; i++) { + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { sensitivity[i] = tilt_ctls[i].tilt_timing.sensitivity; } return ESP_OK; @@ -365,22 +365,22 @@ void relay_chn_tilt_set_sensitivity(uint8_t sensitivity) { relay_chn_tilt_compute_set_sensitivity(&tilt_ctl, sensitivity); -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 relay_chn_nvs_set_tilt_sensitivity(0, sensitivity); -#endif // RELAY_CHN_ENABLE_NVS +#endif // CONFIG_RELAY_CHN_ENABLE_NVS } uint8_t relay_chn_tilt_get_sensitivity() { return tilt_ctl.tilt_timing.sensitivity; } -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 void relay_chn_tilt_reset_count(relay_chn_tilt_ctl_t *tilt_ctl) { tilt_ctl->tilt_count = 0; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 esp_timer_stop(tilt_ctl->flush_timer); #endif } @@ -450,7 +450,7 @@ static uint16_t relay_chn_tilt_count_update(relay_chn_tilt_ctl_t *tilt_ctl) return 0; } -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 static esp_err_t relay_chn_tilt_save_tilt_count(relay_chn_tilt_ctl_t *tilt_ctl) { // Save the tilt count to NVS storage @@ -486,7 +486,7 @@ static void relay_chn_tilt_execute_stop(relay_chn_tilt_ctl_t *tilt_ctl) } relay_chn_dispatch_cmd(tilt_ctl->chn_ctl, RELAY_CHN_CMD_STOP); -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // Start the flush debounce timer relay_chn_start_esp_timer_once(tilt_ctl->flush_timer, RELAY_CHN_TILT_FLUSH_DEBOUNCE_MS); #endif @@ -599,7 +599,7 @@ static void relay_chn_tilt_timer_cb(void *arg) } } -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 static esp_err_t relay_chn_tilt_load_sensitivity(uint8_t ch, uint8_t *sensitivity) { esp_err_t ret = relay_chn_nvs_get_tilt_sensitivity(ch, sensitivity); @@ -622,7 +622,7 @@ static esp_err_t relay_chn_tilt_load_tilt_count(uint8_t ch, uint16_t *tilt_count ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load tilt counters for channel %d", ch); return ESP_OK; } -#endif // RELAY_CHN_ENABLE_NVS +#endif // CONFIG_RELAY_CHN_ENABLE_NVS static esp_err_t relay_chn_tilt_ctl_init(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_ctl_t *chn_ctl, @@ -648,7 +648,7 @@ static esp_err_t relay_chn_tilt_ctl_init(relay_chn_tilt_ctl_t *tilt_ctl, esp_err_t ret = esp_timer_create(&timer_args, &tilt_ctl->tilt_timer); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create tilt timer for channel %d", chn_ctl->id); -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 // Create flush timer for the tilt counters snprintf(timer_name, sizeof(timer_name), "relay_chn_%2d_tilt_flush_timer", chn_ctl->id); timer_args.callback = relay_chn_tilt_flush_timer_cb; @@ -664,9 +664,9 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls) uint8_t sensitivity; uint16_t tilt_count; -#if RELAY_CHN_COUNT > 1 - for (int i = 0; i < RELAY_CHN_COUNT; i++) { -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_COUNT > 1 + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 esp_err_t ret = relay_chn_tilt_load_sensitivity(i, &sensitivity); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load tilt sensitivity for channel %d", i); ret = relay_chn_tilt_load_tilt_count(i, &tilt_count); @@ -674,7 +674,7 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls) #else sensitivity = RELAY_CHN_TILT_DEFAULT_SENSITIVITY; tilt_count = 0; -#endif // RELAY_CHN_ENABLE_NVS == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_NVS == 1 ret = relay_chn_tilt_ctl_init(&tilt_ctls[i], &chn_ctls[i], tilt_count, sensitivity); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to init tilt control for channel %d", i); } @@ -682,14 +682,14 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls) #else sensitivity = RELAY_CHN_TILT_DEFAULT_SENSITIVITY; tilt_count = 0; -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 esp_err_t ret = relay_chn_tilt_load_sensitivity(0, &sensitivity); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load tilt sensitivity for channel %d", 0); ret = relay_chn_tilt_load_tilt_count(0, &tilt_count); ESP_RETURN_ON_ERROR(ret, TAG, "Failed to load tilt count for channel %d", 0); -#endif // RELAY_CHN_ENABLE_NVS == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_NVS == 1 return relay_chn_tilt_ctl_init(&tilt_ctl, chn_ctls, tilt_count, sensitivity); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 } void relay_chn_tilt_ctl_deinit(relay_chn_tilt_ctl_t *tilt_ctl) @@ -698,21 +698,21 @@ void relay_chn_tilt_ctl_deinit(relay_chn_tilt_ctl_t *tilt_ctl) esp_timer_delete(tilt_ctl->tilt_timer); tilt_ctl->tilt_timer = NULL; } -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 if (tilt_ctl->flush_timer != NULL) { esp_timer_delete(tilt_ctl->flush_timer); tilt_ctl->flush_timer = NULL; } -#endif // RELAY_CHN_ENABLE_NVS == 1 +#endif // CONFIG_RELAY_CHN_ENABLE_NVS == 1 } void relay_chn_tilt_deinit() { -#if RELAY_CHN_COUNT > 1 - for (int i = 0; i < RELAY_CHN_COUNT; i++) { +#if CONFIG_RELAY_CHN_COUNT > 1 + for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { relay_chn_tilt_ctl_deinit(&tilt_ctls[i]); } #else relay_chn_tilt_ctl_deinit(&tilt_ctl); -#endif // RELAY_CHN_COUNT > 1 +#endif // CONFIG_RELAY_CHN_COUNT > 1 } \ No newline at end of file diff --git a/test_apps/main/test_app_main.c b/test_apps/main/test_app_main.c index 460659c..0a4501e 100644 --- a/test_apps/main/test_app_main.c +++ b/test_apps/main/test_app_main.c @@ -7,7 +7,7 @@ #include "unity_test_runner.h" #include "test_common.h" -#if RELAY_CHN_ENABLE_NVS == 1 +#if CONFIG_RELAY_CHN_ENABLE_NVS == 1 #include "nvs_flash.h" #include "relay_chn_nvs.h" #endif @@ -32,14 +32,14 @@ void tearDown() static void test_nvs_flash_init(void) { esp_err_t ret; -#if RELAY_CHN_NVS_CUSTOM_PARTITION == 1 - ret = nvs_flash_init_partition(RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); +#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1 + ret = nvs_flash_init_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); ESP_LOGI(TEST_TAG, "test_nvs_flash_init: NVS flash init partition return: %s", esp_err_to_name(ret)); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { // NVS partition is truncated and needs to be erased - ret = nvs_flash_erase_partition(RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); + ret = nvs_flash_erase_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); if (ret == ESP_OK) { - ret = nvs_flash_init_partition(RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); + ret = nvs_flash_init_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); } } #else @@ -61,8 +61,8 @@ TEST_ESP_OK(ret); static void test_nvs_flash_deinit(void) { esp_err_t ret; -#if RELAY_CHN_NVS_CUSTOM_PARTITION == 1 - ret = nvs_flash_deinit_partition(RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); +#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1 + ret = nvs_flash_deinit_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME); #else ret = nvs_flash_deinit(); #endif diff --git a/test_apps/main/test_relay_chn_core_multi.c b/test_apps/main/test_relay_chn_core_multi.c index 1abcd7b..9015228 100644 --- a/test_apps/main/test_relay_chn_core_multi.c +++ b/test_apps/main/test_relay_chn_core_multi.c @@ -8,7 +8,7 @@ TEST_CASE("relay_chn_create handles invalid arguments", "[relay_chn][core]") // 1. Test with NULL gpio_map TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(NULL, gpio_count)); - // 2. Test with incorrect gpio_count (must be RELAY_CHN_COUNT * 2) + // 2. Test with incorrect gpio_count (must be CONFIG_RELAY_CHN_COUNT * 2) TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, gpio_count - 1)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, 1)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, 0)); diff --git a/test_apps/main/test_relay_chn_core_single.c b/test_apps/main/test_relay_chn_core_single.c index b21823f..b1d58de 100644 --- a/test_apps/main/test_relay_chn_core_single.c +++ b/test_apps/main/test_relay_chn_core_single.c @@ -8,7 +8,7 @@ TEST_CASE("relay_chn_create handles invalid arguments", "[relay_chn][core]") // 1. Test with NULL gpio_map TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(NULL, gpio_count)); - // 2. Test with incorrect gpio_count (must be RELAY_CHN_COUNT * 2) + // 2. Test with incorrect gpio_count (must be CONFIG_RELAY_CHN_COUNT * 2) TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, gpio_count - 1)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, 1)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_create(gpio_map, 0)); diff --git a/test_apps/main/test_relay_chn_nvs_multi.c b/test_apps/main/test_relay_chn_nvs_multi.c index d591dbb..920e34d 100644 --- a/test_apps/main/test_relay_chn_nvs_multi.c +++ b/test_apps/main/test_relay_chn_nvs_multi.c @@ -41,7 +41,7 @@ TEST_CASE("Test invalid parameters", "[relay_chn][nvs]") TEST_ESP_OK(relay_chn_nvs_init()); // Test NULL pointer for all channels - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_nvs_get_direction(channel, NULL)); } @@ -54,13 +54,13 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]") // Store some test data first relay_chn_direction_t direction = RELAY_CHN_DIRECTION_FLIPPED; - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { TEST_ESP_OK(relay_chn_nvs_set_direction(0, direction)); } -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING uint8_t sensitivity = 50; - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(0, sensitivity)); TEST_ESP_OK(relay_chn_nvs_set_tilt_count(0, 100)); } @@ -73,7 +73,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]") relay_chn_direction_t read_direction; TEST_ASSERT_EQUAL(ESP_ERR_NVS_NOT_FOUND, relay_chn_nvs_get_direction(0, &read_direction)); -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING uint8_t read_sensitivity; TEST_ASSERT_EQUAL(ESP_ERR_NVS_NOT_FOUND, relay_chn_nvs_get_tilt_sensitivity(0, &read_sensitivity)); @@ -101,7 +101,7 @@ TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]") } #endif -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]") { TEST_ESP_OK(relay_chn_nvs_init()); @@ -110,7 +110,7 @@ TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]") uint8_t sensitivity; // Test all channels - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(channel, test_sensitivity)); TEST_ESP_OK(relay_chn_nvs_get_tilt_sensitivity(channel, &sensitivity)); TEST_ASSERT_EQUAL(test_sensitivity, sensitivity); @@ -127,7 +127,7 @@ TEST_CASE("Test tilt counter operations", "[relay_chn][nvs][tilt]") uint16_t tilt_count_read; // Test all channels - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { // Test setting counters TEST_ESP_OK(relay_chn_nvs_set_tilt_count(channel, tilt_count)); TEST_ESP_OK(relay_chn_nvs_get_tilt_count(channel, &tilt_count_read)); @@ -142,11 +142,11 @@ TEST_CASE("Test tilting invalid parameters", "[relay_chn][nvs][tilt]") TEST_ESP_OK(relay_chn_nvs_init()); // Test NULL pointers for all channels - for (int channel = 0; channel < RELAY_CHN_COUNT; channel++) { + for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) { TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_nvs_get_tilt_sensitivity(channel, NULL)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, relay_chn_nvs_get_tilt_count(channel, NULL)); } TEST_ESP_OK(relay_chn_nvs_deinit()); } -#endif // RELAY_CHN_ENABLE_TILTING \ No newline at end of file +#endif // CONFIG_RELAY_CHN_ENABLE_TILTING \ No newline at end of file diff --git a/test_apps/main/test_relay_chn_nvs_single.c b/test_apps/main/test_relay_chn_nvs_single.c index 2872d5c..3bb2921 100644 --- a/test_apps/main/test_relay_chn_nvs_single.c +++ b/test_apps/main/test_relay_chn_nvs_single.c @@ -53,7 +53,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]") relay_chn_direction_t direction = RELAY_CHN_DIRECTION_FLIPPED; TEST_ESP_OK(relay_chn_nvs_set_direction(0, direction)); -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING uint8_t sensitivity = 50; TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(0, sensitivity)); TEST_ESP_OK(relay_chn_nvs_set_tilt_count(0, 100)); @@ -66,7 +66,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]") relay_chn_direction_t read_direction; TEST_ASSERT_EQUAL(ESP_ERR_NVS_NOT_FOUND, relay_chn_nvs_get_direction(0, &read_direction)); -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING uint8_t read_sensitivity; TEST_ASSERT_EQUAL(ESP_ERR_NVS_NOT_FOUND, relay_chn_nvs_get_tilt_sensitivity(0, &read_sensitivity)); @@ -93,7 +93,7 @@ TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]") } #endif -#ifdef RELAY_CHN_ENABLE_TILTING +#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]") { TEST_ESP_OK(relay_chn_nvs_init()); @@ -134,4 +134,4 @@ TEST_CASE("Test tilting invalid parameters", "[relay_chn][nvs][tilt]") TEST_ESP_OK(relay_chn_nvs_deinit()); } -#endif // RELAY_CHN_ENABLE_TILTING \ No newline at end of file +#endif // CONFIG_RELAY_CHN_ENABLE_TILTING \ No newline at end of file