diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 1950e2377..d34f1e9a9 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -720,6 +720,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) command::create_identify(cluster); command::create_identify_query(cluster); command::create_identify_query_response(cluster); + command::create_trigger_effect(cluster); return cluster; } diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 2179d5879..b53c90813 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -444,6 +444,17 @@ static esp_err_t esp_matter_command_callback_identify_query(const ConcreteComman return ESP_OK; } +static esp_err_t esp_matter_command_callback_trigger_effect(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::Identify::Commands::TriggerEffect::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfIdentifyClusterTriggerEffectCallback((CommandHandler *)opaque_ptr, command_path, command_data); + } + return ESP_OK; +} + static esp_err_t esp_matter_command_callback_add_group(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr) { @@ -1259,6 +1270,12 @@ command_t *create_identify_query_response(cluster_t *cluster) NULL); } +command_t *create_trigger_effect(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, Identify::Commands::TriggerEffect::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_trigger_effect); +} + } /* command */ } /* identify */ diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index e04a58fa8..179ae1c31 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -108,6 +108,7 @@ namespace command { command_t *create_identify(cluster_t *cluster); command_t *create_identify_query(cluster_t *cluster); command_t *create_identify_query_response(cluster_t *cluster); +command_t *create_trigger_effect(cluster_t *cluster); } /* command */ } /* identify */ diff --git a/components/esp_matter_identify/CMakeLists.txt b/components/esp_matter_identify/CMakeLists.txt new file mode 100644 index 000000000..65bdf04b7 --- /dev/null +++ b/components/esp_matter_identify/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "esp_matter_identify.cpp" + INCLUDE_DIRS "." + REQUIRES esp_matter) diff --git a/components/esp_matter_identify/esp_matter_identify.cpp b/components/esp_matter_identify/esp_matter_identify.cpp new file mode 100644 index 000000000..9e4d5275a --- /dev/null +++ b/components/esp_matter_identify/esp_matter_identify.cpp @@ -0,0 +1,45 @@ +// Copyright 2022 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +using namespace esp_matter; +static const char *TAG = "esp_matter_identify"; + +esp_err_t esp_matter_init_identify(chip::EndpointId endpoint, identify_callback start_cb, identify_callback stop_cb, + EmberAfIdentifyIdentifyType type, identify_callback effect_cb) +{ + endpoint_t *ep = endpoint::get(node::get(), endpoint); + if (!ep) { + ESP_LOGE(TAG, "Couldn't get the endpoint for endpointid: %d", endpoint); + return ESP_ERR_INVALID_ARG; + } + + cluster_t *cluster = cluster::get(ep, chip::app::Clusters::Identify::Id); + // TODO: use cluster::identify::get_id() instead of chip::app::Clusters::Identify::Id + if (!cluster) { + ESP_LOGE(TAG, "Couldn't get the identify cluster on endpointid: %d", endpoint); + return ESP_ERR_INVALID_ARG; + } + + Identify *identify = new Identify(endpoint, start_cb, stop_cb, type, effect_cb); + if (!identify) { + ESP_LOGE(TAG, "Fail to create identify object"); + return ESP_ERR_NO_MEM; + } + return ESP_OK; +} diff --git a/components/esp_matter_identify/esp_matter_identify.h b/components/esp_matter_identify/esp_matter_identify.h new file mode 100644 index 000000000..d3a9a2724 --- /dev/null +++ b/components/esp_matter_identify/esp_matter_identify.h @@ -0,0 +1,23 @@ +// Copyright 2022 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +typedef void (*identify_callback)(Identify * identify); + +esp_err_t esp_matter_init_identify(chip::EndpointId endpoint, identify_callback start_cb, identify_callback stop_cb, + EmberAfIdentifyIdentifyType type, identify_callback effect_cb); diff --git a/examples/light/main/CMakeLists.txt b/examples/light/main/CMakeLists.txt index b9a2c8e4b..f9bc051ff 100644 --- a/examples/light/main/CMakeLists.txt +++ b/examples/light/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota esp_matter_identify) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index cad25a9bb..f9da3f50c 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -24,6 +25,12 @@ uint16_t light_endpoint_id = 0; using namespace esp_matter; using namespace esp_matter::attribute; using namespace esp_matter::endpoint; + +static void on_identify_trigger_effect(Identify *identify) +{ + ESP_LOGI(TAG, "currenr identify trigger effect id: %d", identify->mCurrentEffectIdentifier); +} + using namespace chip::app::Clusters; static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) @@ -89,6 +96,10 @@ extern "C" void app_main() hue_saturation_config.current_saturation = DEFAULT_SATURATION; cluster::color_control::feature::hue_saturation::add(cluster, &hue_saturation_config); + /* Initialize identify */ + esp_matter_init_identify(light_endpoint_id, NULL, NULL, EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, + on_identify_trigger_effect); + /* Initialize driver */ app_driver_init();