From 699d8d0f783493bb466c461db2384bbab8b58f49 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 12 Aug 2024 12:57:54 +0530 Subject: [PATCH] examples: simplified attribute retrieval api --- .../all_device_types_app/main/app_driver.cpp | 10 ++------ examples/demo/badge/main/app_driver.cpp | 25 +++++-------------- .../esp-now_bridge_light/main/app_driver.cpp | 24 ++++++------------ .../esp-now_bridge_light/main/app_espnow.cpp | 10 ++------ examples/light/main/app_driver.cpp | 24 ++++++------------ .../room_air_conditioner/main/app_driver.cpp | 12 ++------- 6 files changed, 26 insertions(+), 79 deletions(-) diff --git a/examples/all_device_types_app/main/app_driver.cpp b/examples/all_device_types_app/main/app_driver.cpp index f2f7f7055..48dc06752 100644 --- a/examples/all_device_types_app/main/app_driver.cpp +++ b/examples/all_device_types_app/main/app_driver.cpp @@ -33,20 +33,14 @@ extern uint16_t app_endpoint_id; static void get_attribute(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val) { - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); attribute::get_val(attribute, val); } static esp_err_t set_attribute(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t val) { - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); return attribute::set_val(attribute, &val); } diff --git a/examples/demo/badge/main/app_driver.cpp b/examples/demo/badge/main/app_driver.cpp index 9102adedd..82a0cee5f 100644 --- a/examples/demo/badge/main/app_driver.cpp +++ b/examples/demo/badge/main/app_driver.cpp @@ -68,10 +68,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data) uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); attribute::get_val(attribute, &val); @@ -86,9 +83,6 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_ char vcard_data[MAX_VCARD_ATTR][MAX_ATTR_SIZE]; memset(vcard_data, '\0', sizeof(MAX_VCARD_ATTR * MAX_ATTR_SIZE)); esp_matter_attr_val_t _val = esp_matter_invalid(NULL); - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, 0x0); - cluster_t *cluster = cluster::get(endpoint, BADGE_CLUSTER_ID); attribute_t *attribute = NULL; uint32_t _attribute_id = NAME_ATTRIBUTE_ID; @@ -100,7 +94,7 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_ _attribute_id++; continue; } - attribute = attribute::get(cluster, _attribute_id); + attribute = attribute::get(0x0, cluster_id, _attribute_id); attribute::get_val(attribute, &_val); memcpy(vcard_data[i], _val.val.a.b, _val.val.a.s); vcard_data[i][_val.val.a.s] = '\0'; @@ -133,15 +127,10 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) esp_err_t err = ESP_OK; void *priv_data = endpoint::get_priv_data(endpoint_id); led_indicator_handle_t handle = (led_indicator_handle_t)priv_data; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = NULL; attribute_t *attribute = NULL; esp_matter_attr_val_t val = esp_matter_invalid(NULL); - endpoint = endpoint::get(node, 0x0); - cluster = cluster::get(endpoint, BADGE_CLUSTER_ID); - attribute = attribute::get(cluster, NAME_ATTRIBUTE_ID); + attribute = attribute::get(0x0, BADGE_CLUSTER_ID, NAME_ATTRIBUTE_ID); attribute::get_val(attribute, &val); if (val.val.a.b[NAME]) { char vcard_data[MAX_VCARD_ATTR][MAX_ATTR_SIZE]; @@ -150,7 +139,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) uint32_t attribute_id = NAME_ATTRIBUTE_ID; do { esp_matter_attr_val_t _val = esp_matter_invalid(NULL); - attribute = attribute::get(cluster, attribute_id); + attribute = attribute::get(0x0, BADGE_CLUSTER_ID, attribute_id); attribute::get_val(attribute, &_val); memcpy(vcard_data[i], _val.val.a.b, _val.val.a.s); vcard_data[i][_val.val.a.s] = '\0'; @@ -163,8 +152,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) } /* If nodelabel value is set then display the nodelabel_input */ - cluster = cluster::get(endpoint, BasicInformation::Id); - attribute = attribute::get(cluster, BasicInformation::Attributes::NodeLabel::Id); + attribute = attribute::get(0x0, BasicInformation::Id, BasicInformation::Attributes::NodeLabel::Id); attribute::get_val(attribute, &val); if (val.val.a.s && !badge_cluster_input_exists) { set_badge_name(&val); @@ -173,8 +161,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) /* Setting power */ if (!nodelabel_input) { - cluster = cluster::get(endpoint, OnOff::Id); - attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + attribute = attribute::get(0x0, OnOff::Id, OnOff::Attributes::OnOff::Id); attribute::get_val(attribute, &val); if (chip::Server::GetInstance().GetFabricTable().FabricCount()) err |= app_driver_light_set_power(handle, &val); diff --git a/examples/esp-now_bridge_light/main/app_driver.cpp b/examples/esp-now_bridge_light/main/app_driver.cpp index f166807d8..20f0ef14d 100644 --- a/examples/esp-now_bridge_light/main/app_driver.cpp +++ b/examples/esp-now_bridge_light/main/app_driver.cpp @@ -266,10 +266,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data) uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); attribute::get_val(attribute, &val); @@ -309,34 +306,28 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) esp_err_t err = ESP_OK; void *priv_data = endpoint::get_priv_data(endpoint_id); led_driver_handle_t handle = (led_driver_handle_t)priv_data; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = NULL; - attribute_t *attribute = NULL; esp_matter_attr_val_t val = esp_matter_invalid(NULL); /* Setting brightness */ - cluster = cluster::get(endpoint, LevelControl::Id); - attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id); + attribute_t *attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_brightness(handle, &val); /* Setting color */ - cluster = cluster::get(endpoint, ColorControl::Id); - attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id); attribute::get_val(attribute, &val); if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) { /* Setting hue */ - attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_hue(handle, &val); /* Setting saturation */ - attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_saturation(handle, &val); } else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) { /* Setting temperature */ - attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_temperature(handle, &val); } else { @@ -344,8 +335,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) } /* Setting power */ - cluster = cluster::get(endpoint, OnOff::Id); - attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_power(handle, &val); diff --git a/examples/esp-now_bridge_light/main/app_espnow.cpp b/examples/esp-now_bridge_light/main/app_espnow.cpp index a01ddaece..86c8f29fc 100644 --- a/examples/esp-now_bridge_light/main/app_espnow.cpp +++ b/examples/esp-now_bridge_light/main/app_espnow.cpp @@ -59,10 +59,7 @@ static void espnow_ctrl_onoff(espnow_addr_t src_addr, bool status) uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); attribute::get_val(attribute, &val); @@ -104,10 +101,7 @@ static void espnow_event_handler(void* handler_args, esp_event_base_t base, int3 uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index cc356b06a..180c1a2b6 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -95,10 +95,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data) uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); attribute::get_val(attribute, &val); @@ -138,34 +135,28 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) esp_err_t err = ESP_OK; void *priv_data = endpoint::get_priv_data(endpoint_id); led_indicator_handle_t handle = (led_indicator_handle_t)priv_data; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = NULL; - attribute_t *attribute = NULL; esp_matter_attr_val_t val = esp_matter_invalid(NULL); /* Setting brightness */ - cluster = cluster::get(endpoint, LevelControl::Id); - attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id); + attribute_t *attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_brightness(handle, &val); /* Setting color */ - cluster = cluster::get(endpoint, ColorControl::Id); - attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id); attribute::get_val(attribute, &val); if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) { /* Setting hue */ - attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_hue(handle, &val); /* Setting saturation */ - attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_saturation(handle, &val); } else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) { /* Setting temperature */ - attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id); + attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_temperature(handle, &val); } else { @@ -173,8 +164,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) } /* Setting power */ - cluster = cluster::get(endpoint, OnOff::Id); - attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id); attribute::get_val(attribute, &val); err |= app_driver_light_set_power(handle, &val); diff --git a/examples/room_air_conditioner/main/app_driver.cpp b/examples/room_air_conditioner/main/app_driver.cpp index ebc6f2c2b..c60969bfd 100644 --- a/examples/room_air_conditioner/main/app_driver.cpp +++ b/examples/room_air_conditioner/main/app_driver.cpp @@ -35,10 +35,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data) uint32_t cluster_id = OnOff::Id; uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); + attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id); esp_matter_attr_val_t val = esp_matter_invalid(NULL); attribute::get_val(attribute, &val); @@ -66,15 +63,10 @@ esp_err_t app_driver_room_air_conditioner_set_defaults(uint16_t endpoint_id) esp_err_t err = ESP_OK; void *priv_data = endpoint::get_priv_data(endpoint_id); led_driver_handle_t handle = (led_driver_handle_t)priv_data; - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = NULL; - attribute_t *attribute = NULL; esp_matter_attr_val_t val = esp_matter_invalid(NULL); /* Setting power */ - cluster = cluster::get(endpoint, OnOff::Id); - attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + attribute_t *attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id); attribute::get_val(attribute, &val); err |= app_driver_room_air_conditioner_set_power(handle, &val);