gadget::AnalogProxy Class Reference

A proxy class to analog devices, used by the Input Manager. More...

#include <gadget/Type/AnalogProxy.h>

Inheritance diagram for gadget::AnalogProxy:

Inheritance graph
[legend]
Collaboration diagram for gadget::AnalogProxy:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AnalogProxy ()
 Constructor.
virtual ~AnalogProxy ()
virtual void updateData ()
 Updates the cached data copy from the device.
virtual vpr::Interval getTimeStamp () const
 Returns the time of last update.
float getData () const
 Gets the current analog data value.
AnaloggetAnalogPtr ()
 Returns a pointer to the gadget::Analog object that we are proxying.
int getUnit () const
 Returns the unit index into the analog device from which this proxy is reading data.
bool config (jccl::ConfigElementPtr element)
 Configures the proxy.
virtual InputgetProxiedInputDevice ()
 Returns a pointer to the base class of the devices being proxied.

Static Public Member Functions

static std::string getElementType ()
 Returns the string rep of the element type used to config this device.

Detailed Description

A proxy class to analog devices, used by the Input Manager.

An analog proxy always points to an analog device and unit number within that device. The Input Manager can therefore keep an array of these around and treat them as analog devices that only return a single sub-device's amount of data (one float).

See also:
Analog

Definition at line 61 of file AnalogProxy.h.


Constructor & Destructor Documentation

gadget::AnalogProxy::AnalogProxy (  )  [inline]

Constructor.

Definition at line 66 of file AnalogProxy.h.

00067       : mUnitNum(-1)
00068       , mData(-1.0f)
00069    {;}

virtual gadget::AnalogProxy::~AnalogProxy (  )  [inline, virtual]

Definition at line 71 of file AnalogProxy.h.

00072    {;}


Member Function Documentation

virtual void gadget::AnalogProxy::updateData (  )  [inline, virtual]

Updates the cached data copy from the device.

Reimplemented from gadget::Proxy.

Definition at line 75 of file AnalogProxy.h.

00076    {
00077       if(!isStupefied())
00078       {
00079          // Make sure dependencies are updated.
00080          getProxiedInputDevice()->updateDataIfNeeded();
00081          mData = mTypedDevice->getAnalogData(mUnitNum);
00082       }
00083    }

virtual vpr::Interval gadget::AnalogProxy::getTimeStamp (  )  const [inline, virtual]

Returns the time of last update.

Implements gadget::Proxy.

Definition at line 86 of file AnalogProxy.h.

00087    {
00088       return mData.getTime();
00089    }

float gadget::AnalogProxy::getData (  )  const [inline]

Gets the current analog data value.

Returns:
The analog data from the device.

Definition at line 95 of file AnalogProxy.h.

00096    {
00097       const float analogDefault(0.0f);
00098       if(isStupefied())
00099       {
00100          return analogDefault;
00101       }
00102       else
00103       {
00104          return mData.getAnalog();
00105       }
00106    }

Analog* gadget::AnalogProxy::getAnalogPtr (  )  [inline]

Returns a pointer to the gadget::Analog object that we are proxying.

Definition at line 109 of file AnalogProxy.h.

00110    {
00111       if(isStupefied())
00112       {
00113          return NULL;
00114       }
00115       else
00116       {
00117          return mTypedDevice;
00118       }
00119    }

int gadget::AnalogProxy::getUnit (  )  const [inline]

Returns the unit index into the analog device from which this proxy is reading data.

Definition at line 125 of file AnalogProxy.h.

00126    {
00127       return mUnitNum;
00128    }

std::string gadget::AnalogProxy::getElementType (  )  [static]

Returns the string rep of the element type used to config this device.

Used by the Input Manager to find elements that construct devices.

Reimplemented from gadget::Proxy.

Definition at line 41 of file AnalogProxy.cpp.

Referenced by gadget::ProxyDepChecker::canHandle(), and config().

00042 {
00043    return "analog_proxy";
00044 }

bool gadget::AnalogProxy::config ( jccl::ConfigElementPtr  element  )  [virtual]

Configures the proxy.

Postcondition:
Proxy is configured (it is not registered yet though).
Returns:
success.

Reimplemented from gadget::Proxy.

Definition at line 46 of file AnalogProxy.cpp.

References gadget::Proxy::config(), gadgetDBG_INPUT_MGR(), getElementType(), gadget::TypedProxy< DEV_TYPE >::mDeviceName, and gadget::TypedProxy< DEV_TYPE >::refresh().

00047 {
00048 vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL,
00049                                  std::string("----------- configuring ANALOG PROXY -----------------\n"),
00050                                  std::string("----------- exit: configuring analog proxy -----------\n"));
00051    vprASSERT(element->getID() == getElementType());
00052 
00053    if ( ! Proxy::config(element) )
00054    {
00055       return false;
00056    }
00057 
00058    mUnitNum = element->getProperty<int>("unit");
00059    mDeviceName = element->getProperty<std::string>("device");
00060 
00061    refresh();     // Refresh the device now that we have something to point at
00062 
00063    return true;
00064 }

virtual Input* gadget::AnalogProxy::getProxiedInputDevice (  )  [inline, virtual]

Returns a pointer to the base class of the devices being proxied.

Returns:
NULL if no device is proxied.

Implements gadget::Proxy.

Definition at line 134 of file AnalogProxy.h.

00135    {
00136       if((NULL == mTypedDevice) || (mStupefied))
00137       {
00138          return NULL;
00139       }
00140 
00141       Input* ret_val = dynamic_cast<Input*>(mTypedDevice);
00142       vprASSERT((ret_val != NULL) && "Cross-cast in AnalogProxy failed");
00143       return ret_val;
00144    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:44:49 2007 for Gadgeteer by  doxygen 1.5.1