From 4cfcf617c90c8b4d37b4d29f36671cc8a5d88765 Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Tue, 12 Jul 2022 19:44:58 +0800 Subject: [PATCH] Feature: Add NumberOfPrimaries, PrimarynX, PrimarynY and PrimarynIntensity attributes in ColorControl cluster --- .../esp_matter/esp_matter_attribute.cpp | 105 ++++++++++++++++++ components/esp_matter/esp_matter_attribute.h | 4 + components/esp_matter/esp_matter_cluster.cpp | 6 + components/esp_matter/esp_matter_cluster.h | 3 +- 4 files changed, 117 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 8e5b8cf8f..80f52143f 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -1005,6 +1005,111 @@ attribute_t *create_color_loop_stored_enhanced_hue(cluster_t *cluster, uint16_t ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); } +attribute_t *create_number_of_primaries(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::NumberOfPrimaries::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); +} + +attribute_t *create_primary_n_x(cluster_t * cluster, uint16_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + default: + break; + } + return NULL; +} + +attribute_t *create_primary_n_y(cluster_t * cluster, uint16_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + default: + break; + } + return NULL; +} + +attribute_t *create_primary_n_intensity(cluster_t * cluster, uint8_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + default: + break; + } + return NULL; +} + } /* attribute */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 97afb00cc..4879032b8 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -265,6 +265,10 @@ attribute_t *create_color_loop_direction(cluster_t *cluster, uint8_t value); attribute_t *create_color_loop_time(cluster_t *cluster, uint16_t value); attribute_t *create_color_loop_start_enhanced_hue(cluster_t *cluster, uint16_t value); attribute_t *create_color_loop_stored_enhanced_hue(cluster_t *cluster, uint16_t value); +attribute_t *create_number_of_primaries(cluster_t *cluster, uint8_t value); +attribute_t *create_primary_n_x(cluster_t * cluster, uint16_t value, uint8_t index); +attribute_t *create_primary_n_y(cluster_t * cluster, uint16_t value, uint8_t index); +attribute_t *create_primary_n_intensity(cluster_t * cluster, uint8_t value, uint8_t index); } /* attribute */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index a6c72e7d2..b7046b92b 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1007,12 +1007,18 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ attribute::create_color_control_options(cluster, config->color_control_options); attribute::create_enhanced_color_mode(cluster, config->enhanced_color_mode); attribute::create_color_capabilities(cluster, config->color_capabilities); + attribute::create_number_of_primaries(cluster, config->number_of_primaries); } else { ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); } /* Attributes managed internally */ attribute::create_remaining_time(cluster, 0); + for (uint8_t idx = 1; idx <= config->number_of_primaries; ++idx) { + attribute::create_primary_n_x(cluster, 0, idx); + attribute::create_primary_n_y(cluster, 0, idx); + attribute::create_primary_n_intensity(cluster, 0, idx); + } } /* Features */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 31301b4fa..15932c9b8 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -223,13 +223,14 @@ typedef struct config { uint8_t color_control_options; uint8_t enhanced_color_mode; uint16_t color_capabilities; + uint8_t number_of_primaries; feature::hue_saturation::config_t hue_saturation; feature::color_temperature::config_t color_temperature; feature::xy::config_t xy; feature::enhanced_hue::config_t enhanced_hue; feature::color_loop::config_t color_loop; config() : cluster_revision(5), color_mode(1), color_control_options(0), enhanced_color_mode(1), - color_capabilities(0) {} + color_capabilities(0), number_of_primaries(0) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);