From 1e3ace5d4671395dfb4dbca54758649b6c714aa9 Mon Sep 17 00:00:00 2001 From: PSONALl Date: Tue, 17 Oct 2023 10:48:41 +0530 Subject: [PATCH] Add robotic vaccum cleaner device type --- .../esp_matter/esp_matter_attribute.cpp | 32 ++++++ components/esp_matter/esp_matter_attribute.h | 14 +++ components/esp_matter/esp_matter_cluster.cpp | 108 ++++++++++++++++++ components/esp_matter/esp_matter_cluster.h | 29 +++++ components/esp_matter/esp_matter_command.cpp | 20 ++++ components/esp_matter/esp_matter_command.h | 12 ++ components/esp_matter/esp_matter_endpoint.cpp | 40 +++++++ components/esp_matter/esp_matter_endpoint.h | 16 +++ 8 files changed, 271 insertions(+) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 5bc1c565e..0dcd48b93 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -3816,5 +3816,37 @@ attribute_t *create_supported(cluster_t *cluster, uint32_t value) } /* attribute */ } /* refrigerator_alarm */ +namespace rvc_run_mode { +namespace attribute { + +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, RvcRunMode::Attributes::SupportedModes::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array((uint8_t*)value, length, count)); +} + +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, RvcRunMode::Attributes::CurrentMode::Id, ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint8(value)); +} + +} /* attribute */ +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +namespace attribute { + +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, RvcCleanMode::Attributes::SupportedModes::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array((uint8_t*)value, length, count)); +} + +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, RvcCleanMode::Attributes::CurrentMode::Id, ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint8(value)); +} + +} /* attribute */ +} /* rvc_clean_mode */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 0029868be..fb0b942c6 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -874,5 +874,19 @@ attribute_t *create_supported(cluster_t *cluster, uint32_t value); } /* attribute */ } /* refrigerator_alarm */ +namespace rvc_run_mode { +namespace attribute { +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value); +} /* attribute */ +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +namespace attribute { +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value); +} /* attribute */ +} /* rvc_clean_mode */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 0c8149429..282d7f376 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -2911,6 +2911,114 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* refrigerator_alarm */ +namespace rvc_run_mode { +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, RvcRunMode::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + global::attribute::create_event_list(cluster, NULL, 0, 0); + attribute::create_supported_modes(cluster, NULL, 0, 0); + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + attribute::create_current_mode(cluster, config->current_mode); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + /* Commands */ + command::create_change_to_mode(cluster); + + return cluster; +} +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +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, RvcCleanMode::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + global::attribute::create_event_list(cluster, NULL, 0, 0); + attribute::create_supported_modes(cluster, NULL, 0, 0); + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + attribute::create_current_mode(cluster, config->current_mode); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + /* Commands */ + command::create_change_to_mode(cluster); + + return cluster; +} +} /* rvc_clean_mode */ + +namespace rvc_operational_state { +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, RvcOperationalState::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + add_function_list(cluster, function_list, function_flags); + } + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + + if (flags & CLUSTER_FLAG_SERVER) { + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + global::attribute::create_event_list(cluster, NULL, 0, 0); + + /* 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."); + } + } + + return cluster; +} +} /* rvc_operational_state */ + // namespace binary_input_basic { // // ToDo // } /* binary_input_basic */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 7698d691d..cdfce0406 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -720,5 +720,34 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* refrigerator_alarm */ +namespace rvc_run_mode { +typedef struct config { + uint16_t cluster_revision; + uint8_t current_mode; + config() : cluster_revision(1), current_mode(0) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +typedef struct config { + uint16_t cluster_revision; + uint8_t current_mode; + config() : cluster_revision(1), current_mode(0) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* rvc_clean_mode */ + +namespace rvc_operational_state { +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); +} /* rvc_operational_state */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 29f3d1461..9c6fca787 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -2250,6 +2250,26 @@ command_t *create_reset_condition(cluster_t *cluster) } /* command */ } /* activated_carbon_filter_monitoring */ +namespace rvc_run_mode { +namespace command { +command_t *create_change_to_mode(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, RvcRunMode::Commands::ChangeToMode::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_change_to_mode); +} + +} /* command */ +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +namespace command { +command_t *create_change_to_mode(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, RvcCleanMode::Commands::ChangeToMode::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_change_to_mode); +} + +} /* command */ +} /* rvc_clean_mode */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index 95db6a8d9..6a998fab0 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -325,5 +325,17 @@ command_t *create_reset_condition(cluster_t *cluster); } /* command */ } /* activated_carbon_filter_monitoring */ +namespace rvc_run_mode { +namespace command { +command_t *create_change_to_mode(cluster_t *cluster); +} /* command */ +} /* rvc_run_mode */ + +namespace rvc_clean_mode { +namespace command { +command_t *create_change_to_mode(cluster_t *cluster); +} /* command */ +} /* rvc_clean_mode */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 792a36e8c..1eebd2a02 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -1399,6 +1399,46 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /** refrigerator **/ +namespace robotic_vaccum_cleaner{ + +uint32_t get_device_type_id() +{ + return ESP_MATTER_ROBOTIC_VACCUM_CLEANER_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_ROBOTIC_VACCUM_CLEANER_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, "Could not create endpoint"); + 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); + identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); + rvc_run_mode::create(endpoint, &(config->rvc_run_mode), CLUSTER_FLAG_SERVER); + rvc_operational_state::create(endpoint, &(config->rvc_operational_state), CLUSTER_FLAG_SERVER); + + return ESP_OK; +} +} /** robotic_vaccum_cleaner **/ + } /* endpoint */ namespace node { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 2f667c2b5..51ca343cc 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -92,6 +92,8 @@ #define ESP_MATTER_PUMP_DEVICE_TYPE_VERSION 2 #define ESP_MATTER_MODE_SELECT_DEVICE_TYPE_ID 0x0027 #define ESP_MATTER_MODE_SELECT_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_ROBOTIC_VACCUM_CLEANER_DEVICE_TYPE_ID 0x0074 +#define ESP_MATTER_ROBOTIC_VACCUM_CLEANER_DEVICE_TYPE_VERSION 1 namespace esp_matter { @@ -576,6 +578,20 @@ 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); } /** refrigerator **/ +namespace robotic_vaccum_cleaner{ +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::identify::config_t identify; + cluster::rvc_run_mode::config_t rvc_run_mode; + cluster::rvc_operational_state::config_t rvc_operational_state; +} 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); +} /** robotic_vaccum_cleaner **/ + } /* endpoint */ namespace node {