Skip to content

Commit

Permalink
feat(matter): fixes matter temperature sensor endpoint to indicate ce…
Browse files Browse the repository at this point in the history
…lsius as measure unit (#10759)
  • Loading branch information
SuGlider authored Jan 7, 2025
1 parent 10d0bf8 commit 5aaccd8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <Temperature Units>\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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t>(temperature * 100.0f));
}
Expand All @@ -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<int16_t>(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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 5aaccd8

Please sign in to comment.