Skip to content

Commit 0300df6

Browse files
committed
Updated versions of DallasTemperature and OneWire libraries
1 parent 2b41450 commit 0300df6

File tree

16 files changed

+1014
-473
lines changed

16 files changed

+1014
-473
lines changed

libraries/DallasTemperature/DallasTemperature.cpp

Lines changed: 521 additions & 379 deletions
Large diffs are not rendered by default.

libraries/DallasTemperature/DallasTemperature.h

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DallasTemperature_h
22
#define DallasTemperature_h
33

4+
#define DALLASTEMPLIBVERSION "3.7.2"
5+
46
// This library is free software; you can redistribute it and/or
57
// modify it under the terms of the GNU Lesser General Public
68
// License as published by the Free Software Foundation; either
@@ -20,9 +22,10 @@
2022
#include <OneWire.h>
2123

2224
// Model IDs
23-
#define DS18S20MODEL 0x10
25+
#define DS18S20MODEL 0x10 // also DS1820
2426
#define DS18B20MODEL 0x28
2527
#define DS1822MODEL 0x22
28+
#define DS1825MODEL 0x3B
2629

2730
// OneWire commands
2831
#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
@@ -51,7 +54,9 @@
5154
#define TEMP_12_BIT 0x7F // 12 bit
5255

5356
// Error Codes
54-
#define DEVICE_DISCONNECTED -127
57+
#define DEVICE_DISCONNECTED_C -127
58+
#define DEVICE_DISCONNECTED_F -196.6
59+
#define DEVICE_DISCONNECTED_RAW -7040
5560

5661
typedef uint8_t DeviceAddress[8];
5762

@@ -61,54 +66,71 @@ class DallasTemperature
6166

6267
DallasTemperature(OneWire*);
6368

64-
// initalize bus
69+
// initialise bus
6570
void begin(void);
6671

6772
// returns the number of devices found on the bus
6873
uint8_t getDeviceCount(void);
6974

7075
// returns true if address is valid
71-
bool validAddress(uint8_t*);
76+
bool validAddress(const uint8_t*);
7277

7378
// finds an address at a given index on the bus
74-
bool getAddress(uint8_t*, const uint8_t);
79+
bool getAddress(uint8_t*, uint8_t);
7580

7681
// attempt to determine if the device at the given address is connected to the bus
77-
bool isConnected(uint8_t*);
82+
bool isConnected(const uint8_t*);
7883

7984
// attempt to determine if the device at the given address is connected to the bus
8085
// also allows for updating the read scratchpad
81-
bool isConnected(uint8_t*, uint8_t*);
86+
bool isConnected(const uint8_t*, uint8_t*);
8287

8388
// read device's scratchpad
84-
void readScratchPad(uint8_t*, uint8_t*);
89+
void readScratchPad(const uint8_t*, uint8_t*);
8590

8691
// write device's scratchpad
87-
void writeScratchPad(uint8_t*, const uint8_t*);
92+
void writeScratchPad(const uint8_t*, const uint8_t*);
8893

8994
// read device's power requirements
90-
bool readPowerSupply(uint8_t*);
95+
bool readPowerSupply(const uint8_t*);
9196

92-
// returns the current resolution, 9-12
93-
uint8_t getResolution(uint8_t*);
97+
// get global resolution
98+
uint8_t getResolution();
99+
100+
// set global resolution to 9, 10, 11, or 12 bits
101+
void setResolution(uint8_t);
94102

95-
// set resolution of a device to 9, 10, 11, or 12 bits
96-
void setResolution(uint8_t*, uint8_t);
103+
// returns the device resolution: 9, 10, 11, or 12 bits
104+
uint8_t getResolution(const uint8_t*);
97105

98-
// sends command for all devices on the bus to perform a temperature conversion
106+
// set resolution of a device to 9, 10, 11, or 12 bits
107+
bool setResolution(const uint8_t*, uint8_t);
108+
109+
// sets/gets the waitForConversion flag
110+
void setWaitForConversion(bool);
111+
bool getWaitForConversion(void);
112+
113+
// sets/gets the checkForConversion flag
114+
void setCheckForConversion(bool);
115+
bool getCheckForConversion(void);
116+
117+
// sends command for all devices on the bus to perform a temperature conversion
99118
void requestTemperatures(void);
100119

101120
// sends command for one device to perform a temperature conversion by address
102-
void requestTemperaturesByAddress(uint8_t*);
121+
bool requestTemperaturesByAddress(const uint8_t*);
103122

104123
// sends command for one device to perform a temperature conversion by index
105-
void requestTemperaturesByIndex(uint8_t);
124+
bool requestTemperaturesByIndex(uint8_t);
125+
126+
// returns temperature raw value (12 bit integer of 1/16 degrees C)
127+
int16_t getTemp(const uint8_t*);
106128

107129
// returns temperature in degrees C
108-
float getTempC(uint8_t*);
130+
float getTempC(const uint8_t*);
109131

110132
// returns temperature in degrees F
111-
float getTempF(uint8_t*);
133+
float getTempF(const uint8_t*);
112134

113135
// Get temperature for device index (slow)
114136
float getTempCByIndex(uint8_t);
@@ -118,26 +140,28 @@ class DallasTemperature
118140

119141
// returns true if the bus requires parasite power
120142
bool isParasitePowerMode(void);
143+
144+
bool isConversionAvailable(const uint8_t*);
121145

122146
#if REQUIRESALARMS
123147

124-
typedef void AlarmHandler(uint8_t*);
148+
typedef void AlarmHandler(const uint8_t*);
125149

126150
// sets the high alarm temperature for a device
127151
// accepts a char. valid range is -55C - 125C
128-
void setHighAlarmTemp(uint8_t*, const char);
152+
void setHighAlarmTemp(const uint8_t*, char);
129153

130154
// sets the low alarm temperature for a device
131155
// accepts a char. valid range is -55C - 125C
132-
void setLowAlarmTemp(uint8_t*, const char);
156+
void setLowAlarmTemp(const uint8_t*, char);
133157

134158
// returns a signed char with the current high alarm temperature for a device
135159
// in the range -55C - 125C
136-
char getHighAlarmTemp(uint8_t*);
160+
char getHighAlarmTemp(const uint8_t*);
137161

138162
// returns a signed char with the current low alarm temperature for a device
139163
// in the range -55C - 125C
140-
char getLowAlarmTemp(uint8_t*);
164+
char getLowAlarmTemp(const uint8_t*);
141165

142166
// resets internal variables used for the alarm search
143167
void resetAlarmSearch(void);
@@ -146,7 +170,7 @@ class DallasTemperature
146170
bool alarmSearch(uint8_t*);
147171

148172
// returns true if ia specific device has an alarm
149-
bool hasAlarm(uint8_t*);
173+
bool hasAlarm(const uint8_t*);
150174

151175
// returns true if any device is reporting an alarm on the bus
152176
bool hasAlarm(void);
@@ -155,22 +179,28 @@ class DallasTemperature
155179
void processAlarms(void);
156180

157181
// sets the alarm handler
158-
void setAlarmHandler(AlarmHandler *);
182+
void setAlarmHandler(const AlarmHandler *);
159183

160184
// The default alarm handler
161-
static void defaultAlarmHandler(uint8_t*);
185+
static void defaultAlarmHandler(const uint8_t*);
162186

163187
#endif
164188

165-
// convert from celcius to farenheit
166-
static float toFahrenheit(const float);
189+
// convert from Celsius to Fahrenheit
190+
static float toFahrenheit(float);
167191

168-
// convert from farenheit to celsius
169-
static float toCelsius(const float);
192+
// convert from Fahrenheit to Celsius
193+
static float toCelsius(float);
194+
195+
// convert from raw to Celsius
196+
static float rawToCelsius(int16_t);
197+
198+
// convert from raw to Fahrenheit
199+
static float rawToFahrenheit(int16_t);
170200

171201
#if REQUIRESNEW
172202

173-
// initalize memory area
203+
// initialize memory area
174204
void* operator new (unsigned int);
175205

176206
// delete memory reference
@@ -186,16 +216,26 @@ class DallasTemperature
186216

187217
// used to determine the delay amount needed to allow for the
188218
// temperature conversion to take place
189-
int conversionDelay;
190-
219+
uint8_t bitResolution;
220+
221+
// used to requestTemperature with or without delay
222+
bool waitForConversion;
223+
224+
// used to requestTemperature to dynamically check if a conversion is complete
225+
bool checkForConversion;
226+
191227
// count of devices on the bus
192228
uint8_t devices;
193229

194230
// Take a pointer to one wire instance
195231
OneWire* _wire;
196232

197-
// reads scratchpad and returns the temperature in degrees C
198-
float calculateTemperature(uint8_t*, uint8_t*);
233+
// reads scratchpad and returns the raw temperature
234+
int16_t calculateTemperature(const uint8_t*, uint8_t*);
235+
236+
int16_t millisToWaitForConversion(uint8_t);
237+
238+
void blockTillConversionComplete(uint8_t, const uint8_t*);
199239

200240
#if REQUIRESALARMS
201241

libraries/DallasTemperature/README renamed to libraries/DallasTemperature/README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,33 @@ Arduino Library for Dallas Temperature ICs
44
Usage
55
-----
66

7-
This library supports the following devices:
8-
DS18B20
9-
DS18S20 - Please note there appears to be an issue with this series.
10-
DS1822
7+
This library supports the following devices :
8+
9+
10+
* DS18B20
11+
* DS18S20 - Please note there appears to be an issue with this series.
12+
* DS1822
13+
* DS1820
14+
1115

1216
You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line
1317
and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The
1418
centre pin is the data line '1-wire'.
1519

1620
We have included a "REQUIRESNEW" and "REQUIRESALARMS" definition. If you
1721
want to slim down the code feel free to use either of these by including
18-
#define REQUIRESNEW or #define REQUIRESALARMS a the top of DallasTemperature.h
22+
23+
24+
25+
#define REQUIRESNEW
26+
27+
or
28+
29+
#define REQUIRESALARMS
30+
31+
32+
at the top of DallasTemperature.h
33+
1934

2035
Credits
2136
-------
@@ -26,6 +41,8 @@ Miles Burton <[email protected]> originally developed this library.
2641
Tim Newsome <[email protected]> added support for multiple sensors on
2742
the same bus.
2843
Guil Barros [[email protected]] added getTempByAddress (v3.5)
44+
Rob Tillaart [[email protected]] added async modus (v3.7.0)
45+
2946

3047
Website
3148
-------
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
This file contains the change history of the Dallas Temperature Control Library.
3+
4+
VERSION 3.7.2 BETA
5+
===================
6+
DATE: 6 DEC 2011
7+
8+
- Jordan Hochenbaum [[email protected]] updated library for compatibility with Arduino 1.0.
9+
10+
VERSION 3.7.0 BETA
11+
===================
12+
DATE: 11 JAN 2011
13+
14+
- Rob Tillaart [[email protected]] added async modus (v3.7.0)
15+
The library is backwards compatible with version 3.6.0
16+
17+
MAJOR: async modus
18+
------------------
19+
- Added - private bool waitForConversion.
20+
This boolean is default set to true in the Constructor to keep the library backwards compatible. If this flag is true calls to requestTemperatures(), requestTemperaturesByAddress() et al, will be blocking with the appropiate time specified (in datasheet) for the resolution used. If the flag is set to false, requestTemperatures() et al, will return immediately after the conversion command is send over the 1-wire interface. The programmer is responsible to wait long enough before reading the temperature values. This enables the application to do other things while waiting for a new reading, like calculations, update LCD, read/write other IO lines etc. See examples.
21+
22+
- Added - void setWaitForConversion(bool);
23+
To set the flag to true or false, depending on the modus needed.
24+
25+
- Added - bool getWaitForConversion(void);
26+
To get the current value of the flag.
27+
28+
- Changed - void requestTemperatures(void);
29+
Added a test (false == waitForConversion) to return immediately after the conversion command instead of waiting until the conversion is ready.
30+
31+
- Changed - bool requestTemperaturesByAddress(uint8_t*);
32+
Added a test (false == waitForConversion) to return immediately after the conversion command instead of waiting until the conversion is ready.
33+
34+
35+
MINOR version number
36+
--------------------
37+
- Added - #define DALLASTEMPLIBVERSION "3.7.0"
38+
To indicate the version number in .h file
39+
40+
41+
MINOR internal var bitResolution
42+
----------------------------
43+
- Changed - private int conversionDelay - is renamed to - private int bitResolution
44+
As this variable holds the resolution. The delay for the conversion is derived from it.
45+
46+
- Changed - uint8_t getResolution(uint8_t* deviceAddress);
47+
If the device is not connected, it returns 0, otherwise it returns the resolution of the device.
48+
49+
- Changed - bool setResolution(uint8_t* deviceAddress, uint8_t newResolution);
50+
If the device is not connected, it returns FALSE (fail), otherwise it returns TRUE (succes).
51+
52+
- Added - uint8_t getResolution();
53+
Returns bitResolution.
54+
55+
- Added - void setResolution(uint8_t newResolution)
56+
Sets the internal variable bitResolution, and all devices to this value
57+
58+
59+
MINOR check connected state
60+
----------------------------
61+
- Changed - bool requestTemperaturesByIndex(deviceIndex)
62+
Changed return type from void to bool. The function returns false if the device identified with [deviceIndex] is not found on the bus and true otherwise.
63+
64+
- Changed - bool requestTemperaturesByAddress(deviceAddress)
65+
Changed return type from void to bool. The function returns false if the device identified with [deviceAddress] is not found on the bus and true otherwise.
66+
Added code to handle the DS18S20 which has a 9 bit resolution separately.
67+
Changed code so the blocking delay matches the bitResolution set in the device with deviceAddress.
68+
69+
- Changed - bool requestTemperaturesByIndex(uint8_t deviceIndex)
70+
Changed return type from void to bool. The function returns false if the device identified with [deviceIndex] is not found on the bus and true otherwise.
71+
72+
73+
74+
VERSION 3.6.0
75+
==============
76+
DATE: 2010-10-10
77+
78+
- no detailed change history known except:
79+
80+
- The OneWire code has been derived from
81+
http://www.arduino.cc/playground/Learning/OneWire.
82+
- Miles Burton <[email protected]> originally developed this library.
83+
- Tim Newsome <[email protected]> added support for multiple sensors on
84+
the same bus.
85+
- Guil Barros [[email protected]] added getTempByAddress (v3.5)

libraries/DallasTemperature/examples/Alarm/Alarm.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <DallasTemperature.h>
33

44
// Data wire is plugged into port 2 on the Arduino
5-
#define ONE_WIRE_BUS 3
5+
#define ONE_WIRE_BUS 2
66

77
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
88
OneWire oneWire(ONE_WIRE_BUS);

libraries/DallasTemperature/examples/AlarmHandler/AlarmHandler.pde

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include <DallasTemperature.h>
33

44
// Data wire is plugged into port 2 on the Arduino
5-
#define ONE_WIRE_BUS 3
6-
#define TEMPERATURE_PRECISION 9
5+
#define ONE_WIRE_BUS 2
76

87
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
98
OneWire oneWire(ONE_WIRE_BUS);

0 commit comments

Comments
 (0)