Add extractor hood device types with delegate

This commit is contained in:
Rohit Jadhav
2024-05-07 17:25:36 +05:30
parent 519df4d508
commit 2d90bbd73f
10 changed files with 141 additions and 4 deletions
+1
View File
@@ -71,3 +71,4 @@ i. Appliance
8. Cooktop
9. Energy Evse
10. Microwave Oven
11. Extractor Hood
@@ -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) {
+6 -3
View File
@@ -369,7 +369,8 @@ typedef struct config {
uint8_t fan_mode_sequence;
nullable<uint8_t> 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);
@@ -20,6 +20,8 @@
#include <app/clusters/energy-evse-server/energy-evse-server.h>
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h>
#include <app/clusters/fan-control-server/fan-control-server.h>
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<FanControl::Delegate*>(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<ResourceMonitoring::Delegate*>(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<uint32_t>(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<ResourceMonitoring::Delegate*>(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<uint32_t>(feature_map), ResourceMonitoring::DegradationDirectionEnum::kDown, true);
activatedCarbonFilterMonitoringInstance->Init();
}
} // namespace delegate_cb
} // namespace cluster
@@ -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
@@ -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 {
@@ -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 {
+20
View File
@@ -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
@@ -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 */
@@ -424,6 +424,11 @@ int create(uint8_t device_type_index)
endpoint = esp_matter::endpoint::microwave_oven::create(node, &microwave_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;