identify: Resturcturing identify to simplify application

Removed the separate identify component, and made it a part of esp_matter itself.
Added a common callback for the application.
This commit is contained in:
Chirag Atal
2022-08-02 13:17:54 +05:30
parent c1dca7810f
commit 0800f66c0e
10 changed files with 174 additions and 97 deletions
+1
View File
@@ -28,6 +28,7 @@ application.
#include <esp_matter_endpoint.h>
#include <esp_matter_event.h>
#include <esp_matter_feature.h>
#include <esp_matter_identify.h>
#include <app-common/zap-generated/att-storage.h>
#include <app/server/Dnssd.h>
@@ -730,6 +730,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
create_default_binding_cluster(endpoint);
}
/* Extra initialization */
uint16_t endpoint_id = endpoint::get_id(endpoint);
esp_matter::identify::init(endpoint_id, config->identify_type);
if (flags & CLUSTER_FLAG_SERVER) {
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
+15 -15
View File
@@ -101,7 +101,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -126,7 +126,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -153,7 +153,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -182,7 +182,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -211,7 +211,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
binding::create(endpoint, &(config->binding), CLUSTER_FLAG_SERVER);
groups::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
scenes::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
@@ -237,7 +237,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
binding::create(endpoint, &(config->binding), CLUSTER_FLAG_SERVER);
groups::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
scenes::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
@@ -264,7 +264,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
binding::create(endpoint, &(config->binding), CLUSTER_FLAG_SERVER);
groups::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
scenes::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
@@ -292,7 +292,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -319,7 +319,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id());
@@ -346,7 +346,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
fan_control::create(endpoint, &(config->fan_control), CLUSTER_FLAG_SERVER);
@@ -370,7 +370,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER);
scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER);
cluster::thermostat::create(endpoint, &(config->thermostat), CLUSTER_FLAG_SERVER);
@@ -428,7 +428,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
set_device_type_id(endpoint, get_device_type_id());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster::door_lock::create(endpoint, &(config->door_lock), CLUSTER_FLAG_SERVER);
time_synchronization::create(endpoint, &(config->time_synchronization), CLUSTER_FLAG_SERVER);
@@ -451,7 +451,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
}
set_device_type_id(endpoint, get_device_type_id());
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
groups::create(endpoint, NULL, CLUSTER_FLAG_CLIENT);
temperature_measurement::create(endpoint, &(config->temperature_measurement), CLUSTER_FLAG_SERVER);
@@ -474,7 +474,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
}
set_device_type_id(endpoint, get_device_type_id());
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
occupancy_sensing::create(endpoint, &(config->occupancy_sensing), CLUSTER_FLAG_SERVER);
return endpoint;
@@ -496,7 +496,7 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags)
}
set_device_type_id(endpoint, get_device_type_id());
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
cluster::identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
boolean_state::create(endpoint, &(config->boolean_state), CLUSTER_FLAG_SERVER);
return endpoint;
@@ -0,0 +1,72 @@
// 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 <esp_log.h>
#include <esp_matter_identify.h>
#include <app/clusters/identify-server/identify-server.h>
static const char *TAG = "esp_matter_identify";
namespace esp_matter {
namespace identify {
static callback_t identify_callback = NULL;
static void *identify_callback_priv_data = NULL;
esp_err_t set_callback(callback_t callback, void *priv_data)
{
identify_callback = callback;
identify_callback_priv_data = priv_data;
return ESP_OK;
}
static esp_err_t execute_callback(callback_type_t type, uint16_t endpoint_id, uint8_t effect_id)
{
if (identify_callback) {
return identify_callback(type, endpoint_id, effect_id, identify_callback_priv_data);
}
return ESP_OK;
}
static void start_cb(Identify *identify)
{
ESP_LOGI(TAG, "Start callback");
execute_callback(START, identify->mEndpoint, identify->mCurrentEffectIdentifier);
}
static void stop_cb(Identify *identify)
{
ESP_LOGI(TAG, "Stop callback");
execute_callback(STOP, identify->mEndpoint, identify->mCurrentEffectIdentifier);
}
static void effect_cb(Identify *identify)
{
ESP_LOGI(TAG, "Effect callback");
execute_callback(EFFECT, identify->mEndpoint, identify->mCurrentEffectIdentifier);
}
esp_err_t init(uint16_t endpoint_id, uint8_t identify_type)
{
Identify *identify = new Identify(endpoint_id, start_cb, stop_cb, (EmberAfIdentifyIdentifyType)identify_type, effect_cb);
if (!identify) {
ESP_LOGE(TAG, "Fail to create identify object");
return ESP_FAIL;
}
return ESP_OK;
}
} /* identify */
} /* esp_matter */
@@ -0,0 +1,72 @@
// 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>
namespace esp_matter {
namespace identify {
/** Identify callback type */
typedef enum callback_type {
/** Callback to start identify */
START,
/** Callback to stop identify */
STOP,
/** Callback to run a specific identify effect */
EFFECT,
} callback_type_t;
/** Callback for identify
*
* @param[in] type callback type.
* @param[in] endpoint_id Endpoint ID to identify.
* @param[in] effect_id Effect ID to identify with.
* @param[in] priv_data Pointer to the private data passed while setting the callback.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
typedef esp_err_t (*callback_t)(callback_type_t type, uint16_t endpoint_id, uint8_t effect_id, void *priv_data);
/** Set identify callback
*
* Set the common identify callback. Whenever an identify request is received by the device, the callback
* will be called with the appropriate `callback_type_t`.
*
* @param[in] callback identify update callback.
* @param[in] priv_data (Optional) Private data associated with the callback. This will be passed to callback. It
* should stay allocated throughout the lifetime of the device.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t set_callback(callback_t callback, void *priv_data);
/** Initialise identify
*
* This initialises the identify object on the given endpoint. This happen internally whenever the identify cluster is
* created on an endpoint. The type in this case is taken from the identify_type attribute.
*
* @param[in] endpoint_id Endpoint ID to identify.
* @param[in] identify_type The type supported by the device.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t init(uint16_t endpoint_id, uint8_t identify_type);
} /* identify */
} /* esp_matter */
@@ -1,3 +0,0 @@
idf_component_register(SRCS "esp_matter_identify.cpp"
INCLUDE_DIRS "."
REQUIRES esp_matter)
@@ -1,45 +0,0 @@
// 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;
}
@@ -1,23 +0,0 @@
// 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 -1
View File
@@ -1,4 +1,4 @@
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota esp_matter_identify)
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota)
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
+9 -10
View File
@@ -12,7 +12,6 @@
#include <esp_matter.h>
#include <esp_matter_console.h>
#include <esp_matter_identify.h>
#include <esp_matter_ota.h>
#include <esp_route_hook.h>
@@ -25,12 +24,6 @@ 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)
@@ -52,7 +45,14 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
}
}
static esp_err_t app_attribute_update_cb(callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id,
static esp_err_t app_identify_cb(identify::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id,
void *priv_data)
{
ESP_LOGI(TAG, "Identify callback: type: %d, effect: %d", type, effect_id);
return ESP_OK;
}
static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id,
uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data)
{
esp_err_t err = ESP_OK;
@@ -97,8 +97,7 @@ extern "C" void app_main()
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);
identify::set_callback(app_identify_cb, NULL);
/* Initialize driver */
app_driver_init();