app_rainmaker: Remapping the param values

Also minor restructuring of files in the examples.
Also minor change to the default values to fix remapping.
This commit is contained in:
Chirag Atal
2022-03-29 19:20:04 +05:30
parent 09cfb92bd4
commit 5a70c12bdb
15 changed files with 102 additions and 109 deletions
+1 -11
View File
@@ -14,21 +14,11 @@
#include <esp_matter.h>
#include <light_driver.h>
#include <app_driver.h>
#include <app_priv.h>
static const char *TAG = "app_driver";
extern int light_endpoint_id;
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define STANDARD_TEMPERATURE 100
#define MATTER_BRIGHTNESS 255
#define MATTER_HUE 255
#define MATTER_SATURATION 255
#define MATTER_TEMPERATURE 255
/* Do any conversions/remapping for the actual value here */
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
{
+1 -6
View File
@@ -15,14 +15,9 @@
#include <esp_matter_ota.h>
#include <esp_route_hook.h>
#include <app_driver.h>
#include <app_priv.h>
#include <app_qrcode.h>
#define DEFAULT_POWER true
#define DEFAULT_BRIGHTNESS 64
#define DEFAULT_HUE 127
#define DEFAULT_SATURATION 254
static const char *TAG = "app_main";
int light_endpoint_id = 0;
@@ -8,13 +8,22 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <esp_err.h>
#include <esp_matter.h>
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define MATTER_BRIGHTNESS 254
#define MATTER_HUE 255
#define MATTER_SATURATION 255
#define DEFAULT_POWER true
#define DEFAULT_BRIGHTNESS 64
#define DEFAULT_HUE 128
#define DEFAULT_SATURATION 255
/** Initialize the board and the drivers
*
* This initializes the selected board, which then initializes the respective drivers associated with it.
@@ -25,7 +34,3 @@ extern "C" {
esp_err_t app_driver_init(void);
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
#ifdef __cplusplus
}
#endif
+1 -11
View File
@@ -14,21 +14,11 @@
#include <esp_matter.h>
#include <light_driver.h>
#include <app_driver.h>
#include <app_priv.h>
static const char *TAG = "app_driver";
extern int light_endpoint_id;
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define STANDARD_TEMPERATURE 100
#define MATTER_BRIGHTNESS 255
#define MATTER_HUE 255
#define MATTER_SATURATION 255
#define MATTER_TEMPERATURE 255
/* Do any conversions/remapping for the actual value here */
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
{
+1 -6
View File
@@ -14,15 +14,10 @@
#include <esp_matter_console.h>
#include <esp_route_hook.h>
#include <app_driver.h>
#include <app_priv.h>
#include <app_qrcode.h>
#include <app_rainmaker.h>
#define DEFAULT_POWER true
#define DEFAULT_BRIGHTNESS 64
#define DEFAULT_HUE 127
#define DEFAULT_SATURATION 254
static const char *TAG = "app_main";
int light_endpoint_id = 0;
@@ -8,13 +8,22 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <esp_err.h>
#include <esp_matter.h>
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define MATTER_BRIGHTNESS 254
#define MATTER_HUE 255
#define MATTER_SATURATION 255
#define DEFAULT_POWER true
#define DEFAULT_BRIGHTNESS 64
#define DEFAULT_HUE 128
#define DEFAULT_SATURATION 255
/** Initialize the board and the drivers
*
* This initializes the selected board, which then initializes the respective drivers associated with it.
@@ -25,7 +34,3 @@ extern "C" {
esp_err_t app_driver_init(void);
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
#ifdef __cplusplus
}
#endif
+56 -25
View File
@@ -19,6 +19,7 @@
#include <esp_rmaker_standard_params.h>
#include <esp_rmaker_standard_types.h>
#include <app_priv.h>
#include <app_rainmaker.h>
#include <esp_matter.h>
#include <esp_matter_console.h>
@@ -29,8 +30,25 @@ extern int light_endpoint_id;
#define DEFAULT_LIGHT_NAME "Light"
static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t *val)
static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t *val, int cluster_id, int attribute_id)
{
/* Attributes which need to be remapped */
if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) {
int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
return esp_rmaker_int(value);
}
} else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE);
return esp_rmaker_int(value);
} else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION);
return esp_rmaker_int(value);
}
}
/* Attributes which don't need to be remapped */
if (val->type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
return esp_rmaker_bool(val->val.b);
} else if (val->type == ESP_MATTER_VAL_TYPE_INTEGER) {
@@ -49,16 +67,33 @@ static esp_rmaker_param_val_t app_rainmaker_get_rmaker_val(esp_matter_attr_val_t
return esp_rmaker_int(0);
}
static esp_matter_attr_val_t app_rainmaker_get_matter_val(esp_rmaker_param_val_t val)
static esp_matter_attr_val_t app_rainmaker_get_matter_val(esp_rmaker_param_val_t *val, int cluster_id, int attribute_id)
{
if (val.type == RMAKER_VAL_TYPE_BOOLEAN) {
return esp_matter_bool(val.val.b);
} else if (val.type == RMAKER_VAL_TYPE_INTEGER) {
return esp_matter_int(val.val.i);
} else if (val.type == RMAKER_VAL_TYPE_FLOAT) {
return esp_matter_float(val.val.f);
/* Attributes which need to be remapped */
if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) {
uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_BRIGHTNESS, MATTER_BRIGHTNESS);
return esp_matter_uint8(value);
}
} else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_HUE, MATTER_HUE);
return esp_matter_uint8(value);
} else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
uint8_t value = REMAP_TO_RANGE(val->val.i, STANDARD_SATURATION, MATTER_SATURATION);
return esp_matter_uint8(value);
}
}
/* Attributes which don't need to be remapped */
if (val->type == RMAKER_VAL_TYPE_BOOLEAN) {
return esp_matter_bool(val->val.b);
} else if (val->type == RMAKER_VAL_TYPE_INTEGER) {
return esp_matter_int(val->val.i);
} else if (val->type == RMAKER_VAL_TYPE_FLOAT) {
return esp_matter_float(val->val.f);
} else {
ESP_LOGE(TAG, "Invalid val type: %d", val.type);
ESP_LOGE(TAG, "Invalid val type: %d", val->type);
}
return esp_matter_int(0);
}
@@ -139,7 +174,7 @@ static const char *app_rainmaker_get_param_ui_type_from_id(int cluster_id, int a
}
} else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
return ESP_RMAKER_UI_SLIDER;
return ESP_RMAKER_UI_HUE_SLIDER;
} else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
return ESP_RMAKER_UI_SLIDER;
}
@@ -149,26 +184,22 @@ static const char *app_rainmaker_get_param_ui_type_from_id(int cluster_id, int a
static bool app_rainmaker_get_param_bounds_from_id(int cluster_id, int attribute_id, int *min, int *max, int *step)
{
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID) {
if (attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
return false;
}
} else if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) {
*min = 0;
*max = 255;
*max = STANDARD_BRIGHTNESS;
*step = 1;
return true;
}
} else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) {
if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
*min = 0;
*max = 255;
*max = STANDARD_HUE;
*step = 1;
return true;
} else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
*min = 0;
*max = 255;
*max = STANDARD_SATURATION;
*step = 1;
return true;
}
@@ -191,17 +222,17 @@ static esp_err_t app_rainmaker_param_add_ui_type(esp_rmaker_param_t *param, esp_
static esp_err_t app_rainmaker_param_add_bounds(esp_rmaker_param_t *param, esp_matter_cluster_t *cluster,
esp_matter_attribute_t *attribute)
{
int cluster_id = esp_matter_cluster_get_id(cluster);
int attribute_id = esp_matter_attribute_get_id(attribute);
esp_matter_attr_bounds_t *bounds = esp_matter_attribute_get_bounds(attribute);
if (bounds) {
esp_rmaker_param_val_t min_val = app_rainmaker_get_rmaker_val(&bounds->min);
esp_rmaker_param_val_t max_val = app_rainmaker_get_rmaker_val(&bounds->max);
esp_rmaker_param_val_t min_val = app_rainmaker_get_rmaker_val(&bounds->min, cluster_id, attribute_id);
esp_rmaker_param_val_t max_val = app_rainmaker_get_rmaker_val(&bounds->max, cluster_id, attribute_id);
esp_rmaker_param_val_t step_val = esp_rmaker_int(1);
return esp_rmaker_param_add_bounds(param, min_val, max_val, step_val);
}
/* If bounds are not set for the attribute, check if there are any bounds to be added based on the id */
int cluster_id = esp_matter_cluster_get_id(cluster);
int attribute_id = esp_matter_attribute_get_id(attribute);
int min = 0, max = 0, step = 0;
bool add_bounds = app_rainmaker_get_param_bounds_from_id(cluster_id, attribute_id, &min, &max, &step);
if (add_bounds) {
@@ -254,7 +285,7 @@ esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int at
const esp_rmaker_node_t *node = esp_rmaker_get_node();
esp_rmaker_device_t *device = esp_rmaker_node_get_device_by_name(node, device_name);
esp_rmaker_param_t *param = esp_rmaker_device_get_param_by_name(device, param_name);
esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(val);
esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(val, cluster_id, attribute_id);
if (!param) {
ESP_LOGE(TAG, "Param not found");
return ESP_FAIL;
@@ -283,7 +314,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
int endpoint_id = app_rainmaker_get_endpoint_id_from_name(device_name);
int cluster_id = app_rainmaker_get_cluster_id_from_name(param_name);
int attribute_id = app_rainmaker_get_attribute_id_from_name(param_name);
esp_matter_attr_val_t matter_val = app_rainmaker_get_matter_val(val);
esp_matter_attr_val_t matter_val = app_rainmaker_get_matter_val((esp_rmaker_param_val_t *)&val, cluster_id, attribute_id);
return esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, &matter_val);
}
@@ -321,7 +352,7 @@ static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *devic
const char *param_type = app_rainmaker_get_param_type_from_id(cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
esp_matter_attribute_get_val(attribute, &val);
esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(&val);
esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(&val, cluster_id, attribute_id);
esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, param_type, rmaker_val,
PROP_FLAG_READ | PROP_FLAG_WRITE);
if (!param) {
+1 -1
View File
@@ -15,7 +15,7 @@
#include <esp_matter_console.h>
#include <light_driver.h>
#include <app_driver.h>
#include <app_priv.h>
using chip::kInvalidClusterId;
static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF;
+1 -1
View File
@@ -15,7 +15,7 @@
#include <esp_matter_ota.h>
#include <esp_route_hook.h>
#include <app_driver.h>
#include <app_priv.h>
#include <app_qrcode.h>
static const char *TAG = "app_main";
@@ -8,10 +8,6 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <esp_err.h>
#include <esp_matter.h>
@@ -25,7 +21,3 @@ extern "C" {
esp_err_t app_driver_init(void);
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
#ifdef __cplusplus
}
#endif
+1 -11
View File
@@ -14,21 +14,11 @@
#include <esp_matter.h>
#include <light_driver.h>
#include <app_driver.h>
#include <app_priv.h>
static const char *TAG = "app_driver";
extern int light_endpoint_id;
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define STANDARD_TEMPERATURE 100
#define MATTER_BRIGHTNESS 255
#define MATTER_HUE 255
#define MATTER_SATURATION 255
#define MATTER_TEMPERATURE 255
/* Do any conversions/remapping for the actual value here */
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
{
+1 -1
View File
@@ -13,7 +13,7 @@
#include <esp_matter.h>
#include <esp_matter_console.h>
#include <esp_route_hook.h>
#include <app_driver.h>
#include <app_priv.h>
#include <app_qrcode.h>
static const char *TAG = "app_main";
@@ -8,13 +8,17 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <esp_err.h>
#include <esp_matter.h>
#define STANDARD_BRIGHTNESS 100
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define MATTER_BRIGHTNESS 254
#define MATTER_HUE 255
#define MATTER_SATURATION 255
/** Initialize the board and the drivers
*
* This initializes the selected board, which then initializes the respective drivers associated with it.
@@ -27,7 +31,3 @@ esp_err_t app_driver_init(void);
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
esp_err_t app_driver_attribute_set_defaults();
#ifdef __cplusplus
}
#endif
@@ -346,9 +346,9 @@
\
/* Endpoint: 1, Cluster: Color Control (server) */ \
{0x00000000, ZAP_TYPE(INT8U), 1, 0, \
ZAP_SIMPLE_DEFAULT(0x7F)}, /* current hue */ \
ZAP_SIMPLE_DEFAULT(0x80)}, /* current hue */ \
{0x00000001, ZAP_TYPE(INT8U), 1, 0, \
ZAP_SIMPLE_DEFAULT(0xFE)}, /* current saturation */ \
ZAP_SIMPLE_DEFAULT(0xFF)}, /* current saturation */ \
{0x00000003, ZAP_TYPE(INT16U), 2, 0, \
ZAP_SIMPLE_DEFAULT(0x616B)}, /* current x */ \
{0x00000004, ZAP_TYPE(INT16U), 2, 0, \
@@ -4736,7 +4736,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x7F",
"defaultValue": "0x80",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
@@ -4751,7 +4751,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0xFE",
"defaultValue": "0xFF",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,