Skip to content

Commit

Permalink
Merge pull request #181 from mkrzewic/master
Browse files Browse the repository at this point in the history
Convenience updates
  • Loading branch information
milesburton authored Dec 28, 2020
2 parents 03159c4 + 30f15de commit 798cfc2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 19 additions & 1 deletion DallasTemperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void DallasTemperature::blockTillConversionComplete(uint8_t bitResolution) {
}

// returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
int16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) {
uint16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) {

switch (bitResolution) {
case 9:
Expand All @@ -469,6 +469,11 @@ int16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) {

}

// returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
uint16_t DallasTemperature::millisToWaitForConversion() {
return millisToWaitForConversion(bitResolution);
}

// Sends command to one device to save values from scratchpad to EEPROM by index
// Returns true if no errors were encountered, false indicates failure
bool DallasTemperature::saveScratchPadByIndex(uint8_t deviceIndex) {
Expand Down Expand Up @@ -740,6 +745,19 @@ float DallasTemperature::rawToCelsius(int16_t raw) {

}

// Convert from Celsius to raw returns temperature in raw integer format.
// The rounding error in the conversion is smaller than 0.01°C
// where the resolution of the sensor is at best 0.0625°C (in 12 bit mode).
// Rounding error can be verified by running:
// for (float t=-55.; t<125.; t+=0.01)
// {
// Serial.println( DallasTemperature::rawToCelsius(DallasTemperature::celsiusToRaw(t))-t, 4 );
// }
int16_t DallasTemperature::celsiusToRaw(float celsius) {

return static_cast<uint16_t>( celsius * 128.f );
}

// convert from raw to Fahrenheit
float DallasTemperature::rawToFahrenheit(int16_t raw) {

Expand Down
7 changes: 6 additions & 1 deletion DallasTemperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ class DallasTemperature {
// Is a conversion complete on the wire? Only applies to the first sensor on the wire.
bool isConversionComplete(void);

int16_t millisToWaitForConversion(uint8_t);
static uint16_t millisToWaitForConversion(uint8_t);

uint16_t millisToWaitForConversion();

// Sends command to one device to save values from scratchpad to EEPROM by index
// Returns true if no errors were encountered, false indicates failure
Expand Down Expand Up @@ -244,6 +246,9 @@ class DallasTemperature {
// convert from raw to Celsius
static float rawToCelsius(int16_t);

// convert from Celsius to raw
static int16_t celsiusToRaw(float);

// convert from raw to Fahrenheit
static float rawToFahrenheit(int16_t);

Expand Down

0 comments on commit 798cfc2

Please sign in to comment.