From 5aaccd8f890ca5448975b08179d4432083958721 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Jan 2025 07:02:30 -0300 Subject: [PATCH] feat(matter): fixes matter temperature sensor endpoint to indicate celsius as measure unit (#10759) --- .../MatterTemperatureSensor/MatterTemperatureSensor.ino | 6 +++--- .../src/MatterEndpoints/MatterTemperatureSensor.cpp | 2 +- .../Matter/src/MatterEndpoints/MatterTemperatureSensor.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/Matter/examples/MatterTemperatureSensor/MatterTemperatureSensor.ino b/libraries/Matter/examples/MatterTemperatureSensor/MatterTemperatureSensor.ino index e8513f12aaa..a2866e4655e 100644 --- a/libraries/Matter/examples/MatterTemperatureSensor/MatterTemperatureSensor.ino +++ b/libraries/Matter/examples/MatterTemperatureSensor/MatterTemperatureSensor.ino @@ -42,7 +42,7 @@ const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s // Simulate a temperature sensor - add your preferred temperature sensor library code here float getSimulatedTemperature() { // The Endpoint implementation keeps an int16_t as internal value information, - // which stores data in 1/100th of any temperature unit + // which stores data in 1/100th Celsius. static float simulatedTempHWSensor = -10.0; // it will increase from -10C to 10C in 0.5C steps to simulate a temperature sensor @@ -70,7 +70,7 @@ void setup() { Serial.println(); // set initial temperature sensor measurement - // Simulated Sensor - it shall initially print -25 degrees and then move to the -10 to 10 range + // Simulated Sensor - it shall initially print -25C and then move to the -10C to 10C range SimulatedTemperatureSensor.begin(-25.00); // Matter beginning - Last step, after all EndPoints are initialized @@ -102,7 +102,7 @@ void loop() { // Print the current temperature value every 5s if (!(timeCounter++ % 10)) { // delaying for 500ms x 10 = 5s // Print the current temperature value - Serial.printf("Current Temperature is %.02f \r\n", SimulatedTemperatureSensor.getTemperature()); + Serial.printf("Current Temperature is %.02fC\r\n", SimulatedTemperatureSensor.getTemperature()); // Update Temperature from the (Simulated) Hardware Sensor // Matter APP shall display the updated temperature percent SimulatedTemperatureSensor.setTemperature(getSimulatedTemperature()); diff --git a/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp b/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp index 903e6b98d98..863f86386c1 100644 --- a/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp +++ b/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp @@ -96,7 +96,7 @@ bool MatterTemperatureSensor::setRawTemperature(int16_t _rawTemperature) { } rawTemperature = _rawTemperature; } - log_v("Temperature Sensor set to %.02f Degrees", (float)_rawTemperature / 100.00); + log_v("Temperature Sensor set to %.02fC", (float)_rawTemperature / 100.00); return true; } diff --git a/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.h b/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.h index 27c61fdb978..3be6101166c 100644 --- a/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.h +++ b/libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.h @@ -23,7 +23,7 @@ class MatterTemperatureSensor : public MatterEndPoint { public: MatterTemperatureSensor(); ~MatterTemperatureSensor(); - // begin Matter Temperature Sensor endpoint with initial float temperature + // begin Matter Temperature Sensor endpoint with initial float temperature in Celsius bool begin(double temperature = 0.00) { return begin(static_cast(temperature * 100.0f)); } @@ -32,11 +32,11 @@ class MatterTemperatureSensor : public MatterEndPoint { // set the reported raw temperature bool setTemperature(double temperature) { - // stores up to 1/100th of a degree precision + // stores up to 1/100th Celsius precision int16_t rawValue = static_cast(temperature * 100.0f); return setRawTemperature(rawValue); } - // returns the reported float temperature with 1/100th of a degree precision + // returns the reported float temperature with 1/100th Celsius precision double getTemperature() { return (double)rawTemperature / 100.0; } @@ -55,7 +55,7 @@ class MatterTemperatureSensor : public MatterEndPoint { protected: bool started = false; - // implementation keeps temperature in 1/100th of a degree, any temperature unit + // implementation keeps temperature in 1/100th Celsius x 100 (int16_t) normalized value int16_t rawTemperature = 0; // internal function to set the raw temperature value (Matter Cluster) bool setRawTemperature(int16_t _rawTemperature);