File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,11 @@ uint16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) {
469
469
470
470
}
471
471
472
+ // returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
473
+ uint16_t DallasTemperature::millisToWaitForConversion () {
474
+ return millisToWaitForConversion (bitResolution);
475
+ }
476
+
472
477
// Sends command to one device to save values from scratchpad to EEPROM by index
473
478
// Returns true if no errors were encountered, false indicates failure
474
479
bool DallasTemperature::saveScratchPadByIndex (uint8_t deviceIndex) {
@@ -740,6 +745,19 @@ float DallasTemperature::rawToCelsius(int16_t raw) {
740
745
741
746
}
742
747
748
+ // Convert from Celsius to raw returns temperature in raw integer format.
749
+ // The rounding error in the conversion is smaller than 0.01°C
750
+ // where the resolution of the sensor is at best 0.0625°C (in 12 bit mode).
751
+ // Rounding error can be verified by running:
752
+ // for (float t=-55.; t<125.; t+=0.01)
753
+ // {
754
+ // Serial.println( DallasTemperature::rawToCelsius(DallasTemperature::celsiusToRaw(t))-t, 4 );
755
+ // }
756
+ int16_t DallasTemperature::celsiusToRaw (float celsius) {
757
+
758
+ return static_cast <uint16_t >( celsius * 128 .f );
759
+ }
760
+
743
761
// convert from raw to Fahrenheit
744
762
float DallasTemperature::rawToFahrenheit (int16_t raw) {
745
763
Original file line number Diff line number Diff line change @@ -158,7 +158,9 @@ class DallasTemperature {
158
158
// Is a conversion complete on the wire? Only applies to the first sensor on the wire.
159
159
bool isConversionComplete (void );
160
160
161
- int16_t millisToWaitForConversion (uint8_t );
161
+ static uint16_t millisToWaitForConversion (uint8_t );
162
+
163
+ uint16_t millisToWaitForConversion ();
162
164
163
165
// Sends command to one device to save values from scratchpad to EEPROM by index
164
166
// Returns true if no errors were encountered, false indicates failure
@@ -244,6 +246,9 @@ class DallasTemperature {
244
246
// convert from raw to Celsius
245
247
static float rawToCelsius (int16_t );
246
248
249
+ // convert from Celsius to raw
250
+ static int16_t celsiusToRaw (float );
251
+
247
252
// convert from raw to Fahrenheit
248
253
static float rawToFahrenheit (int16_t );
249
254
You can’t perform that action at this time.
0 commit comments