General code and comment cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ static const char *TAG = "RELAY_CHN_TILT";
|
||||
/**@{*/
|
||||
/*
|
||||
* Tilt Pattern Timing Definitions
|
||||
*
|
||||
*
|
||||
* The min and max timing definitions as well as the default timing definitions.
|
||||
* These definitions are used to define and adjust the tilt sensitivity.
|
||||
*/
|
||||
@@ -85,7 +85,7 @@ static uint32_t relay_chn_tilt_get_required_timing_before_tilting(relay_chn_tilt
|
||||
return 0;
|
||||
else if (cmd == RELAY_CHN_TILT_CMD_REVERSE && last_run_cmd == RELAY_CHN_CMD_FORWARD)
|
||||
return 0;
|
||||
|
||||
|
||||
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 CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS - inertia_time_passed_ms;
|
||||
@@ -115,13 +115,13 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t
|
||||
relay_chn_tilt_dispatch_cmd(tilt_ctl, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (relay_chn_run_info_get_last_run_cmd(tilt_ctl->chn_ctl->run_info) == RELAY_CHN_CMD_NONE) {
|
||||
// Do not tilt if the channel hasn't been run before
|
||||
ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: Tilt will not be executed since the channel hasn't been run yet");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (tilt_ctl->cmd == cmd) {
|
||||
ESP_LOGD(TAG, "relay_chn_tilt_issue_cmd: There is already a tilt command in progress!");
|
||||
return;
|
||||
@@ -134,7 +134,7 @@ static void relay_chn_tilt_issue_cmd(relay_chn_tilt_ctl_t *tilt_ctl, relay_chn_t
|
||||
// Relay channel is free, tilt can be issued immediately
|
||||
relay_chn_tilt_dispatch_cmd(tilt_ctl, cmd);
|
||||
break;
|
||||
|
||||
|
||||
case RELAY_CHN_STATE_FORWARD_PENDING:
|
||||
case RELAY_CHN_STATE_REVERSE_PENDING:
|
||||
// Issue a stop command first so that the timer and pending cmd get cleared
|
||||
@@ -322,7 +322,7 @@ static void relay_chn_tilt_compute_set_sensitivity(relay_chn_tilt_ctl_t *tilt_ct
|
||||
uint32_t tilt_run_time_ms = 0, tilt_pause_time_ms = 0;
|
||||
tilt_run_time_ms = RELAY_CHN_TILT_RUN_MIN_MS + (sensitivity * (RELAY_CHN_TILT_RUN_MAX_MS - RELAY_CHN_TILT_RUN_MIN_MS) / 100);
|
||||
tilt_pause_time_ms = RELAY_CHN_TILT_PAUSE_MIN_MS + (sensitivity * (RELAY_CHN_TILT_PAUSE_MAX_MS - RELAY_CHN_TILT_PAUSE_MIN_MS) / 100);
|
||||
|
||||
|
||||
relay_chn_tilt_set_timing_values(&tilt_ctl->tilt_timing,
|
||||
sensitivity,
|
||||
tilt_run_time_ms,
|
||||
@@ -336,7 +336,7 @@ void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity)
|
||||
if (relay_chn_is_channel_id_valid(chn_id)) {
|
||||
ADJUST_TILT_SENS_BOUNDARIES(sensitivity);
|
||||
relay_chn_tilt_compute_set_sensitivity(&tilt_ctls[chn_id], sensitivity);
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
relay_chn_nvs_set_tilt_sensitivity(chn_id, sensitivity);
|
||||
#endif // CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
@@ -346,7 +346,7 @@ void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity)
|
||||
esp_err_t relay_chn_tilt_set_sensitivity_all(uint8_t *sensitivities)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(sensitivities != NULL, ESP_ERR_INVALID_ARG, TAG, "set_sensitivity_all: sensitivities is NULL");
|
||||
|
||||
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
uint8_t *src_sensitivity = &sensitivities[i];
|
||||
if (src_sensitivity == NULL) {
|
||||
@@ -382,7 +382,7 @@ uint8_t relay_chn_tilt_get_sensitivity(uint8_t chn_id)
|
||||
esp_err_t relay_chn_tilt_get_sensitivity_all(uint8_t *sensitivities)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(sensitivities != NULL, ESP_ERR_INVALID_ARG, TAG, "get_sensitivity_all: sensitivities is NULL");
|
||||
|
||||
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
uint8_t *dest_sensitivity = &sensitivities[i];
|
||||
if (dest_sensitivity == NULL) {
|
||||
@@ -400,7 +400,7 @@ void relay_chn_tilt_set_sensitivity(uint8_t sensitivity)
|
||||
{
|
||||
ADJUST_TILT_SENS_BOUNDARIES(sensitivity);
|
||||
relay_chn_tilt_compute_set_sensitivity(&tilt_ctl, sensitivity);
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
relay_chn_nvs_set_tilt_sensitivity(0, sensitivity);
|
||||
#endif // CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
@@ -423,25 +423,25 @@ void relay_chn_tilt_reset_count(relay_chn_tilt_ctl_t *tilt_ctl)
|
||||
|
||||
/**
|
||||
* @brief Update tilt count automatically and return the current value.
|
||||
*
|
||||
*
|
||||
* This helper function updates the relevant tilt count depending on the
|
||||
* last run info and helps the tilt module in deciding whether the requested
|
||||
* tilt should execute or not.
|
||||
*
|
||||
*
|
||||
* This is useful to control reverse tilting for the same direction particularly.
|
||||
* For example:
|
||||
* - If the channel's last run was FORWARD and a TILT_FORWARD is requested,
|
||||
* then the tilt count will count up on the relay_chn_tilt_ctl_t::tilt_count
|
||||
* then the tilt count will count up on the relay_chn_tilt_ctl_t::tilt_count
|
||||
* and the function will return the actual count.
|
||||
* - If the channel's last run was FORWARD and a TILT_REVERSE is requested,
|
||||
* then the relay_chn_tilt_ctl_t::tilt_count will be checked against zero first,
|
||||
* and then it will count down and return the actual count if it is greater
|
||||
* then the relay_chn_tilt_ctl_t::tilt_count will be checked against zero first,
|
||||
* and then it will count down and return the actual count if it is greater
|
||||
* than 0, else the function will return 0.
|
||||
* - If the tilt command is irrelevant then the function will return 0.
|
||||
* - If the last run is irrelevant then the function will return 0.
|
||||
*
|
||||
*
|
||||
* @param tilt_ctl The relay channel handle.
|
||||
*
|
||||
*
|
||||
* @return The actual value of the relevant count.
|
||||
* @return 1 if the last tilt_count was 1 and decremented to 0.
|
||||
* @return 0 if:
|
||||
@@ -612,7 +612,7 @@ static void relay_chn_tilt_timer_cb(void *arg)
|
||||
{
|
||||
relay_chn_tilt_ctl_t* tilt_ctl = (relay_chn_tilt_ctl_t*) arg;
|
||||
ESP_RETURN_VOID_ON_FALSE(tilt_ctl != NULL, TAG, "relay_chn_tilt_timer_cb: timer arg is NULL");
|
||||
|
||||
|
||||
switch (tilt_ctl->step)
|
||||
{
|
||||
case RELAY_CHN_TILT_STEP_MOVE:
|
||||
@@ -632,7 +632,7 @@ static void relay_chn_tilt_timer_cb(void *arg)
|
||||
// Just dispatch the pending tilt command
|
||||
relay_chn_tilt_dispatch_cmd(tilt_ctl, tilt_ctl->cmd);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -667,7 +667,7 @@ static esp_err_t relay_chn_tilt_ctl_init(relay_chn_tilt_ctl_t *tilt_ctl,
|
||||
|
||||
tilt_ctl->chn_ctl = chn_ctl;
|
||||
tilt_ctl->chn_ctl->tilt_ctl = tilt_ctl;
|
||||
|
||||
|
||||
// Create tilt timer for the channel
|
||||
char timer_name[32];
|
||||
snprintf(timer_name, sizeof(timer_name), "relay_chn_%2d_tilt_timer", chn_ctl->id);
|
||||
@@ -694,7 +694,7 @@ esp_err_t relay_chn_tilt_init(relay_chn_ctl_t *chn_ctls)
|
||||
{
|
||||
uint8_t sensitivity;
|
||||
uint16_t tilt_count;
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_COUNT > 1
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
esp_err_t ret;
|
||||
|
||||
Reference in New Issue
Block a user