Cluster: Add trigger effect for identify cluster

This commit is contained in:
WanqQixiang
2022-06-17 11:52:40 +08:00
parent 03062214c3
commit 10437e4cbe
8 changed files with 102 additions and 1 deletions
@@ -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);