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:
43
README.md
43
README.md
@@ -13,17 +13,21 @@ An ESP-IDF component for controlling relay channels, specifically designed for d
|
||||
- State monitoring and reporting
|
||||
- Optional sensitivty adjustable tilting feature
|
||||
- Optional NVS storage for persistent configuration
|
||||
- Optional configurable run limit protection
|
||||
|
||||
## Description
|
||||
|
||||
Each relay channel consists of 2 output relays controlled by 2 GPIO pins. The component provides APIs to control these relay pairs while ensuring safe operation, particularly for driving bipolar motors. To prevent mechanical strain on the motor, the component automatically manages direction changes with a configurable inertia delay, protecting it from abrupt reversals. Hence, the component handles all the required timing between the movement transitions automatically to ensure reliable operation.
|
||||
|
||||
The run limit feature provides an additional layer of protection by automatically stopping channels after a configurable time period. This is particularly useful for motor-driven applications where continuous operation beyond a certain duration could cause damage or safety issues. Each channel can have its own run limit setting, and when enabled, the component will automatically stop the channel once it has been running for the specified duration.
|
||||
|
||||
It also provides an optional tilting interface per channel base. Tilting makes a channel move with a specific pattern moving with small steps at a time. Tilting is specifically designed for controlling some types of curtains that need to be adjusted to let enter specific amount of day light.
|
||||
Since it operates on relays, the switching frequency is limited to 10Hz which complies with the most of the general purpose relays' requirements. The minimum frequency is 2Hz and the duty cycle is about 10% in all ranges.
|
||||
|
||||
Another optional feature is NVS storage, which saves the configuration permanently across reboots of the device. These configurations are:
|
||||
|
||||
- Direction
|
||||
- Run limit duration
|
||||
- Tilt sensitivity
|
||||
- Last tilt position
|
||||
|
||||
@@ -33,9 +37,16 @@ Configure the component through menuconfig under "Relay Channel Driver Configura
|
||||
|
||||
- `CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS`: Time to wait before changing direction (200-1500ms, default: 800ms)
|
||||
- `CONFIG_RELAY_CHN_COUNT`: Number of relay channels (1-8, default: 1)
|
||||
- `CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT`: Enable run limit protection (default: n)
|
||||
- `CONFIG_RELAY_CHN_ENABLE_TILTING`: Enable tilting interface on all channels. (default: n)
|
||||
- `CONFIG_RELAY_CHN_ENABLE_NVS`: Enable persistent storage in NVS (default: n)
|
||||
|
||||
When run limit is enabled (`CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT`), the following configuration options become available:
|
||||
|
||||
- `CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC`: Minimum allowed run limit duration (1-60s, default: 10s)
|
||||
- `CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC`: Maximum allowed run limit duration (60-3600s, default: 600s)
|
||||
- `CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC`: Default run limit duration for channels (10-3600s, default: 60s)
|
||||
|
||||
When NVS storage is enabled (`CONFIG_RELAY_CHN_ENABLE_NVS`), additional configuration options become available:
|
||||
|
||||
- `CONFIG_RELAY_CHN_NVS_NAMESPACE`: NVS namespace for storing relay channel data (default: "relay_chn")
|
||||
@@ -225,7 +236,37 @@ relay_chn_direction_t direction = relay_chn_get_direction(0);
|
||||
/* The listener is same for multi mode */
|
||||
```
|
||||
|
||||
### 4. Tilting Interface (if enabled)
|
||||
### 4. Run Limit Control (if enabled)
|
||||
|
||||
For single mode:
|
||||
|
||||
```c
|
||||
// Assuming CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT is enabled
|
||||
|
||||
// Get current run limit (in seconds)
|
||||
uint16_t limit = relay_chn_get_run_limit();
|
||||
|
||||
// Set new run limit (in seconds)
|
||||
relay_chn_set_run_limit(120); // Set to 120 seconds
|
||||
```
|
||||
|
||||
For multi mode:
|
||||
|
||||
```c
|
||||
// Assuming CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT is enabled
|
||||
|
||||
// Get run limit for channel #0 (in seconds)
|
||||
uint16_t limit = relay_chn_get_run_limit(0);
|
||||
|
||||
// Set new run limit for specific channels (in seconds)
|
||||
relay_chn_set_run_limit(0, 120); // Set channel #0 to 120 seconds
|
||||
relay_chn_set_run_limit(1, 180); // Set channel #1 to 180 seconds
|
||||
relay_chn_set_run_limit(RELAY_CHN_ID_ALL, 90); // Set all channels to 90 seconds
|
||||
```
|
||||
> [!NOTE]
|
||||
> When a channel reaches its run limit, it will automatically stop. The run limit timer is reset whenever the channel starts running in either direction.
|
||||
|
||||
### 5. Tilting Interface (if enabled)
|
||||
|
||||
For single mode:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user