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:
@@ -146,6 +146,33 @@ void relay_chn_flip_direction(uint8_t chn_id);
|
||||
*/
|
||||
relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id);
|
||||
|
||||
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
/**
|
||||
* @brief Get the run limit for the specified channel
|
||||
*
|
||||
* @param chn_id The ID of the relay channel to query.
|
||||
*
|
||||
* @return The run limit value for the relevant channel if the channel ID is valid.
|
||||
* 0 if the channel ID is invalid.
|
||||
*/
|
||||
uint16_t relay_chn_get_run_limit(uint8_t chn_id);
|
||||
|
||||
/**
|
||||
* @brief Set the run limit for the specified channel
|
||||
*
|
||||
* Sets the time limit in seconds for the specified channel. It will not proceed
|
||||
* if the channel ID is invalid.
|
||||
* If the time_sec value is lesser than the CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC,
|
||||
* the value will be set to CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC.
|
||||
* If the time_sec value is greater than the CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC,
|
||||
* the value will be set to CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC.
|
||||
*
|
||||
* @param chn_id The ID of the relay channel to query.
|
||||
* @param time_sec The run limit time in seconds.
|
||||
*/
|
||||
void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec);
|
||||
#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
|
||||
|
||||
@@ -275,6 +302,29 @@ void relay_chn_flip_direction(void);
|
||||
*/
|
||||
relay_chn_direction_t relay_chn_get_direction(void);
|
||||
|
||||
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
/**
|
||||
* @brief Get the run limit for the channel
|
||||
*
|
||||
* @return The run limit value for the channel.
|
||||
*/
|
||||
uint16_t relay_chn_get_run_limit(void);
|
||||
|
||||
/**
|
||||
* @brief Set the run limit for the channel
|
||||
*
|
||||
* Sets the time limit in seconds for the channel. It will not proceed
|
||||
* if the channel ID is invalid.
|
||||
* If the time_sec value is lesser than the CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC,
|
||||
* the value will be set to CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC.
|
||||
* If the time_sec value is greater than the CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC,
|
||||
* the value will be set to CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC.
|
||||
*
|
||||
* @param time_sec The run limit time in seconds.
|
||||
*/
|
||||
void relay_chn_set_run_limit(uint16_t time_sec);
|
||||
#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
|
||||
|
||||
#if CONFIG_RELAY_CHN_ENABLE_TILTING == 1
|
||||
|
||||
|
||||
@@ -101,6 +101,36 @@ static inline relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id)
|
||||
return relay_chn_ctl_get_direction(chn_id);
|
||||
}
|
||||
|
||||
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
/**
|
||||
* @brief Get the run limit for the specified channel
|
||||
*
|
||||
* @param chn_id The ID of the relay channel to query.
|
||||
*
|
||||
* @return The run limit value for the relevant channel if the channel ID is valid.
|
||||
* 0 if the channel ID is invalid.
|
||||
*/
|
||||
extern uint16_t relay_chn_ctl_get_run_limit(uint8_t chn_id);
|
||||
|
||||
/**
|
||||
* @brief Set the run limit for the specified channel
|
||||
*
|
||||
* @param chn_id The ID of the relay channel to query.
|
||||
* @param time_sec The run limit time in seconds.
|
||||
*/
|
||||
extern void relay_chn_ctl_set_run_limit(uint8_t chn_id, uint16_t time_sec);
|
||||
|
||||
static inline uint16_t relay_chn_get_run_limit(uint8_t chn_id)
|
||||
{
|
||||
return relay_chn_ctl_get_run_limit(chn_id);
|
||||
}
|
||||
|
||||
static inline void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec)
|
||||
{
|
||||
relay_chn_ctl_set_run_limit(chn_id, time_sec);
|
||||
}
|
||||
#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
@@ -179,6 +209,32 @@ static inline relay_chn_direction_t relay_chn_get_direction(void)
|
||||
return relay_chn_ctl_get_direction();
|
||||
}
|
||||
|
||||
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
/**
|
||||
* @brief Get the run limit for the channel
|
||||
*
|
||||
* @return The run limit value for the channel.
|
||||
*/
|
||||
extern uint16_t relay_chn_ctl_get_run_limit(void);
|
||||
|
||||
/**
|
||||
* @brief Set the run limit for the channel
|
||||
*
|
||||
* @param time_sec The run limit time in seconds.
|
||||
*/
|
||||
extern void relay_chn_ctl_set_run_limit(uint16_t time_sec);
|
||||
|
||||
static inline uint16_t relay_chn_get_run_limit(void)
|
||||
{
|
||||
return relay_chn_ctl_get_run_limit();
|
||||
}
|
||||
|
||||
static inline void relay_chn_set_run_limit(uint16_t time_sec)
|
||||
{
|
||||
relay_chn_ctl_set_run_limit(time_sec);
|
||||
}
|
||||
#endif // RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
|
||||
#endif // RELAY_CHN_COUNT > 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -15,6 +15,7 @@ extern "C" {
|
||||
#define RELAY_CHN_COUNT CONFIG_RELAY_CHN_COUNT
|
||||
#define RELAY_CHN_ENABLE_TILTING CONFIG_RELAY_CHN_ENABLE_TILTING
|
||||
#define RELAY_CHN_ENABLE_NVS CONFIG_RELAY_CHN_ENABLE_NVS
|
||||
#define RELAY_CHN_ENABLE_RUN_LIMIT CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
|
||||
|
||||
#if RELAY_CHN_ENABLE_NVS == 1
|
||||
#define RELAY_CHN_NVS_NAMESPACE CONFIG_RELAY_CHN_NVS_NAMESPACE
|
||||
@@ -28,6 +29,12 @@ extern "C" {
|
||||
#define RELAY_CHN_ID_ALL RELAY_CHN_COUNT /*!< Special ID to address all channels */
|
||||
#endif
|
||||
|
||||
#if RELAY_CHN_ENABLE_RUN_LIMIT == 1
|
||||
#define RELAY_CHN_RUN_LIMIT_MIN_SEC CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC
|
||||
#define RELAY_CHN_RUN_LIMIT_MAX_SEC CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC
|
||||
#define RELAY_CHN_RUN_LIMIT_DEFAULT_SEC CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user