root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/AnalogProxy.h

Revision 19729, 3.6 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #ifndef _GADGET_ANALOGPROXY_H_
28 #define _GADGET_ANALOGPROXY_H_
29
30 #include <gadget/gadgetConfig.h>
31 #include <gadget/Type/Analog.h>
32 #include <gadget/Type/Proxy.h>
33 #include <gadget/Type/AnalogData.h>
34
35 namespace gadget
36 {
37
38 /** \class AnalogProxy AnalogProxy.h gadget/Type/AnalogProxy.h
39  *
40  * A proxy class to analog devices, used by the Input Manager.
41  *
42  * An analog proxy always points to an analog  device and unit number within
43  * that device.  The Input Manager can therefore keep an array of these
44  * around and treat them as analog devices that only return a single
45  * sub-device's amount of data (one float).
46  *
47  * @see Analog
48  */
49 class GADGET_CLASS_API AnalogProxy : public TypedProxy<Analog>
50 {
51
52 public:
53    /** Constructor. */
54    AnalogProxy(const std::string& deviceName = "UnknownAnalog",
55                const int unitNum = -1)
56       : TypedProxy<Analog>(deviceName)
57       , mUnitNum(unitNum)
58       , mData(-1.0f)
59    {;}
60
61    virtual ~AnalogProxy()
62    {;}
63
64    /** Updates the cached data copy from the device. */
65    virtual void updateData()
66    {
67       if(!isStupefied())
68       {
69          // Make sure dependencies are updated.
70          getProxiedInputDevice()->updateDataIfNeeded();
71          mData = mTypedDevice->getAnalogData(mUnitNum);
72       }
73    }
74
75    /** Returns the time of last update. */
76    virtual vpr::Interval getTimeStamp() const
77    {
78       return mData.getTime();
79    }
80
81    /**
82     * Gets the current analog data value.
83     * @return The analog data from the device.
84     */
85    float getData() const
86    {
87       const float analogDefault(0.0f);
88       if(isStupefied())
89       {
90          return analogDefault;
91       }
92       else
93       {
94          return mData.getAnalog();
95       }
96    }
97
98    /** Returns a pointer to the gadget::Analog object that we are proxying. */
99    Analog* getAnalogPtr()
100    {
101       if(isStupefied())
102       {
103          return NULL;
104       }
105       else
106       {
107          return mTypedDevice;
108       }
109    }
110
111    /**
112     * Returns the unit index into the analog device from which this proxy
113     * is reading data.
114     */
115    int getUnit() const
116    {
117       return mUnitNum;
118    }
119
120    static std::string getElementType();
121
122    bool config(jccl::ConfigElementPtr element);
123
124    virtual Input* getProxiedInputDevice()
125    {
126       if((NULL == mTypedDevice) || (mStupefied))
127       {
128          return NULL;
129       }
130
131       Input* ret_val = dynamic_cast<Input*>(mTypedDevice);
132       vprASSERT((ret_val != NULL) && "Cross-cast in AnalogProxy failed");
133       return ret_val;
134    }
135
136 private:
137    int         mUnitNum;
138    AnalogData  mData;
139 };
140
141 } // End of gadget namespace
142
143 #endif
Note: See TracBrowser for help on using the browser.