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

Only updates the supplied deviceAddress if a valid index is specified #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 20 additions & 15 deletions DallasTemperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ bool DallasTemperature::validAddress(const uint8_t* deviceAddress) {
// finds an address at a given index on the bus
// returns true if the device was found
bool DallasTemperature::getAddress(uint8_t* deviceAddress, uint8_t index) {
if (index < devices) {
uint8_t depth = 0;

uint8_t depth = 0;
_wire->reset_search();

_wire->reset_search();

while (depth <= index && _wire->search(deviceAddress)) {
if (depth == index && validAddress(deviceAddress))
return true;
depth++;
while (depth <= index && _wire->search(deviceAddress)) {
if (depth == index && validAddress(deviceAddress))
return true;
depth++;
}
}

return false;

}

// attempt to determine if the device at the given address is connected to the bus
Expand Down Expand Up @@ -723,22 +723,27 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress,
// the numeric value of DEVICE_DISCONNECTED_RAW is defined in
// DallasTemperature.h. It is a large negative number outside the
// operating range of the device
int32_t DallasTemperature::getTemp(const uint8_t* deviceAddress) {
int32_t DallasTemperature::getTemp(const uint8_t* deviceAddress, byte retryCount = 0) {

ScratchPad scratchPad;
if (isConnected(deviceAddress, scratchPad))
return calculateTemperature(deviceAddress, scratchPad);
return DEVICE_DISCONNECTED_RAW;


byte retries = 0;

while (retries++ <= retryCount) {
if (isConnected(deviceAddress, scratchPad))
return calculateTemperature(deviceAddress, scratchPad);
}

return DEVICE_DISCONNECTED_RAW;
}

// returns temperature in degrees C or DEVICE_DISCONNECTED_C if the
// device's scratch pad cannot be read successfully.
// the numeric value of DEVICE_DISCONNECTED_C is defined in
// DallasTemperature.h. It is a large negative number outside the
// operating range of the device
float DallasTemperature::getTempC(const uint8_t* deviceAddress) {
return rawToCelsius(getTemp(deviceAddress));
float DallasTemperature::getTempC(const uint8_t* deviceAddress, byte retryCount = 0) {
return rawToCelsius(getTemp(deviceAddress, retryCount));
}

// returns temperature in degrees F or DEVICE_DISCONNECTED_F if the
Expand Down
4 changes: 2 additions & 2 deletions DallasTemperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ class DallasTemperature {
request_t requestTemperaturesByIndex(uint8_t);

// returns temperature raw value (12 bit integer of 1/128 degrees C)
int32_t getTemp(const uint8_t*);
int32_t getTemp(const uint8_t*, byte retryCount = 0);

// returns temperature in degrees C
float getTempC(const uint8_t*);
float getTempC(const uint8_t*, byte retryCount = 0);

// returns temperature in degrees F
float getTempF(const uint8_t*);
Expand Down