Fix config parameters check

Unnecessary `#if CONFIG_FOO == 1` checks were removed and the
statements were simplified to` #if CONFIG_FOO`.
`#ifdef CONFIG_FOO` statements were also changed to `#if CONFIG_FOO`
to keep the style as uniform as possible.

Refs #1085
This commit is contained in:
2025-08-25 10:56:01 +03:00
parent 5afefc4dc0
commit 6ff16b5797
17 changed files with 77 additions and 77 deletions

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;