@@ -15,10 +15,10 @@ extern "C" {
1515
1616// OneWire commands
1717#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
18- #define COPYSCRATCH 0x48 // Copy EEPROM
19- #define READSCRATCH 0xBE // Read EEPROM
20- #define WRITESCRATCH 0x4E // Write to EEPROM
21- #define RECALLSCRATCH 0xB8 // Reload from last known
18+ #define COPYSCRATCH 0x48 // Copy scratchpad to EEPROM
19+ #define READSCRATCH 0xBE // Read from scratchpad
20+ #define WRITESCRATCH 0x4E // Write to scratchpad
21+ #define RECALLSCRATCH 0xB8 // Recall from EEPROM to scratchpad
2222#define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power
2323#define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition
2424
@@ -41,20 +41,15 @@ extern "C" {
4141
4242#define NO_ALARM_HANDLER ((AlarmHandler *)0 )
4343
44- DallasTemperature::DallasTemperature ()
45- {
44+ DallasTemperature::DallasTemperature () {
4645#if REQUIRESALARMS
4746setAlarmHandler (NO_ALARM_HANDLER);
4847#endif
4948 useExternalPullup = false ;
5049}
51- DallasTemperature::DallasTemperature (OneWire* _oneWire)
52- {
50+
51+ DallasTemperature::DallasTemperature (OneWire* _oneWire) : DallasTemperature() {
5352setOneWire (_oneWire);
54- #if REQUIRESALARMS
55- setAlarmHandler (NO_ALARM_HANDLER);
56- #endif
57- useExternalPullup = false ;
5853}
5954
6055bool DallasTemperature::validFamily (const uint8_t * deviceAddress) {
@@ -74,8 +69,8 @@ bool DallasTemperature::validFamily(const uint8_t* deviceAddress) {
7469 * Constructs DallasTemperature with strong pull-up turned on. Strong pull-up is mandated in DS18B20 datasheet for parasitic
7570 * power (2 wires) setup. (https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf, p. 7, section 'Powering the DS18B20').
7671 */
77- DallasTemperature::DallasTemperature (OneWire* _oneWire, uint8_t _pullupPin) : DallasTemperature(_oneWire){
78- setPullupPin (_pullupPin);
72+ DallasTemperature::DallasTemperature (OneWire* _oneWire, uint8_t _pullupPin) : DallasTemperature(_oneWire) {
73+ setPullupPin (_pullupPin);
7974}
8075
8176void DallasTemperature::setPullupPin (uint8_t _pullupPin) {
@@ -267,7 +262,7 @@ void DallasTemperature::setResolution(uint8_t newResolution) {
267262}
268263
269264// set resolution of a device to 9, 10, 11, or 12 bits
270- // if new resolution is out of range, 9 bits is used .
265+ // if new resolution is out of range, it is constrained .
271266bool DallasTemperature::setResolution (const uint8_t * deviceAddress,
272267uint8_t newResolution, bool skipGlobalBitResolutionCalculation) {
273268
@@ -428,16 +423,16 @@ bool DallasTemperature::requestTemperaturesByAddress(
428423// Continue to check if the IC has responded with a temperature
429424void DallasTemperature::blockTillConversionComplete (uint8_t bitResolution) {
430425
431- unsigned long delms = millisToWaitForConversion (bitResolution);
432- if (checkForConversion && !parasite) {
433- unsigned long start = millis ();
434- while (! isConversionComplete () && ( millis () - start < delms))
435- yield ();
436- } else {
437- activateExternalPullup ();
438- delay (delms);
439- deactivateExternalPullup ();
440- }
426+ if (checkForConversion && !parasite) {
427+ unsigned long start = millis ();
428+ while (! isConversionComplete () && ( millis () - start < MAX_CONVERSION_TIMEOUT ))
429+ yield ();
430+ } else {
431+ unsigned long delms = millisToWaitForConversion (bitResolution);
432+ activateExternalPullup ();
433+ delay (delms);
434+ deactivateExternalPullup ();
435+ }
441436
442437}
443438
@@ -480,11 +475,10 @@ bool DallasTemperature::requestTemperaturesByIndex(uint8_t deviceIndex) {
480475// Fetch temperature for device index
481476float DallasTemperature::getTempCByIndex (uint8_t deviceIndex) {
482477
483- DeviceAddress deviceAddress;
478+ DeviceAddress deviceAddress;
484479if (!getAddress (deviceAddress, deviceIndex)) {
485480return DEVICE_DISCONNECTED_C;
486481}
487-
488482return getTempC ((uint8_t *) deviceAddress);
489483
490484}
0 commit comments