00001 /*************************************************************************** 00002 LOW_devDS1820.h - description 00003 ------------------- 00004 begin : Sat Jul 6 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@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 @author Harald Roelle, Helmut Reiser 00047 */ 00048 class LOW_devDS1820 : public LOW_device { 00049 00050 //======================================================================================= 00051 public: 00052 00053 //===================================================================================== 00054 // 00055 // exceptions 00056 // 00057 00058 /** Exception base class for all exceptions thrown by LOW_devDS1820. */ 00059 class_DERIVE_FROM_EXCEPTION( devDS1820_error, LOW_exception); 00060 00061 00062 00063 //===================================================================================== 00064 // 00065 // constants 00066 // 00067 00068 /** Family code of this specific device. */ 00069 static const LOW_deviceIDRaw::devFamCode_t familyCode = 0x10; 00070 00071 /** Family name of this specific device. */ 00072 static const string familyName; 00073 00074 static const owCommand_t ConvertT_COMMAND = 0x44; /**< 1-Wire command byte constant */ 00075 static const owCommand_t ReadScratchpad_COMMAND = 0xbe; /**< 1-Wire command byte constant */ 00076 static const owCommand_t WriteScratchpad_COMMAND = 0x4e; /**< 1-Wire command byte constant */ 00077 static const owCommand_t CopyScratchpad_COMMAND = 0x48; /**< 1-Wire command byte constant */ 00078 static const owCommand_t RecallE2_COMMAND = 0xb8; /**< 1-Wire command byte constant */ 00079 static const owCommand_t ReadPowerSupply_COMMAND = 0xb4; /**< 1-Wire command byte constant */ 00080 00081 00082 //===================================================================================== 00083 // 00084 // type definitions 00085 // 00086 00087 typedef std::vector<LOW_devDS1820*> devDS1820PtrVec_t; /**< Vector type of class device pointers. */ 00088 00089 /** DS1820 internal scratchpad as defined by Dallas. */ 00090 typedef struct scratchpadDS1820_t { 00091 uint8_t tempLSB; 00092 uint8_t tempMSB; 00093 uint8_t tH; 00094 uint8_t tL; 00095 uint8_t reserved0; 00096 uint8_t reserved1; 00097 uint8_t cntRemain; 00098 uint8_t cntPerCelsius; 00099 uint8_t crc8; 00100 } scratchpadDS1820_t; 00101 00102 00103 //===================================================================================== 00104 // 00105 // constructors 00106 // 00107 00108 /** Real constructor corresponding to static pseudo constructor new_Instance(). 00109 00110 External power supply status is initially detected here. 00111 00112 @param inSegment Reference to network segment the device is on. 00113 @param inDevID Reference to device's ID. 00114 */ 00115 LOW_devDS1820( LOW_netSegment &inSegment, const LOW_deviceID &inDevID); 00116 00117 00118 /** Destructor. 00119 */ 00120 ~LOW_devDS1820(); 00121 00122 00123 //===================================================================================== 00124 // 00125 // methods 00126 // 00127 00128 /** Get the device's family name. 00129 @return Family name of the device. 00130 */ 00131 virtual string getFamilyName() const { return familyName; }; 00132 00133 00134 /** Get whether the device is externally powered. 00135 No real activity on the 1-Wire bus occures. 00136 @return Boolean value indicating status of external power. 00137 */ 00138 bool getIsExternalPowered() const; 00139 00140 00141 /** Initiate a single temperature conversion. 00142 00143 Following the conversion, the resulting thermal data is stored in the 2-byte 00144 temperature register in the scratchpad memory and the DS18S20 returns to its 00145 low-power idle state. 00146 00147 The method uses different techniquies to detect the end of the conversion: 00148 - If the device is being used in parasite power mode, a strong pullup 00149 is enabled on the 1-Wire bus. Conversion ends when strong pullup ends. 00150 00151 - If the device is powered by an external supply, the device is actively 00152 polled for the end of the conversion. 00153 */ 00154 void cmd_ConvertT() const; 00155 00156 00157 /** Read the contents of the scratchpad. 00158 00159 After fully reading the scratchpad a CRC verification is performed. 00160 00161 @param outScratchpad Pointer to a scratchpad structure which will be filled in. 00162 @throw LOW_helper_CRC::crc_error Thrown on CRC mismatch in transferred scratchpad. 00163 */ 00164 void cmd_ReadScratchpad( scratchpadDS1820_t *outScratchpad) const; 00165 00166 00167 /** Write 2 bytes of data to the DS18S20 scratchpad. 00168 00169 @param inTL Byte to write to TL byte of scratchpad. 00170 @param inTH Byte to write to TH byte of scratchpad. 00171 */ 00172 void cmd_WriteScratchpad( const uint8_t inTL, const uint8_t inTH) const; 00173 00174 00175 /** Copy the contents of the scratchpad TH and TL registers to EEPROM. 00176 00177 If the device is being used in parasite power mode, a strong pullup on the 00178 1-Wire bus is enabled. 00179 */ 00180 void cmd_CopyScratchpad() const; 00181 00182 00183 /** Recall the alarm trigger values (TH and TL) from EEPROM and place the data in 00184 bytes 2 and 3, respectively, in the scratchpad memory. 00185 00186 The method uses different techniquies to detect the end of reading: 00187 - If the device is being used in parasite power mode, a strong pullup 00188 is enabled on the 1-Wire bus. Reading ends when strong pullup ends. 00189 00190 - If the device is powered by an external supply, the device is actively 00191 polled for the end of reading. 00192 */ 00193 void cmd_RecallE2() const; 00194 00195 00196 /** Determine the device is using parasite power. 00197 00198 @return True when device is externally powered. False when on parasite power. 00199 */ 00200 bool cmd_ReadPowerSupply() const; 00201 00202 00203 00204 //======================================================================================= 00205 protected: 00206 00207 //===================================================================================== 00208 // 00209 // attributes 00210 // 00211 00212 bool isExternalPowered; /**< Indicating wether the device is externally powered. */ 00213 00214 00215 //===================================================================================== 00216 // 00217 // static methods 00218 // 00219 00220 /** Static pseudo constructor for registering with LOW_deviceFactory. 00221 @param inSegment Reference to network segment the device is on. 00222 @param inDevID Reference to device's ID. 00223 @return New dynamic instance of specific device class. 00224 */ 00225 static LOW_device* new_Instance( LOW_netSegment &inNetSegment, const LOW_deviceID &inDevID); 00226 00227 00228 00229 //======================================================================================= 00230 private: 00231 00232 //===================================================================================== 00233 // 00234 // static initializer 00235 // 00236 00237 /** Needed for dirty little C++ hack to force static initialization on application start. 00238 @see initialize() 00239 */ 00240 static int initHelper; 00241 00242 /** Static inizializer to register the class with LOW_deviceFactory. 00243 @see initHelper 00244 */ 00245 static int initialize(); 00246 00247 }; 00248 00249 #endif