Merge branch 'feat/add-closure_dimension-cluster' into 'main'

Add closure_dimension Cluster to esp-matter Data Model

See merge request app-frameworks/esp-matter!1327
This commit is contained in:
Hrishikesh Dhayagude
2025-12-05 14:05:34 +08:00
11 changed files with 432 additions and 1 deletions
@@ -4987,5 +4987,83 @@ attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value)
} /* closure_control */
namespace closure_dimension {
namespace attribute {
attribute_t *create_current_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::CurrentState::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
}
attribute_t *create_target_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::TargetState::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
}
attribute_t *create_resolution(cluster_t *cluster, uint16_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Resolution::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_uint16(value));
}
attribute_t *create_step_value(cluster_t *cluster, uint16_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::StepValue::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_uint16(value));
}
attribute_t *create_unit(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Unit::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_unit_range(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::UnitRange::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
}
attribute_t *create_limit_range(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::LimitRange::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count));
}
attribute_t *create_translation_direction(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::TranslationDirection::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_rotation_axis(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::RotationAxis::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_overflow(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Overflow::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_modulation_type(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::ModulationType::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::LatchControlModes::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_bitmap8(value));
}
} /* attribute */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -1291,5 +1291,23 @@ attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value);
} /* attribute */
} /* closure_control */
namespace closure_dimension {
namespace attribute {
attribute_t *create_current_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_target_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_resolution(cluster_t *cluster, uint16_t value);
attribute_t *create_step_value(cluster_t *cluster, uint16_t value);
attribute_t *create_unit(cluster_t *cluster, uint8_t value);
attribute_t *create_unit_range(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_limit_range(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_translation_direction(cluster_t *cluster, uint8_t value);
attribute_t *create_rotation_axis(cluster_t *cluster, uint8_t value);
attribute_t *create_overflow(cluster_t *cluster, uint8_t value);
attribute_t *create_modulation_type(cluster_t *cluster, uint8_t value);
attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value);
} /* attribute */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -58,9 +58,10 @@ enum class feature_policy
{
k_exact_one = 0, // O.a
k_at_least_one = 1, // 0.a+
k_at_most_one = 2, // 0.a-
};
const char feature_policy_strs[2][16] = {"Exactly one", "At least one"};
const char feature_policy_strs[3][16] = {"Exactly one", "At least one", "At most one"};
bool validate_features(uint32_t feature_flag, feature_policy policy,
const char *feature_name, std::initializer_list<uint32_t> features)
@@ -81,6 +82,9 @@ bool validate_features(uint32_t feature_flag, feature_policy policy,
case feature_policy::k_at_least_one:
result = count >= 1;
break;
case feature_policy::k_at_most_one:
result = count <= 1;
break;
}
if (!result) {
@@ -99,6 +103,10 @@ bool validate_features(uint32_t feature_flag, feature_policy policy,
do { if (!validate_features(config->feature_flags, feature_policy::k_at_least_one, name, {__VA_ARGS__})) \
return ABORT_CLUSTER_CREATE(cluster); } while(0)
#define VALIDATE_FEATURES_AT_MOST_ONE(name, ...) \
do { if (!validate_features(config->feature_flags, feature_policy::k_at_most_one, name, {__VA_ARGS__})) \
return ABORT_CLUSTER_CREATE(cluster); } while(0)
} // anonymous namespace
namespace esp_matter {
@@ -4164,5 +4172,75 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
} /* closure_control */
namespace closure_dimension {
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 = esp_matter::cluster::create(endpoint, ClosureDimension::Id, flags);
VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, ClosureDimension::Id));
if (flags & CLUSTER_FLAG_SERVER) {
if (config->delegate != nullptr) {
static const auto delegate_init_cb = ClosureDimensionDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
static const auto plugin_server_init_cb = CALL_ONCE(MatterClosureDimensionPluginServerInitCallback);
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
add_function_list(cluster, function_list, function_flags);
VerifyOrReturnValue(config != NULL, ABORT_CLUSTER_CREATE(cluster));
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, config->feature_flags);
attribute::create_current_state(cluster, NULL, 0, 0);
attribute::create_target_state(cluster, NULL, 0, 0);
/* Attributes not managed internally */
global::attribute::create_cluster_revision(cluster, cluster_revision);
// check against O.a+ feature conformance
VALIDATE_FEATURES_AT_LEAST_ONE("Positioning,MotionLatching",
feature::positioning::get_id(), feature::motion_latching::get_id());
if (has(feature::positioning::get_id())) {
VerifyOrReturnValue(feature::positioning::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
VALIDATE_FEATURES_AT_MOST_ONE("Translation, Rotation, Modulation",
feature::translation::get_id(), feature::rotation::get_id(), feature::modulation::get_id());
if (has(feature::translation::get_id())) {
VerifyOrReturnValue(feature::translation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::rotation::get_id())) {
VerifyOrReturnValue(feature::rotation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::modulation::get_id())) {
VerifyOrReturnValue(feature::modulation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::speed::get_id())) {
VerifyOrReturnValue(feature::speed::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::unit::get_id())) {
VerifyOrReturnValue(feature::unit::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::limitation::get_id())) {
VerifyOrReturnValue(feature::limitation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
}
if (has(feature::motion_latching::get_id())) {
VerifyOrReturnValue(feature::motion_latching::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
command::create_set_target(cluster);
}
if (flags & CLUSTER_FLAG_CLIENT) {
create_default_binding_cluster(endpoint);
}
return cluster;
}
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -1017,5 +1017,15 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* closure_control */
namespace closure_dimension {
typedef struct config {
void *delegate;
uint32_t feature_flags = 0;
config() : delegate(nullptr), feature_flags(0) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -3036,5 +3036,22 @@ command_t *create_calibrate(cluster_t *cluster)
} /* command */
} /* closure_control */
namespace closure_dimension {
namespace command {
command_t *create_set_target(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ClosureDimension::Commands::SetTarget::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}
command_t *create_step(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ClosureDimension::Commands::Step::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}
} /* command */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -560,5 +560,12 @@ command_t *create_calibrate(cluster_t *cluster);
} /* command */
} /* closure_control */
namespace closure_dimension {
namespace command {
command_t *create_set_target(cluster_t *cluster);
command_t *create_step(cluster_t *cluster);
} /* command */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -49,6 +49,7 @@
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
#include <app/clusters/chime-server/chime-server.h>
#include <app/clusters/closure-control-server/closure-control-server.h>
#include <app/clusters/closure-dimension-server/closure-dimension-server.h>
#include <unordered_map>
using namespace chip::app::Clusters;
@@ -559,6 +560,17 @@ void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id)
server_interface->Init();
}
void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
VerifyOrReturn(delegate != nullptr);
ClosureDimension::DelegateBase *closure_dimension_delegate = static_cast<ClosureDimension::DelegateBase*>(delegate);
ClosureDimension::MatterContext *matter_context = new ClosureDimension::MatterContext(endpoint_id);
ClosureDimension::ClusterLogic *cluster_logic = new ClosureDimension::ClusterLogic(*closure_dimension_delegate, *matter_context);
ClosureDimension::Interface *server_interface = new ClosureDimension::Interface(endpoint_id, *cluster_logic);
server_interface->Init();
}
} // namespace delegate_cb
} // namespace cluster
} // namespace esp_matter
@@ -57,6 +57,7 @@ void OtaSoftwareUpdateProviderDelegateInitCB(void *delegate, uint16_t endpoint_i
void DiagnosticLogsDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id);
} // namespace delegate_cb
} // namespace cluster
@@ -4366,5 +4366,157 @@ esp_err_t add(cluster_t *cluster)
} /* feature */
} /* closure_control */
namespace closure_dimension {
namespace feature {
namespace positioning {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kPositioning);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_resolution(cluster, 0);
attribute::create_step_value(cluster, 0);
// Commands
command::create_step(cluster);
return ESP_OK;
}
} /* positioning */
namespace motion_latching {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kMotionLatching);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_latch_control_modes(cluster, 0);
return ESP_OK;
}
} /* motion_latching */
namespace unit {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kUnit);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_unit(cluster, 0);
attribute::create_unit_range(cluster, NULL, 0, 0);
return ESP_OK;
}
} /* unit */
namespace limitation {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kLimitation);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_limit_range(cluster, NULL, 0, 0);
return ESP_OK;
}
} /* limitation */
namespace speed {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kSpeed);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* speed */
namespace translation {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kTranslation);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_translation_direction(cluster, 0);
return ESP_OK;
}
} /* translation */
namespace rotation {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kRotation);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_rotation_axis(cluster, 0);
attribute::create_overflow(cluster, 0);
return ESP_OK;
}
} /* rotation */
namespace modulation {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureDimension::Feature::kModulation);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Attributes
attribute::create_modulation_type(cluster, 0);
return ESP_OK;
}
} /* modulation */
} /* feature */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -1952,5 +1952,59 @@ esp_err_t add(cluster_t *cluster);
} /* feature */
} /* closure_control */
namespace closure_dimension {
namespace feature {
namespace positioning {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* positioning */
namespace motion_latching {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* motion_latching */
namespace unit {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* unit */
namespace limitation {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* limitation */
namespace speed {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* speed */
namespace translation {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* translation */
namespace rotation {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* rotation */
namespace modulation {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* modulation */
} /* feature */
} /* closure_dimension */
} /* cluster */
} /* esp_matter */
@@ -387,6 +387,10 @@ namespace closure_control {
constexpr uint16_t cluster_revision = 1;
} // namespace closure_control
namespace closure_dimension {
constexpr uint16_t cluster_revision = 1;
} // namespace closure_dimension
} // namespace cluster
} // namespace esp_matter