comparison service/arduinoNode/arduino-libraries/DallasTemperature/DallasTemperature.h @ 165:af4e9d9f0bd8

some external arduino libs, minus examples and docs Ignore-this: 444126f11a1755109b3b29cbeaa6b9bd
author drewp@bigasterisk.com
date Sat, 11 Apr 2015 01:43:14 -0700
parents
children
comparison
equal deleted inserted replaced
164:49c1756b2edb 165:af4e9d9f0bd8
1 #ifndef DallasTemperature_h
2 #define DallasTemperature_h
3
4 #define DALLASTEMPLIBVERSION "3.7.2"
5
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10
11 // set to true to include code for new and delete operators
12 #ifndef REQUIRESNEW
13 #define REQUIRESNEW false
14 #endif
15
16 // set to true to include code implementing alarm search functions
17 #ifndef REQUIRESALARMS
18 #define REQUIRESALARMS true
19 #endif
20
21 #include <inttypes.h>
22 #include <OneWire.h>
23
24 // Model IDs
25 #define DS18S20MODEL 0x10 // also DS1820
26 #define DS18B20MODEL 0x28
27 #define DS1822MODEL 0x22
28 #define DS1825MODEL 0x3B
29
30 // OneWire commands
31 #define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
32 #define COPYSCRATCH 0x48 // Copy EEPROM
33 #define READSCRATCH 0xBE // Read EEPROM
34 #define WRITESCRATCH 0x4E // Write to EEPROM
35 #define RECALLSCRATCH 0xB8 // Reload from last known
36 #define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power
37 #define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition
38
39 // Scratchpad locations
40 #define TEMP_LSB 0
41 #define TEMP_MSB 1
42 #define HIGH_ALARM_TEMP 2
43 #define LOW_ALARM_TEMP 3
44 #define CONFIGURATION 4
45 #define INTERNAL_BYTE 5
46 #define COUNT_REMAIN 6
47 #define COUNT_PER_C 7
48 #define SCRATCHPAD_CRC 8
49
50 // Device resolution
51 #define TEMP_9_BIT 0x1F // 9 bit
52 #define TEMP_10_BIT 0x3F // 10 bit
53 #define TEMP_11_BIT 0x5F // 11 bit
54 #define TEMP_12_BIT 0x7F // 12 bit
55
56 // Error Codes
57 #define DEVICE_DISCONNECTED_C -127
58 #define DEVICE_DISCONNECTED_F -196.6
59 #define DEVICE_DISCONNECTED_RAW -7040
60
61 typedef uint8_t DeviceAddress[8];
62
63 class DallasTemperature
64 {
65 public:
66
67 DallasTemperature(OneWire*);
68
69 // initialise bus
70 void begin(void);
71
72 // returns the number of devices found on the bus
73 uint8_t getDeviceCount(void);
74
75 // returns true if address is valid
76 bool validAddress(const uint8_t*);
77
78 // finds an address at a given index on the bus
79 bool getAddress(uint8_t*, uint8_t);
80
81 // attempt to determine if the device at the given address is connected to the bus
82 bool isConnected(const uint8_t*);
83
84 // attempt to determine if the device at the given address is connected to the bus
85 // also allows for updating the read scratchpad
86 bool isConnected(const uint8_t*, uint8_t*);
87
88 // read device's scratchpad
89 void readScratchPad(const uint8_t*, uint8_t*);
90
91 // write device's scratchpad
92 void writeScratchPad(const uint8_t*, const uint8_t*);
93
94 // read device's power requirements
95 bool readPowerSupply(const uint8_t*);
96
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);
102
103 // returns the device resolution: 9, 10, 11, or 12 bits
104 uint8_t getResolution(const uint8_t*);
105
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
118 void requestTemperatures(void);
119
120 // sends command for one device to perform a temperature conversion by address
121 bool requestTemperaturesByAddress(const uint8_t*);
122
123 // sends command for one device to perform a temperature conversion by index
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*);
128
129 // returns temperature in degrees C
130 float getTempC(const uint8_t*);
131
132 // returns temperature in degrees F
133 float getTempF(const uint8_t*);
134
135 // Get temperature for device index (slow)
136 float getTempCByIndex(uint8_t);
137
138 // Get temperature for device index (slow)
139 float getTempFByIndex(uint8_t);
140
141 // returns true if the bus requires parasite power
142 bool isParasitePowerMode(void);
143
144 bool isConversionAvailable(const uint8_t*);
145
146 #if REQUIRESALARMS
147
148 typedef void AlarmHandler(const uint8_t*);
149
150 // sets the high alarm temperature for a device
151 // accepts a char. valid range is -55C - 125C
152 void setHighAlarmTemp(const uint8_t*, char);
153
154 // sets the low alarm temperature for a device
155 // accepts a char. valid range is -55C - 125C
156 void setLowAlarmTemp(const uint8_t*, char);
157
158 // returns a signed char with the current high alarm temperature for a device
159 // in the range -55C - 125C
160 char getHighAlarmTemp(const uint8_t*);
161
162 // returns a signed char with the current low alarm temperature for a device
163 // in the range -55C - 125C
164 char getLowAlarmTemp(const uint8_t*);
165
166 // resets internal variables used for the alarm search
167 void resetAlarmSearch(void);
168
169 // search the wire for devices with active alarms
170 bool alarmSearch(uint8_t*);
171
172 // returns true if ia specific device has an alarm
173 bool hasAlarm(const uint8_t*);
174
175 // returns true if any device is reporting an alarm on the bus
176 bool hasAlarm(void);
177
178 // runs the alarm handler for all devices returned by alarmSearch()
179 void processAlarms(void);
180
181 // sets the alarm handler
182 void setAlarmHandler(const AlarmHandler *);
183
184 // The default alarm handler
185 static void defaultAlarmHandler(const uint8_t*);
186
187 #endif
188
189 // convert from Celsius to Fahrenheit
190 static float toFahrenheit(float);
191
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);
200
201 #if REQUIRESNEW
202
203 // initialize memory area
204 void* operator new (unsigned int);
205
206 // delete memory reference
207 void operator delete(void*);
208
209 #endif
210
211 private:
212 typedef uint8_t ScratchPad[9];
213
214 // parasite power on or off
215 bool parasite;
216
217 // used to determine the delay amount needed to allow for the
218 // temperature conversion to take place
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
227 // count of devices on the bus
228 uint8_t devices;
229
230 // Take a pointer to one wire instance
231 OneWire* _wire;
232
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*);
239
240 #if REQUIRESALARMS
241
242 // required for alarmSearch
243 uint8_t alarmSearchAddress[8];
244 char alarmSearchJunction;
245 uint8_t alarmSearchExhausted;
246
247 // the alarm handler function pointer
248 AlarmHandler *_AlarmHandler;
249
250 #endif
251
252 };
253 #endif