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

LOW_devDS2890.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_devDS2890.h  -  description
00003                              -------------------
00004     begin                : Sun Nov 9 2003
00005     copyright            : (C) 2003 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_DEVDS2890_H
00019 #define LOW_DEVDS2890_H
00020 
00021 
00022 #include "LOW_device.h"
00023 #include "LOW_deviceFactory.h"
00024 
00025 
00026 
00027 /** Device class for DS2890 1-Wire Digital Potentiometer.
00028 
00029     DS2890 features:
00030 
00031     - Single element 256-position linear taper potentiometer
00032     - Supports potentiometer terminal working voltages up to 11V
00033     - Potentiometer terminal voltage independent of supply voltage
00034     - Potentiometer wiper position controlled and read over minimal 1-Wire bus interface
00035     - 100 kOhm resistor element value
00036     - Provides 1-Wire and VDD power modes
00037     - Supports Conditional Search based on power-on default wiper position
00038     - Multiple DS2890 s can be identified on a common 1-Wire bus and operated independently
00039     - Unique factory lasered 64-bit registration number assures error free device selection and absolute part identity
00040     - Built-in multi-drop controller ensures compatibility with other 1-Wire Network products
00041     - Supports Overdrive mode which boosts communication speed up to 142 kbits per second
00042     - -40oC to +85oC operating temperature range
00043     - 2.8V to 6.0V operating voltage range
00044 
00045     This class is thread-safe.
00046 
00047     @author Harald Roelle
00048     @author  Parts of the documentation by Dallas Semiconductors / Maxim Integrated Products
00049  */
00050 class LOW_devDS2890 : public LOW_device  {
00051 
00052 //=======================================================================================
00053 public:
00054 
00055   //=====================================================================================
00056   //
00057   // exceptions
00058   //
00059 
00060   /** Exception base class for all exceptions thrown by LOW_devDS2890. */
00061   class_DERIVE_FROM_EXCEPTION( devDS2890_error, LOW_exception);
00062 
00063 
00064   //=====================================================================================
00065   //
00066   // constants
00067   //
00068 
00069   /** Family code of this specific device. */
00070   static const LOW_deviceIDRaw::devFamCode_t  familyCode = 0x2c;
00071 
00072   /** Family name of this specific device. */
00073   static const std::string familyName;
00074 
00075   static const owCommand_t  ReadPosition_COMMAND         = 0xf0; /**< 1-Wire command byte constant */
00076   static const owCommand_t  WritePosition_COMMAND        = 0x0f; /**< 1-Wire command byte constant */
00077   static const owCommand_t  ReadControlRegister_COMMAND  = 0xaa; /**< 1-Wire command byte constant */
00078   static const owCommand_t  WriteControlRegister_COMMAND = 0x55; /**< 1-Wire command byte constant */
00079   static const owCommand_t  Increment_COMMAND            = 0xc3; /**< 1-Wire command byte constant */
00080   static const owCommand_t  Decrement_COMMAND            = 0x99; /**< 1-Wire command byte constant */
00081 
00082 
00083   //=====================================================================================
00084   //
00085   // type definitions
00086   //
00087 
00088   typedef std::vector<LOW_devDS2890*> devDS2890PtrVec_t;  /**< Vector type of class device pointers. */
00089 
00090   typedef uint16_t wiperPosition_t;  /**< Type for position setting of wiper. */
00091   
00092   /** DS2890 internal control register as defined by Dallas. */
00093   typedef struct controlRegister_t {
00094     uint8_t  controlledWiperNum;  /**< Currently selected wiper to be manupulated by commands. */
00095     bool     isChargePumpOn;      /**< Whether charge punp is enabled. */
00096   };
00097   typedef struct controlRegister_t controlRegister_t;
00098 
00099 
00100   //=====================================================================================
00101   //
00102   // constructors
00103   //
00104 
00105   /** Real constructor corresponding to static pseudo constructor new_Instance().
00106 
00107       Device features are initially detected here.
00108 
00109       @param  inSegment  Reference to network segment the device is on.
00110       @param  inDevID    Reference to device's ID.
00111    */
00112   LOW_devDS2890( LOW_netSegment &inSegment, const LOW_deviceID &inDevID);
00113 
00114 
00115   /** Destructor.
00116    */
00117   virtual ~LOW_devDS2890();
00118 
00119 
00120   //=====================================================================================
00121   //
00122   // methods
00123   //
00124 
00125   /** Get the device's family code.
00126       <B>Note:</B> Subclasses must implement this method to return their specific family code.
00127       @return Family name of the device.
00128    */
00129   virtual const LOW_deviceIDRaw::devFamCode_t getFamilyCode() const { return familyCode; };
00130 
00131   /** Get the device's family name.
00132       <B>Note:</B> Subclasses must implement this method to return a clear text
00133                    name of their family.
00134       @return Family name of the device.
00135    */
00136   virtual const std::string getFamilyName() const { return familyName; };
00137 
00138   /** Set whether charge pump is allowed for this device.
00139       Charge pump is only allowed to be used when external voltage supply is present.
00140       As this cannot be sensed by the device it has to set manually using this method.
00141       No real activity on the 1-Wire bus occures.
00142       @param  inCharpePumpAllowed .
00143    */
00144   virtual void setChargePumpAllowed( const bool inCharpePumpAllowed);
00145 
00146   /** Get whether charge pump is allowed for this device.
00147       No real activity on the 1-Wire bus occures.
00148       @return Whether charge pump is allowed for this device.
00149       @see setChargePumpAllowed()
00150    */
00151   virtual bool getChargePumpAllowed();
00152 
00153   /** Get whether the device has logarithmic or linear potentiometer elements.
00154       No real activity on the 1-Wire bus occures.
00155       @return Boolean value indicating the potentiometer type.
00156    */
00157   virtual bool getHasLinearPotElements() const;
00158 
00159   /** Get whether the wiper settings are volatile.
00160       No real activity on the 1-Wire bus occures.
00161       @return Boolean value indicating whether wiper settings are volatile.
00162    */
00163   virtual bool getIsWiperSettingVolatile() const;
00164 
00165   /** Get number of potentiometers in the device.
00166       No real activity on the 1-Wire bus occures.
00167       @return Number of potentiometers in the device.
00168    */
00169   virtual uint8_t getPotentiometerCount() const;
00170 
00171   /** Get number of positions selectable for each wiper.
00172       No real activity on the 1-Wire bus occures.
00173       @return Number of positions selectable for each wiper.
00174    */
00175   virtual wiperPosition_t getWiperPositionsCount() const;
00176 
00177   /** Get potentiometer resistance in ohm.
00178       No real activity on the 1-Wire bus occures.
00179       @return Potentiometer resistance in ohm.
00180    */
00181   virtual uint32_t getPotentiometerResistance() const;
00182 
00183   /** Get the cached value of the currently activated wiper.
00184       No real activity on the 1-Wire bus occures.
00185       @return  Cached wiper number.
00186    */
00187   virtual uint8_t getCachedWiperNumber();
00188 
00189   /** Get the cached value of a wiper position.
00190       No real activity on the 1-Wire bus occures.
00191       @param inControlledWiperNum  Wiper number to get value from.
00192       @return  Cached wiper position.
00193    */
00194   virtual wiperPosition_t getCachedWiperPosition( const uint8_t inControlledWiperNum = 0);
00195 
00196   /** The Read Position command is used to obtain the wiper setting of the potentiometer currently
00197       addressed by the Control Register. Although the DS2890 is a single element potentiometer, wiper
00198       addressing still applies and the Control Register wiper number used for addressing must be set
00199       accordingly.
00200 
00201       @return Current position of active wiper.
00202    */
00203   virtual wiperPosition_t cmd_ReadPosition();
00204   
00205   /** The Write Position command is used to set the position of the currently addressed potentiometer
00206       wiper. Although the DS2890 is a single element potentiometer, wiper addressing still applies
00207       and the Control Register wiper number used for addressing must be set accordingly.
00208 
00209       @param inNewPosition  New position of the wiper.
00210    */
00211   virtual void cmd_WritePosition( const wiperPosition_t inNewPosition);
00212 
00213   /** The Read Control Register command is used to obtain both the Control Register and potentiometer
00214       Feature Register. The Feature Register is not returned directly, but stored in internal attributes
00215       which are accessible via the various get*() methods.
00216 
00217       @return The control register value.
00218    */
00219   virtual controlRegister_t cmd_ReadControlRegister();
00220 
00221   /** The Write Control Register command is used to manipulate DS2890 state bits located in the
00222       Control Register. This command is used to set the potentiometer wiper address and charge pump state.
00223       Note that for enabling the charge pump this feature must explicitely enabled
00224       by setChargePumpAllowed().
00225       
00226       @param inControlledWiperNum   The wiper to be controlled.
00227       @param inChargePumpOn         Whether to turn on charge pump.
00228    */
00229   virtual void cmd_WriteControlRegister( const uint8_t inControlledWiperNum = 0, const bool inChargePumpOn = false);
00230 
00231   /** The Increment command is used for a one step position increase of the currently addressed
00232       potentiometer wiper. Although the DS2890 is a single element potentiometer, wiper addressing still
00233       applies and the Control Register wiper number used for addressing must be set accordingly.
00234       No position change is made if the DS2890 wiper is at the maximum position and
00235       an Increment command is received.
00236 
00237       @return New position of the wiper.
00238    */
00239   virtual wiperPosition_t cmd_Increment();
00240 
00241   /** The Decrement command is used for a one step position decrease of the currently addressed
00242       potentiometer wiper. Although the DS2890 is a single element potentiometer, wiper addressing still
00243       applies and the Control Register wiper number used for addressing must be set accordingly.
00244       No position change is made if the DS2890 wiper is at the minimum position (00h) and
00245       a Decrement command is received.
00246 
00247       @return New position of the wiper.
00248    */
00249   virtual wiperPosition_t cmd_Decrement();
00250 
00251 
00252   
00253 //=======================================================================================
00254 protected:
00255 
00256 
00257   //=====================================================================================
00258   //
00259   // constants
00260   //
00261 
00262   static const uint8_t releaseCode_subcommand = 0x96;  /**< Special byte to activate new values. */
00263 
00264   //! @name Feature register masks.
00265   //!@{
00266   static const uint8_t potentiometerType_featRegMask       = 0x01;
00267   static const uint8_t wiperSetVolatility_featRegMask      = 0x02;
00268   static const uint8_t potentiometerCount_featRegMask      = 0x0c;
00269   static const uint8_t wiperPositions_featRegMask          = 0x30;
00270   static const uint8_t potentiometerResistance_featRegMask = 0xc0;
00271   //!@}
00272 
00273   //! @name Control register masks.
00274   //!@{
00275   static const uint8_t wiperNum_ctlRegMsk     = 0x03;
00276   static const uint8_t invWiperNum_ctlRegMsk  = 0x0c;
00277   static const uint8_t chargePump_ctlRegMsk   = 0x40;
00278   //!@}
00279 
00280 
00281   //=====================================================================================
00282   //
00283   // attributes
00284   //
00285 
00286   bool              chargePumpAllowed;        /**< Enables setting chage pump option. */
00287   bool              hasLinearPotElements;     /**< Feature register value. */
00288   bool              isWiperSettingVolatile;   /**< Feature register value. */
00289   uint8_t           potentiometerCount;       /**< Feature register value. */
00290   wiperPosition_t   wiperPositionsCount;      /**< Feature register value. */
00291   uint32_t          potentiometerResistance;  /**< Feature register value. */
00292   wiperPosition_t   *cachedWiperPos;          /**< Cached wiper positions. */
00293   uint8_t           cachedCurrentWiper;       /**< Wiper which was selected. */
00294 
00295 
00296   //=====================================================================================
00297   //
00298   // static methods
00299   //
00300 
00301   /** Static pseudo constructor for registering with LOW_deviceFactory.
00302       @param  inSegment  Reference to network segment the device is on.
00303       @param  inDevID    Reference to device's ID.
00304       @return  New dynamic instance of specific device class.
00305    */
00306   static LOW_device* new_Instance( LOW_netSegment &inNetSegment, const LOW_deviceID &inDevID);
00307 
00308 
00309 
00310 //=======================================================================================
00311 private:
00312 
00313   //=====================================================================================
00314   //
00315   // static initializer
00316   //
00317 
00318   /** Needed for dirty little C++ hack to force static initialization on application start.
00319       @see initialize()
00320   */
00321   static int initHelper;
00322 
00323   /** Static inizializer to register the class with LOW_deviceFactory.
00324       @see initHelper
00325   */
00326   static int initialize();
00327 
00328 };
00329 
00330 #endif

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