esp_matter: Using namespaces everywhere

Adding constructors to structs for default values of the cluster configs.
esp_matter_command: Removing the support for custom command callbacks and instead using the standard command callback itself. Also some other minor changes to make it easier for the application to use the standard command callback.
This commit is contained in:
Chirag Atal
2022-04-01 17:14:44 +05:30
parent 8a14138e17
commit b4d240e4a1
42 changed files with 4058 additions and 3737 deletions
+8 -6
View File
@@ -22,6 +22,9 @@
#include "zigbee_bridge.h"
static const char *TAG = "app_main";
using namespace esp_matter;
using namespace esp_matter::attribute;
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
{
if (event->Type == chip::DeviceLayer::DeviceEventType::PublicEventTypes::kInterfaceIpAddressChanged) {
@@ -31,12 +34,12 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
ESP_LOGI(TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int endpoint_id, int cluster_id,
static esp_err_t app_attribute_update_cb(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 err = ESP_OK;
if (type == ESP_MATTER_CALLBACK_TYPE_PRE_ATTRIBUTE) {
if (type == PRE_ATTRIBUTE) {
err = zigbee_bridge_attribute_update(endpoint_id, cluster_id, attribute_id, val);
}
return err;
@@ -50,8 +53,8 @@ extern "C" void app_main()
nvs_flash_init();
/* Create matter device */
esp_matter_node_config_t node_config = NODE_CONFIG_DEFAULT();
esp_matter_node_t *node = esp_matter_node_create(&node_config, app_attribute_update_cb, NULL);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, NULL);
/* These node and endpoint handles can be used to create/add other endpoints and clusters. */
if (!node) {
@@ -59,8 +62,7 @@ extern "C" void app_main()
}
/* Matter start */
err = esp_matter_start(app_event_cb);
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Matter start failed: %d", err);
}
@@ -21,4 +21,4 @@
#include <esp_matter_cluster.h>
#define MATTER_PLUGINS_INIT esp_matter_cluster_plugin_init_callback_common();
#define MATTER_PLUGINS_INIT esp_matter::cluster::plugin_init_callback_common();
@@ -20,17 +20,20 @@
static const char *TAG = "zigbee_bridge";
using namespace esp_matter;
using namespace esp_matter::cluster;
static esp_err_t init_bridged_onoff_light(esp_matter_bridge_device_t *dev)
{
if (!dev) {
ESP_LOGE(TAG, "Invalid bridge device to be initialized");
return ESP_ERR_INVALID_ARG;
}
esp_matter_cluster_on_off_config_t on_off_config = CLUSTER_CONFIG_ON_OFF_DEFAULT();
esp_matter_cluster_create_on_off(dev->endpoint, &on_off_config, CLUSTER_MASK_SERVER, ESP_MATTER_NONE_FEATURE_ID);
if (esp_matter_endpoint_enable(dev->endpoint) != ESP_OK) {
on_off::config_t config;
on_off::create(dev->endpoint, &config, CLUSTER_MASK_SERVER, ESP_MATTER_NONE_FEATURE_ID);
if (endpoint::enable(dev->endpoint) != ESP_OK) {
ESP_LOGE(TAG, "ESP Matter enable dynamic endpoint failed");
esp_matter_endpoint_delete(dev->node, dev->endpoint);
endpoint::destroy(dev->node, dev->endpoint);
return ESP_FAIL;
}
return ESP_OK;
@@ -46,7 +49,7 @@ void zigbee_bridge_match_bridged_onoff_light_cb(zb_bufid_t bufid)
if ((p_resp->status == ZB_ZDP_STATUS_SUCCESS) && (p_resp->match_len > 0)) {
p_match_ep = (zb_uint8_t *)(p_resp + 1);
esp_matter_node_t *node = esp_matter_node_get();
node_t *node = node::get();
ESP_GOTO_ON_FALSE(node, ESP_ERR_INVALID_STATE, exit, TAG, "Could not find esp_matter node");
if (app_bridge_get_zigbee_device_by_zigbee_shortaddr(p_ind->src_addr)) {
ESP_LOGI(TAG, "Bridged node for 0x%04x zigbee device on endpoint %d has been created", p_ind->src_addr,
@@ -18,11 +18,13 @@
#include <app_bridge_zigbee_device.h>
using esp_matter::node_t;
static const char *TAG = "esp_matter_bridge_zigbee";
static app_bridge_zigbee_device_t *device_list = NULL;
static uint8_t current_bridged_device_count = 0;
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(esp_matter_node_t *node, uint8_t zigbee_endpointid,
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
uint16_t zigbee_shortaddr)
{
if (current_bridged_device_count >= MAX_BRIDGED_DEVICE_COUNT) {
@@ -17,6 +17,8 @@
#if CONFIG_ZB_ENABLED
#include <esp_matter_bridge.h>
using esp_matter::node_t;
typedef struct app_bridge_zigbee_device {
esp_matter_bridge_device_t *dev;
uint8_t zigbee_endpointid;
@@ -24,7 +26,7 @@ typedef struct app_bridge_zigbee_device {
struct app_bridge_zigbee_device *next;
} app_bridge_zigbee_device_t;
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(esp_matter_node_t *node, uint8_t zigbee_endpointid,
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
uint16_t zigbee_shortaddr);
uint16_t app_bridge_get_zigbee_shortaddr_by_matter_endpointid(int matter_endpointid);
+13 -11
View File
@@ -16,6 +16,8 @@
#include <app_priv.h>
using namespace esp_matter;
static const char *TAG = "app_driver";
extern int light_endpoint_id;
@@ -70,24 +72,24 @@ static esp_err_t app_driver_attribute_set_defaults()
{
/* Get the default value (current value) from esp_matter and update the app_driver */
esp_err_t err = ESP_OK;
esp_matter_node_t *node = esp_matter_node_get();
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(node);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get_first(node);
while (endpoint) {
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
int endpoint_id = endpoint::get_id(endpoint);
cluster_t *cluster = cluster::get_first(endpoint);
while (cluster) {
int cluster_id = esp_matter_cluster_get_id(cluster);
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
int cluster_id = cluster::get_id(cluster);
attribute_t *attribute = attribute::get_first(cluster);
while (attribute) {
int attribute_id = esp_matter_attribute_get_id(attribute);
int attribute_id = attribute::get_id(attribute);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
err |= esp_matter_attribute_get_val(attribute, &val);
err |= attribute::get_val(attribute, &val);
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
attribute = esp_matter_attribute_get_next(attribute);
attribute = attribute::get_next(attribute);
}
cluster = esp_matter_cluster_get_next(cluster);
cluster = cluster::get_next(cluster);
}
endpoint = esp_matter_endpoint_get_next(endpoint);
endpoint = endpoint::get_next(endpoint);
}
return err;
}
+14 -12
View File
@@ -21,6 +21,10 @@
static const char *TAG = "app_main";
int light_endpoint_id = 0;
using namespace esp_matter;
using namespace esp_matter::attribute;
using namespace esp_matter::endpoint;
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
{
if (event->Type == chip::DeviceLayer::DeviceEventType::PublicEventTypes::kInterfaceIpAddressChanged) {
@@ -32,15 +36,15 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
ESP_LOGI(TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
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)
static esp_err_t app_attribute_update_cb(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 err = ESP_OK;
if (type == ESP_MATTER_CALLBACK_TYPE_PRE_ATTRIBUTE) {
if (type == PRE_ATTRIBUTE) {
/* Driver update */
err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
} else if (type == ESP_MATTER_CALLBACK_TYPE_POST_ATTRIBUTE) {
} else if (type == POST_ATTRIBUTE) {
/* Other ecosystems update */
}
@@ -55,17 +59,16 @@ extern "C" void app_main()
nvs_flash_init();
/* Create matter device */
esp_matter_node_config_t node_config = NODE_CONFIG_DEFAULT();
esp_matter_node_t *node = esp_matter_node_create(&node_config, app_attribute_update_cb, NULL);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, NULL);
esp_matter_endpoint_color_dimmable_light_config_t light_config = ENDPOINT_CONFIG_COLOR_DIMMABLE_LIGHT_DEFAULT();
color_dimmable_light::config_t light_config;
light_config.on_off.on_off = DEFAULT_POWER;
light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
light_config.color_control.hue_saturation.current_hue = DEFAULT_HUE;
light_config.color_control.hue_saturation.current_saturation = DEFAULT_SATURATION;
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_create_color_dimmable_light(node, &light_config,
ESP_MATTER_ENDPOINT_FLAG_NONE);
light_endpoint_id = esp_matter_endpoint_get_id(endpoint);
endpoint_t *endpoint = color_dimmable_light::create(node, &light_config, ESP_MATTER_ENDPOINT_FLAG_NONE);
light_endpoint_id = endpoint::get_id(endpoint);
/* These node and endpoint handles can be used to create/add other endpoints and clusters. */
if (!node || !endpoint) {
@@ -77,8 +80,7 @@ extern "C" void app_main()
app_driver_init();
/* Matter start */
err = esp_matter_start(app_event_cb);
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Matter start failed: %d", err);
}
@@ -21,4 +21,4 @@
#include <esp_matter_cluster.h>
#define MATTER_PLUGINS_INIT esp_matter_cluster_plugin_init_callback_common();
#define MATTER_PLUGINS_INIT esp_matter::cluster::plugin_init_callback_common();
+13 -11
View File
@@ -16,6 +16,8 @@
#include <app_priv.h>
using namespace esp_matter;
static const char *TAG = "app_driver";
extern int light_endpoint_id;
@@ -70,24 +72,24 @@ static esp_err_t app_driver_attribute_set_defaults()
{
/* Get the default value (current value) from esp_matter and update the app_driver */
esp_err_t err = ESP_OK;
esp_matter_node_t *node = esp_matter_node_get();
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(node);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get_first(node);
while (endpoint) {
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
int endpoint_id = endpoint::get_id(endpoint);
cluster_t *cluster = cluster::get_first(endpoint);
while (cluster) {
int cluster_id = esp_matter_cluster_get_id(cluster);
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
int cluster_id = cluster::get_id(cluster);
attribute_t *attribute = attribute::get_first(cluster);
while (attribute) {
int attribute_id = esp_matter_attribute_get_id(attribute);
int attribute_id = attribute::get_id(attribute);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
err |= esp_matter_attribute_get_val(attribute, &val);
err |= attribute::get_val(attribute, &val);
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
attribute = esp_matter_attribute_get_next(attribute);
attribute = attribute::get_next(attribute);
}
cluster = esp_matter_cluster_get_next(cluster);
cluster = cluster::get_next(cluster);
}
endpoint = esp_matter_endpoint_get_next(endpoint);
endpoint = endpoint::get_next(endpoint);
}
return err;
}
+14 -20
View File
@@ -21,6 +21,10 @@
static const char *TAG = "app_main";
int light_endpoint_id = 0;
using namespace esp_matter;
using namespace esp_matter::attribute;
using namespace esp_matter::endpoint;
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
{
if (event->Type == chip::DeviceLayer::DeviceEventType::PublicEventTypes::kInterfaceIpAddressChanged) {
@@ -32,15 +36,15 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
ESP_LOGI(TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
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)
static esp_err_t app_attribute_update_cb(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 err = ESP_OK;
if (type == ESP_MATTER_CALLBACK_TYPE_PRE_ATTRIBUTE) {
if (type == PRE_ATTRIBUTE) {
/* Driver update */
err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
} else if (type == ESP_MATTER_CALLBACK_TYPE_POST_ATTRIBUTE) {
} else if (type == POST_ATTRIBUTE) {
/* Other ecosystems update */
err = app_rainmaker_attribute_update(endpoint_id, cluster_id, attribute_id, val);
}
@@ -48,14 +52,6 @@ static esp_err_t app_attribute_update_cb(esp_matter_callback_type_t type, int en
return err;
}
esp_err_t app_command_callback(int endpoint_id, int cluster_id, int command_id, TLVReader &tlv_data, void *priv_data)
{
esp_err_t err = ESP_OK;
/* Pass all the commands to all the ecosystems, if their command callbacks exist */
err = app_rainmaker_command_callback(endpoint_id, cluster_id, command_id, tlv_data, priv_data);
return err;
}
extern "C" void app_main()
{
esp_err_t err = ESP_OK;
@@ -64,17 +60,16 @@ extern "C" void app_main()
nvs_flash_init();
/* Create matter device */
esp_matter_node_config_t node_config = NODE_CONFIG_DEFAULT();
esp_matter_node_t *node = esp_matter_node_create(&node_config, app_attribute_update_cb, NULL);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, NULL);
esp_matter_endpoint_color_dimmable_light_config_t light_config = ENDPOINT_CONFIG_COLOR_DIMMABLE_LIGHT_DEFAULT();
color_dimmable_light::config_t light_config;
light_config.on_off.on_off = DEFAULT_POWER;
light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
light_config.color_control.hue_saturation.current_hue = DEFAULT_HUE;
light_config.color_control.hue_saturation.current_saturation = DEFAULT_SATURATION;
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_create_color_dimmable_light(node, &light_config,
ESP_MATTER_ENDPOINT_FLAG_NONE);
light_endpoint_id = esp_matter_endpoint_get_id(endpoint);
endpoint_t *endpoint = color_dimmable_light::create(node, &light_config, ESP_MATTER_ENDPOINT_FLAG_NONE);
light_endpoint_id = endpoint::get_id(endpoint);
/* These node and endpoint handles can be used to create/add other endpoints and clusters. */
if (!node || !endpoint) {
@@ -86,11 +81,10 @@ extern "C" void app_main()
app_driver_init();
/* Initialize rainmaker */
esp_matter_command_set_custom_callback(app_command_callback, NULL);
app_rainmaker_init();
/* Matter start */
err = esp_matter_start(app_event_cb);
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Matter start failed: %d", err);
}
+28 -33
View File
@@ -25,6 +25,8 @@
#include <esp_matter_console.h>
#include <esp_matter_rainmaker.h>
using namespace esp_matter;
static const char *TAG = "app_rainmaker";
extern int light_endpoint_id;
@@ -108,7 +110,7 @@ static const char *app_rainmaker_get_device_name_from_id(int endpoint_id)
static const char *app_rainmaker_get_device_type_from_id(int device_type_id)
{
if (device_type_id == ESP_MATTER_COLOR_DIMMABLE_LIGHT_DEVICE_TYPE_ID) {
if (device_type_id == endpoint::color_dimmable_light::get_device_type_id()) {
return ESP_RMAKER_DEVICE_LIGHTBULB;
}
return NULL;
@@ -207,11 +209,10 @@ static bool app_rainmaker_get_param_bounds_from_id(int cluster_id, int attribute
return false;
}
static esp_err_t app_rainmaker_param_add_ui_type(esp_rmaker_param_t *param, esp_matter_cluster_t *cluster,
esp_matter_attribute_t *attribute)
static esp_err_t app_rainmaker_param_add_ui_type(esp_rmaker_param_t *param, cluster_t *cluster, attribute_t *attribute)
{
int cluster_id = esp_matter_cluster_get_id(cluster);
int attribute_id = esp_matter_attribute_get_id(attribute);
int cluster_id = cluster::get_id(cluster);
int attribute_id = attribute::get_id(attribute);
const char *ui_type = app_rainmaker_get_param_ui_type_from_id(cluster_id, attribute_id);
if (!ui_type) {
return ESP_OK;
@@ -219,12 +220,11 @@ static esp_err_t app_rainmaker_param_add_ui_type(esp_rmaker_param_t *param, esp_
return esp_rmaker_param_add_ui_type(param, ui_type);
}
static esp_err_t app_rainmaker_param_add_bounds(esp_rmaker_param_t *param, esp_matter_cluster_t *cluster,
esp_matter_attribute_t *attribute)
static esp_err_t app_rainmaker_param_add_bounds(esp_rmaker_param_t *param, cluster_t *cluster, 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);
int cluster_id = cluster::get_id(cluster);
int attribute_id = attribute::get_id(attribute);
esp_matter_attr_bounds_t *bounds = attribute::get_bounds(attribute);
if (bounds) {
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);
@@ -294,12 +294,6 @@ esp_err_t app_rainmaker_attribute_update(int endpoint_id, int cluster_id, int at
return esp_rmaker_param_update_and_report(param, rmaker_val);
}
esp_err_t app_rainmaker_command_callback(int endpoint_id, int cluster_id, int command_id, TLVReader &tlv_data,
void *priv_data)
{
return esp_matter_rainmaker_command_callback(endpoint_id, cluster_id, command_id, tlv_data, priv_data);
}
/* Callback to handle commands received from the RainMaker cloud */
static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
@@ -314,20 +308,21 @@ 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((esp_rmaker_param_val_t *)&val, cluster_id, attribute_id);
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);
return attribute::update(endpoint_id, cluster_id, attribute_id, &matter_val);
}
static esp_rmaker_device_t *app_rainmaker_device_create(const esp_rmaker_node_t *node, esp_matter_endpoint_t *endpoint)
static esp_rmaker_device_t *app_rainmaker_device_create(const esp_rmaker_node_t *node, endpoint_t *endpoint)
{
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
int endpoint_id = endpoint::get_id(endpoint);
const char *device_name = app_rainmaker_get_device_name_from_id(endpoint_id);
if (!device_name) {
return NULL;
}
/* Add this device only if endpoint_id has been handled */
int device_type_id = esp_matter_endpoint_get_device_type_id(endpoint_id);
int device_type_id = endpoint::get_device_type_id(endpoint_id);
const char *device_type = app_rainmaker_get_device_type_from_id(device_type_id);
esp_rmaker_device_t *device = esp_rmaker_device_create(device_name, device_type, NULL);
if (!device) {
@@ -339,11 +334,11 @@ static esp_rmaker_device_t *app_rainmaker_device_create(const esp_rmaker_node_t
return device;
}
static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *device, esp_matter_cluster_t *cluster,
esp_matter_attribute_t *attribute)
static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *device, cluster_t *cluster,
attribute_t *attribute)
{
int cluster_id = esp_matter_cluster_get_id(cluster);
int attribute_id = esp_matter_attribute_get_id(attribute);
int cluster_id = cluster::get_id(cluster);
int attribute_id = attribute::get_id(attribute);
const char *param_name = app_rainmaker_get_param_name_from_id(cluster_id, attribute_id);
if (!param_name) {
return NULL;
@@ -351,7 +346,7 @@ static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *devic
/* Add this param only if attribute_id corresponding to the cluster_id is handled */
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);
attribute::get_val(attribute, &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);
@@ -369,27 +364,27 @@ static esp_rmaker_param_t *app_rainmaker_param_create(esp_rmaker_device_t *devic
static void app_rainmaker_data_model_create()
{
const esp_rmaker_node_t *node = esp_rmaker_get_node();
esp_matter_node_t *matter_node = esp_matter_node_get();
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(matter_node);
node_t *matter_node = node::get();
endpoint_t *endpoint = endpoint::get_first(matter_node);
/* Parse all endpoints */
while (endpoint) {
esp_rmaker_device_t *device = app_rainmaker_device_create(node, endpoint);
/* Proceed only if the device has been handled */
if (device) {
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
cluster_t *cluster = cluster::get_first(endpoint);
/* Parse all clusters */
while (cluster) {
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
attribute_t *attribute = attribute::get_first(cluster);
/* Parse all attributes */
while (attribute) {
app_rainmaker_param_create(device, cluster, attribute);
attribute = esp_matter_attribute_get_next(attribute);
attribute = attribute::get_next(attribute);
}
cluster = esp_matter_cluster_get_next(cluster);
cluster = cluster::get_next(cluster);
}
}
endpoint = esp_matter_endpoint_get_next(endpoint);
endpoint = endpoint::get_next(endpoint);
}
}
@@ -36,9 +36,6 @@ esp_err_t app_rainmaker_start(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_command_callback(int endpoint_id, int cluster_id, int command_id, TLVReader &tlv_data,
void *priv_data);
#ifdef __cplusplus
}
#endif
@@ -21,4 +21,4 @@
#include <esp_matter_cluster.h>
#define MATTER_PLUGINS_INIT esp_matter_cluster_plugin_init_callback_common();
#define MATTER_PLUGINS_INIT esp_matter::cluster::plugin_init_callback_common();
+22 -19
View File
@@ -18,7 +18,10 @@
#include <app_priv.h>
using chip::kInvalidClusterId;
static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF;
static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF;
using namespace esp_matter;
using namespace esp_matter::cluster;
static const char *TAG = "app_driver";
extern int switch_endpoint_id;
@@ -41,7 +44,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
g_cluster_id = cluster_id;
g_command_id = command_id;
esp_matter_client_cluster_update(endpoint_id, cluster_id);
client::cluster_update(endpoint_id, cluster_id);
} else if (argc == 6 && strncmp(argv[0], "send", sizeof("send")) == 0) {
int fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
int node_id = strtol((const char *)&argv[2][2], NULL, 16);
@@ -51,7 +54,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
g_cluster_id = cluster_id;
g_command_id = command_id;
esp_matter_connect(fabric_index, node_id, remote_endpoint_id);
client::connect(fabric_index, node_id, remote_endpoint_id);
} else {
ESP_LOGE(TAG, "Incorrect arguments. Check help for more details.");
return ESP_ERR_INVALID_ARG;
@@ -70,17 +73,17 @@ static void app_driver_register_commands()
esp_matter_console_add_command(&command);
}
void app_driver_client_command_callback(esp_matter_peer_device_t *peer_device, int remote_endpoint_id, void *priv_data)
void app_driver_client_command_callback(client::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.
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);
on_off::command::send_off(peer_device, remote_endpoint_id);
} else if (g_command_id == ZCL_ON_COMMAND_ID) {
esp_matter_on_off_send_command_on(peer_device, remote_endpoint_id);
on_off::command::send_on(peer_device, remote_endpoint_id);
} else if (g_command_id == ZCL_TOGGLE_COMMAND_ID) {
esp_matter_on_off_send_command_toggle(peer_device, remote_endpoint_id);
on_off::command::send_toggle(peer_device, remote_endpoint_id);
}
}
}
@@ -95,24 +98,24 @@ static esp_err_t app_driver_attribute_set_defaults()
{
/* Get the default value (current value) from esp_matter and update the app_driver */
esp_err_t err = ESP_OK;
esp_matter_node_t *node = esp_matter_node_get();
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(node);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get_first(node);
while (endpoint) {
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
int endpoint_id = endpoint::get_id(endpoint);
cluster_t *cluster = cluster::get_first(endpoint);
while (cluster) {
int cluster_id = esp_matter_cluster_get_id(cluster);
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
int cluster_id = cluster::get_id(cluster);
attribute_t *attribute = attribute::get_first(cluster);
while (attribute) {
int attribute_id = esp_matter_attribute_get_id(attribute);
int attribute_id = attribute::get_id(attribute);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
err |= esp_matter_attribute_get_val(attribute, &val);
err |= attribute::get_val(attribute, &val);
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, &val);
attribute = esp_matter_attribute_get_next(attribute);
attribute = attribute::get_next(attribute);
}
cluster = esp_matter_cluster_get_next(cluster);
cluster = cluster::get_next(cluster);
}
endpoint = esp_matter_endpoint_get_next(endpoint);
endpoint = endpoint::get_next(endpoint);
}
return err;
}
@@ -123,6 +126,6 @@ esp_err_t app_driver_init()
// device_init();
app_driver_attribute_set_defaults();
app_driver_register_commands();
esp_matter_set_client_command_callback(app_driver_client_command_callback, NULL);
client::set_command_callback(app_driver_client_command_callback, NULL);
return ESP_OK;
}
+14 -12
View File
@@ -21,6 +21,10 @@
static const char *TAG = "app_main";
int switch_endpoint_id = 0;
using namespace esp_matter;
using namespace esp_matter::attribute;
using namespace esp_matter::endpoint;
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
{
if (event->Type == chip::DeviceLayer::DeviceEventType::PublicEventTypes::kInterfaceIpAddressChanged) {
@@ -32,15 +36,15 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
ESP_LOGI(TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
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)
static esp_err_t app_attribute_update_cb(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 err = ESP_OK;
if (type == ESP_MATTER_CALLBACK_TYPE_PRE_ATTRIBUTE) {
if (type == PRE_ATTRIBUTE) {
/* Driver update */
err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
} else if (type == ESP_MATTER_CALLBACK_TYPE_POST_ATTRIBUTE) {
} else if (type == POST_ATTRIBUTE) {
/* Other ecosystems update */
}
@@ -55,13 +59,12 @@ extern "C" void app_main()
nvs_flash_init();
/* Create matter device */
esp_matter_node_config_t node_config = NODE_CONFIG_DEFAULT();
esp_matter_node_t *node = esp_matter_node_create(&node_config, app_attribute_update_cb, NULL);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, NULL);
esp_matter_endpoint_on_off_switch_config_t switch_config = ENDPOINT_CONFIG_ON_OFF_SWITCH_DEFAULT();
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_create_on_off_switch(node, &switch_config,
ESP_MATTER_ENDPOINT_FLAG_NONE);
switch_endpoint_id = esp_matter_endpoint_get_id(endpoint);
on_off_switch::config_t switch_config;
endpoint_t *endpoint = on_off_switch::create(node, &switch_config, ESP_MATTER_ENDPOINT_FLAG_NONE);
switch_endpoint_id = endpoint::get_id(endpoint);
/* These node and endpoint handles can be used to create/add other endpoints and clusters. */
if (!node || !endpoint) {
@@ -73,8 +76,7 @@ extern "C" void app_main()
app_driver_init();
/* Matter start */
err = esp_matter_start(app_event_cb);
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Matter start failed: %d", err);
}
@@ -21,4 +21,4 @@
#include <esp_matter_cluster.h>
#define MATTER_PLUGINS_INIT esp_matter_cluster_plugin_init_callback_common();
#define MATTER_PLUGINS_INIT esp_matter::cluster::plugin_init_callback_common();
+8 -6
View File
@@ -16,6 +16,8 @@
#include <app_priv.h>
using namespace esp_matter;
static const char *TAG = "app_driver";
extern int light_endpoint_id;
@@ -69,7 +71,7 @@ esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attri
esp_err_t app_driver_attribute_set_defaults()
{
/* When using static endpoints, i.e. using the data model from zap-generated, this needs to be done
after esp_matter_start() */
after esp_matter::start() */
/* Get the default value (current value) from matter submodule and update the app_driver */
esp_err_t err = ESP_OK;
uint8_t value;
@@ -81,28 +83,28 @@ esp_err_t app_driver_attribute_set_defaults()
endpoint_id = light_endpoint_id;
cluster_id = ZCL_ON_OFF_CLUSTER_ID;
attribute_id = ZCL_ON_OFF_ATTRIBUTE_ID;
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
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);
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));
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);
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));
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);
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));
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);
@@ -113,6 +115,6 @@ esp_err_t app_driver_init()
{
ESP_LOGI(TAG, "Initialising driver");
device_init();
/* Attribute defaults are set after esp_matter_start() from app_main() */
/* Attribute defaults are set after esp_matter::start() from app_main() */
return ESP_OK;
}
+11 -7
View File
@@ -13,9 +13,13 @@
#include <esp_matter.h>
#include <esp_matter_console.h>
#include <esp_route_hook.h>
#include <app_priv.h>
#include <app_qrcode.h>
using namespace esp_matter;
using namespace esp_matter::attribute;
static const char *TAG = "app_main";
int light_endpoint_id = 0;
@@ -30,15 +34,15 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
ESP_LOGI(TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
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)
static esp_err_t app_attribute_update_cb(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 err = ESP_OK;
if (type == ESP_MATTER_CALLBACK_TYPE_PRE_ATTRIBUTE) {
if (type == PRE_ATTRIBUTE) {
/* Driver update */
err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
} else if (type == ESP_MATTER_CALLBACK_TYPE_POST_ATTRIBUTE) {
} else if (type == POST_ATTRIBUTE) {
/* Other ecosystems update */
}
@@ -53,14 +57,14 @@ extern "C" void app_main()
nvs_flash_init();
/* Initialize matter callback */
esp_matter_attribute_callback_set(app_attribute_update_cb, NULL);
light_endpoint_id = 1; /* This is from zap-generated/endpoint_config.h */
attribute::set_callback(app_attribute_update_cb, NULL);
light_endpoint_id = 1; /* This is from zap-generated/endpoint_config.h */
/* Initialize driver */
app_driver_init();
/* Matter start */
err = esp_matter_start(app_event_cb);
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Matter start failed: %d", err);
}