Added the OneWire and DallasTemperature libraries to
[ruwai.git] / software / arduino / libraries / DallasTemperature / DallasTemperature.h
blob0157c60b6791b610057319eeefe30326581a85c2
1 #ifndef DallasTemperature_h
2 #define DallasTemperature_h
4 #define DALLASTEMPLIBVERSION "3.7.9" // To be deprecated
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.
11 // set to true to include code for new and delete operators
12 #ifndef REQUIRESNEW
13 #define REQUIRESNEW false
14 #endif
16 // set to true to include code implementing alarm search functions
17 #ifndef REQUIRESALARMS
18 #define REQUIRESALARMS true
19 #endif
21 #include <inttypes.h>
22 #include <OneWire.h>
24 // Model IDs
25 #define DS18S20MODEL 0x10 // also DS1820
26 #define DS18B20MODEL 0x28
27 #define DS1822MODEL 0x22
28 #define DS1825MODEL 0x3B
29 #define DS28EA00MODEL 0x42
31 // Error Codes
32 #define DEVICE_DISCONNECTED_C -127
33 #define DEVICE_DISCONNECTED_F -196.6
34 #define DEVICE_DISCONNECTED_RAW -7040
36 typedef uint8_t DeviceAddress[8];
38 class DallasTemperature {
39 public:
41 DallasTemperature();
42 DallasTemperature(OneWire*);
44 void setOneWire(OneWire*);
46 // initialise bus
47 void begin(void);
49 // returns the number of devices found on the bus
50 uint8_t getDeviceCount(void);
52 // returns the number of DS18xxx Family devices on bus
53 uint8_t getDS18Count(void);
55 // returns true if address is valid
56 bool validAddress(const uint8_t*);
58 // returns true if address is of the family of sensors the lib supports.
59 bool validFamily(const uint8_t* deviceAddress);
61 // finds an address at a given index on the bus
62 bool getAddress(uint8_t*, uint8_t);
64 // attempt to determine if the device at the given address is connected to the bus
65 bool isConnected(const uint8_t*);
67 // attempt to determine if the device at the given address is connected to the bus
68 // also allows for updating the read scratchpad
69 bool isConnected(const uint8_t*, uint8_t*);
71 // read device's scratchpad
72 bool readScratchPad(const uint8_t*, uint8_t*);
74 // write device's scratchpad
75 void writeScratchPad(const uint8_t*, const uint8_t*);
77 // read device's power requirements
78 bool readPowerSupply(const uint8_t*);
80 // get global resolution
81 uint8_t getResolution();
83 // set global resolution to 9, 10, 11, or 12 bits
84 void setResolution(uint8_t);
86 // returns the device resolution: 9, 10, 11, or 12 bits
87 uint8_t getResolution(const uint8_t*);
89 // set resolution of a device to 9, 10, 11, or 12 bits
90 bool setResolution(const uint8_t*, uint8_t,
91 bool skipGlobalBitResolutionCalculation = false);
93 // sets/gets the waitForConversion flag
94 void setWaitForConversion(bool);
95 bool getWaitForConversion(void);
97 // sets/gets the checkForConversion flag
98 void setCheckForConversion(bool);
99 bool getCheckForConversion(void);
101 // sends command for all devices on the bus to perform a temperature conversion
102 void requestTemperatures(void);
104 // sends command for one device to perform a temperature conversion by address
105 bool requestTemperaturesByAddress(const uint8_t*);
107 // sends command for one device to perform a temperature conversion by index
108 bool requestTemperaturesByIndex(uint8_t);
110 // returns temperature raw value (12 bit integer of 1/128 degrees C)
111 int16_t getTemp(const uint8_t*);
113 // returns temperature in degrees C
114 float getTempC(const uint8_t*);
116 // returns temperature in degrees F
117 float getTempF(const uint8_t*);
119 // Get temperature for device index (slow)
120 float getTempCByIndex(uint8_t);
122 // Get temperature for device index (slow)
123 float getTempFByIndex(uint8_t);
125 // returns true if the bus requires parasite power
126 bool isParasitePowerMode(void);
128 // Is a conversion complete on the wire? Only applies to the first sensor on the wire.
129 bool isConversionComplete(void);
131 int16_t millisToWaitForConversion(uint8_t);
133 #if REQUIRESALARMS
135 typedef void AlarmHandler(const uint8_t*);
137 // sets the high alarm temperature for a device
138 // accepts a int8_t. valid range is -55C - 125C
139 void setHighAlarmTemp(const uint8_t*, int8_t);
141 // sets the low alarm temperature for a device
142 // accepts a int8_t. valid range is -55C - 125C
143 void setLowAlarmTemp(const uint8_t*, int8_t);
145 // returns a int8_t with the current high alarm temperature for a device
146 // in the range -55C - 125C
147 int8_t getHighAlarmTemp(const uint8_t*);
149 // returns a int8_t with the current low alarm temperature for a device
150 // in the range -55C - 125C
151 int8_t getLowAlarmTemp(const uint8_t*);
153 // resets internal variables used for the alarm search
154 void resetAlarmSearch(void);
156 // search the wire for devices with active alarms
157 bool alarmSearch(uint8_t*);
159 // returns true if ia specific device has an alarm
160 bool hasAlarm(const uint8_t*);
162 // returns true if any device is reporting an alarm on the bus
163 bool hasAlarm(void);
165 // runs the alarm handler for all devices returned by alarmSearch()
166 void processAlarms(void);
168 // sets the alarm handler
169 void setAlarmHandler(const AlarmHandler *);
171 // returns true if an AlarmHandler has been set
172 bool hasAlarmHandler();
174 #endif
176 // if no alarm handler is used the two bytes can be used as user data
177 // example of such usage is an ID.
178 // note if device is not connected it will fail writing the data.
179 // note if address cannot be found no error will be reported.
180 // in short use carefully
181 void setUserData(const uint8_t*, int16_t);
182 void setUserDataByIndex(uint8_t, int16_t);
183 int16_t getUserData(const uint8_t*);
184 int16_t getUserDataByIndex(uint8_t);
186 // convert from Celsius to Fahrenheit
187 static float toFahrenheit(float);
189 // convert from Fahrenheit to Celsius
190 static float toCelsius(float);
192 // convert from raw to Celsius
193 static float rawToCelsius(int16_t);
195 // convert from raw to Fahrenheit
196 static float rawToFahrenheit(int16_t);
198 #if REQUIRESNEW
200 // initialize memory area
201 void* operator new (unsigned int);
203 // delete memory reference
204 void operator delete(void*);
206 #endif
207 // Take a pointer to one wire instance
208 OneWire* _wire;
210 private:
211 typedef uint8_t ScratchPad[9];
213 // parasite power on or off
214 bool parasite;
216 // used to determine the delay amount needed to allow for the
217 // temperature conversion to take place
218 uint8_t bitResolution;
220 // used to requestTemperature with or without delay
221 bool waitForConversion;
223 // used to requestTemperature to dynamically check if a conversion is complete
224 bool checkForConversion;
226 // count of devices on the bus
227 uint8_t devices;
229 // count of DS18xxx Family devices on bus
230 uint8_t ds18Count;
233 // reads scratchpad and returns the raw temperature
234 int16_t calculateTemperature(const uint8_t*, uint8_t*);
236 void blockTillConversionComplete(uint8_t);
238 #if REQUIRESALARMS
240 // required for alarmSearch
241 uint8_t alarmSearchAddress[8];
242 int8_t alarmSearchJunction;
243 uint8_t alarmSearchExhausted;
245 // the alarm handler function pointer
246 AlarmHandler *_AlarmHandler;
248 #endif
251 #endif