From 438ceb36b9871fc9064130f6efed56ad5dd4782b Mon Sep 17 00:00:00 2001 From: liyashuai Date: Thu, 18 Aug 2022 13:50:00 +0800 Subject: [PATCH] user-label: add-user-label-cluster --- .../esp_matter/esp_matter_attribute.cpp | 12 ++++++ components/esp_matter/esp_matter_attribute.h | 6 +++ components/esp_matter/esp_matter_cluster.cpp | 38 +++++++++++++++++++ components/esp_matter/esp_matter_cluster.h | 9 +++++ 4 files changed, 65 insertions(+) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 0a1903444..ba1d7c979 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -699,6 +699,18 @@ attribute_t *create_reachable(cluster_t *cluster, bool value) } /* attribute */ } /* bridged_device_basic */ +namespace user_label { +namespace attribute { + +attribute_t *create_label_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, UserLabel::Attributes::LabelList::Id, ATTRIBUTE_FLAG_WRITABLE, + esp_matter_array(value, length, count)); +} + +} /* attribute */ +} /* user_label */ + namespace fixed_label { namespace attribute { diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 234be42ec..814d34906 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -206,6 +206,12 @@ attribute_t *create_reachable(cluster_t *cluster, bool value); } /* attribute */ } /* bridged_device_basic */ +namespace user_label { +namespace attribute { +attribute_t *create_label_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +} /* attribute */ +} /* user_label */ + namespace fixed_label { namespace attribute { attribute_t *create_label_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index bc7e7e6f0..b49a1d0a8 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -780,6 +780,44 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* bridged_device_basic */ +namespace user_label { +const function_generic_t *function_list = NULL; +const int function_flags = CLUSTER_FLAG_NONE; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) +{ + cluster_t *cluster = cluster::create(endpoint, UserLabel::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + set_plugin_server_init_callback(cluster, MatterUserLabelPluginServerInitCallback); + add_function_list(cluster, function_list, function_flags); + } + if (flags & CLUSTER_FLAG_CLIENT) { + set_plugin_client_init_callback(cluster, MatterUserLabelPluginClientInitCallback); + create_default_binding_cluster(endpoint); + } + + if (flags & CLUSTER_FLAG_SERVER) { + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_label_list(cluster, NULL, 0, 0); + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + return cluster; +} +} /* user_label */ + namespace fixed_label { const function_generic_t *function_list = NULL; const int function_flags = CLUSTER_FLAG_NONE; diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 3bdf64792..2c0889fcd 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -175,6 +175,15 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* bridged_device_basic */ +namespace user_label { +typedef struct config { + uint16_t cluster_revision; + config() : cluster_revision(1) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* user_label */ + namespace fixed_label { typedef struct config { uint16_t cluster_revision;