Skip to content

Commit ccca176

Browse files
shahpiyushvchiragatal
authored andcommitted
esp_rmaker_params: Added an API to indicate max number of elements allowed in an array param
1 parent b61dc04 commit ccca176

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

components/esp_rainmaker/include/esp_rmaker_core.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,20 @@ esp_err_t esp_rmaker_param_add_bounds(const esp_rmaker_param_t *param,
622622
*/
623623
esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, const char *strs[], uint8_t count);
624624

625+
/** Add max count for an array parameter
626+
*
627+
* This can be used to put a limit on the maximum number of elements in an array.
628+
*
629+
* @note The RainMaker core does not check the values. It is upto the application to handle it.
630+
*
631+
* @param[in] param Parameter handle.
632+
* @param[in] count Max number of elements allowed in the array.
633+
*
634+
* @return ESP_OK on success.
635+
* return error in case of failure.
636+
*/
637+
esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count);
638+
625639
/** Update and report a parameter
626640
*
627641
* Calling this API will update the parameter and report it to ESP RainMaker cloud.

components/esp_rainmaker/src/core/esp_rmaker_param.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,30 @@ esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, c
488488
return ESP_OK;
489489
}
490490

491+
esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count)
492+
{
493+
if (!param) {
494+
ESP_LOGE(TAG, "Param handle cannot be NULL.");
495+
return ESP_ERR_INVALID_ARG;
496+
}
497+
_esp_rmaker_param_t *_param = (_esp_rmaker_param_t *)param;
498+
if (_param->val.type != RMAKER_VAL_TYPE_ARRAY) {
499+
ESP_LOGE(TAG, "Only array params can have max count.");
500+
return ESP_ERR_INVALID_ARG;
501+
}
502+
esp_rmaker_param_bounds_t *bounds = calloc(1, sizeof(esp_rmaker_param_bounds_t));
503+
if (!bounds) {
504+
ESP_LOGE(TAG, "Failed to allocate memory for parameter bounds.");
505+
return ESP_ERR_NO_MEM;
506+
}
507+
bounds->max = esp_rmaker_int(count);
508+
if (_param->bounds) {
509+
free(_param->bounds);
510+
}
511+
_param->bounds = bounds;
512+
return ESP_OK;
513+
}
514+
491515
esp_err_t esp_rmaker_param_add_ui_type(const esp_rmaker_param_t *param, const char *ui_type)
492516
{
493517
if (!param || !ui_type) {

0 commit comments

Comments
 (0)