mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 11:03:05 +00:00
Cluster: Add trigger effect for identify cluster
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "esp_matter_identify.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES esp_matter)
|
||||
@@ -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 <stdio.h>
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_identify.h>
|
||||
#include <lib/support/CHIPMem.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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 <esp_err.h>
|
||||
#include <app/clusters/identify-server/identify-server.h>
|
||||
|
||||
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);
|
||||
@@ -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 "."
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <esp_matter.h>
|
||||
#include <esp_matter_console.h>
|
||||
#include <esp_matter_identify.h>
|
||||
#include <esp_matter_ota.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user