opt/1085-optimization-and-cleanup #37

Merged
ismail merged 36 commits from opt/1085-optimization-and-cleanup into dev 2025-09-05 10:05:42 +02:00
17 changed files with 77 additions and 77 deletions
Showing only changes of commit 6ff16b5797 - Show all commits

View File

@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the specified channel
*
@@ -171,7 +171,7 @@ void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec);
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
/**
* @brief Enables automatic tilting for the specified relay channel.
@@ -299,7 +299,7 @@ void relay_chn_flip_direction(void);
*/
relay_chn_direction_t relay_chn_get_direction(void);
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the channel
*
@@ -323,7 +323,7 @@ void relay_chn_set_run_limit(uint16_t time_sec);
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
/**
* @brief Enables automatic tilting for the relay channel.

View File

@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the specified channel
*
@@ -209,7 +209,7 @@ static inline relay_chn_direction_t relay_chn_get_direction(void)
return relay_chn_ctl_get_direction();
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the channel
*

View File

@@ -33,7 +33,7 @@ typedef enum relay_chn_state_enum {
RELAY_CHN_STATE_REVERSE, /*!< The relay channel is running in the reverse direction */
RELAY_CHN_STATE_FORWARD_PENDING, /*!< The relay channel is pending to run in the forward direction */
RELAY_CHN_STATE_REVERSE_PENDING, /*!< The relay channel is pending to run in the reverse direction */
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
RELAY_CHN_STATE_TILT_FORWARD, /*!< The relay channel is tilting for forward */
RELAY_CHN_STATE_TILT_REVERSE, /*!< The relay channel is tilting for reverse */
#endif

View File

@@ -28,7 +28,7 @@ extern "C" {
*/
esp_err_t relay_chn_init_timer(relay_chn_ctl_t *chn_ctl);
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Initializes the relay channel run limit timer.
*

View File

@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Store relay channel run limit in NVS.
*
@@ -65,7 +65,7 @@ esp_err_t relay_chn_nvs_set_run_limit(uint8_t ch, uint16_t time_sec);
esp_err_t relay_chn_nvs_get_run_limit(uint8_t ch, uint16_t *time_sec);
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if CONFIG_RELAY_CHN_ENABLE_TILTING
/**
* @brief Store tilt sensitivity in NVS.
*

View File

@@ -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 CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
/// @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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
esp_timer_handle_t run_limit_timer; /*!< Timer to handle the run limit */
uint16_t run_limit_sec; /*!< Run limit in seconds */
#endif
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
relay_chn_tilt_ctl_t *tilt_ctl; /*!< Pointer to the tilt control structure if tilting is enabled */
#endif
} relay_chn_ctl_t;

View File

@@ -12,11 +12,11 @@
#include "relay_chn_run_info.h"
#include "relay_chn_ctl.h"
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
#include "relay_chn_tilt.h"
#endif
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/*
* 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
ret = relay_chn_nvs_init();
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize NVS for relay channel");
#endif
@@ -114,7 +114,7 @@ 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 CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
// Initialize the tilt feature
#if CONFIG_RELAY_CHN_COUNT > 1
relay_chn_ctl_t *chn_ctls = relay_chn_ctl_get_all();
@@ -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 CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
relay_chn_tilt_deinit();
#endif
relay_chn_ctl_deinit();
relay_chn_output_deinit();
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
relay_chn_nvs_deinit();
#endif
@@ -369,7 +369,7 @@ void relay_chn_issue_cmd(relay_chn_ctl_t* chn_ctl, relay_chn_cmd_t cmd)
relay_chn_start_esp_timer_once(chn_ctl->inertia_timer, CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS);
break;
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
case RELAY_CHN_STATE_TILT_FORWARD:
// Terminate tilting first
relay_chn_tilt_dispatch_cmd(chn_ctl->tilt_ctl, RELAY_CHN_TILT_CMD_STOP);
@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
esp_timer_stop(chn_ctl->run_limit_timer);
#endif
@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
relay_chn_start_esp_timer_once(chn_ctl->run_limit_timer, chn_ctl->run_limit_sec * 1000);
#endif
}
@@ -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 CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
// 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 CONFIG_RELAY_CHN_ENABLE_TILTING == 1
#if CONFIG_RELAY_CHN_ENABLE_TILTING
case RELAY_CHN_STATE_TILT_FORWARD:
return "TILT_FORWARD";
case RELAY_CHN_STATE_TILT_REVERSE:

View File

@@ -10,7 +10,7 @@
#include "relay_chn_ctl.h"
#include "relay_chn_output.h"
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#include "relay_chn_nvs.h"
#endif
@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
uint16_t run_limit_sec = CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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) {
@@ -61,7 +61,7 @@ void relay_chn_ctl_deinit()
esp_timer_delete(chn_ctl->inertia_timer);
chn_ctl->inertia_timer = NULL;
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
if (chn_ctl->run_limit_timer != NULL) {
esp_timer_delete(chn_ctl->run_limit_timer);
chn_ctl->run_limit_timer = NULL;
@@ -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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
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) {
@@ -171,7 +171,7 @@ void relay_chn_ctl_set_run_limit(uint8_t chn_id, uint16_t time_sec)
chn_ctls[chn_id].run_limit_sec = time_sec;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
relay_chn_nvs_set_run_limit(chn_id, time_sec);
#endif
}

View File

@@ -10,7 +10,7 @@
#include "relay_chn_ctl.h"
#include "relay_chn_output.h"
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
uint16_t run_limit_sec = CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC;
esp_err_t ret;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
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 CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
uint16_t relay_chn_ctl_get_run_limit()
{
return chn_ctl.run_limit_sec;
@@ -111,7 +111,7 @@ void relay_chn_ctl_set_run_limit(uint16_t time_sec)
chn_ctl.run_limit_sec = time_sec;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
relay_chn_nvs_set_run_limit(chn_ctl.id, time_sec);
#endif
}

View File

@@ -8,10 +8,10 @@
#include "relay_chn_nvs.h"
#define RELAY_CHN_KEY_DIR "dir" /*!< Direction key */
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
#define RELAY_CHN_KEY_RLIM(ch) "rlim_%d" /*!< Run limit key */
#endif
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if 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,7 +23,7 @@ static nvs_handle_t relay_chn_nvs;
esp_err_t relay_chn_nvs_init()
{
esp_err_t ret;
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION
ret = nvs_open_from_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME,
CONFIG_RELAY_CHN_NVS_NAMESPACE,
NVS_READWRITE,
@@ -72,7 +72,7 @@ esp_err_t relay_chn_nvs_get_direction(uint8_t ch, relay_chn_direction_t *directi
return ESP_OK;
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
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);
@@ -88,7 +88,7 @@ esp_err_t relay_chn_nvs_get_run_limit(uint8_t ch, uint16_t *time_sec)
}
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if 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);

View File

@@ -10,7 +10,7 @@
#include "relay_chn_output.h"
#include "relay_chn_core.h"
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#include "relay_chn_nvs.h"
#endif
@@ -73,7 +73,7 @@ static esp_err_t relay_chn_output_ctl_init(relay_chn_output_t *output,
return ESP_OK;
}
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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);
@@ -101,7 +101,7 @@ esp_err_t relay_chn_output_init(const uint8_t* gpio_map, uint8_t gpio_count)
gpio_num_t reverse_pin = (gpio_num_t) gpio_map[gpio_index + 1];
relay_chn_direction_t direction = RELAY_CHN_DIRECTION_DEFAULT;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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);
@@ -194,7 +194,7 @@ void relay_chn_output_flip(relay_chn_output_t *output)
? RELAY_CHN_DIRECTION_FLIPPED
: RELAY_CHN_DIRECTION_DEFAULT;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
uint8_t ch = 0;
#if CONFIG_RELAY_CHN_COUNT > 1
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {

View File

@@ -10,7 +10,7 @@
#include "relay_chn_run_info.h"
#include "relay_chn_tilt.h"
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#include "relay_chn_nvs.h"
#define RELAY_CHN_TILT_FLUSH_DEBOUNCE_MS 3000
@@ -63,7 +63,7 @@ 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
esp_timer_handle_t flush_timer; /*!< Flush timer to avoid frequent write of tilt counters */
#endif
} relay_chn_tilt_ctl_t;
@@ -330,7 +330,7 @@ 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
relay_chn_nvs_set_tilt_sensitivity(chn_id, sensitivity);
#endif // CONFIG_RELAY_CHN_ENABLE_NVS
}
@@ -365,7 +365,7 @@ void relay_chn_tilt_set_sensitivity(uint8_t sensitivity)
{
relay_chn_tilt_compute_set_sensitivity(&tilt_ctl, sensitivity);
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
relay_chn_nvs_set_tilt_sensitivity(0, sensitivity);
#endif // CONFIG_RELAY_CHN_ENABLE_NVS
}
@@ -380,7 +380,7 @@ void relay_chn_tilt_reset_count(relay_chn_tilt_ctl_t *tilt_ctl)
{
tilt_ctl->tilt_count = 0;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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);
@@ -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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// 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;
@@ -666,7 +666,7 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls)
#if CONFIG_RELAY_CHN_COUNT > 1
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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);
@@ -682,7 +682,7 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls)
#else
sensitivity = RELAY_CHN_TILT_DEFAULT_SENSITIVITY;
tilt_count = 0;
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
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);
@@ -698,7 +698,7 @@ 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 CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
if (tilt_ctl->flush_timer != NULL) {
esp_timer_delete(tilt_ctl->flush_timer);
tilt_ctl->flush_timer = NULL;

View File

@@ -7,7 +7,7 @@
#include "unity_test_runner.h"
#include "test_common.h"
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
#include "nvs_flash.h"
#include "relay_chn_nvs.h"
#endif
@@ -28,11 +28,11 @@ void tearDown()
reset_channels_to_idle_state();
}
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
static void test_nvs_flash_init(void)
{
esp_err_t ret;
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION
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) {
@@ -57,11 +57,11 @@ TEST_ESP_OK(ret);
}
#endif
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
static void test_nvs_flash_deinit(void)
{
esp_err_t ret;
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION == 1
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION
ret = nvs_flash_deinit_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME);
#else
ret = nvs_flash_deinit();
@@ -72,7 +72,7 @@ static void test_nvs_flash_deinit(void)
void app_main(void)
{
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// Init NVS once for all tests
test_nvs_flash_init();
#endif
@@ -98,7 +98,7 @@ void app_main(void)
// Destroy relay_chn
relay_chn_destroy();
#if CONFIG_RELAY_CHN_ENABLE_NVS == 1
#if CONFIG_RELAY_CHN_ENABLE_NVS
// Deinit NVS
test_nvs_flash_deinit();
#endif

View File

@@ -344,7 +344,7 @@ TEST_CASE("Direction flip handles invalid channel ID gracefully", "[relay_chn][c
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(invalid_ch));
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
#define TEST_RUN_LIMIT_SEC 5
#define TEST_SHORT_RUN_LIMIT_SEC 2
// ### Run Limit Tests

View File

@@ -173,7 +173,7 @@ TEST_CASE("Flipping a running channel stops it and flips direction", "[relay_chn
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_FLIPPED, relay_chn_get_direction());
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
#define TEST_RUN_LIMIT_SEC 5
#define TEST_SHORT_RUN_LIMIT_SEC 2
// ### Run Limit Tests

View File

@@ -58,7 +58,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]")
TEST_ESP_OK(relay_chn_nvs_set_direction(0, direction));
}
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if CONFIG_RELAY_CHN_ENABLE_TILTING
uint8_t sensitivity = 50;
for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) {
TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(0, sensitivity));
@@ -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 CONFIG_RELAY_CHN_ENABLE_TILTING
#if 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));
@@ -84,7 +84,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]")
TEST_ESP_OK(relay_chn_nvs_deinit());
}
#ifdef CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]")
{
TEST_ESP_OK(relay_chn_nvs_init());
@@ -101,7 +101,7 @@ TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]")
}
#endif
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if CONFIG_RELAY_CHN_ENABLE_TILTING
TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]")
{
TEST_ESP_OK(relay_chn_nvs_init());

View File

@@ -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 CONFIG_RELAY_CHN_ENABLE_TILTING
#if 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 CONFIG_RELAY_CHN_ENABLE_TILTING
#if 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));
@@ -77,7 +77,7 @@ TEST_CASE("Test relay_chn_nvs_erase_all", "[relay_chn][nvs]")
TEST_ESP_OK(relay_chn_nvs_deinit());
}
#ifdef CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]")
{
TEST_ESP_OK(relay_chn_nvs_init());
@@ -93,7 +93,7 @@ TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]")
}
#endif
#ifdef CONFIG_RELAY_CHN_ENABLE_TILTING
#if CONFIG_RELAY_CHN_ENABLE_TILTING
TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]")
{
TEST_ESP_OK(relay_chn_nvs_init());