Skip to content

Commit b8c43cc

Browse files
committed
feat(matter): general commentaries and code review
1 parent ff79cac commit b8c43cc

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

libraries/Matter/examples/MatterTemperatureSensor/MatterTemperatureSensor.ino

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
/*
16-
* This example is the smallest code that will create a Matter Device which can be
16+
* This example is an example code that will create a Matter Device which can be
1717
* commissioned and controlled from a Matter Environment APP.
1818
* Additionally the ESP32 will send debug messages indicating the Matter activity.
1919
* Turning DEBUG Level ON may be useful to following Matter Accessory and Controller messages.
@@ -25,16 +25,13 @@
2525

2626
// List of Matter Endpoints for this Node
2727
// Celcius Temperature Sensor Endpoint
28-
29-
3028
MatterTemperatureSensor CelciusTempSensor;
3129

3230
// WiFi is manually set and started
3331
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
3432
const char *password = "your-password"; // Change this to your WiFi password
3533

3634
// Simulate a temperature sensor - add your prefered temperature sensor library code here
37-
3835
float getTemperature() {
3936
static float CelciusTempHWSensor = -10.0;
4037

@@ -60,7 +57,7 @@ void setup() {
6057
Serial.println();
6158

6259
// set initial temperature sensor measurement
63-
// Simulated Sensor - it shall print -25C first and then move to the -10C to 10C range
60+
// Simulated Sensor - it shall initially print -25C and then move to the -10C to 10C range
6461
CelciusTempSensor.begin(-25.00);
6562

6663
// Matter beginning - Last step, after all EndPoints are initialized
@@ -89,8 +86,7 @@ void setup() {
8986
void loop() {
9087
Serial.printf("Current Temperature is %.02fC\r\n", (float)CelciusTempSensor);
9188
// update the temperature sensor value every 5 seconds
92-
// Matter phone APP shall display the temperature change
93-
89+
// Matter APP shall display the updated temperature
9490
delay(5000);
9591
CelciusTempSensor = getTemperature();
9692
}

libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL
1717

1818
#include <Matter.h>
19-
#include <app/server/Server.h>
2019
#include <MatterEndpoints/MatterTemperatureSensor.h>
2120

2221
using namespace esp_matter;
@@ -48,7 +47,7 @@ bool MatterTemperatureSensor::begin(int16_t _rawTemperature) {
4847
temperature_sensor_config.temperature_measurement.min_measured_value = nullptr;
4948
temperature_sensor_config.temperature_measurement.max_measured_value = nullptr;
5049

51-
// endpoint handles can be used to add/modify clusters.
50+
// endpoint handles can be used to add/modify clusters
5251
endpoint_t *endpoint = temperature_sensor::create(node::get(), &temperature_sensor_config, ENDPOINT_FLAG_NONE, (void *)this);
5352
if (endpoint == nullptr) {
5453
log_e("Failed to create Temperature Sensor endpoint");

libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ class MatterTemperatureSensor : public MatterEndPoint {
2323
public:
2424
MatterTemperatureSensor();
2525
~MatterTemperatureSensor();
26-
// default initial raw temperature
26+
// begin Matter Temperature Sensor endpoint
2727
virtual bool begin(int16_t _rawTemperature = 0);
2828
bool begin(double temperatureCelcius) {
2929
int16_t rawValue = static_cast<int16_t>(temperatureCelcius * 100.0f);
3030
return begin(rawValue);
3131
}
32-
// this will just stop processing Temperature Sensor Matter events
32+
// this will stop processing Temperature Sensor Matter events
3333
void end();
3434

3535
// set the reported raw temperature
@@ -38,23 +38,25 @@ class MatterTemperatureSensor : public MatterEndPoint {
3838
int16_t rawValue = static_cast<int16_t>(temperatureCelcius * 100.0f);
3939
return setRawTemperature(rawValue);
4040
}
41-
int16_t getRawTemperature() { // returns the reported raw temperature
41+
// returns the reported raw temperature (in 1/100th of a degree)
42+
int16_t getRawTemperature() {
4243
return rawTemperature;
4344
}
44-
double getTemperatureCelsius() { // returns the reported temperature in Celcius
45+
// returns the reported temperature in Celcius
46+
double getTemperatureCelsius() {
4547
return (double)rawTemperature / 100.0;
4648
}
47-
void operator=(double temperatureCelcius) { // sets the reported temperature in Celcius
49+
// sets the reported temperature in Celcius
50+
void operator=(double temperatureCelcius) {
4851
int16_t rawValue = static_cast<int16_t>(temperatureCelcius * 100.0f);
4952
setRawTemperature(rawValue);
5053
}
51-
operator double() { // returns the reported temperature in Celcius
54+
operator double() {
5255
return (double) getTemperatureCelsius();
5356
}
5457

5558
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
5659
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
57-
// User Callback for whenever the Light state is changed by the Matter Controller
5860

5961
protected:
6062
bool started = false;

0 commit comments

Comments
 (0)