00001 /*************************************************************************** 00002 LOW_devDS1820.h - description 00003 ------------------- 00004 begin : Sat Jul 6 2002 00005 copyright : (C) 2002 by Harald Roelle 00006 email : roelle@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_DEVDS1820_H 00019 #define LOW_DEVDS1820_H 00020 00021 00022 00023 #include "LOW_device.h" 00024 00025 00026 00027 /** Device class for DS18S20 High-Precision 1-Wire Digital Thermometer. 00028 00029 DS1820 features: 00030 00031 - Unique 1-Wire interface requires only one port pin for communication 00032 - Each device has a unique 64-bit serial code stored in an onboard ROM 00033 - Multidrop capability simplifies distributed temperature sensing applications 00034 - Requires no external components 00035 - Can be powered from data line. Power supply range is 3.0V to 5.5V 00036 - Measures temperatures from 55°C to +125°C ( 67°F to +257°F) 00037 - 0.5 C accuracy from 10°C to +85°C 00038 - 9-bit thermometer resolution 00039 - Converts temperature in 750ms (max.) 00040 - User-definable nonvolatile (NV) alarm settings 00041 - Alarm search command identifies and addresses devices whose temperature is outside 00042 of programmed limits (temperature alarm condition) 00043 - Applications include thermostatic controls, industrial systems, consumer products, 00044 thermometers, or any thermally sensitive system 00045 00046 This class is thread-safe. 00047 00048 @author Harald Roelle 00049 @author Parts of the documentation by Dallas Semiconductors / Maxim Integrated Products 00050 */ 00051 class LOW_devDS1820 : public LOW_device { 00052 00053 //======================================================================================= 00054 public: 00055 00056 //===================================================================================== 00057 // 00058 // exceptions 00059 // 00060 00061 /** Exception base class for all exceptions thrown by LOW_devDS1820. */ 00062 class_DERIVE_FROM_EXCEPTION( devDS1820_error, LOW_exception); 00063 00064 00065 00066 //===================================================================================== 00067 // 00068 // constants 00069 // 00070 00071 /** Family code of this specific device. */ 00072 static const LOW_deviceIDRaw::devFamCode_t familyCode = 0x10; 00073 00074 /** Family name of this specific device. */ 00075 static const std::string familyName; 00076 00077 static const owCommand_t ConvertT_COMMAND = 0x44; /**< 1-Wire command byte constant */ 00078 static const owCommand_t ReadScratchpad_COMMAND = 0xbe; /**< 1-Wire command byte constant */ 00079 static const owCommand_t WriteScratchpad_COMMAND = 0x4e; /**< 1-Wire command byte constant */ 00080 static const owCommand_t CopyScratchpad_COMMAND = 0x48; /**< 1-Wire command byte constant */ 00081 static const owCommand_t RecallE2_COMMAND = 0xb8; /**< 1-Wire command byte constant */ 00082 static const owCommand_t ReadPowerSupply_COMMAND = 0xb4; /**< 1-Wire command byte constant */ 00083 00084 00085 //===================================================================================== 00086 // 00087 // type definitions 00088 // 00089 00090 typedef std::vector<LOW_devDS1820*> devDS1820PtrVec_t; /**< Vector type of class device pointers. */ 00091 00092 /** DS1820 internal scratchpad as defined by Dallas. */ 00093 typedef struct scratchpadDS1820_t { 00094 uint8_t tempLSB; 00095 uint8_t tempMSB; 00096 uint8_t tH; 00097 uint8_t tL; 00098 uint8_t reserved0; 00099 uint8_t reserved1; 00100 uint8_t cntRemain; 00101 uint8_t cntPerCelsius; 00102 uint8_t crc8; 00103 } scratchpadDS1820_t; 00104 00105 00106 //===================================================================================== 00107 // 00108 // constructors 00109 // 00110 00111 /** Real constructor corresponding to static pseudo constructor new_Instance(). 00112 00113 External power supply status is initially detected here. 00114 00115 @param inSegment Reference to network segment the device is on. 00116 @param inDevID Reference to device's ID. 00117 */ 00118 LOW_devDS1820( LOW_netSegment &inSegment, const LOW_deviceID &inDevID); 00119 00120 00121 /** Destructor. 00122 */ 00123 virtual ~LOW_devDS1820(); 00124 00125 00126 //===================================================================================== 00127 // 00128 // methods 00129 // 00130 00131 /** Get the device's family name. 00132 @return Family name of the device. 00133 */ 00134 virtual std::string getFamilyName() const { return familyName; }; 00135 00136 00137 /** Get whether the device is externally powered. 00138 No real activity on the 1-Wire bus occures. 00139 @return Boolean value indicating status of external power. 00140 */ 00141 virtual bool getIsExternalPowered() const; 00142 00143 00144 /** Initiate a single temperature conversion. 00145 00146 Following the conversion, the resulting thermal data is stored in the 2-byte 00147 temperature register in the scratchpad memory and the DS18S20 returns to its 00148 low-power idle state. 00149 00150 The method uses different techniquies to detect the end of the conversion: 00151 - If the device is being used in parasite power mode, a strong pullup 00152 is enabled on the 1-Wire bus. Conversion ends when strong pullup ends. 00153 00154 - If the device is powered by an external supply, the device is actively 00155 polled for the end of the conversion. 00156 */ 00157 virtual void cmd_ConvertT() const; 00158 00159 00160 /** Read the contents of the scratchpad. 00161 00162 After fully reading the scratchpad a CRC verification is performed. 00163 00164 @param outScratchpad Pointer to a scratchpad structure which will be filled in. 00165 @throw LOW_helper_CRC::crc_error Thrown on CRC mismatch in transferred scratchpad. 00166 */ 00167 void cmd_ReadScratchpad( scratchpadDS1820_t *outScratchpad) const; 00168 00169 00170 /** Write 2 bytes of data to the DS18S20 scratchpad. 00171 00172 @param inTL Byte to write to TL byte of scratchpad. 00173 @param inTH Byte to write to TH byte of scratchpad. 00174 */ 00175 virtual void cmd_WriteScratchpad( const uint8_t inTL, const uint8_t inTH) const; 00176 00177 00178 /** Copy the contents of the scratchpad TH and TL registers to EEPROM. 00179 00180 If the device is being used in parasite power mode, a strong pullup on the 00181 1-Wire bus is enabled. 00182 */ 00183 virtual void cmd_CopyScratchpad() const; 00184 00185 00186 /** Recall the alarm trigger values (TH and TL) from EEPROM and place the data in 00187 bytes 2 and 3, respectively, in the scratchpad memory. 00188 00189 The method uses different techniquies to detect the end of reading: 00190 - If the device is being used in parasite power mode, a strong pullup 00191 is enabled on the 1-Wire bus. Reading ends when strong pullup ends. 00192 00193 - If the device is powered by an external supply, the device is actively 00194 polled for the end of reading. 00195 */ 00196 virtual void cmd_RecallE2() const; 00197 00198 00199 /** Determine the device is using parasite power. 00200 00201 @return True when device is externally powered. False when on parasite power. 00202 */ 00203 virtual bool cmd_ReadPowerSupply() const; 00204 00205 00206 00207 //======================================================================================= 00208 protected: 00209 00210 //===================================================================================== 00211 // 00212 // attributes 00213 // 00214 00215 bool isExternalPowered; /**< Indicating wether the device is externally powered. */ 00216 00217 00218 //===================================================================================== 00219 // 00220 // static methods 00221 // 00222 00223 /** Static pseudo constructor for registering with LOW_deviceFactory. 00224 @param inSegment Reference to network segment the device is on. 00225 @param inDevID Reference to device's ID. 00226 @return New dynamic instance of specific device class. 00227 */ 00228 static LOW_device* new_Instance( LOW_netSegment &inNetSegment, const LOW_deviceID &inDevID); 00229 00230 00231 00232 //======================================================================================= 00233 private: 00234 00235 //===================================================================================== 00236 // 00237 // static initializer 00238 // 00239 00240 /** Needed for dirty little C++ hack to force static initialization on application start. 00241 @see initialize() 00242 */ 00243 static int initHelper; 00244 00245 /** Static inizializer to register the class with LOW_deviceFactory. 00246 @see initHelper 00247 */ 00248 static int initialize(); 00249 00250 }; 00251 00252 #endif