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
This commit is contained in:
2025-08-25 10:24:13 +03:00
parent 9d3f8ddbff
commit 5afefc4dc0
21 changed files with 186 additions and 207 deletions

View File

@@ -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
}