Skip to content

Commit

Permalink
Merge branch 'device/pressure-sensor' into 'main'
Browse files Browse the repository at this point in the history
Added pressure sensor device type

See merge request app-frameworks/esp-matter!267
  • Loading branch information
dhrishi committed Feb 18, 2023
2 parents e18933a + e2a69d2 commit 4d8c6f9
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 1 deletion.
64 changes: 64 additions & 0 deletions components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,5 +1804,69 @@ attribute_t *create_illuminance_light_sensor_type(cluster_t *cluster, nullable<u
} /* attribute */
} /* illuminance_measurement */

namespace pressure_measurement {
namespace attribute {

attribute_t *create_pressure_measured_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::MeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_min_measured_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::MinMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_max_measured_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::MaxMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PressureMeasurement::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_pressure_scaled_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::ScaledValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_min_scaled_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::MinScaledValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_max_scaled_value(cluster_t *cluster, nullable<int16_t> value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::MaxScaledValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_int16(value));
}

attribute_t *create_pressure_scaled_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::ScaledTolerance::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_pressure_scale(cluster_t *cluster, int8_t value)
{
return esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::Scale::Id, ATTRIBUTE_FLAG_NONE, esp_matter_int8(value));
}

} /* attribute */
} /* pressure_measurement */


} /* cluster */
} /* esp_matter */
14 changes: 14 additions & 0 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,19 @@ attribute_t *create_illuminance_light_sensor_type(cluster_t *cluster, nullable<u
} /* attribute */
} /* illuminance_measurement */

namespace pressure_measurement {
namespace attribute {
attribute_t *create_pressure_measured_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_min_measured_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_max_measured_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max);
attribute_t *create_pressure_scaled_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_min_scaled_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_max_scaled_value(cluster_t *cluster, nullable<int16_t> value);
attribute_t *create_pressure_scaled_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max);
attribute_t *create_pressure_scale(cluster_t *cluster, int8_t value);
} /* attribute */
} /* pressure_measurement */

} /* cluster */
} /* esp_matter */
38 changes: 38 additions & 0 deletions components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,5 +1685,43 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
}
} /* illuminance_measurement */

namespace pressure_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, PressureMeasurement::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}
if (flags & CLUSTER_FLAG_SERVER) {
set_plugin_server_init_callback(cluster, MatterPressureMeasurementPluginServerInitCallback);
add_function_list(cluster, function_list, function_flags);
}
if (flags & CLUSTER_FLAG_CLIENT) {
set_plugin_client_init_callback(cluster, MatterPressureMeasurementPluginClientInitCallback);
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_pressure_measured_value(cluster, config->pressure_measured_value);
attribute::create_pressure_min_measured_value(cluster, config->pressure_min_measured_value);
attribute::create_pressure_max_measured_value(cluster, config->pressure_max_measured_value);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
}

return cluster;
}
} /* pressure_measurement */

} /* cluster */
} /* esp_matter */
14 changes: 13 additions & 1 deletion components/esp_matter/esp_matter_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,19 @@ typedef struct config {
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
}
} /* illuminance_measurement */

namespace pressure_measurement {
typedef struct config {
uint16_t cluster_revision;
nullable<int16_t> pressure_measured_value;
nullable<int16_t> pressure_min_measured_value;
nullable<int16_t> pressure_max_measured_value;
config() : cluster_revision(3), pressure_measured_value(), pressure_min_measured_value(), pressure_max_measured_value() {}
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* pressure_measurement */

} /* cluster */
} /* esp_matter */
33 changes: 33 additions & 0 deletions components/esp_matter/esp_matter_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,39 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config)
}
} /* light_sensor */

namespace pressure_sensor {
uint32_t get_device_type_id()
{
return ESP_MATTER_PRESSURE_SENSOR_DEVICE_TYPE_ID;
}

uint8_t get_device_type_version()
{
return ESP_MATTER_PRESSURE_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);
pressure_measurement::create(endpoint, &(config->pressure_measurement), CLUSTER_FLAG_SERVER);

return endpoint;
}
} /* pressure_sensor */

} /* endpoint */

namespace node {
Expand Down
14 changes: 14 additions & 0 deletions components/esp_matter/esp_matter_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#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_PRESSURE_SENSOR_DEVICE_TYPE_ID 0x0305
#define ESP_MATTER_PRESSURE_SENSOR_DEVICE_TYPE_VERSION 2

#define ESP_MATTER_FAN_DEVICE_TYPE_ID 0x002B
#define ESP_MATTER_FAN_DEVICE_TYPE_VERSION 1
Expand Down Expand Up @@ -354,6 +356,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);
} /* light_sensor */

namespace pressure_sensor {
typedef struct config {
cluster::identify::config_t identify;
cluster::pressure_measurement::config_t pressure_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);
} /* pressure_sensor */

} /* endpoint */

namespace node {
Expand Down

0 comments on commit 4d8c6f9

Please sign in to comment.