+#ifndef DallasTemperature_h\r
+#define DallasTemperature_h\r
+\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+\r
+// set to true to include code for new and delete operators\r
+#ifndef REQUIRESNEW\r
+#define REQUIRESNEW false\r
+#endif\r
+\r
+// set to true to include code implementing alarm search functions\r
+#ifndef REQUIRESALARMS\r
+#define REQUIRESALARMS true\r
+#endif\r
+\r
+#include <inttypes.h>\r
+#include <OneWire.h>\r
+\r
+// Model IDs\r
+#define DS18S20MODEL 0x10\r
+#define DS18B20MODEL 0x28\r
+#define DS1822MODEL 0x22\r
+\r
+// OneWire commands\r
+#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad\r
+#define COPYSCRATCH 0x48 // Copy EEPROM\r
+#define READSCRATCH 0xBE // Read EEPROM\r
+#define WRITESCRATCH 0x4E // Write to EEPROM\r
+#define RECALLSCRATCH 0xB8 // Reload from last known\r
+#define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power\r
+#define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition\r
+\r
+// Scratchpad locations\r
+#define TEMP_LSB 0\r
+#define TEMP_MSB 1\r
+#define HIGH_ALARM_TEMP 2\r
+#define LOW_ALARM_TEMP 3\r
+#define CONFIGURATION 4\r
+#define INTERNAL_BYTE 5\r
+#define COUNT_REMAIN 6\r
+#define COUNT_PER_C 7\r
+#define SCRATCHPAD_CRC 8\r
+\r
+// Device resolution\r
+#define TEMP_9_BIT 0x1F // 9 bit\r
+#define TEMP_10_BIT 0x3F // 10 bit\r
+#define TEMP_11_BIT 0x5F // 11 bit\r
+#define TEMP_12_BIT 0x7F // 12 bit\r
+\r
+// Error Codes\r
+#define DEVICE_DISCONNECTED -127\r
+\r
+typedef uint8_t DeviceAddress[8];\r
+\r
+class DallasTemperature\r
+{\r
+ public:\r
+\r
+ DallasTemperature(OneWire*);\r
+\r
+ // initalize bus\r
+ void begin(void);\r
+\r
+ // returns the number of devices found on the bus\r
+ uint8_t getDeviceCount(void);\r
+ \r
+ // returns true if address is valid\r
+ bool validAddress(uint8_t*);\r
+\r
+ // finds an address at a given index on the bus \r
+ bool getAddress(uint8_t*, const uint8_t);\r
+ \r
+ // attempt to determine if the device at the given address is connected to the bus\r
+ bool isConnected(uint8_t*);\r
+\r
+ // attempt to determine if the device at the given address is connected to the bus\r
+ // also allows for updating the read scratchpad\r
+ bool isConnected(uint8_t*, uint8_t*);\r
+\r
+ // read device's scratchpad\r
+ void readScratchPad(uint8_t*, uint8_t*);\r
+\r
+ // write device's scratchpad\r
+ void writeScratchPad(uint8_t*, const uint8_t*);\r
+\r
+ // read device's power requirements\r
+ bool readPowerSupply(uint8_t*);\r
+\r
+ // returns the current resolution, 9-12\r
+ uint8_t getResolution(uint8_t*);\r
+\r
+ // set resolution of a device to 9, 10, 11, or 12 bits\r
+ void setResolution(uint8_t*, uint8_t);\r
+\r
+ // sends command for all devices on the bus to perform a temperature conversion\r
+ void requestTemperatures(void);\r
+ \r
+ // sends command for one device to perform a temperature conversion by address\r
+ void requestTemperaturesByAddress(uint8_t*);\r
+\r
+ // sends command for one device to perform a temperature conversion by index\r
+ void requestTemperaturesByIndex(uint8_t);\r
+\r
+ // returns temperature in degrees C\r
+ float getTempC(uint8_t*);\r
+\r
+ // returns temperature in degrees F\r
+ float getTempF(uint8_t*);\r
+\r
+ // Get temperature for device index (slow)\r
+ float getTempCByIndex(uint8_t);\r
+ \r
+ // Get temperature for device index (slow)\r
+ float getTempFByIndex(uint8_t);\r
+ \r
+ // returns true if the bus requires parasite power\r
+ bool isParasitePowerMode(void);\r
+\r
+ #if REQUIRESALARMS\r
+ \r
+ typedef void AlarmHandler(uint8_t*);\r
+\r
+ // sets the high alarm temperature for a device\r
+ // accepts a char. valid range is -55C - 125C\r
+ void setHighAlarmTemp(uint8_t*, const char);\r
+\r
+ // sets the low alarm temperature for a device\r
+ // accepts a char. valid range is -55C - 125C\r
+ void setLowAlarmTemp(uint8_t*, const char);\r
+\r
+ // returns a signed char with the current high alarm temperature for a device\r
+ // in the range -55C - 125C\r
+ char getHighAlarmTemp(uint8_t*);\r
+\r
+ // returns a signed char with the current low alarm temperature for a device\r
+ // in the range -55C - 125C\r
+ char getLowAlarmTemp(uint8_t*);\r
+ \r
+ // resets internal variables used for the alarm search\r
+ void resetAlarmSearch(void);\r
+\r
+ // search the wire for devices with active alarms\r
+ bool alarmSearch(uint8_t*);\r
+\r
+ // returns true if ia specific device has an alarm\r
+ bool hasAlarm(uint8_t*);\r
+\r
+ // returns true if any device is reporting an alarm on the bus\r
+ bool hasAlarm(void);\r
+\r
+ // runs the alarm handler for all devices returned by alarmSearch()\r
+ void processAlarms(void);\r
+ \r
+ // sets the alarm handler\r
+ void setAlarmHandler(AlarmHandler *);\r
+ \r
+ // The default alarm handler\r
+ static void defaultAlarmHandler(uint8_t*);\r
+\r
+ #endif\r
+\r
+ // convert from celcius to farenheit\r
+ static float toFahrenheit(const float);\r
+\r
+ // convert from farenheit to celsius\r
+ static float toCelsius(const float);\r
+\r
+ #if REQUIRESNEW\r
+\r
+ // initalize memory area\r
+ void* operator new (unsigned int);\r
+\r
+ // delete memory reference\r
+ void operator delete(void*);\r
+ \r
+ #endif\r
+\r
+ private:\r
+ typedef uint8_t ScratchPad[9];\r
+ \r
+ // parasite power on or off\r
+ bool parasite;\r
+\r
+ // used to determine the delay amount needed to allow for the\r
+ // temperature conversion to take place\r
+ int conversionDelay;\r
+\r
+ // count of devices on the bus\r
+ uint8_t devices;\r
+ \r
+ // Take a pointer to one wire instance\r
+ OneWire* _wire;\r
+\r
+ // reads scratchpad and returns the temperature in degrees C\r
+ float calculateTemperature(uint8_t*, uint8_t*);\r
+ \r
+ #if REQUIRESALARMS\r
+\r
+ // required for alarmSearch \r
+ uint8_t alarmSearchAddress[8];\r
+ char alarmSearchJunction;\r
+ uint8_t alarmSearchExhausted;\r
+\r
+ // the alarm handler function pointer\r
+ AlarmHandler *_AlarmHandler;\r
+\r
+ #endif\r
+ \r
+};\r
+#endif\r