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

@@ -14,7 +14,6 @@
#pragma once
#include "esp_err.h"
#include "relay_chn_defs.h"
#include "relay_chn_types.h"
#include "relay_chn_adapter.h"
@@ -75,6 +74,18 @@ void relay_chn_unregister_listener(relay_chn_state_listener_t listener);
*/
relay_chn_state_t relay_chn_get_state(uint8_t chn_id);
/**
* @brief Gets the current state of all relay channels.
*
* This function populates an array with the current states of all configured
* relay channels. The caller must ensure the `states` array is large enough
* to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param states Pointer to an array where the states will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `states` is NULL.
*/
esp_err_t relay_chn_ctl_get_state_all(relay_chn_state_t *states);
/**
* @brief Get the state string of the specified relay channel.
*
@@ -100,6 +111,14 @@ char *relay_chn_get_state_str(uint8_t chn_id);
*/
void relay_chn_run_forward(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to run in the forward direction.
*
* This function iterates through all configured relay channels and issues a command
* to each to move in the forward direction.
*/
void relay_chn_ctl_run_forward_all(void);
/**
* @brief Runs the relay channel in reverse.
*
@@ -109,6 +128,14 @@ void relay_chn_run_forward(uint8_t chn_id);
*/
void relay_chn_run_reverse(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to run in the reverse direction.
*
* This function iterates through all configured relay channels and issues a command
* to each to move in the reverse direction.
*/
void relay_chn_ctl_run_reverse_all(void);
/**
* @brief Stops the relay channel specified by the channel ID.
*
@@ -120,6 +147,14 @@ void relay_chn_run_reverse(uint8_t chn_id);
*/
void relay_chn_stop(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to stop.
*
* This function iterates through all configured relay channels and issues a command
* to each to stop any ongoing movement.
*/
void relay_chn_ctl_stop_all(void);
/**
* @brief Flips the direction of the specified relay channel.
*
@@ -131,6 +166,14 @@ void relay_chn_stop(uint8_t chn_id);
*/
void relay_chn_flip_direction(uint8_t chn_id);
/**
* @brief Flips the logical direction of all configured relay channels.
*
* This function iterates through all configured relay channels and swaps the
* physical GPIO pins assigned to the forward and reverse directions for each.
*/
void relay_chn_ctl_flip_direction_all(void);
/**
* @brief Get the direction of the specified relay channel.
*
@@ -143,6 +186,18 @@ void relay_chn_flip_direction(uint8_t chn_id);
*/
relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id);
/**
* @brief Gets the current logical direction of all configured relay channels.
*
* This function populates an array with the current logical directions of all
* configured relay channels. The caller must ensure the `directions` array is
* large enough to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param directions Pointer to an array where the directions will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `directions` is NULL.
*/
esp_err_t relay_chn_ctl_get_direction_all(relay_chn_direction_t *directions);
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the specified channel
@@ -154,6 +209,18 @@ relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id);
*/
uint16_t relay_chn_get_run_limit(uint8_t chn_id);
/**
* @brief Gets the configured run limits for all configured relay channels.
*
* This function populates an array with the run limits (in seconds) of all
* configured relay channels. The caller must ensure the `limits_sec` array is
* large enough to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param limits_sec Pointer to an array where the run limits will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `limits_sec` is NULL.
*/
esp_err_t relay_chn_ctl_get_run_limit_all(uint16_t *limits_sec);
/**
* @brief Set the run limit for the specified channel
*
@@ -168,6 +235,31 @@ uint16_t relay_chn_get_run_limit(uint8_t chn_id);
* @param time_sec The run limit time in seconds.
*/
void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec);
/**
* @brief Sets the run limits for all configured relay channels.
*
* This function iterates through all configured relay channels and sets their
* run limits based on the values provided in the `limits_sec` array. Each value
* will be clamped within the configured `RELAY_CHN_RUN_LIMIT_MIN_SEC` and
* `RELAY_CHN_RUN_LIMIT_MAX_SEC` boundaries. The new run limits are persisted
* in NVS if enabled.
*
* @param limits_sec Pointer to an array containing the desired run limits in seconds.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `limits_sec` is NULL.
*/
esp_err_t relay_chn_ctl_set_run_limit_all(uint16_t *limits_sec);
/**
* @brief Sets a single run limit value for all configured relay channels.
*
* This function sets the same `limit_sec` value for all configured relay channels.
* The value will be clamped within the configured `RELAY_CHN_RUN_LIMIT_MIN_SEC`
* and `RELAY_CHN_RUN_LIMIT_MAX_SEC` boundaries.
* @param limit_sec The desired run limit in seconds to apply to all channels.
* @return ESP_OK on success.
*/
esp_err_t relay_chn_ctl_set_run_limit_all_with(uint16_t limit_sec);
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
@@ -184,6 +276,14 @@ void relay_chn_set_run_limit(uint8_t chn_id, uint16_t time_sec);
*/
void relay_chn_tilt_auto(uint8_t chn_id);
/**
* @brief Initiates an automatic tilt operation for all configured relay channels.
*
* This function iterates through all configured relay channels and initiates an
* automatic tilt operation for each, based on their individual last run commands.
*/
void relay_chn_tilt_auto_all(void);
/**
* @brief Tilts the specified relay channel forward.
*
@@ -193,6 +293,11 @@ void relay_chn_tilt_auto(uint8_t chn_id);
*/
void relay_chn_tilt_forward(uint8_t chn_id);
/**
* @brief Initiates a forward tilt operation for all configured relay channels.
*/
void relay_chn_tilt_forward_all(void);
/**
* @brief Tilts the specified relay channel reverse.
*
@@ -202,6 +307,11 @@ void relay_chn_tilt_forward(uint8_t chn_id);
*/
void relay_chn_tilt_reverse(uint8_t chn_id);
/**
* @brief Initiates a reverse tilt operation for all configured relay channels.
*/
void relay_chn_tilt_reverse_all(void);
/**
* @brief Stops the tilting action on the specified relay channel.
*
@@ -211,6 +321,11 @@ void relay_chn_tilt_reverse(uint8_t chn_id);
*/
void relay_chn_tilt_stop(uint8_t chn_id);
/**
* @brief Stops any ongoing tilt operation for all configured relay channels.
*/
void relay_chn_tilt_stop_all(void);
/**
* @brief Sets the tilting sensitivity for the specified relay channel.
*
@@ -222,6 +337,33 @@ void relay_chn_tilt_stop(uint8_t chn_id);
*/
void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity);
/**
* @brief Sets the tilt sensitivity for all configured relay channels.
*
* This function sets the tilt sensitivity for each channel based on the values
* provided in the `sensitivities` array. Each sensitivity value (0-100%)
* determines the `move_time_ms` and `pause_time_ms` for tilt operations.
* The new sensitivities are persisted in NVS if enabled.
*
* @param sensitivities Pointer to an array containing the desired tilt sensitivities.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: When sensitivities parameter is NULL
*/
esp_err_t relay_chn_tilt_set_sensitivity_all(uint8_t *sensitivities);
/**
* @brief Sets a single tilt sensitivity value for all configured relay channels.
*
* This function sets the same `sensitivity` value for all configured relay channels.
* The sensitivity value (0-100%) determines the `move_time_ms` and `pause_time_ms`
* for tilt operations. The new sensitivities are persisted in NVS if enabled.
*
* @param sensitivity The desired tilt sensitivity in percentage (0-100) to apply to all channels.
*/
void relay_chn_tilt_set_sensitivity_all_with(uint8_t sensitivity);
/**
* @brief Gets the tilting sensitivity for the specified relay channel.
*
@@ -235,7 +377,19 @@ void relay_chn_tilt_set_sensitivity(uint8_t chn_id, uint8_t sensitivity);
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
esp_err_t relay_chn_tilt_get_sensitivity(uint8_t chn_id, uint8_t *sensitivity, size_t length);
uint8_t relay_chn_tilt_get_sensitivity(uint8_t chn_id);
/**
* @brief Gets the current tilt sensitivities for all configured relay channels.
*
* This function populates an array with the current tilt sensitivities (0-100%)
* of all configured relay channels. The caller must ensure the `sensitivity` array
* is large enough to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param sensitivity Pointer to an array where the sensitivities will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `sensitivity` is NULL.
*/
esp_err_t relay_chn_tilt_get_sensitivity_all(uint8_t *sensitivities);
#endif // CONFIG_RELAY_CHN_ENABLE_TILTING

View File

@@ -22,6 +22,19 @@ extern "C" {
*/
extern relay_chn_state_t relay_chn_ctl_get_state(uint8_t chn_id);
/**
* @brief Gets the current state of all relay channels.
*
* This function populates an array with the current states of all configured
* relay channels. The caller must ensure the `states` array is large enough
* to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param states Pointer to an array where the states will be stored.
*
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `states` is NULL.
*/
extern esp_err_t relay_chn_ctl_get_state_all(relay_chn_state_t *states);
/**
* @brief Get string representation of a relay channel's state.
*
@@ -33,31 +46,62 @@ extern char *relay_chn_ctl_get_state_str(uint8_t chn_id);
/**
* @brief Run a relay channel in forward direction.
*
* @param[in] chn_id Channel ID to run forward, or RELAY_CHN_ID_ALL for all channels.
* @param[in] chn_id Channel ID to run forward.
*/
extern void relay_chn_ctl_run_forward(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to run in the forward direction.
*
* This function iterates through all configured relay channels and issues a command
* to each to move in the forward direction.
*/
extern void relay_chn_ctl_run_forward_all(void);
/**
* @brief Run a relay channel in reverse direction.
*
* @param[in] chn_id Channel ID to run reverse, or RELAY_CHN_ID_ALL for all channels.
* @param[in] chn_id Channel ID to run reverse.
*/
extern void relay_chn_ctl_run_reverse(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to run in the reverse direction.
*
* This function iterates through all configured relay channels and issues a command
* to each to move in the reverse direction.
*/
extern void relay_chn_ctl_run_reverse_all(void);
/**
* @brief Stop a relay channel.
*
* @param[in] chn_id Channel ID to stop, or RELAY_CHN_ID_ALL for all channels.
* @param[in] chn_id Channel ID to stop.
*/
extern void relay_chn_ctl_stop(uint8_t chn_id);
/**
* @brief Commands all configured relay channels to stop.
*
* This function iterates through all configured relay channels and issues a command to each to stop any ongoing movement.
*/
extern void relay_chn_ctl_stop_all(void);
/**
* @brief Flip the running direction of a relay channel.
*
* @param[in] chn_id Channel ID to flip direction for, or RELAY_CHN_ID_ALL for all channels.
* @param[in] chn_id Channel ID to flip direction for.
*/
extern void relay_chn_ctl_flip_direction(uint8_t chn_id);
/**
* @brief Flips the logical direction of all configured relay channels.
*
* This function iterates through all configured relay channels and swaps the
* physical GPIO pins assigned to the forward and reverse directions for each.
*/
extern void relay_chn_ctl_flip_direction_all(void);
/**
* @brief Get the current direction of a relay channel.
*
@@ -66,11 +110,28 @@ extern void relay_chn_ctl_flip_direction(uint8_t chn_id);
*/
extern relay_chn_direction_t relay_chn_ctl_get_direction(uint8_t chn_id);
/**
* @brief Gets the current logical direction of all configured relay channels.
*
* This function populates an array with the current logical directions of all
* configured relay channels. The caller must ensure the `directions` array is
* large enough to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param directions Pointer to an array where the directions will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `directions` is NULL.
*/
esp_err_t relay_chn_ctl_get_direction_all(relay_chn_direction_t *directions);
static inline relay_chn_state_t relay_chn_get_state(uint8_t chn_id)
{
return relay_chn_ctl_get_state(chn_id);
}
static inline esp_err_t relay_chn_get_state_all(relay_chn_state_t *states)
{
return relay_chn_ctl_get_state_all(states);
}
static inline char *relay_chn_get_state_str(uint8_t chn_id)
{
return relay_chn_ctl_get_state_str(chn_id);
@@ -81,26 +142,51 @@ static inline void relay_chn_run_forward(uint8_t chn_id)
relay_chn_ctl_run_forward(chn_id);
}
static inline void relay_chn_run_forward_all(void)
{
relay_chn_ctl_run_forward_all();
}
static inline void relay_chn_run_reverse(uint8_t chn_id)
{
relay_chn_ctl_run_reverse(chn_id);
}
static inline void relay_chn_run_reverse_all(void)
{
relay_chn_ctl_run_reverse_all();
}
static inline void relay_chn_stop(uint8_t chn_id)
{
relay_chn_ctl_stop(chn_id);
}
static inline void relay_chn_stop_all(void)
{
relay_chn_ctl_stop_all();
}
static inline void relay_chn_flip_direction(uint8_t chn_id)
{
relay_chn_ctl_flip_direction(chn_id);
}
static inline void relay_chn_flip_direction_all(void)
{
relay_chn_ctl_flip_direction_all();
}
static inline relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id)
{
return relay_chn_ctl_get_direction(chn_id);
}
static inline esp_err_t relay_chn_get_direction_all(relay_chn_direction_t *directions)
{
return relay_chn_ctl_get_direction_all(directions);
}
#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT
/**
* @brief Get the run limit for the specified channel
@@ -112,6 +198,18 @@ static inline relay_chn_direction_t relay_chn_get_direction(uint8_t chn_id)
*/
extern uint16_t relay_chn_ctl_get_run_limit(uint8_t chn_id);
/**
* @brief Gets the configured run limits for all configured relay channels.
*
* This function populates an array with the run limits (in seconds) of all
* configured relay channels. The caller must ensure the `limits_sec` array is
* large enough to hold `CONFIG_RELAY_CHN_COUNT` elements.
*
* @param limits_sec Pointer to an array where the run limits will be stored.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `limits_sec` is NULL.
*/
esp_err_t relay_chn_ctl_get_run_limit_all(uint16_t *limits_sec);
/**
* @brief Set the run limit for the specified channel
*
@@ -120,15 +218,55 @@ extern uint16_t relay_chn_ctl_get_run_limit(uint8_t chn_id);
*/
extern void relay_chn_ctl_set_run_limit(uint8_t chn_id, uint16_t time_sec);
/**
* @brief Sets the run limits for all configured relay channels.
*
* This function iterates through all configured relay channels and sets their
* run limits based on the values provided in the `limits_sec` array. Each value
* will be clamped within the configured `RELAY_CHN_RUN_LIMIT_MIN_SEC` and
* `RELAY_CHN_RUN_LIMIT_MAX_SEC` boundaries. The new run limits are persisted
* in NVS if enabled.
*
* @param limits_sec Pointer to an array containing the desired run limits in seconds.
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if `limits_sec` is NULL.
*/
esp_err_t relay_chn_ctl_set_run_limit_all(uint16_t *limits_sec);
/**
* @brief Sets a single run limit value for all configured relay channels.
*
* This function sets the same `limit_sec` value for all configured relay channels.
* The value will be clamped within the configured `RELAY_CHN_RUN_LIMIT_MIN_SEC`
* and `RELAY_CHN_RUN_LIMIT_MAX_SEC` boundaries.
* @param limit_sec The desired run limit in seconds to apply to all channels.
* @return ESP_OK on success.
*/
esp_err_t relay_chn_ctl_set_run_limit_all_with(uint16_t limit_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 esp_err_t relay_chn_get_run_limit_all(uint16_t *limits_sec)
{
return relay_chn_ctl_get_run_limit_all(limits_sec);
}
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);
}
static inline esp_err_t relay_chn_set_run_limit_all(uint16_t *limits_sec)
{
return relay_chn_ctl_set_run_limit_all(limits_sec);
}
static inline esp_err_t relay_chn_set_run_limit_all_with(uint16_t limit_sec)
{
return relay_chn_ctl_set_run_limit_all_with(limit_sec);
}
#endif // CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT == 1
#else

View File

@@ -1,19 +0,0 @@
/*
* SPDX-FileCopyrightText: 2025 Kozmotronik Tech
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#if RELAY_CHN_COUNT > 1
#define RELAY_CHN_ID_ALL RELAY_CHN_COUNT /*!< Special ID to address all channels */
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -7,7 +7,6 @@
#pragma once
#include <stdint.h>
#include "relay_chn_defs.h"
#ifdef __cplusplus
extern "C" {