mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'bugfix/attribute_values' into 'main'
esp_matter_attribute: Fix attribute values for uint16 and strings See merge request app-frameworks/esp-matter!92
This commit is contained in:
+3
-3
@@ -26,7 +26,7 @@ There is now just one attribute update callback which calls the other callbacks
|
||||
The application receives this callback twice, once before updating the value in the data model (pre_attribute)
|
||||
and once after updating the value (post_attribute).
|
||||
```
|
||||
esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val, void *priv_data);
|
||||
esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val, void *priv_data);
|
||||
```
|
||||
|
||||
The app_driver component has been moved to the application itself and it now uses the endpoint_id,
|
||||
@@ -34,7 +34,7 @@ cluster_id, attribute_id for setting/getting the values. The application calls t
|
||||
for drivers first when it gets the pre_attribute callback. If this returns success, i.e. ESP_OK, only then
|
||||
the data model value is updated and the application receives the post_attribute callback.
|
||||
```
|
||||
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_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
```
|
||||
|
||||
The rainmaker example creates its data model dynamically based on the ESP Matter data model. New
|
||||
@@ -45,7 +45,7 @@ callback.
|
||||
/* Create a device and add the relevant parameters to it */
|
||||
app_rainmaker_device_create();
|
||||
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
```
|
||||
|
||||
Non-mandatory endpoints, clusters, attributes or commands can also be easily added by using the
|
||||
|
||||
@@ -67,7 +67,7 @@ set(INCLUDE_DIRS_LIST "."
|
||||
"${MATTER_SDK_PATH}/src"
|
||||
"${ZAP_GENERATED_PATH}/../")
|
||||
|
||||
set(REQUIRES_LIST chip bt)
|
||||
set(REQUIRES_LIST chip bt esp_matter_console)
|
||||
|
||||
if ("${IDF_TARGET}" STREQUAL "esp32h2")
|
||||
list(APPEND REQUIRES_LIST openthread esp_matter_openthread)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,6 @@ typedef enum {
|
||||
ESP_MATTER_VAL_TYPE_INTEGER,
|
||||
/** Floating point number */
|
||||
ESP_MATTER_VAL_TYPE_FLOAT,
|
||||
/** NULL terminated string */
|
||||
ESP_MATTER_VAL_TYPE_STRING,
|
||||
/** Array Eg. [1,2,3] */
|
||||
ESP_MATTER_VAL_TYPE_ARRAY,
|
||||
/** Byte String Eg. "123" */
|
||||
@@ -60,10 +58,6 @@ typedef enum {
|
||||
ESP_MATTER_VAL_TYPE_BITMAP16,
|
||||
/** 32 bit bitmap */
|
||||
ESP_MATTER_VAL_TYPE_BITMAP32,
|
||||
/** NULL terminated JSON Object string Eg. "{\"name\":\"value\"}" */
|
||||
ESP_MATTER_VAL_TYPE_JSON_OBJECT,
|
||||
/** NULL terminated JSON Array string Eg. "[1,2,3]" */
|
||||
ESP_MATTER_VAL_TYPE_JSON_ARRAY,
|
||||
} esp_matter_val_type_t;
|
||||
|
||||
/* ESP Matter Value */
|
||||
@@ -74,8 +68,6 @@ typedef union {
|
||||
int i;
|
||||
/** Float */
|
||||
float f;
|
||||
/** NULL terminated string. It should stay allocated throughout the lifetime of the device. */
|
||||
char *s;
|
||||
/** 8 bit signed integer */
|
||||
int8_t i8;
|
||||
/** 8 bit unsigned integer */
|
||||
@@ -92,10 +84,12 @@ typedef union {
|
||||
struct {
|
||||
/** Buffer */
|
||||
uint8_t *b;
|
||||
/** Total size */
|
||||
/** Data size */
|
||||
uint16_t s;
|
||||
/** Total count */
|
||||
/** Data count */
|
||||
uint16_t n;
|
||||
/** Total size */
|
||||
uint16_t t;
|
||||
} a;
|
||||
/** Pointer */
|
||||
void *p;
|
||||
@@ -122,15 +116,6 @@ esp_matter_attr_val_t esp_matter_int(int val);
|
||||
/** Float */
|
||||
esp_matter_attr_val_t esp_matter_float(float val);
|
||||
|
||||
/** String */
|
||||
esp_matter_attr_val_t esp_matter_str(const char *val);
|
||||
|
||||
/** JSON object string */
|
||||
esp_matter_attr_val_t esp_matter_json_obj(const char *val);
|
||||
|
||||
/** JSON array string */
|
||||
esp_matter_attr_val_t esp_matter_json_array(const char *val);
|
||||
|
||||
/** 8 bit integer */
|
||||
esp_matter_attr_val_t esp_matter_int8(int8_t val);
|
||||
|
||||
@@ -162,22 +147,22 @@ esp_matter_attr_val_t esp_matter_bitmap16(uint16_t val);
|
||||
esp_matter_attr_val_t esp_matter_bitmap32(uint32_t val);
|
||||
|
||||
/** Character string */
|
||||
esp_matter_attr_val_t esp_matter_char_str(char *val, uint16_t total_size);
|
||||
esp_matter_attr_val_t esp_matter_char_str(char *val, uint16_t data_size);
|
||||
|
||||
/** Octet string */
|
||||
esp_matter_attr_val_t esp_matter_octet_str(uint8_t *val, uint16_t total_size, uint16_t count);
|
||||
esp_matter_attr_val_t esp_matter_octet_str(uint8_t *val, uint16_t data_size);
|
||||
|
||||
/** Array */
|
||||
esp_matter_attr_val_t esp_matter_array(uint8_t *val, uint16_t total_size, uint16_t count);
|
||||
esp_matter_attr_val_t esp_matter_array(uint8_t *val, uint16_t data_size, uint16_t count);
|
||||
|
||||
/** Attribute update
|
||||
*
|
||||
* This API updates the attribute value
|
||||
*/
|
||||
esp_err_t esp_matter_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
esp_err_t esp_matter_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
/** Attribute value print
|
||||
*
|
||||
* This API prints the attribute value according to the type
|
||||
*/
|
||||
void esp_matter_attribute_val_print(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
void esp_matter_attribute_val_print(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
@@ -358,7 +358,7 @@ esp_matter_cluster_t *esp_matter_cluster_create_ota_requestor(esp_matter_endpoin
|
||||
esp_matter_uint16(config->cluster_revision));
|
||||
esp_matter_attribute_create(cluster, ZCL_DEFAULT_OTA_PROVIDERS_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
esp_matter_octet_str(config->default_ota_providers,
|
||||
sizeof(config->default_ota_providers), 0));
|
||||
sizeof(config->default_ota_providers)));
|
||||
esp_matter_attribute_create(cluster, ZCL_UPDATE_POSSIBLE_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
esp_matter_bool(config->update_possible));
|
||||
esp_matter_attribute_create(cluster, ZCL_UPDATE_STATE_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
@@ -448,7 +448,7 @@ esp_matter_cluster_t *esp_matter_cluster_create_network_commissioning(esp_matter
|
||||
esp_matter_attribute_create(cluster, ZCL_LAST_NETWORKING_STATUS_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
esp_matter_enum8(config->last_networking_status));
|
||||
esp_matter_attribute_create(cluster, ZCL_LAST_NETWORK_ID_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
esp_matter_octet_str(config->last_network_id, sizeof(config->last_network_id), 0));
|
||||
esp_matter_octet_str(config->last_network_id, sizeof(config->last_network_id)));
|
||||
esp_matter_attribute_create(cluster, ZCL_LAST_CONNECT_ERROR_VALUE_ATTRIBUTE_ID, ESP_MATTER_ATTRIBUTE_FLAG_NONE,
|
||||
esp_matter_uint32(config->last_connect_error_value));
|
||||
|
||||
|
||||
@@ -578,24 +578,46 @@ esp_err_t esp_matter_cluster_add_function_list(esp_matter_cluster_t *cluster,
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_matter_attr_val_t esp_matter_attribute_get_val(esp_matter_attribute_t *attribute)
|
||||
esp_err_t esp_matter_attribute_get_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t *val)
|
||||
{
|
||||
if (!attribute) {
|
||||
ESP_LOGE(TAG, "Attribute cannot be NULL");
|
||||
return esp_matter_invalid(NULL);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
_esp_matter_attribute_t *current_attribute = (_esp_matter_attribute_t *)attribute;
|
||||
return current_attribute->val;
|
||||
memcpy((void *)val, (void *)¤t_attribute->val, sizeof(esp_matter_attr_val_t));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_matter_attribute_set_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t val)
|
||||
esp_err_t esp_matter_attribute_set_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t *val)
|
||||
{
|
||||
if (!attribute) {
|
||||
ESP_LOGE(TAG, "Attribute cannot be NULL");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
_esp_matter_attribute_t *current_attribute = (_esp_matter_attribute_t *)attribute;
|
||||
current_attribute->val = val;
|
||||
if (val->type == ESP_MATTER_VAL_TYPE_CHAR_STRING || val->type == ESP_MATTER_VAL_TYPE_OCTET_STRING
|
||||
|| val->type == ESP_MATTER_VAL_TYPE_ARRAY) {
|
||||
/* Free old buf */
|
||||
if (current_attribute->val.val.a.b) {
|
||||
free(current_attribute->val.val.a.b);
|
||||
}
|
||||
if (val->val.a.s > 0) {
|
||||
/* Alloc new buf */
|
||||
uint8_t *new_buf = (uint8_t *)calloc(1, val->val.a.s);
|
||||
if (!new_buf) {
|
||||
ESP_LOGE(TAG, "Could not allocate new buffer");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
/* Copy to new buf and assign */
|
||||
memcpy(new_buf, val->val.a.b, val->val.a.s);
|
||||
val->val.a.b = new_buf;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Set val called with string with size 0");
|
||||
val->val.a.b = NULL;
|
||||
}
|
||||
}
|
||||
memcpy((void *)¤t_attribute->val, (void *)val, sizeof(esp_matter_attr_val_t));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -645,6 +667,14 @@ static esp_err_t esp_matter_attribute_delete(esp_matter_attribute_t *attribute)
|
||||
_esp_matter_attribute_t *current_attribute = (_esp_matter_attribute_t *)attribute;
|
||||
|
||||
/* Delete val here, if required */
|
||||
if (current_attribute->val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING
|
||||
|| current_attribute->val.type == ESP_MATTER_VAL_TYPE_OCTET_STRING
|
||||
|| current_attribute->val.type == ESP_MATTER_VAL_TYPE_ARRAY) {
|
||||
/* Free buf */
|
||||
if (current_attribute->val.val.a.b) {
|
||||
free(current_attribute->val.val.a.b);
|
||||
}
|
||||
}
|
||||
|
||||
/* Free */
|
||||
free(current_attribute);
|
||||
@@ -672,7 +702,7 @@ esp_matter_attribute_t *esp_matter_attribute_create(esp_matter_cluster_t *cluste
|
||||
attribute->attribute_id = attribute_id;
|
||||
attribute->flags = flags;
|
||||
attribute->flags |= ESP_MATTER_ATTRIBUTE_FLAG_EXTERNAL_STORAGE;
|
||||
attribute->val = val;
|
||||
esp_matter_attribute_set_val((esp_matter_attribute_t *)attribute, &val);
|
||||
|
||||
/* Add */
|
||||
_esp_matter_attribute_t *previous_attribute = NULL;
|
||||
|
||||
@@ -42,7 +42,7 @@ typedef enum esp_matter_callback_type {
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
typedef esp_err_t (*esp_matter_attribute_callback_t)(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data);
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data);
|
||||
|
||||
typedef void (*esp_matter_event_callback_t)(const ChipDeviceEvent *event, intptr_t arg);
|
||||
|
||||
@@ -109,8 +109,8 @@ esp_matter_attribute_t *esp_matter_attribute_get_next(esp_matter_attribute_t *at
|
||||
int esp_matter_attribute_get_id(esp_matter_attribute_t *attribute);
|
||||
|
||||
/** Attribute val APIs */
|
||||
esp_err_t esp_matter_attribute_set_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t val);
|
||||
esp_matter_attr_val_t esp_matter_attribute_get_val(esp_matter_attribute_t *attribute);
|
||||
esp_err_t esp_matter_attribute_set_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t *val);
|
||||
esp_err_t esp_matter_attribute_get_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t *val);
|
||||
esp_err_t esp_matter_attribute_get_val_raw(int endpoint_id, int cluster_id, int attribute_id, uint8_t *value,
|
||||
uint16_t attribute_size);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
}
|
||||
|
||||
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data)
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
||||
@@ -117,13 +117,13 @@ void zigbee_bridge_send_off(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr)
|
||||
ZB_ZCL_CMD_ON_OFF_OFF_ID, NULL);
|
||||
}
|
||||
|
||||
esp_err_t zigbee_bridge_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val)
|
||||
esp_err_t zigbee_bridge_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
app_bridge_zigbee_device_t *zigbee_device = app_bridge_get_zigbee_device_by_matter_endpointid(endpoint_id);
|
||||
if (zigbee_device && zigbee_device->dev && zigbee_device->dev->endpoint) {
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID) {
|
||||
if (attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
zb_buf_get_out_delayed_ext((val.val.b ? zigbee_bridge_send_on : zigbee_bridge_send_off),
|
||||
zb_buf_get_out_delayed_ext((val->val.b ? zigbee_bridge_send_on : zigbee_bridge_send_off),
|
||||
zigbee_device->zigbee_shortaddr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void zigbee_bridge_match_bridged_onoff_light(zb_bufid_t bufid);
|
||||
|
||||
void zigbee_bridge_match_bridged_onoff_light_timeout(zb_bufid_t bufid);
|
||||
|
||||
esp_err_t zigbee_bridge_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
esp_err_t zigbee_bridge_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <device.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#include <app_driver.h>
|
||||
@@ -30,78 +29,31 @@ extern int light_endpoint_id;
|
||||
#define MATTER_SATURATION 255
|
||||
#define MATTER_TEMPERATURE 255
|
||||
|
||||
static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
{
|
||||
if (argc == 5 && strncmp(argv[0], "set", sizeof("set")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else if (argc == 4 && strncmp(argv[0], "get", sizeof("get")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
|
||||
esp_matter_node_t *node = esp_matter_node_get();
|
||||
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get(node, endpoint_id);
|
||||
esp_matter_cluster_t *cluster = esp_matter_cluster_get(endpoint, cluster_id);
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get(cluster, attribute_id);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
esp_matter_attribute_val_print(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Incorrect arguments");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void app_driver_register_commands()
|
||||
{
|
||||
esp_matter_console_command_t command = {
|
||||
.name = "driver",
|
||||
.description = "This can be used to simulate on-device control. "
|
||||
"Usage: matter esp driver <set|get> <endpoint_id> <cluster_id> <attribute_id> [value]. "
|
||||
"Example1: matter esp driver set 0x1001 0x0006 0x0000 1. "
|
||||
"Example2: matter esp driver get 0x1001 0x0006 0x0000.",
|
||||
.handler = app_driver_console_handler,
|
||||
};
|
||||
esp_matter_console_add_command(&command);
|
||||
}
|
||||
|
||||
/* Do any conversions/remapping for the actual value here */
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
|
||||
{
|
||||
return light_driver_set_power(val.val.b);
|
||||
return light_driver_set_power(val->val.b);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
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_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
if (endpoint_id == light_endpoint_id) {
|
||||
@@ -138,8 +90,9 @@ static esp_err_t app_driver_attribute_set_defaults()
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
|
||||
while (attribute) {
|
||||
int attribute_id = esp_matter_attribute_get_id(attribute);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
||||
err |= esp_matter_attribute_get_val(attribute, &val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
attribute = esp_matter_attribute_get_next(attribute);
|
||||
}
|
||||
cluster = esp_matter_cluster_get_next(cluster);
|
||||
@@ -153,6 +106,5 @@ esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
app_driver_attribute_set_defaults();
|
||||
app_driver_register_commands();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ 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);
|
||||
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
}
|
||||
|
||||
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data)
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <device.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#include <app_driver.h>
|
||||
@@ -30,78 +29,31 @@ extern int light_endpoint_id;
|
||||
#define MATTER_SATURATION 255
|
||||
#define MATTER_TEMPERATURE 255
|
||||
|
||||
static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
{
|
||||
if (argc == 5 && strncmp(argv[0], "set", sizeof("set")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else if (argc == 4 && strncmp(argv[0], "get", sizeof("get")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
|
||||
esp_matter_node_t *node = esp_matter_node_get();
|
||||
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get(node, endpoint_id);
|
||||
esp_matter_cluster_t *cluster = esp_matter_cluster_get(endpoint, cluster_id);
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get(cluster, attribute_id);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
esp_matter_attribute_val_print(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Incorrect arguments");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void app_driver_register_commands()
|
||||
{
|
||||
esp_matter_console_command_t command = {
|
||||
.name = "driver",
|
||||
.description = "This can be used to simulate on-device control. "
|
||||
"Usage: matter esp driver <set|get> <endpoint_id> <cluster_id> <attribute_id> [value]. "
|
||||
"Example1: matter esp driver set 0x1001 0x0006 0x0000 1. "
|
||||
"Example2: matter esp driver get 0x1001 0x0006 0x0000.",
|
||||
.handler = app_driver_console_handler,
|
||||
};
|
||||
esp_matter_console_add_command(&command);
|
||||
}
|
||||
|
||||
/* Do any conversions/remapping for the actual value here */
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
|
||||
{
|
||||
return light_driver_set_power(val.val.b);
|
||||
return light_driver_set_power(val->val.b);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
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_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
if (endpoint_id == light_endpoint_id) {
|
||||
@@ -138,8 +90,9 @@ static esp_err_t app_driver_attribute_set_defaults()
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
|
||||
while (attribute) {
|
||||
int attribute_id = esp_matter_attribute_get_id(attribute);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
||||
err |= esp_matter_attribute_get_val(attribute, &val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
attribute = esp_matter_attribute_get_next(attribute);
|
||||
}
|
||||
cluster = esp_matter_cluster_get_next(cluster);
|
||||
@@ -153,6 +106,5 @@ esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
app_driver_attribute_set_defaults();
|
||||
app_driver_register_commands();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ 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);
|
||||
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
}
|
||||
|
||||
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data)
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
||||
@@ -195,28 +195,22 @@ static int app_rainmaker_get_attribute_id_from_name(const char *param_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (val.type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
|
||||
return esp_rmaker_bool(val.val.b);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_INTEGER) {
|
||||
return esp_rmaker_int(val.val.i);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_FLOAT) {
|
||||
return esp_rmaker_float(val.val.f);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_STRING) {
|
||||
return esp_rmaker_str(val.val.s);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_JSON_OBJECT) {
|
||||
return esp_rmaker_obj(val.val.s);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_JSON_ARRAY) {
|
||||
return esp_rmaker_array(val.val.s);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_UINT8) {
|
||||
return esp_rmaker_int(val.val.u8);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_INT16) {
|
||||
return esp_rmaker_int(val.val.i16);
|
||||
} else if (val.type == ESP_MATTER_VAL_TYPE_UINT16) {
|
||||
return esp_rmaker_int(val.val.u16);
|
||||
if (val->type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
|
||||
return esp_rmaker_bool(val->val.b);
|
||||
} else if (val->type == ESP_MATTER_VAL_TYPE_INTEGER) {
|
||||
return esp_rmaker_int(val->val.i);
|
||||
} else if (val->type == ESP_MATTER_VAL_TYPE_FLOAT) {
|
||||
return esp_rmaker_float(val->val.f);
|
||||
} else if (val->type == ESP_MATTER_VAL_TYPE_UINT8) {
|
||||
return esp_rmaker_int(val->val.u8);
|
||||
} else if (val->type == ESP_MATTER_VAL_TYPE_INT16) {
|
||||
return esp_rmaker_int(val->val.i16);
|
||||
} else if (val->type == ESP_MATTER_VAL_TYPE_UINT16) {
|
||||
return esp_rmaker_int(val->val.u16);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid val type: %d", val.type);
|
||||
ESP_LOGE(TAG, "Invalid val type: %d", val->type);
|
||||
}
|
||||
return esp_rmaker_int(0);
|
||||
}
|
||||
@@ -229,19 +223,13 @@ static esp_matter_attr_val_t app_rainmaker_get_matter_val(esp_rmaker_param_val_t
|
||||
return esp_matter_int(val.val.i);
|
||||
} else if (val.type == RMAKER_VAL_TYPE_FLOAT) {
|
||||
return esp_matter_float(val.val.f);
|
||||
} else if (val.type == RMAKER_VAL_TYPE_STRING) {
|
||||
return esp_matter_str(val.val.s);
|
||||
} else if (val.type == RMAKER_VAL_TYPE_OBJECT) {
|
||||
return esp_matter_json_obj(val.val.s);
|
||||
} else if (val.type == RMAKER_VAL_TYPE_ARRAY) {
|
||||
return esp_matter_json_array(val.val.s);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid val type: %d", val.type);
|
||||
}
|
||||
return esp_matter_int(0);
|
||||
}
|
||||
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val)
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
const char *device_name = app_rainmaker_get_device_name_from_id(endpoint_id);
|
||||
const char *param_name = app_rainmaker_get_param_name_from_id(cluster_id, attribute_id);
|
||||
@@ -278,7 +266,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
|
||||
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);
|
||||
|
||||
return esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, matter_val);
|
||||
return esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, &matter_val);
|
||||
}
|
||||
|
||||
static void app_rainmaker_device_create()
|
||||
@@ -321,8 +309,9 @@ static void app_rainmaker_device_create()
|
||||
bool add_bounds = app_rainmaker_get_param_bounds_from_id(cluster_id, attribute_id, &min, &max,
|
||||
&step);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
esp_rmaker_param_val_t rmaker_val = app_rainmaker_get_rmaker_val(val);
|
||||
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_t *param = esp_rmaker_param_create(param_name, param_type, rmaker_val,
|
||||
PROP_FLAG_READ | PROP_FLAG_WRITE);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ extern "C" {
|
||||
*/
|
||||
esp_err_t app_rainmaker_init(void);
|
||||
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -30,39 +30,10 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
if (argc == 1 && strncmp(argv[0], "help", sizeof("help")) == 0) {
|
||||
printf("Driver commands:\n"
|
||||
"\thelp: Print help\n"
|
||||
"\tset: <endpoint_id> <cluster_id> <attribute_id> <value>."
|
||||
"Example: matter esp driver set 0x0001 0x0006 0x0000 1.\n"
|
||||
"\tget: <endpoint_id> <cluster_id> <attribute_id>. "
|
||||
"Example: matter esp driver get 0x0001 0x0006 0x0000.\n"
|
||||
"\tsend_bind: <endpoint_id> <cluster_id> <command_id>. "
|
||||
"Example: matter esp driver send_bind 0x0001 0x0006 0x0002.\n"
|
||||
"\tsend: <fabric_index> <remote_node_id> <remote_endpoint_id> <cluster_id> <command_id>. "
|
||||
"Example: matter esp driver send 0x0001 0xBC5C01 0x0001 0x0006 0x0002.\n");
|
||||
} else if (argc == 5 && strncmp(argv[0], "set", sizeof("set")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else if (argc == 4 && strncmp(argv[0], "get", sizeof("get")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
|
||||
esp_matter_node_t *node = esp_matter_node_get();
|
||||
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get(node, endpoint_id);
|
||||
esp_matter_cluster_t *cluster = esp_matter_cluster_get(endpoint, cluster_id);
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get(cluster, attribute_id);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
esp_matter_attribute_val_print(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else if (argc == 4 && strncmp(argv[0], "send_bind", sizeof("send_bind")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
@@ -93,7 +64,7 @@ static void app_driver_register_commands()
|
||||
esp_matter_console_command_t command = {
|
||||
.name = "driver",
|
||||
.description = "This can be used to simulate on-device control. Usage: matter esp driver <driver_command>. "
|
||||
"Driver commands: help, set, get, send, send_bind",
|
||||
"Driver commands: help, send, send_bind",
|
||||
.handler = app_driver_console_handler,
|
||||
};
|
||||
esp_matter_console_add_command(&command);
|
||||
@@ -101,7 +72,8 @@ static void app_driver_register_commands()
|
||||
|
||||
void app_driver_client_command_callback(esp_matter_peer_device_t *peer_device, int remote_endpoint_id, void *priv_data)
|
||||
{
|
||||
/** TODO: Find a better way to get the cluster_id and command_id */
|
||||
/** TODO: Find a better way to get the cluster_id and command_id.
|
||||
Once done, move the console commands to esp_matter_client. */
|
||||
if (g_cluster_id == ZCL_ON_OFF_CLUSTER_ID) {
|
||||
if (g_command_id == ZCL_OFF_COMMAND_ID) {
|
||||
esp_matter_on_off_send_command_off(peer_device, remote_endpoint_id);
|
||||
@@ -113,7 +85,7 @@ void app_driver_client_command_callback(esp_matter_peer_device_t *peer_device, i
|
||||
}
|
||||
}
|
||||
|
||||
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_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
/* Nothing to do here */
|
||||
return ESP_OK;
|
||||
@@ -133,8 +105,9 @@ static esp_err_t app_driver_attribute_set_defaults()
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
|
||||
while (attribute) {
|
||||
int attribute_id = esp_matter_attribute_get_id(attribute);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
||||
err |= esp_matter_attribute_get_val(attribute, &val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
attribute = esp_matter_attribute_get_next(attribute);
|
||||
}
|
||||
cluster = esp_matter_cluster_get_next(cluster);
|
||||
|
||||
@@ -24,7 +24,7 @@ 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);
|
||||
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
}
|
||||
|
||||
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data)
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <device.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <light_driver.h>
|
||||
|
||||
#include <app_driver.h>
|
||||
@@ -30,107 +29,31 @@ extern int light_endpoint_id;
|
||||
#define MATTER_SATURATION 255
|
||||
#define MATTER_TEMPERATURE 255
|
||||
|
||||
static uint32_t app_driver_light_get_attribute(int endpoint_id, int cluster_id, int attribute_id)
|
||||
{
|
||||
uint32_t value = 0;
|
||||
if (endpoint_id == light_endpoint_id) {
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID) {
|
||||
if (attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
value = (uint32_t)light_driver_get_power();
|
||||
}
|
||||
} else if (cluster_id == ZCL_LEVEL_CONTROL_CLUSTER_ID) {
|
||||
if (attribute_id == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) {
|
||||
value = (uint32_t)light_driver_get_brightness();
|
||||
value = REMAP_TO_RANGE(value, STANDARD_BRIGHTNESS, MATTER_BRIGHTNESS);
|
||||
}
|
||||
} else if (cluster_id == ZCL_COLOR_CONTROL_CLUSTER_ID) {
|
||||
if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) {
|
||||
value = (uint32_t)light_driver_get_hue();
|
||||
value = REMAP_TO_RANGE(value, STANDARD_HUE, MATTER_HUE);
|
||||
} else if (attribute_id == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID) {
|
||||
value = (uint32_t)light_driver_get_saturation();
|
||||
value = REMAP_TO_RANGE(value, STANDARD_SATURATION, MATTER_SATURATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
{
|
||||
if (argc == 5 && strncmp(argv[0], "set", sizeof("set")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
esp_matter_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else if (argc == 4 && strncmp(argv[0], "get", sizeof("get")) == 0) {
|
||||
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
|
||||
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = app_driver_light_get_attribute(endpoint_id, cluster_id, attribute_id);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
val.type = ESP_MATTER_VAL_TYPE_BOOLEAN;
|
||||
val.val.b = (bool)value;
|
||||
}
|
||||
esp_matter_attribute_val_print(endpoint_id, cluster_id, attribute_id, val);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Incorrect arguments");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void app_driver_register_commands()
|
||||
{
|
||||
esp_matter_console_command_t command = {
|
||||
.name = "driver",
|
||||
.description = "This can be used to simulate on-device control. "
|
||||
"Usage: matter esp driver <set|get> <endpoint_id> <cluster_id> <attribute_id> [value]. "
|
||||
"Example1: matter esp driver set 0x1001 0x0006 0x0000 1. "
|
||||
"Example2: matter esp driver get 0x1001 0x0006 0x0000.",
|
||||
.handler = app_driver_console_handler,
|
||||
};
|
||||
esp_matter_console_add_command(&command);
|
||||
}
|
||||
|
||||
/* Do any conversions/remapping for the actual value here */
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t *val)
|
||||
{
|
||||
return light_driver_set_power(val.val.b);
|
||||
return light_driver_set_power(val->val.b);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t *val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
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_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
if (endpoint_id == light_endpoint_id) {
|
||||
@@ -170,28 +93,28 @@ esp_err_t app_driver_attribute_set_defaults()
|
||||
attribute_id = ZCL_ON_OFF_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_bool(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
|
||||
endpoint_id = light_endpoint_id;
|
||||
cluster_id = ZCL_LEVEL_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_CURRENT_LEVEL_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
|
||||
endpoint_id = light_endpoint_id;
|
||||
cluster_id = ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
|
||||
endpoint_id = light_endpoint_id;
|
||||
cluster_id = ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -199,6 +122,5 @@ esp_err_t app_driver_attribute_set_defaults()
|
||||
esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
app_driver_register_commands();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ 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);
|
||||
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();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
}
|
||||
|
||||
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
|
||||
int attribute_id, esp_matter_attr_val_t val, void *priv_data)
|
||||
int attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user