Skip to content

Commit f484fe9

Browse files
authored
Merge pull request #220 from Andersama/patch-1
Perform search for setResolution linearly?
2 parents acd2626 + 5e835dc commit f484fe9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

DallasTemperature.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ void DallasTemperature::setResolution(uint8_t newResolution) {
261261

262262
bitResolution = constrain(newResolution, 9, 12);
263263
DeviceAddress deviceAddress;
264+
_wire->reset_search();
264265
for (uint8_t i = 0; i < devices; i++) {
265-
getAddress(deviceAddress, i);
266-
setResolution(deviceAddress, bitResolution, true);
266+
if(_wire->search(deviceAddress) && validAddress(deviceAddress)) {
267+
setResolution(deviceAddress, bitResolution, true);
268+
}
267269
}
268270
}
269271

@@ -325,12 +327,14 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress,
325327
if (skipGlobalBitResolutionCalculation == false) {
326328
bitResolution = newResolution;
327329
if (devices > 1) {
330+
DeviceAddress deviceAddr;
331+
_wire->reset_search();
328332
for (uint8_t i = 0; i < devices; i++) {
329333
if (bitResolution == 12) break;
330-
DeviceAddress deviceAddr;
331-
getAddress(deviceAddr, i);
332-
uint8_t b = getResolution(deviceAddr);
333-
if (b > bitResolution) bitResolution = b;
334+
if (_wire->search(deviceAddr) && validAddress(deviceAddr)) {
335+
uint8_t b = getResolution(deviceAddr);
336+
if (b > bitResolution) bitResolution = b;
337+
}
334338
}
335339
}
336340
}

0 commit comments

Comments
 (0)