diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index 2f9a7dcba..55b86519c 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -89,3 +89,6 @@ j. Energy k. Network Infrastructure 1. Thread Border Router + +l. Camera Device Types +1. Chime diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index df050082f..6f86c8229 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4060,10 +4060,9 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) cluster_t *cluster = esp_matter::cluster::create(endpoint, Chime::Id, flags); VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, Chime::Id)); if (flags & CLUSTER_FLAG_SERVER) { - if (config->delegate != nullptr) { - static const auto delegate_init_cb = ChimeDelegateInitCB; - set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); - } + VerifyOrReturnValue(config != NULL && config->delegate != nullptr, NULL, ESP_LOGE(TAG, "Delegate cannot be nullptr")); + static const auto delegate_init_cb = ChimeDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); static const auto plugin_server_init_cb = CALL_ONCE(MatterChimePluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); @@ -4078,7 +4077,6 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) global::attribute::create_cluster_revision(cluster, cluster_revision); command::create_play_chime_sound(cluster); - } if (flags & CLUSTER_FLAG_CLIENT) { diff --git a/components/esp_matter/data_model/esp_matter_endpoint.cpp b/components/esp_matter/data_model/esp_matter_endpoint.cpp index c77d5d686..ed7aaf017 100644 --- a/components/esp_matter/data_model/esp_matter_endpoint.cpp +++ b/components/esp_matter/data_model/esp_matter_endpoint.cpp @@ -2053,6 +2053,30 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } /* camera */ +namespace chime { +uint32_t get_device_type_id() +{ + return ESP_MATTER_CHIME_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_CHIME_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + return common::create(node, config, flags, priv_data, add); +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + VerifyOrReturnError(err == ESP_OK, err); + VerifyOrReturnError(cluster::chime::create(endpoint, &(config->chime), CLUSTER_FLAG_SERVER), ESP_ERR_NO_MEM); + return ESP_OK; +} +} /* chime */ namespace thermostat_controller { uint32_t get_device_type_id() diff --git a/components/esp_matter/data_model/esp_matter_endpoint.h b/components/esp_matter/data_model/esp_matter_endpoint.h index 2653ccd31..d781b107f 100644 --- a/components/esp_matter/data_model/esp_matter_endpoint.h +++ b/components/esp_matter/data_model/esp_matter_endpoint.h @@ -159,6 +159,8 @@ #define ESP_MATTER_CLOSURE_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_CLOSURE_PANEL_DEVICE_TYPE_ID 0x0231 #define ESP_MATTER_CLOSURE_PANEL_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_CHIME_DEVICE_TYPE_ID 0x0146 +#define ESP_MATTER_CHIME_DEVICE_TYPE_VERSION 1 namespace esp_matter { @@ -1047,6 +1049,20 @@ esp_err_t add(endpoint_t *endpoint, config_t *config); } /* camera */ +namespace chime { + +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::chime::config_t chime; +} config_t; + +uint32_t get_device_type_id(); +uint8_t get_device_type_version(); +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); +esp_err_t add(endpoint_t *endpoint, config_t *config); + +} /* chime */ + namespace thermostat_controller { using config_t = app_client_config; diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index 595509f59..461fb93db 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -59,6 +59,7 @@ enum device_type_enum { ESP_MATTER_SOLAR_POWER, ESP_MATTER_BATTERY_STORAGE, ESP_MATTER_HEAT_PUMP, + ESP_MATTER_CHIME, ESP_MATTER_THERMOSTAT_CONTROLLER, ESP_MATTER_CLOSURE_CONTROLLER, ESP_MATTER_CLOSURE, @@ -128,6 +129,7 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"solar_power", ESP_MATTER_SOLAR_POWER}, {"battery_storage", ESP_MATTER_BATTERY_STORAGE}, {"heat_pump", ESP_MATTER_HEAT_PUMP}, + {"chime", ESP_MATTER_CHIME}, {"thermostat_controller", ESP_MATTER_THERMOSTAT_CONTROLLER}, {"closure_controller", ESP_MATTER_CLOSURE_CONTROLLER}, {"closure", ESP_MATTER_CLOSURE}, diff --git a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp index 64138f0a6..7a5de910a 100644 --- a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp +++ b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp @@ -29,6 +29,7 @@ #include #include #include "electrical_measurement/electrical_measurement.h" +#include "mock_delegates/mock_chime_delegate.h" // External variables for electrical sensor initialization bool g_electrical_sensor_created = false; @@ -168,6 +169,8 @@ static void initialize_console(void) namespace esp_matter { static chip::app::Clusters::PowerTopology::PowerTopologyDelegate powerTopologyDelegate; +static chip::app::Clusters::Chime::MockChimeDelegate chimeDelegate; + namespace data_model { int create(uint8_t device_type_index) @@ -582,6 +585,12 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::heat_pump::create(node, &heat_pump_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_CHIME: { + esp_matter::endpoint::chime::config_t chime_config; + chime_config.chime.delegate = &chimeDelegate; + endpoint = esp_matter::endpoint::chime::create(node, &chime_config, ENDPOINT_FLAG_NONE, NULL); + break; + } case ESP_MATTER_THERMOSTAT_CONTROLLER: { esp_matter::endpoint::thermostat_controller::config_t thermostat_controller_config; endpoint = esp_matter::endpoint::thermostat_controller::create(node, &thermostat_controller_config, ENDPOINT_FLAG_NONE, NULL); diff --git a/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.cpp b/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.cpp new file mode 100644 index 000000000..78f3f8e07 --- /dev/null +++ b/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.cpp @@ -0,0 +1,44 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include "esp_log.h" + +#include "mock_chime_delegate.h" + +namespace chip { +namespace app { +namespace Clusters { +namespace Chime { + +MockChimeDelegate::~MockChimeDelegate() = default; + +CHIP_ERROR MockChimeDelegate::GetChimeSoundByIndex(uint8_t chimeIndex, uint8_t & chimeID, MutableCharSpan & name) +{ + // Implement your own logic here. + ESP_LOGE(LOG_TAG, "%s is not implemented", __func__); + return CHIP_NO_ERROR; +} + +CHIP_ERROR MockChimeDelegate::GetChimeIDByIndex(uint8_t chimeIndex, uint8_t & chimeID) +{ + // Implement your own logic here. + ESP_LOGE(LOG_TAG, "%s is not implemented", __func__); + return CHIP_NO_ERROR; +} + +Protocols::InteractionModel::Status MockChimeDelegate::PlayChimeSound() +{ + // Implement your own logic here. + ESP_LOGE(LOG_TAG, "%s is not implemented", __func__); + return Protocols::InteractionModel::Status::Success; +} + +} // namespace Chime +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.h b/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.h new file mode 100644 index 000000000..4bb180f61 --- /dev/null +++ b/examples/all_device_types_app/main/mock_delegates/mock_chime_delegate.h @@ -0,0 +1,43 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#pragma once + +#include + +#include + +/* + * Mock Chime Delegate Implementation + * This file provides a mock implementation of the Chime::Delegate interface + * that returns success for all methods. +*/ + +namespace chip { +namespace app { +namespace Clusters { +namespace Chime { + +class MockChimeDelegate : public ChimeDelegate +{ +public: + MockChimeDelegate() = default; + ~MockChimeDelegate() override; + + CHIP_ERROR GetChimeSoundByIndex(uint8_t chimeIndex, uint8_t & chimeID, MutableCharSpan & name) override; + CHIP_ERROR GetChimeIDByIndex(uint8_t chimeIndex, uint8_t & chimeID) override; + Protocols::InteractionModel::Status PlayChimeSound() override; + +private: + const char *LOG_TAG = "chime"; +}; + +} // namespace Chime +} // namespace Clusters +} // namespace app +} // namespace chip