Adafruit MAX31850 DallasTemp Library
DallasTemperature.h
Go to the documentation of this file.
1 
4 #ifndef DallasTemperature_h
5 #define DallasTemperature_h
6 
7 #define DALLASTEMPLIBVERSION "3.7.2"
8 
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 
14 #ifndef REQUIRESNEW
15 #define REQUIRESNEW \
16  false
17 #endif
18 
19 #ifndef REQUIRESALARMS
20 #define REQUIRESALARMS \
21  true
22 #endif
23 
24 #include <OneWire.h>
25 #include <inttypes.h>
26 
27 // Model IDs
28 #define DS18S20MODEL 0x10
29 #define DS18B20MODEL 0x28
30 #define DS1822MODEL 0x22
31 #define MAX31850MODEL 0x3B
32 
33 // OneWire commands
34 #define STARTCONVO \
35  0x44
36 #define COPYSCRATCH 0x48
38 #define READSCRATCH 0xBE
39 #define WRITESCRATCH 0x4E
40 #define RECALLSCRATCH 0xB8
41 #define READPOWERSUPPLY 0xB4
42 #define ALARMSEARCH 0xEC
43 
44 // Scratchpad locations
45 #define TEMP_LSB 0
46 #define TEMP_MSB 1
47 #define HIGH_ALARM_TEMP 2
48 #define LOW_ALARM_TEMP 3
49 #define CONFIGURATION \
50  4
51 #define INTERNAL_BYTE 5
52 #define COUNT_REMAIN \
53  6
54 #define COUNT_PER_C 7
55 #define SCRATCHPAD_CRC 8
56 
57 // Device resolution
58 #define TEMP_9_BIT 0x1F
59 #define TEMP_10_BIT 0x3F
60 #define TEMP_11_BIT 0x5F
61 #define TEMP_12_BIT 0x7F
62 
63 // Error Codes
64 #define DEVICE_DISCONNECTED -127
65 
66 typedef uint8_t DeviceAddress[8];
67 
72 public:
76  DallasTemperature(OneWire *);
77 
81  void begin(void);
82 
87  uint8_t getDeviceCount(void);
88 
93  bool isConversionComplete(void);
94 
100  bool validAddress(uint8_t *);
101 
108  bool getAddress(uint8_t *, const uint8_t);
109 
116  bool isConnected(uint8_t *);
117 
125  bool isConnected(uint8_t *, uint8_t *);
126 
132  void readScratchPad(uint8_t *, uint8_t *);
133 
139  void writeScratchPad(uint8_t *, const uint8_t *);
140 
146  bool readPowerSupply(uint8_t *);
147 
152  uint8_t getResolution();
153 
158  void setResolution(uint8_t);
159 
165  uint8_t getResolution(uint8_t *);
166 
173  bool setResolution(uint8_t *, uint8_t);
174 
179  void setWaitForConversion(bool);
184  bool getWaitForConversion(void);
185 
190  void setCheckForConversion(bool);
195  bool getCheckForConversion(void);
196 
201  void requestTemperatures(void);
202 
209  bool requestTemperaturesByAddress(uint8_t *);
210 
217  bool requestTemperaturesByIndex(uint8_t);
218 
229  float getTempC(uint8_t *);
230 
237  float getTempF(uint8_t *);
238 
245  float getTempCByIndex(uint8_t);
246 
253  float getTempFByIndex(uint8_t);
254 
259  bool isParasitePowerMode(void);
260 
267  bool isConversionAvailable(uint8_t *);
268 
269 #if REQUIRESALARMS
270 
271  typedef void AlarmHandler(uint8_t *);
272 
273  // sets the high alarm temperature for a device
274  // accepts a char. valid range is -55C - 125C
275  void setHighAlarmTemp(uint8_t *, const char);
276 
277  // sets the low alarm temperature for a device
278  // accepts a char. valid range is -55C - 125C
279  void setLowAlarmTemp(uint8_t *, const char);
280 
281  // returns a signed char with the current high alarm temperature for a device
282  // in the range -55C - 125C
283  char getHighAlarmTemp(uint8_t *);
284 
285  // returns a signed char with the current low alarm temperature for a device
286  // in the range -55C - 125C
287  char getLowAlarmTemp(uint8_t *);
288 
289  // resets internal variables used for the alarm search
290  void resetAlarmSearch(void);
291 
292  // search the wire for devices with active alarms
293  bool alarmSearch(uint8_t *);
294 
295  // returns true if ia specific device has an alarm
296  bool hasAlarm(uint8_t *);
297 
298  // returns true if any device is reporting an alarm on the bus
299  bool hasAlarm(void);
300 
301  // runs the alarm handler for all devices returned by alarmSearch()
302  void processAlarms(void);
303 
304  // sets the alarm handler
305  void setAlarmHandler(AlarmHandler *);
306 
307  // The default alarm handler
308  static void defaultAlarmHandler(uint8_t *);
309 
310 #endif
311 
317  static float toFahrenheit(const float);
318 
324  static float toCelsius(const float);
325 
326 #if REQUIRESNEW
327 
328  // initalize memory area
329  void *operator new(unsigned int);
330 
331  // delete memory reference
332  void operator delete(void *);
333 
334 #endif
335 
336 private:
337  typedef uint8_t ScratchPad[9];
338 
339  // parasite power on or off
340  bool parasite;
341 
342  // used to determine the delay amount needed to allow for the
343  // temperature conversion to take place
344  uint8_t bitResolution;
345 
346  // used to requestTemperature with or without delay
347  bool waitForConversion;
348 
349  // used to requestTemperature to dynamically check if a conversion is complete
350  bool checkForConversion;
351 
352  // count of devices on the bus
353  uint8_t devices;
354 
355  // Take a pointer to one wire instance
356  OneWire *_wire;
357 
358  // reads scratchpad and returns the temperature in degrees C
359  float calculateTemperature(uint8_t *, uint8_t *);
360 
361  void blockTillConversionComplete(uint8_t *, uint8_t *);
362 
363 #if REQUIRESALARMS
364 
365  // required for alarmSearch
366  uint8_t alarmSearchAddress[8];
367  char alarmSearchJunction;
368  uint8_t alarmSearchExhausted;
369 
370  // the alarm handler function pointer
371  AlarmHandler *_AlarmHandler;
372 
373 #endif
374 };
375 #endif
bool getAddress(uint8_t *, const uint8_t)
finds an address at a given index on the bus
Definition: DallasTemperature.cpp:83
float getTempF(uint8_t *)
returns temperature in degrees F
Definition: DallasTemperature.cpp:477
void requestTemperatures(void)
sends command for all devices on the bus to perform a temperature conversion
Definition: DallasTemperature.cpp:317
bool isConversionAvailable(uint8_t *)
Checks if the clock has been raised indicating the conversion is complete.
Definition: DallasTemperature.cpp:309
float getTempC(uint8_t *)
returns temperature in degrees C or DEVICE_DISCONNECTED if the device&#39;s scratch pad cannot be read su...
Definition: DallasTemperature.cpp:463
float getTempCByIndex(uint8_t)
Get temperature for device index (slow)
Definition: DallasTemperature.cpp:391
uint8_t getDeviceCount(void)
returns the number of devices found on the bus
Definition: DallasTemperature.cpp:74
static float toCelsius(const float)
convert float farenheit to celsius
Definition: DallasTemperature.cpp:701
void writeScratchPad(uint8_t *, const uint8_t *)
write device&#39;s scratchpad
Definition: DallasTemperature.cpp:183
void setResolution(uint8_t)
set global resolution to 9, 10, 11, or 12 bits
Definition: DallasTemperature.cpp:215
DallasTemperature class.
Definition: DallasTemperature.h:71
static float toFahrenheit(const float)
convert float celsius to farenheit
Definition: DallasTemperature.cpp:696
bool requestTemperaturesByAddress(uint8_t *)
sends command for one device to perform a temperature conversion by address
Definition: DallasTemperature.cpp:333
void setCheckForConversion(bool)
sets the checkForConversion flag
Definition: DallasTemperature.cpp:302
uint8_t DeviceAddress[8]
Device address.
Definition: DallasTemperature.h:66
DallasTemperature(OneWire *)
DallasTemp constructor.
Definition: DallasTemperature.cpp:37
bool getCheckForConversion(void)
gets the value of the checkForConversion flag
Definition: DallasTemperature.cpp:307
float getTempFByIndex(uint8_t)
Get temperature for device index (slow)
Definition: DallasTemperature.cpp:398
bool requestTemperaturesByIndex(uint8_t)
sends command for one device to perform a temperature conversion by index
Definition: DallasTemperature.cpp:384
uint8_t getResolution()
gets global resolution
Definition: DallasTemperature.cpp:255
bool validAddress(uint8_t *)
returns true if address is valid
Definition: DallasTemperature.cpp:77
bool readPowerSupply(uint8_t *)
read device&#39;s power requirements
Definition: DallasTemperature.cpp:202
void begin(void)
initalise the bus
Definition: DallasTemperature.cpp:51
bool isConversionComplete(void)
Checks if a conversion is complete on the wire.
bool getWaitForConversion(void)
gets the value of the waitForConversion flag
Definition: DallasTemperature.cpp:296
void setWaitForConversion(bool)
sets the waitForConversion flag
Definition: DallasTemperature.cpp:291
void readScratchPad(uint8_t *, uint8_t *)
read device&#39;s scratchpad
Definition: DallasTemperature.cpp:113
bool isParasitePowerMode(void)
returns true if the bus requires parasite power
Definition: DallasTemperature.cpp:482
bool isConnected(uint8_t *)
attempt to determine if the device at the given address is connected to the bus
Definition: DallasTemperature.cpp:99