@@ -64,25 +64,39 @@ bool DS18X20Hardware::IsTimerExpired() {
64
64
return millis () - _prv_period > _period;
65
65
}
66
66
67
- OneWireNg::ErrorCode DS18X20Hardware::ReadTemperatureC () {
67
+ float DS18X20Hardware::GetTemperatureC () { return _temp_c; }
68
+
69
+ float DS18X20Hardware::GetTemperatureF () { return _temp_f; }
70
+
71
+ bool DS18X20Hardware::ReadTemperatureF () {
72
+ bool is_success = ReadTemperatureC ();
73
+ // Did we read the temperature successfully?
74
+ if (!is_success)
75
+ return false ;
76
+ // We have the temperature in Celsius, convert to Fahrenheit
77
+ _temp_f = _temp_c * 9.0 / 5.0 + 32.0 ;
78
+ return true ;
79
+ }
80
+
81
+ bool DS18X20Hardware::ReadTemperatureC () {
68
82
// Start temperature conversion for the first identified sensor on the OneWire
69
83
// bus
70
84
OneWireNg::ErrorCode ec =
71
85
_drv_therm.convertTemp (_sensorId, DSTherm::MAX_CONV_TIME, false );
72
86
if (ec != OneWireNg::EC_SUCCESS)
73
- return ec;
87
+ return false
74
88
75
- // Scratchpad placeholder is static to allow reuse of the associated
76
- // sensor id while reissuing readScratchpadSingle() calls.
77
- // Note, due to its storage class the placeholder is zero initialized.
78
- static Placeholder<DSTherm::Scratchpad> scrpd;
89
+ // Scratchpad placeholder is static to allow reuse of the associated
90
+ // sensor id while reissuing readScratchpadSingle() calls.
91
+ // Note, due to its storage class the placeholder is zero initialized.
92
+ static Placeholder<DSTherm::Scratchpad>
93
+ scrpd;
79
94
ec = _drv_therm.readScratchpadSingle (scrpd);
80
95
if (ec != OneWireNg::EC_SUCCESS)
81
- return ec ;
96
+ return false ;
82
97
83
98
// Read the temperature from the sensor
84
99
long temp = scrpd->getTemp2 ();
85
100
_temp_c = temp / 16.0 ; // Convert from 16-bit int to float
86
-
87
- return ec;
101
+ return true ;
88
102
}
0 commit comments