@@ -23,43 +23,41 @@ class MatterTemperatureSensor : public MatterEndPoint {
23
23
public:
24
24
MatterTemperatureSensor ();
25
25
~MatterTemperatureSensor ();
26
- // begin Matter Temperature Sensor endpoint
27
- virtual bool begin (int16_t _rawTemperature = 0 );
28
- bool begin (double temperatureCelcius) {
29
- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
30
- return begin (rawValue);
26
+ // begin Matter Temperature Sensor endpoint with initial float temperature
27
+ bool begin (double temperature) {
28
+ return setTemperature (temperature);
31
29
}
32
30
// this will stop processing Temperature Sensor Matter events
33
31
void end ();
34
32
35
33
// set the reported raw temperature
36
- bool setRawTemperature ( int16_t _rawTemperature);
37
- bool setTemperatureCelsius ( double temperatureCelcius) {
38
- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
34
+ bool setTemperature ( double temperature) {
35
+ // stores up to 1/100th of a degree precision
36
+ int16_t rawValue = static_cast <int16_t >(temperature * 100 .0f );
39
37
return setRawTemperature (rawValue);
40
38
}
41
- // returns the reported raw temperature (in 1/100th of a degree)
42
- int16_t getRawTemperature () {
43
- return rawTemperature;
44
- }
45
- // returns the reported temperature in Celcius
46
- double getTemperatureCelsius () {
39
+ // returns the reported float temperature with 1/100th of a degree precision
40
+ double getTemperature () {
47
41
return (double )rawTemperature / 100.0 ;
48
42
}
49
- // sets the reported temperature in Celcius
50
- void operator =(double temperatureCelcius) {
51
- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
52
- setRawTemperature (rawValue);
43
+ // double conversion operator
44
+ void operator =(double temperature) {
45
+ setTemperature (temperature);
53
46
}
47
+ // double conversion operator
54
48
operator double () {
55
- return (double ) getTemperatureCelsius ();
49
+ return (double ) getTemperature ();
56
50
}
57
51
58
52
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
59
53
bool attributeChangeCB (uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
60
54
61
55
protected:
62
56
bool started = false ;
63
- int16_t rawTemperature = 0 ; // default initial reported temperature
57
+ // implementation keeps temperature in 1/100th of a degree, any temperature unit
58
+ int16_t rawTemperature = 0 ;
59
+ // internal function to set the raw temperature value (Matter Cluster)
60
+ bool setRawTemperature (int16_t _rawTemperature);
61
+ bool begin (int16_t _rawTemperature);
64
62
};
65
63
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
0 commit comments