Skip to content

Commit d56212e

Browse files
authored
Merge pull request #75 from Nzbuu/fix/move_constants
Move internal constants to DallasTemperature.cpp
2 parents dec0c80 + df3d4d5 commit d56212e

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

DallasTemperature.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ extern "C" {
1414
}
1515
#endif
1616

17+
// OneWire commands
18+
#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
19+
#define COPYSCRATCH 0x48 // Copy EEPROM
20+
#define READSCRATCH 0xBE // Read EEPROM
21+
#define WRITESCRATCH 0x4E // Write to EEPROM
22+
#define RECALLSCRATCH 0xB8 // Reload from last known
23+
#define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power
24+
#define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition
25+
26+
// Scratchpad locations
27+
#define TEMP_LSB 0
28+
#define TEMP_MSB 1
29+
#define HIGH_ALARM_TEMP 2
30+
#define LOW_ALARM_TEMP 3
31+
#define CONFIGURATION 4
32+
#define INTERNAL_BYTE 5
33+
#define COUNT_REMAIN 6
34+
#define COUNT_PER_C 7
35+
#define SCRATCHPAD_CRC 8
36+
37+
// Device resolution
38+
#define TEMP_9_BIT 0x1F // 9 bit
39+
#define TEMP_10_BIT 0x3F // 10 bit
40+
#define TEMP_11_BIT 0x5F // 11 bit
41+
#define TEMP_12_BIT 0x7F // 12 bit
42+
1743
DallasTemperature::DallasTemperature() {}
1844
DallasTemperature::DallasTemperature(OneWire* _oneWire)
1945

@@ -200,7 +226,7 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress, uint8_t newR
200226

201227
// ensure same behavior as setResolution(uint8_t newResolution)
202228
newResolution = constrain(newResolution, 9, 12);
203-
229+
204230
// return when stored value == new value
205231
if(getResolution(deviceAddress) == newResolution) return true;
206232

@@ -229,7 +255,7 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress, uint8_t newR
229255

230256
// without calculation we can always set it to max
231257
bitResolution = max(bitResolution, newResolution);
232-
258+
233259
if(!skipGlobalBitResolutionCalculation && (bitResolution > newResolution)){
234260
bitResolution = newResolution;
235261
DeviceAddress deviceAddr;
@@ -354,15 +380,15 @@ bool DallasTemperature::requestTemperaturesByAddress(const uint8_t* deviceAddres
354380

355381
// Continue to check if the IC has responded with a temperature
356382
void DallasTemperature::blockTillConversionComplete(uint8_t bitResolution){
357-
383+
358384
int delms = millisToWaitForConversion(bitResolution);
359385
if (checkForConversion && !parasite){
360386
unsigned long now = millis();
361387
while(!isConversionComplete() && (millis() - delms < now));
362388
} else {
363389
delay(delms);
364390
}
365-
391+
366392
}
367393

368394
// returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
@@ -622,7 +648,7 @@ void DallasTemperature::setHighAlarmTemp(const uint8_t* deviceAddress, char cels
622648
// accepts a float, but the alarm resolution will ignore anything
623649
// after a decimal point. valid range is -55C - 125C
624650
void DallasTemperature::setLowAlarmTemp(const uint8_t* deviceAddress, char celsius){
625-
651+
626652
// return when stored value == new value
627653
if(getLowAlarmTemp(deviceAddress) == celsius) return;
628654

DallasTemperature.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@
2828
#define DS1825MODEL 0x3B
2929
#define DS28EA00MODEL 0x42
3030

31-
// OneWire commands
32-
#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
33-
#define COPYSCRATCH 0x48 // Copy EEPROM
34-
#define READSCRATCH 0xBE // Read EEPROM
35-
#define WRITESCRATCH 0x4E // Write to EEPROM
36-
#define RECALLSCRATCH 0xB8 // Reload from last known
37-
#define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power
38-
#define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition
39-
40-
// Scratchpad locations
41-
#define TEMP_LSB 0
42-
#define TEMP_MSB 1
43-
#define HIGH_ALARM_TEMP 2
44-
#define LOW_ALARM_TEMP 3
45-
#define CONFIGURATION 4
46-
#define INTERNAL_BYTE 5
47-
#define COUNT_REMAIN 6
48-
#define COUNT_PER_C 7
49-
#define SCRATCHPAD_CRC 8
50-
51-
// Device resolution
52-
#define TEMP_9_BIT 0x1F // 9 bit
53-
#define TEMP_10_BIT 0x3F // 10 bit
54-
#define TEMP_11_BIT 0x5F // 11 bit
55-
#define TEMP_12_BIT 0x7F // 12 bit
56-
5731
// Error Codes
5832
#define DEVICE_DISCONNECTED_C -127
5933
#define DEVICE_DISCONNECTED_F -196.6
@@ -147,10 +121,10 @@ class DallasTemperature
147121

148122
// returns true if the bus requires parasite power
149123
bool isParasitePowerMode(void);
150-
124+
151125
// Is a conversion complete on the wire?
152126
bool isConversionComplete(void);
153-
127+
154128
int16_t millisToWaitForConversion(uint8_t);
155129

156130
#if REQUIRESALARMS

0 commit comments

Comments
 (0)