From 2d74e4d104f4ecf27b0b7fd6911ac1b91a57b49f Mon Sep 17 00:00:00 2001 From: PSONALl Date: Wed, 29 Nov 2023 14:58:30 +0530 Subject: [PATCH] Add keypad-input cluster --- components/esp_matter/esp_matter_cluster.cpp | 45 ++++++++++++-- components/esp_matter/esp_matter_cluster.h | 9 +++ components/esp_matter/esp_matter_command.cpp | 25 ++++++++ components/esp_matter/esp_matter_command.h | 7 +++ components/esp_matter/esp_matter_feature.cpp | 63 ++++++++++++++++++++ components/esp_matter/esp_matter_feature.h | 24 ++++++++ 6 files changed, 169 insertions(+), 4 deletions(-) diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 35ba891aa..02dc0b790 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -3244,6 +3244,47 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* rvc_operational_state */ +namespace keypad_input { +const function_generic_t *function_list = NULL; +const int function_flags = CLUSTER_FLAG_NONE; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) +{ + cluster_t *cluster = cluster::create(endpoint, KeypadInput::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + + if (flags & CLUSTER_FLAG_SERVER) { + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); +#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE + global::attribute::create_event_list(cluster, NULL, 0, 0); +#endif + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + /* Commands */ + command::create_send_key(cluster); + command::create_send_key_response(cluster); + + return cluster; +} +} /* keypad_input */ + // namespace binary_input_basic { // // ToDo // } /* binary_input_basic */ @@ -3304,10 +3345,6 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) // // ToDo // } /* lowpower */ -// namespace keypad_input { -// // ToDo -// } /* keypad_input */ - // namespace content_launcher { // // ToDo // } /* content_launcher */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 1abd509e9..9309f2020 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -777,5 +777,14 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* rvc_operational_state */ +namespace keypad_input { +typedef struct config { + uint16_t cluster_revision; + config() : cluster_revision(1) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* keypad_input */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 5a31c7afb..99aabea86 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -1227,6 +1227,16 @@ static esp_err_t esp_matter_command_callback_disable_action_with_duration(const return ESP_OK; } +static esp_err_t esp_matter_command_callback_send_key(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::KeypadInput::Commands::SendKey::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfKeypadInputClusterSendKeyCallback((CommandHandler *)opaque_ptr, command_path, command_data); + } + return ESP_OK; +} + namespace esp_matter { namespace cluster { @@ -2353,6 +2363,21 @@ command_t *create_change_to_mode(cluster_t *cluster) } /* command */ } /* rvc_clean_mode */ +namespace keypad_input { +namespace command { +command_t *create_send_key(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, KeypadInput::Commands::SendKey::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_send_key); +} + +command_t *create_send_key_response(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, KeypadInput::Commands::SendKeyResponse::Id, COMMAND_FLAG_GENERATED, NULL); +} + +} /* command */ +} /* keypad_input */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index b3fa15e0c..17ad2b90d 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -359,5 +359,12 @@ command_t *create_change_to_mode(cluster_t *cluster); } /* command */ } /* rvc_clean_mode */ +namespace keypad_input { +namespace command { +command_t *create_send_key(cluster_t *cluster); +command_t *create_send_key_response(cluster_t *cluster); +} /* command */ +} /* keypad_input */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_feature.cpp b/components/esp_matter/esp_matter_feature.cpp index ce4464b42..db94240fe 100644 --- a/components/esp_matter/esp_matter_feature.cpp +++ b/components/esp_matter/esp_matter_feature.cpp @@ -3318,5 +3318,68 @@ esp_err_t add(cluster_t *cluster, config_t *config) } /* feature */ } /* fan_control */ +namespace keypad_input { +namespace feature { + +namespace navigation_key_codes { + +uint32_t get_id() +{ + return (uint32_t)KeypadInput::Feature::kNavigationKeyCodes; +} + +esp_err_t add(cluster_t *cluster) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + return ESP_OK; +} +} /* navigation_key_codes */ + +namespace location_keys { + +uint32_t get_id() +{ + return (uint32_t)KeypadInput::Feature::kLocationKeys; +} + +esp_err_t add(cluster_t *cluster) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + return ESP_OK; +} +} /* location_keys */ + +namespace number_keys { + +uint32_t get_id() +{ + return (uint32_t)KeypadInput::Feature::kNumberKeys; +} + +esp_err_t add(cluster_t *cluster) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + return ESP_OK; +} +} /* number_keys */ + +} /* feature */ +} /* keypad_input */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_feature.h b/components/esp_matter/esp_matter_feature.h index 13bbf48ef..84f044073 100644 --- a/components/esp_matter/esp_matter_feature.h +++ b/components/esp_matter/esp_matter_feature.h @@ -1530,5 +1530,29 @@ esp_err_t add(cluster_t *cluster, config_t *config); } /* feature */ } /* fan_control */ +namespace keypad_input { +namespace feature { + +namespace navigation_key_codes { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* navigation_key_codes */ + +namespace location_keys { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* location_keys */ + +namespace number_keys { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* number_keys */ + +} /* feature */ +} /* keypad_input */ + } /* cluster */ } /* esp_matter */