From 2d90bbd73f854c787cdc14dfc21cac959362249d Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Tue, 7 May 2024 17:25:36 +0530 Subject: [PATCH] Add extractor hood device types with delegate --- SUPPORTED_DEVICE_TYPES.md | 1 + components/esp_matter/esp_matter_cluster.cpp | 12 ++++++ components/esp_matter/esp_matter_cluster.h | 9 +++-- .../esp_matter_delegate_callbacks.cpp | 40 +++++++++++++++++++ .../esp_matter_delegate_callbacks.h | 3 ++ components/esp_matter/esp_matter_endpoint.cpp | 37 +++++++++++++++++ components/esp_matter/esp_matter_endpoint.h | 14 +++++++ docs/en/app_guide.rst | 20 ++++++++++ .../all_device_types_app/main/device_types.h | 4 +- .../main/esp_matter_console_helpers.cpp | 5 +++ 10 files changed, 141 insertions(+), 4 deletions(-) diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index 4489f7072..ec3b28f4b 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -71,3 +71,4 @@ i. Appliance 8. Cooktop 9. Energy Evse 10. Microwave Oven +11. Extractor Hood diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 1fa87f013..b3e3ddf0d 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1526,6 +1526,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = FanControlDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } static const auto plugin_server_init_cb = CALL_ONCE(MatterFanControlPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); @@ -1724,6 +1728,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = HepaFilterMonitoringDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } add_function_list(cluster, function_list, function_flags); } if (flags & CLUSTER_FLAG_CLIENT) { @@ -1763,6 +1771,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = ActivatedCarbonFilterMonitoringDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } add_function_list(cluster, function_list, function_flags); } if (flags & CLUSTER_FLAG_CLIENT) { diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 02657fa99..23234856e 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -369,7 +369,8 @@ typedef struct config { uint8_t fan_mode_sequence; nullable percent_setting; uint8_t percent_current; - config() : cluster_revision(4), fan_mode(0), fan_mode_sequence(2), percent_setting(0), percent_current(0) {} + void *delegate; + config() : cluster_revision(4), fan_mode(0), fan_mode_sequence(2), percent_setting(0), percent_current(0), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); @@ -417,7 +418,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); namespace hepa_filter_monitoring { typedef struct config { uint16_t cluster_revision; - config() : cluster_revision(1) {} + void *delegate; + config() : cluster_revision(1), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); @@ -426,7 +428,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); namespace activated_carbon_filter_monitoring { typedef struct config { uint16_t cluster_revision; - config() : cluster_revision(1) {} + void *delegate; + config() : cluster_revision(1), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); diff --git a/components/esp_matter/esp_matter_delegate_callbacks.cpp b/components/esp_matter/esp_matter_delegate_callbacks.cpp index 0fc8b9d00..40b507a8e 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/esp_matter_delegate_callbacks.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include using namespace chip::app::Clusters; namespace esp_matter { @@ -143,6 +145,44 @@ void OperationalStateDelegateInitCB(void *delegate, uint16_t endpoint_id) operationalStateInstance->Init(); } +void FanControlDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + FanControl::Delegate *fan_control_delegate = static_cast(delegate); + FanControl::SetDefaultDelegate(endpoint_id, fan_control_delegate); +} + +void HepaFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + static ResourceMonitoring::Instance * hepaFilterMonitoringInstance = nullptr; + ResourceMonitoring::Delegate *resource_monitoring_delegate = static_cast(delegate); + uint32_t feature_map = get_feature_map_value(endpoint_id, HepaFilterMonitoring::Id); + hepaFilterMonitoringInstance = new ResourceMonitoring::Instance(resource_monitoring_delegate, endpoint_id, HepaFilterMonitoring::Id, + static_cast(feature_map), ResourceMonitoring::DegradationDirectionEnum::kDown, true); + hepaFilterMonitoringInstance->Init(); +} + +void ActivatedCarbonFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + static ResourceMonitoring::Instance * activatedCarbonFilterMonitoringInstance = nullptr; + ResourceMonitoring::Delegate *resource_monitoring_delegate = static_cast(delegate); + uint32_t feature_map = get_feature_map_value(endpoint_id, ActivatedCarbonFilterMonitoring::Id); + activatedCarbonFilterMonitoringInstance = new ResourceMonitoring::Instance(resource_monitoring_delegate, endpoint_id, ActivatedCarbonFilterMonitoring::Id, + static_cast(feature_map), ResourceMonitoring::DegradationDirectionEnum::kDown, true); + activatedCarbonFilterMonitoringInstance->Init(); +} + } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/esp_matter_delegate_callbacks.h b/components/esp_matter/esp_matter_delegate_callbacks.h index 29d18f297..ca0cec698 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/esp_matter_delegate_callbacks.h @@ -27,6 +27,9 @@ void EnergyEvseDelegateInitCB(void *delegate, uint16_t endpoint_id); void MicrowaveOvenModeDelegateInitCB(void *delegate, uint16_t endpoint_id); void MicrowaveOvenControlDelegateInitCB(void *delegate, uint16_t endpoint_id); void OperationalStateDelegateInitCB(void *delegate, uint16_t endpoint_id); +void FanControlDelegateInitCB(void *delegate, uint16_t endpoint_id); +void HepaFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ActivatedCarbonFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 178c09396..1d9e50f80 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -1831,6 +1831,43 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /* microwave_oven */ +namespace extractor_hood { +uint32_t get_device_type_id() +{ + return ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + endpoint_t *endpoint = endpoint::create(node, flags, priv_data); + add(endpoint, config); + return endpoint; +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + if (!endpoint) { + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; + } + + descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); + fan_control::create(endpoint, &(config->fan_control), CLUSTER_FLAG_SERVER); + + return ESP_OK; +} +} /* extractor_hood */ + } /* endpoint */ namespace node { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 878a4575a..215192f07 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -114,6 +114,8 @@ #define ESP_MATTER_WATER_FREEZE_DETECTOR_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_ENERGY_EVSE_DEVICE_TYPE_ID 0x050C #define ESP_MATTER_ENERGY_EVSE_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_ID 0x007A +#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_VERSION 1 namespace esp_matter { @@ -738,6 +740,18 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat esp_err_t add(endpoint_t *endpoint, config_t *config); } /* microwave_oven */ +namespace extractor_hood { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::fan_control::config_t fan_control; +} 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); +} /* extractor_hood */ + } /* endpoint */ namespace node { diff --git a/docs/en/app_guide.rst b/docs/en/app_guide.rst index 96325ef2a..9f47f19d5 100644 --- a/docs/en/app_guide.rst +++ b/docs/en/app_guide.rst @@ -85,6 +85,22 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. `Microwave Oven Control`_, None +9.1.5 Fan Control Cluster +------------------------- + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Fan Control`_, `Fan Control Delegate`_ + +9.1.6 Resource Monitoring Cluster +--------------------------------- + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Resource Monitoring`_, `Resource Monitoring Delegate`_ + .. note:: Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster. @@ -106,3 +122,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. _`Operational State`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/operational-state-server/operational-state-server.h .. _`Operational State Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/operational-state-delegate-impl.h .. _`Microwave Oven Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h +.. _`Fan Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/fan-control-server/fan-control-delegate.h +.. _`Fan Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp +.. _`Resource Monitoring`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h +.. _`Resource Monitoring Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-delegates.h diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index ba718ba11..b5f05d03b 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -46,6 +46,7 @@ enum device_type_enum { ESP_MATTER_COOKTOP, ESP_MATTER_ENERGY_EVSE, ESP_MATTER_MICROWAVE_OVEN, + ESP_MATTER_EXTRACTOR_HOOD, ESP_MATTER_DEVICE_TYPE_MAX }; @@ -97,6 +98,7 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"oven", ESP_MATTER_OVEN}, {"cooktop", ESP_MATTER_COOKTOP}, {"energy_evse", ESP_MATTER_ENERGY_EVSE}, - {"microwave_oven", ESP_MATTER_MICROWAVE_OVEN} + {"microwave_oven", ESP_MATTER_MICROWAVE_OVEN}, + {"extractor_hood", ESP_MATTER_EXTRACTOR_HOOD} }; } /* namespace esp_matter */ 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 545f1ac94..9424f93da 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 @@ -424,6 +424,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::microwave_oven::create(node, µwave_oven_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_EXTRACTOR_HOOD: { + esp_matter::endpoint::extractor_hood::config_t extractor_hood_config; + endpoint = esp_matter::endpoint::extractor_hood::create(node, &extractor_hood_config, ENDPOINT_FLAG_NONE, NULL); + break; + } default: { ESP_LOGE(TAG, "Please input a valid device type"); break;