Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_devDS1820.h

Go to the documentation of this file.
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 code.
00132       <B>Note:</B> Subclasses must implement this method to return their specific family code.
00133       @return Family name of the device.
00134    */
00135   virtual const LOW_deviceIDRaw::devFamCode_t getFamilyCode() const { return familyCode; };
00136 
00137   /** Get the device's family name.
00138       <B>Note:</B> Subclasses must implement this method to return a clear text
00139                    name of their family.
00140       @return Family name of the device.
00141    */
00142   virtual const std::string getFamilyName() const { return familyName; };
00143 
00144   /** Get whether the device is externally powered.
00145       No real activity on the 1-Wire bus occures.
00146       @return Boolean value indicating status of external power.
00147    */
00148   virtual bool getIsExternalPowered() const;
00149   
00150   
00151   /** Initiate a single temperature conversion. 
00152   
00153       Following the conversion, the resulting thermal data is stored in the 2-byte 
00154       temperature register in the scratchpad memory and the DS18S20 returns to its 
00155       low-power idle state. 
00156       
00157       The method uses different techniquies to detect the end of the conversion:
00158         - If the device is being used in parasite power mode, a strong pullup 
00159           is enabled on the 1-Wire bus. Conversion ends when strong pullup ends.
00160       
00161         - If the device is powered by an external supply, the device is actively
00162           polled for the end of the conversion.
00163   */
00164   virtual void cmd_ConvertT() const;
00165 
00166     
00167   /** Read the contents of the scratchpad. 
00168   
00169       After fully reading the scratchpad a CRC verification is performed.
00170   
00171       @param  outScratchpad  Pointer to a scratchpad structure which will be filled in.
00172       @throw LOW_helper_CRC::crc_error  Thrown on CRC mismatch in transferred scratchpad.
00173   */
00174   void cmd_ReadScratchpad( scratchpadDS1820_t *outScratchpad) const;
00175 
00176         
00177   /** Write 2 bytes of data to the DS18S20 scratchpad. 
00178   
00179       @param  inTL  Byte to write to TL byte of scratchpad.
00180       @param  inTH  Byte to write to TH byte of scratchpad.
00181   */
00182   virtual void cmd_WriteScratchpad( const uint8_t inTL, const uint8_t inTH) const;
00183 
00184     
00185   /** Copy the contents of the scratchpad TH and TL registers to EEPROM.
00186   
00187       If the device is being used in parasite power mode, a strong pullup on the 
00188       1-Wire bus is enabled.
00189   */
00190   virtual void cmd_CopyScratchpad() const;
00191 
00192     
00193   /** Recall the alarm trigger values (TH and TL) from EEPROM and place the data in 
00194       bytes 2 and 3, respectively, in the scratchpad memory. 
00195       
00196       The method uses different techniquies to detect the end of reading:
00197         - If the device is being used in parasite power mode, a strong pullup 
00198           is enabled on the 1-Wire bus. Reading ends when strong pullup ends.
00199       
00200         - If the device is powered by an external supply, the device is actively
00201           polled for the end of reading.
00202   */
00203   virtual void cmd_RecallE2() const;
00204 
00205           
00206   /** Determine the device is using parasite power. 
00207   
00208       @return   True when device is externally powered. False when on parasite power.
00209   */
00210   virtual bool cmd_ReadPowerSupply() const;
00211   
00212 
00213 
00214 //=======================================================================================
00215 protected:
00216 
00217   //=====================================================================================
00218   //
00219   // attributes
00220   //
00221   
00222   bool  isExternalPowered; /**< Indicating wether the device is externally powered. */
00223 
00224     
00225   //=====================================================================================
00226   //
00227   // static methods
00228   //
00229 
00230   /** Static pseudo constructor for registering with LOW_deviceFactory.
00231       @param  inSegment  Reference to network segment the device is on.
00232       @param  inDevID    Reference to device's ID.
00233       @return  New dynamic instance of specific device class.
00234    */
00235   static LOW_device* new_Instance( LOW_netSegment &inNetSegment, const LOW_deviceID &inDevID);
00236 
00237   
00238   
00239 //=======================================================================================
00240 private:
00241 
00242   //=====================================================================================
00243   //
00244   // static initializer
00245   //
00246   
00247   /** Needed for dirty little C++ hack to force static initialization on application start.
00248       @see initialize()
00249   */
00250   static int initHelper;
00251 
00252   /** Static inizializer to register the class with LOW_deviceFactory.
00253       @see initHelper
00254   */
00255   static int initialize();
00256     
00257 };
00258 
00259 #endif

Generated on Tue Feb 3 11:30:25 2004 for OneWireLibrary++ by doxygen 1.3.2