Add run limit feature for relay channels with NVS support

- Introduced configuration options for enabling run limits in Kconfig.
- Added APIs to get and set run limits for individual relay channels.
- Implemented run limit timer functionality to automatically stop channels.
- Updated NVS handling to store and retrieve run limit values.
- Enhanced documentation in README and code comments to reflect new feature.

Closes #1080
This commit is contained in:
2025-08-22 12:29:07 +03:00
parent 19d02836dd
commit 40633e03d8
13 changed files with 384 additions and 3 deletions

View File

@@ -33,6 +33,20 @@ ESP_EVENT_DECLARE_BASE(RELAY_CHN_CMD_EVENT);
*/
esp_err_t relay_chn_init_timer(relay_chn_ctl_t *chn_ctl);
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
/**
* @brief Initializes the relay channel run limit timer.
*
* This function creates a timer for the relay channel to handle run time limit.
* Required by *_ctl_* module.
*
* @param chn_ctl Pointer to the relay channel control structure.
*
* @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
/**
* @brief Issues a command to the relay channel.
*

View File

@@ -45,6 +45,26 @@ 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
/**
* @brief Store relay channel run limit in NVS.
*
* @param[in] ch Channel number.
* @param[in] direction Run limit value to store.
* @return ESP_OK on success, error code otherwise.
*/
esp_err_t relay_chn_nvs_set_run_limit(uint8_t ch, uint16_t time_sec);
/**
* @brief Retrieve relay channel run limit from NVS.
*
* @param[in] ch Channel number.
* @param[out] direction Pointer to store retrieved run limit value.
* @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
#ifdef RELAY_CHN_ENABLE_TILTING
/**
* @brief Store tilt sensitivity in NVS.

View File

@@ -68,6 +68,10 @@ 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
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
relay_chn_tilt_ctl_t *tilt_ctl; /*!< Pointer to the tilt control structure if tilting is enabled */
#endif