Merge branch 'device/light_sensor' into 'main'

Added light-sensor device type

See merge request app-frameworks/esp-matter!266
This commit is contained in:
Hrishikesh Dhayagude
2023-02-17 21:36:27 +08:00
6 changed files with 169 additions and 1 deletions
@@ -1743,5 +1743,66 @@ attribute_t *create_supported_calendar_types(cluster_t *cluster, uint8_t *value,
} /* attribute */
} /* time_format_localization */
namespace illuminance_measurement {
namespace attribute {
attribute_t *create_illuminance_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
attribute_t *create_illuminance_min_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MinMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
attribute_t *create_illuminance_max_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MaxMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
attribute_t *create_illuminance_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::Tolerance::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(max));
return attribute;
}
attribute_t *create_illuminance_light_sensor_type(cluster_t *cluster, nullable<uint8_t> value, nullable<uint8_t> min, nullable<uint8_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::LightSensorType::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_enum8(min), esp_matter_nullable_enum8(max));
return attribute;
}
} /* attribute */
} /* illuminance_measurement */
} /* cluster */
} /* esp_matter */
@@ -433,5 +433,15 @@ attribute_t *create_supported_calendar_types(cluster_t *cluster, uint8_t *value,
} /* attribute */
} /* time_format_localization */
namespace illuminance_measurement {
namespace attribute {
attribute_t *create_illuminance_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max);
attribute_t *create_illuminance_min_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max);
attribute_t *create_illuminance_max_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max);
attribute_t *create_illuminance_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max);
attribute_t *create_illuminance_light_sensor_type(cluster_t *cluster, nullable<uint8_t> value, nullable<uint8_t> min, nullable<uint8_t> max);
} /* attribute */
} /* illuminance_measurement */
} /* cluster */
} /* esp_matter */
+38 -1
View File
@@ -1645,8 +1645,45 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
return cluster;
}
} /* time_format_localization */
namespace illuminance_measurement {
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, IlluminanceMeasurement::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}
if (flags & CLUSTER_FLAG_SERVER) {
set_plugin_server_init_callback(cluster, MatterIlluminanceMeasurementPluginServerInitCallback);
add_function_list(cluster, function_list, function_flags);
}
if (flags & CLUSTER_FLAG_CLIENT) {
set_plugin_client_init_callback(cluster, MatterIlluminanceMeasurementPluginClientInitCallback);
create_default_binding_cluster(endpoint);
}
if (flags & CLUSTER_FLAG_SERVER) {
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
/** Attributes not managed internally **/
if (config) {
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
attribute::create_illuminance_measured_value(cluster, config->illuminance_measured_value, 0x0000, 0xFFFF);
attribute::create_illuminance_min_measured_value(cluster, config->illuminance_min_measured_value, 0x0001, 0xFFFD);
attribute::create_illuminance_max_measured_value(cluster, config->illuminance_max_measured_value, 0x0002, 0xFFFE);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
}
return cluster;
}
} /* illuminance_measurement */
} /* cluster */
} /* esp_matter */
@@ -414,5 +414,17 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* time_format_localization */
namespace illuminance_measurement {
typedef struct config {
uint16_t cluster_revision;
nullable<uint16_t> illuminance_measured_value;
nullable<uint16_t> illuminance_min_measured_value;
nullable<uint16_t> illuminance_max_measured_value;
config() : cluster_revision(3), illuminance_measured_value(0), illuminance_min_measured_value(1), illuminance_max_measured_value(2) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
}
} /* cluster */
} /* esp_matter */
@@ -741,6 +741,40 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config)
return endpoint;
}
} /* contact_sensor */
namespace light_sensor {
uint32_t get_device_type_id()
{
return ESP_MATTER_LIGHT_SENSOR_DEVICE_TYPE_ID;
}
uint8_t get_device_type_version()
{
return ESP_MATTER_LIGHT_SENSOR_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);
return add(endpoint, config);
}
endpoint_t *add(endpoint_t *endpoint, config_t *config)
{
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint cannot be NULL");
return NULL;
}
add_device_type(endpoint, get_device_type_id(), get_device_type_version());
descriptor::create(endpoint, CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
illuminance_measurement::create(endpoint, &(config->illuminance_measurement), CLUSTER_FLAG_SERVER);
return endpoint;
}
} /* light_sensor */
} /* endpoint */
namespace node {
@@ -55,6 +55,8 @@
#define ESP_MATTER_OCCUPANCY_SENSOR_DEVICE_TYPE_VERSION 2
#define ESP_MATTER_CONTACT_SENSOR_DEVICE_TYPE_ID 0x0015
#define ESP_MATTER_CONTACT_SENSOR_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_LIGHT_SENSOR_DEVICE_TYPE_ID 0x0106
#define ESP_MATTER_LIGHT_SENSOR_DEVICE_TYPE_VERSION 2
#define ESP_MATTER_FAN_DEVICE_TYPE_ID 0x002B
#define ESP_MATTER_FAN_DEVICE_TYPE_VERSION 1
@@ -340,6 +342,18 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
endpoint_t *add(endpoint_t *endpoint, config_t *config);
} /* contact_sensor */
namespace light_sensor {
typedef struct config {
cluster::identify::config_t identify;
cluster::illuminance_measurement::config_t illuminance_measurement;
} 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);
endpoint_t *add(endpoint_t *endpoint, config_t *config);
} /* light_sensor */
} /* endpoint */
namespace node {