From c23555fcf77420b9d9b8972b7dc65bb1f653d8cf Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 15 Jun 2022 15:08:55 +0800 Subject: [PATCH] Cluster: Add enhanced-hue and color-loop features to color-control cluster --- .../esp_matter/esp_matter_attribute.cpp | 42 +++++++++ components/esp_matter/esp_matter_attribute.h | 7 ++ components/esp_matter/esp_matter_cluster.cpp | 12 +++ components/esp_matter/esp_matter_cluster.h | 3 + components/esp_matter/esp_matter_command.cpp | 90 +++++++++++++++++++ components/esp_matter/esp_matter_command.h | 5 ++ components/esp_matter/esp_matter_feature.cpp | 56 ++++++++++++ components/esp_matter/esp_matter_feature.h | 29 ++++++ 8 files changed, 244 insertions(+) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 00b3a7236..30c6603a5 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -758,6 +758,12 @@ attribute_t *create_current_saturation(cluster_t *cluster, uint8_t value) esp_matter_uint8(value)); } +attribute_t *create_remaining_time(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::RemainingTime::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); +} + attribute_t *create_color_mode(cluster_t *cluster, uint8_t value) { return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorMode::Id, ATTRIBUTE_FLAG_NONE, @@ -824,6 +830,42 @@ attribute_t *create_current_y(cluster_t *cluster, uint16_t value) esp_matter_uint16(value)); } +attribute_t *create_enhanced_current_hue(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::EnhancedCurrentHue::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); +} + +attribute_t *create_color_loop_active(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorLoopActive::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); +} + +attribute_t *create_color_loop_direction(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorLoopDirection::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); +} + +attribute_t *create_color_loop_time(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorLoopTime::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); +} + +attribute_t *create_color_loop_start_enhanced_hue(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorLoopStartEnhancedHue::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); +} + +attribute_t *create_color_loop_stored_enhanced_hue(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::ColorLoopStoredEnhancedHue::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); +} + } /* attribute */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index c95d6f523..8f0e7c11a 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -224,6 +224,7 @@ namespace color_control { namespace attribute { attribute_t *create_current_hue(cluster_t *cluster, uint8_t value); attribute_t *create_current_saturation(cluster_t *cluster, uint8_t value); +attribute_t *create_remaining_time(cluster_t *cluster, uint16_t value); attribute_t *create_color_mode(cluster_t *cluster, uint8_t value); attribute_t *create_color_control_options(cluster_t *cluster, uint8_t value); attribute_t *create_enhanced_color_mode(cluster_t *cluster, uint8_t value); @@ -235,6 +236,12 @@ attribute_t *create_couple_color_temp_to_level_min_mireds(cluster_t *cluster, ui attribute_t *create_startup_color_temperature_mireds(cluster_t *cluster, uint16_t value); attribute_t *create_current_x(cluster_t *cluster, uint16_t value); attribute_t *create_current_y(cluster_t *cluster, uint16_t value); +attribute_t *create_enhanced_current_hue(cluster_t *cluster, uint16_t value); +attribute_t *create_color_loop_active(cluster_t *cluster, uint8_t value); +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 */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index fae30c086..a6c72e7d2 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1010,6 +1010,9 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ } else { ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); } + + /* Attributes managed internally */ + attribute::create_remaining_time(cluster, 0); } /* Features */ @@ -1019,6 +1022,15 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ if (features & feature::color_temperature::get_id()) { feature::color_temperature::add(cluster, &(config->color_temperature)); } + if (features & feature::xy::get_id()) { + feature::xy::add(cluster, &(config->xy)); + } + if (features & feature::enhanced_hue::get_id()) { + feature::enhanced_hue::add(cluster, &(config->enhanced_hue)); + } + if (features & feature::color_loop::get_id()) { + feature::color_loop::add(cluster, &(config->color_loop)); + } return cluster; } diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index a2a7d35fd..31301b4fa 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -225,6 +225,9 @@ typedef struct config { uint16_t color_capabilities; 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) {} } config_t; diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 57774a5d3..8ec9702b6 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -855,6 +855,66 @@ static esp_err_t esp_matter_command_callback_step_color_temperature(const Concre return ESP_OK; } +static esp_err_t esp_matter_command_callback_enhanced_move_to_hue(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::ColorControl::Commands::EnhancedMoveToHue::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfColorControlClusterEnhancedMoveToHueCallback((CommandHandler *)opaque_ptr, command_path, + command_data); + } + return ESP_OK; +} + +static esp_err_t esp_matter_command_callback_enhanced_move_hue(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::ColorControl::Commands::EnhancedMoveHue::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfColorControlClusterEnhancedMoveHueCallback((CommandHandler *)opaque_ptr, command_path, + command_data); + } + return ESP_OK; +} + +static esp_err_t esp_matter_command_callback_enhanced_step_hue(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::ColorControl::Commands::EnhancedStepHue::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfColorControlClusterEnhancedStepHueCallback((CommandHandler *)opaque_ptr, command_path, + command_data); + } + return ESP_OK; +} + +static esp_err_t esp_matter_command_callback_enhanced_move_to_hue_and_saturation(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::ColorControl::Commands::EnhancedMoveToHueAndSaturation::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfColorControlClusterEnhancedMoveToHueAndSaturationCallback((CommandHandler *)opaque_ptr, command_path, + command_data); + } + return ESP_OK; +} + +static esp_err_t esp_matter_command_callback_color_loop_set(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::ColorControl::Commands::ColorLoopSet::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfColorControlClusterColorLoopSetCallback((CommandHandler *)opaque_ptr, command_path, + command_data); + } + return ESP_OK; +} + static esp_err_t esp_matter_command_callback_move_to_color(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr) { @@ -1611,6 +1671,36 @@ command_t *create_step_color(cluster_t *cluster) esp_matter_command_callback_step_color); } +command_t *create_enhanced_move_to_hue(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ColorControl::Commands::EnhancedMoveToHue::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_enhanced_move_to_hue); +} + +command_t *create_enhanced_move_hue(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ColorControl::Commands::EnhancedMoveHue::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_enhanced_move_hue); +} + +command_t *create_enhanced_step_hue(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ColorControl::Commands::EnhancedStepHue::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_enhanced_step_hue); +} + +command_t *create_enhanced_move_to_hue_and_saturation(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ColorControl::Commands::EnhancedMoveToHueAndSaturation::Id, + COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_enhanced_move_to_hue_and_saturation); +} + +command_t *create_color_loop_set(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ColorControl::Commands::ColorLoopSet::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_color_loop_set); +} + } /* command */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index ca5e968e8..6bbc5fb31 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -194,6 +194,11 @@ command_t *create_step_color_temperature(cluster_t *cluster); command_t *create_move_to_color(cluster_t *cluster); command_t *create_move_color(cluster_t *cluster); command_t *create_step_color(cluster_t *cluster); +command_t *create_enhanced_move_to_hue(cluster_t *cluster); +command_t *create_enhanced_move_hue(cluster_t *cluster); +command_t *create_enhanced_step_hue(cluster_t *cluster); +command_t *create_enhanced_move_to_hue_and_saturation(cluster_t *cluster); +command_t *create_color_loop_set(cluster_t *cluster); } /* command */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_feature.cpp b/components/esp_matter/esp_matter_feature.cpp index 0f6637c18..059f3f787 100644 --- a/components/esp_matter/esp_matter_feature.cpp +++ b/components/esp_matter/esp_matter_feature.cpp @@ -237,6 +237,62 @@ esp_err_t add(cluster_t *cluster, config_t *config) } } /* xy */ + +namespace enhanced_hue { + +uint32_t get_id() +{ + return (uint32_t)chip::app::Clusters::ColorControl::ColorCapabilities::kEnhancedHueSupported; +} + +esp_err_t add(cluster_t *cluster, config_t *config) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + /* Attributes not managed internally */ + attribute::create_enhanced_current_hue(cluster, config->enhanced_current_hue); + + /* Commands */ + command::create_enhanced_move_to_hue(cluster); + command::create_enhanced_move_hue(cluster); + command::create_enhanced_step_hue(cluster); + command::create_enhanced_move_to_hue_and_saturation(cluster); + + return ESP_OK; +} +} /* enhanced_hue */ + +namespace color_loop { +uint32_t get_id() +{ + return (uint32_t)chip::app::Clusters::ColorControl::ColorCapabilities::kColorLoopSupported; +} + +esp_err_t add(cluster_t *cluster, config_t *config) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + /* Attributes not managed internally */ + attribute::create_color_loop_active(cluster, config->color_loop_active); + attribute::create_color_loop_direction(cluster, config->color_loop_direction); + attribute::create_color_loop_time(cluster, config->color_loop_time); + attribute::create_color_loop_start_enhanced_hue(cluster, config->color_loop_start_enhanced_hue); + attribute::create_color_loop_stored_enhanced_hue(cluster, config->color_loop_stored_enhanced_hue); + + /* Commands */ + command::create_color_loop_set(cluster); + + return ESP_OK; +} +} /* color_loop */ } /* feature */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_feature.h b/components/esp_matter/esp_matter_feature.h index 643322663..f68626034 100644 --- a/components/esp_matter/esp_matter_feature.h +++ b/components/esp_matter/esp_matter_feature.h @@ -121,6 +121,35 @@ uint32_t get_id(); esp_err_t add(cluster_t *cluster, config_t *config); } /* xy */ + +namespace enhanced_hue { + +typedef struct config { + uint16_t enhanced_current_hue; + config() : enhanced_current_hue(0) {} +} config_t; + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster, config_t *config); + +} /* enhanced_hue */ + +namespace color_loop { + +typedef struct config { + uint8_t color_loop_active; + uint8_t color_loop_direction; + uint16_t color_loop_time; + uint16_t color_loop_start_enhanced_hue; + uint16_t color_loop_stored_enhanced_hue; + config() : color_loop_active(0), color_loop_direction(0), color_loop_time(0), + color_loop_start_enhanced_hue(0), color_loop_stored_enhanced_hue(0) {} +} config_t; + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster, config_t *config); + +} /* color_loop */ } /* feature */ } /* color_control */