Skip to content

Commit e55aa05

Browse files
committed
fix milesburton#158 renamed 'magic' address fields
1 parent 953b0bf commit e55aa05

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
@@ -33,6 +33,10 @@ extern "C" {
3333
#define COUNT_PER_C 7
3434
#define SCRATCHPAD_CRC 8
3535

36+
// DSROM FIELDS
37+
#define DSROM_FAMILY 0
38+
#define DSROM_CRC 7
39+
3640
// Device resolution
3741
#define TEMP_9_BIT 0x1F // 9 bit
3842
#define TEMP_10_BIT 0x3F // 10 bit
@@ -57,7 +61,7 @@ DallasTemperature::DallasTemperature(OneWire* _oneWire) : DallasTemperature() {
5761
}
5862

5963
bool DallasTemperature::validFamily(const uint8_t* deviceAddress) {
60-
switch (deviceAddress[0]) {
64+
switch (deviceAddress[DSROM_FAMILY]) {
6165
case DS18S20MODEL:
6266
case DS18B20MODEL:
6367
case DS1822MODEL:
@@ -135,7 +139,7 @@ uint8_t DallasTemperature::getDS18Count(void) {
135139

136140
// returns true if address is valid
137141
bool DallasTemperature::validAddress(const uint8_t* deviceAddress) {
138-
return (_wire->crc8(deviceAddress, 7) == deviceAddress[7]);
142+
return (_wire->crc8(deviceAddress, 7) == deviceAddress[DSROM_CRC]);
139143
}
140144

141145
// finds an address at a given index on the bus
@@ -214,7 +218,7 @@ void DallasTemperature::writeScratchPad(const uint8_t* deviceAddress,
214218
_wire->write(scratchPad[LOW_ALARM_TEMP]); // low alarm temp
215219

216220
// DS1820 and DS18S20 have no configuration register
217-
if (deviceAddress[0] != DS18S20MODEL)
221+
if (deviceAddress[DSROM_FAMILY] != DS18S20MODEL)
218222
_wire->write(scratchPad[CONFIGURATION]);
219223

220224
if (autoSaveScratchPad)
@@ -266,7 +270,7 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress,
266270
bool success = false;
267271

268272
// DS1820 and DS18S20 have no resolution configuration register
269-
if (deviceAddress[0] == DS18S20MODEL)
273+
if (deviceAddress[DSROM_FAMILY] == DS18S20MODEL)
270274
{
271275
success = true;
272276
}
@@ -339,7 +343,7 @@ uint8_t DallasTemperature::getResolution() {
339343
uint8_t DallasTemperature::getResolution(const uint8_t* deviceAddress) {
340344

341345
// DS1820 and DS18S20 have no resolution configuration register
342-
if (deviceAddress[0] == DS18S20MODEL)
346+
if (deviceAddress[DSROM_FAMILY] == DS18S20MODEL)
343347
return 12;
344348

345349
ScratchPad scratchPad;
@@ -628,7 +632,7 @@ int16_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress,
628632
See - http://myarduinotoy.blogspot.co.uk/2013/02/12bit-result-from-ds18s20.html
629633
*/
630634

631-
if ((deviceAddress[0] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) {
635+
if ((deviceAddress[DSROM_FAMILY] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) {
632636
fpTemperature = ((fpTemperature & 0xfff0) << 3) - 32
633637
+ (((scratchPad[COUNT_PER_C] - scratchPad[COUNT_REMAIN]) << 7)
634638
/ scratchPad[COUNT_PER_C]);

0 commit comments

Comments
 (0)