From f2f94a35cda5a7259c55c935e89d87e8c8eb92e5 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 9 Aug 2024 14:59:59 +0530 Subject: [PATCH] esp-matter/components: Add delegate for mode-select cluster --- components/esp_matter/esp_matter_cluster.cpp | 4 ++++ components/esp_matter/esp_matter_cluster.h | 3 ++- .../esp_matter/esp_matter_delegate_callbacks.cpp | 11 +++++++++++ components/esp_matter/esp_matter_delegate_callbacks.h | 1 + docs/en/app_guide.rst | 11 +++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index ee942a389..256dfab2b 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -2639,6 +2639,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ return NULL; } if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = ModeSelectDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } static const auto plugin_server_init_cb = CALL_ONCE(MatterModeSelectPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 3c536039a..38ad2d3af 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -683,7 +683,8 @@ typedef struct config { const nullable standard_namespace; uint8_t current_mode; feature::on_off::config_t on_off; - config() : mode_select_description{0}, standard_namespace(), current_mode(0) {} + void *delegate; + config() : mode_select_description{0}, standard_namespace(), current_mode(0), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features); diff --git a/components/esp_matter/esp_matter_delegate_callbacks.cpp b/components/esp_matter/esp_matter_delegate_callbacks.cpp index 106a7d3d0..360fcac24 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/esp_matter_delegate_callbacks.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace chip::app::Clusters; namespace esp_matter { @@ -343,6 +344,16 @@ void KeypadInputDelegateInitCB(void *delegate, uint16_t endpoint_id) KeypadInput::SetDefaultDelegate(endpoint_id, keypad_input_delegate); } +void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + ModeSelect::SupportedModesManager *supported_modes_manager = static_cast(delegate); + ModeSelect::setSupportedModesManager(supported_modes_manager); +} + } // 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 1db1ad4da..a4310cfe4 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/esp_matter_delegate_callbacks.h @@ -44,6 +44,7 @@ void LaundryWasherControlsDelegateInitCB(void *delegate, uint16_t endpoint_id); void WindowCoveringDelegateInitCB(void *delegate, uint16_t endpoint_id); void DishwasherAlarmDelegateInitCB(void *delegate, uint16_t endpoint_id); void KeypadInputDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/docs/en/app_guide.rst b/docs/en/app_guide.rst index 49dd29c1d..0008eefd4 100644 --- a/docs/en/app_guide.rst +++ b/docs/en/app_guide.rst @@ -44,6 +44,7 @@ List of clusters with delegate: - Account Login Cluster. - Wake On Lan Cluster. - Target Navigator Cluster. + - Mode Select Cluster. 9.1.1 Mode Base Cluster ----------------------- @@ -207,6 +208,14 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. `Keypad Input`_, `Keypad Input Delegate`_ +9.1.20 Mode Select Cluster +-------------------------- + +.. csv-table:: + :header: "Delegate Class", "Reference Implementation" + + `Mode Select`_, `Mode Select Delegate`_ + .. note:: Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster. @@ -258,3 +267,5 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. _`Dishwasher Alarm Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/src/dishwasher-alarm-stub.cpp .. _`Keypad Input`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/keypad-input-server/keypad-input-server.h .. _`Keypad Input Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/chef/common/clusters/keypad-input/KeypadInputManager.h +.. _`Mode Select`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/mode-select-server/supported-modes-manager.h +.. _`Mode Select Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h