Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::DigitalProxy Class Reference

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

#include <DigitalProxy.h>

Inheritance diagram for gadget::DigitalProxy:

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

Collaboration graph
[legend]
List of all members.

Public Methods

virtual void updateData ()
virtual vpr::Interval getTimeStamp () const
 Returns time of last update. More...

gadget::Digital::State getData () const
 Get the digital data. More...

DigitalDatagetDigitalData ()
DigitalgetDigitalPtr ()
int getUnit () const
bool config (jccl::ConfigElementPtr element)
 Configures the proxy. More...

virtual InputgetProxiedInputDevice ()
 Returns a pointer to the base class of the devices being proxied. More...

Construction/Destruction
 DigitalProxy ()
virtual ~DigitalProxy ()

Static Public Methods

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


Detailed Description

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

A DigitalProxy always points to a digital device and subUnit number, the inputgroup can therefore keep an array of these around and treat them as digital devices which only return a single subDevice's amount of data. (one int)

Definition at line 52 of file DigitalProxy.h.


Constructor & Destructor Documentation

gadget::DigitalProxy::DigitalProxy   [inline]
 

Definition at line 58 of file DigitalProxy.h.

00059       : mUnitNum(-1), mData(0)
00060    {;}

virtual gadget::DigitalProxy::~DigitalProxy   [inline, virtual]
 

Definition at line 62 of file DigitalProxy.h.

00063    {;}


Member Function Documentation

void gadget::DigitalProxy::updateData   [virtual]
 

Reimplemented from gadget::Proxy.

Definition at line 68 of file DigitalProxy.cpp.

References gadget::Proxy::isStupified, and gadget::TypedProxy< Digital >::mTypedDevice.

00069 {
00070 
00071    if (!isStupified())
00072    {
00073       int old_state = mData.getDigital();
00074       mData = mTypedDevice->getDigitalData(mUnitNum);
00075       int new_state = mData.getDigital();
00076 
00077       if (Digital::OFF == old_state)
00078       {
00079          if (new_state)     // Button now pressed
00080             mData = Digital::TOGGLE_ON;
00081          else              // Button now released
00082             mData = Digital::OFF;
00083       }
00084       else if (Digital::ON == old_state)
00085       {
00086          if (new_state)     // Button now pressed
00087             mData = Digital::ON;
00088          else              // Button now released
00089             mData = Digital::TOGGLE_OFF;
00090       }
00091       else if (Digital::TOGGLE_ON == old_state)
00092       {
00093          if (new_state)     // Button now pressed
00094             mData = Digital::ON;
00095          else              // Button now released
00096             mData = Digital::TOGGLE_OFF;
00097       }
00098       else if (Digital::TOGGLE_OFF == old_state)
00099       {
00100          if (new_state)     // Button now pressed
00101             mData = Digital::TOGGLE_ON;
00102          else              // Button now released
00103             mData = Digital::OFF;
00104       }
00105    }
00106 }

virtual vpr::Interval gadget::DigitalProxy::getTimeStamp   const [inline, virtual]
 

Returns time of last update.

Implements gadget::Proxy.

Definition at line 69 of file DigitalProxy.h.

00070    {
00071       return mData.getTime();
00072    }

gadget::Digital::State gadget::DigitalProxy::getData   const [inline]
 

Get the digital data.

Digital::OFF: Button not pressed, and was not pressed last update either.
Digital::ON: Button on, and was on last frame as well.
Digital::TOGGLE_ON: Button was off, now it is on.
Digital::TOGGLE_OFF: Button was on, now it is going off.

The identifiers are defined so that a simple test for non-zero means the button is pressed in some way.

Note:
Because of how TOGGLE_OFF is defined, testing for non-zero will result in a one update lag in detecting the button not being pressed.

Definition at line 88 of file DigitalProxy.h.

References gadget::Digital::State.

00089    {
00090       // If we're stupified, return gadget::Digital::OFF.  Otherwise, return
00091       // the current digital value.
00092       return (isStupified() ? Digital::OFF
00093                             : (gadget::Digital::State) mData.getDigital());
00094    }

DigitalData* gadget::DigitalProxy::getDigitalData   [inline]
 

Definition at line 96 of file DigitalProxy.h.

00097    {
00098       return &mData;
00099    }

Digital* gadget::DigitalProxy::getDigitalPtr   [inline]
 

Definition at line 101 of file DigitalProxy.h.

00102    {
00103       // If we're stupified, return NULL.  Otherwise, return mTypedDevice.
00104       return (isStupified() ? NULL : mTypedDevice);
00105    }

int gadget::DigitalProxy::getUnit   const [inline]
 

Definition at line 107 of file DigitalProxy.h.

00108    {
00109       return mUnitNum;
00110    }

std::string gadget::DigitalProxy::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 DigitalProxy.cpp.

Referenced by config.

00042 {
00043    return "digital_proxy";
00044 }

bool gadget::DigitalProxy::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 DigitalProxy.cpp.

References gadgetDBG_INPUT_MGR, getElementType, gadget::TypedProxy< Digital >::mDeviceName, and gadget::TypedProxy< Digital >::refresh.

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

virtual Input* gadget::DigitalProxy::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 116 of file DigitalProxy.h.

00117    {
00118       if((NULL == mTypedDevice) || (mStupified))
00119       {
00120          return NULL;
00121       }
00122 
00123       Input* ret_val = dynamic_cast<Input*>(mTypedDevice);
00124       vprASSERT((ret_val != NULL) && "Cross-cast in DigitalProxy failed");
00125       return ret_val;
00126    }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:26:57 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002