Implement specific *all functions

Specific `_*all` and `_*all_with` functions were implemented to make
the API more concise and clean, and to replace the use of
`RELAY_CHN_ID_ALL`, which caused confusion within the API.

Refs #1085
This commit is contained in:
2025-08-25 18:50:21 +03:00
parent be4a2ebef6
commit 3831384169
14 changed files with 578 additions and 221 deletions

View File

@@ -180,22 +180,22 @@ For multi mode
// Run channel #0 forward
relay_chn_run_forward(0);
// Run all channels forward
relay_chn_run_forward(RELAY_CHN_ID_ALL);
relay_chn_run_forward_all();
// Run channel #1 reverse
relay_chn_run_reverse(1);
// Run all channels reverse
relay_chn_run_reverse(RELAY_CHN_ID_ALL);
relay_chn_run_reverse_all();
// Stop channel #1
relay_chn_stop(1);
// Stop all channels
relay_chn_stop(RELAY_CHN_ID_ALL);
relay_chn_stop_all();
// Flip direction of channel #0
relay_chn_flip_direction(0);
// Flip direction of all channels
relay_chn_flip_direction(RELAY_CHN_ID_ALL);
relay_chn_flip_direction_all();
```
### 3. Monitor channel state
@@ -227,12 +227,21 @@ For multi mode:
```c
// Get channel #0 state
relay_chn_state_t state = relay_chn_get_state(0);
// Get states for all channels
relay_chn_state_t states[CONFIG_RELAY_CHN_COUNT];
relay_chn_get_states(states);
// Get the string representation of the state of the channel #0
char *state_str = relay_chn_get_state_str(0);
// Get channel #0 direction
relay_chn_direction_t direction = relay_chn_get_direction(0);
// Get directions for all channels
relay_chn_direction_t directions[CONFIG_RELAY_CHN_COUNT];
relay_chn_get_directions(directions);
/* The listener is same for multi mode */
```
@@ -261,7 +270,11 @@ 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
relay_chn_set_run_limit_all_with(90); // Set all channels to 90 seconds
// Assuming the CONFIG_RELAY_CHN_COUNT is 4
uint16_t limits_sec[CONFIG_RELAY_CHN_COUNT] = { 30, 35, 40, 45 };
relay_chn_set_run_limit_all(limits_sec); // Set all channels according to the array
```
> [!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.
@@ -286,7 +299,7 @@ relay_chn_tilt_reverse();
relay_chn_tilt_stop();
// Set tilting sensitivity (sensitivity as percentage)
relay_chn_tilt_sensitivity_set(90);
relay_chn_tilt_set_sensitivity(90);
// Get tilting sensitivity (sensitivty as percentage)
uint8_t sensitivity = relay_chn_tilt_get_sensitivity();
@@ -299,27 +312,34 @@ For multi mode:
// Start tilting automatically on channel #0
relay_chn_tilt_auto(0);
relay_chn_tilt_auto(RELAY_CHN_ID_ALL); // on all channels
relay_chn_tilt_auto_all(); // on all channels
// Tilt forward on channel #1
relay_chn_tilt_forward(1);
relay_chn_tilt_forward(RELAY_CHN_ID_ALL);
relay_chn_tilt_forward_all();
// Tilt reverse on channel #2
relay_chn_tilt_reverse(2);
relay_chn_tilt_reverse(RELAY_CHN_ID_ALL);
relay_chn_tilt_reverse_all();
// Stop tilting on channel #0
relay_chn_tilt_stop(0);
relay_chn_tilt_stop(RELAY_CHN_ID_ALL);
relay_chn_tilt_stop_all();
// Set tilting sensitivity (sensitivity as percentage) for channel #0
relay_chn_tilt_sensitivity_set(0, 90);
relay_chn_tilt_sensitivity_set(RELAY_CHN_ID_ALL, 90);
relay_chn_tilt_set_sensitivity(0, 90);
relay_chn_tilt_set_sensitivity_all_with(90);
// Assuming the CONFIG_RELAY_CHN_COUNT is 4
uint8_t sensitivities[CONFIG_RELAY_CHN_COUNT] = { 90, 85, 80, 75 };
relay_chn_tilt_set_sensitivity_all(sensitivity); // Set all channels according to the array
// Get tilt sensitivity for channel #0
uint8_t sensitivity = relay_chn_tilt_get_sensitivity(0);
// Get tilting sensitivity (sensitivty as percentage)
uint8_t sensitivity;
relay_chn_tilt_get_sensitivity(0, &sensitivity, sizeof(sensitivity));
uint8_t sensitivities[CONFIG_RELAY_CHN_COUNT];
relay_chn_tilt_get_sensitivity_all(sensitivities);
```
## License