Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform search for setResolution linearly? #220

Merged
merged 1 commit into from
Jun 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions DallasTemperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ void DallasTemperature::setResolution(uint8_t newResolution) {

bitResolution = constrain(newResolution, 9, 12);
DeviceAddress deviceAddress;
_wire->reset_search();
for (uint8_t i = 0; i < devices; i++) {
getAddress(deviceAddress, i);
setResolution(deviceAddress, bitResolution, true);
if(_wire->search(deviceAddress) && validAddress(deviceAddress)) {
setResolution(deviceAddress, bitResolution, true);
}
}
}

Expand Down Expand Up @@ -325,12 +327,14 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress,
if (skipGlobalBitResolutionCalculation == false) {
bitResolution = newResolution;
if (devices > 1) {
DeviceAddress deviceAddr;
_wire->reset_search();
for (uint8_t i = 0; i < devices; i++) {
if (bitResolution == 12) break;
DeviceAddress deviceAddr;
getAddress(deviceAddr, i);
uint8_t b = getResolution(deviceAddr);
if (b > bitResolution) bitResolution = b;
if (_wire->search(deviceAddr) && validAddress(deviceAddr)) {
uint8_t b = getResolution(deviceAddr);
if (b > bitResolution) bitResolution = b;
}
}
}
}
Expand Down