File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,7 @@ bool DallasTemperature::isConnected(const uint8_t* deviceAddress) {
152
152
bool DallasTemperature::isConnected (const uint8_t * deviceAddress,
153
153
uint8_t * scratchPad) {
154
154
bool b = readScratchPad (deviceAddress, scratchPad);
155
- return b && (_wire->crc8 (scratchPad, 8 ) == scratchPad[SCRATCHPAD_CRC]);
155
+ return b && ! isAllZeros (scratchPad) && (_wire->crc8 (scratchPad, 8 ) == scratchPad[SCRATCHPAD_CRC]);
156
156
}
157
157
158
158
bool DallasTemperature::readScratchPad (const uint8_t * deviceAddress,
@@ -614,6 +614,17 @@ float DallasTemperature::rawToFahrenheit(int16_t raw) {
614
614
615
615
}
616
616
617
+ // Returns true if all bytes of scratchPad are '\0'
618
+ bool DallasTemperature::isAllZeros (const uint8_t * const scratchPad, const size_t length) {
619
+ for (size_t i = 0 ; i < length; i++) {
620
+ if (scratchPad[i] != 0 ) {
621
+ return false ;
622
+ }
623
+ }
624
+
625
+ return true ;
626
+ }
627
+
617
628
#if REQUIRESALARMS
618
629
619
630
/*
Original file line number Diff line number Diff line change @@ -239,6 +239,9 @@ class DallasTemperature {
239
239
240
240
void blockTillConversionComplete (uint8_t );
241
241
242
+ // Returns true if all bytes of scratchPad are '\0'
243
+ bool isAllZeros (const uint8_t * const scratchPad, const size_t length = 9 );
244
+
242
245
#if REQUIRESALARMS
243
246
244
247
// required for alarmSearch
You can’t perform that action at this time.
0 commit comments