gadget::Digital Class Reference

Digital is the abstract base class from which devices with digital data derive (through gadget::InputMixer). More...

#include <gadget/Type/Digital.h>

Inheritance diagram for gadget::Digital:

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

Collaboration graph
[legend]
List of all members.

Public Types

enum  State { OFF = 0, ON = 1, TOGGLE_ON = 2, TOGGLE_OFF = 3 }
 Enum for the state of the digital buttons. More...
typedef gadget::SampleBuffer<
DigitalData
SampleBuffer_t

Public Member Functions

 Digital ()
virtual ~Digital ()
virtual bool config (jccl::ConfigElementPtr e)
const DigitalData getDigitalData (int devNum=0)
 Gets the digital data for the given devNum.
void addDigitalSample (const std::vector< DigitalData > &digSample)
 Helper method to add a collection of digital samples to the sample buffers.
void swapDigitalBuffers ()
 Swaps the digital data buffers.
const SampleBuffer_t::buffer_tgetDigitalDataBuffer ()
 Returns the current stable sample buffers for this device.
virtual std::string getInputTypeName ()
virtual vpr::ReturnStatus writeObject (vpr::ObjectWriter *writer)
 Serializes this object.
virtual vpr::ReturnStatus readObject (vpr::ObjectReader *reader)
 De-serializes this object.

Protected Member Functions

 Digital (const gadget::Digital &d)
void operator= (const gadget::Digital &)

Detailed Description

Digital is the abstract base class from which devices with digital data derive (through gadget::InputMixer).

This is in addition to gadget::Input. gadget::Input provides pure virtual function constraints in the following functions: startSampling(), stopSampling(), sample(), and updateData().

gadget::Digital adds the function getDigitalData() for retreiving the received digital data. This is similar to the additions made by gadget::Position and gadget::Analog.

See also:
Input, InputMixer

Definition at line 66 of file Digital.h.


Member Typedef Documentation

typedef gadget::SampleBuffer<DigitalData> gadget::Digital::SampleBuffer_t

Definition at line 69 of file Digital.h.


Member Enumeration Documentation

enum gadget::Digital::State

Enum for the state of the digital buttons.

Used in DigitalProxy.

Enumerator:
OFF  Device is in the "off" state.
ON  Device is in the "on" state.
TOGGLE_ON  Device was in the "off" state and has changed to "on" since the last frame.
TOGGLE_OFF  Device was in the "on" state and has changed to "off" since the last frame.

Definition at line 76 of file Digital.h.

00077       {
00078          OFF = 0,       
00079          ON = 1,        
00080          TOGGLE_ON = 2, 
00082          TOGGLE_OFF = 3 
00084       };


Constructor & Destructor Documentation

gadget::Digital::Digital (  )  [inline]

Definition at line 88 of file Digital.h.

00089       {
00090          ;
00091       }

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

Definition at line 93 of file Digital.h.

00094       {
00095       }

gadget::Digital::Digital ( const gadget::Digital d  )  [inline, protected]

Definition at line 164 of file Digital.h.

00164 : vpr::SerializableObject(d) {;}


Member Function Documentation

virtual bool gadget::Digital::config ( jccl::ConfigElementPtr  e  )  [inline, virtual]

Reimplemented in gadget::SimGloveGesture.

Definition at line 97 of file Digital.h.

Referenced by gadget::SimDigitalGlove::config(), and gadget::SimDigital::config().

00098       {
00099          boost::ignore_unused_variable_warning(e);
00100          return true;
00101       }

const DigitalData gadget::Digital::getDigitalData ( int  devNum = 0  ) 

Gets the digital data for the given devNum.

Returns:
Digital 0 or 1, if devNum makes sense. -1 is returned if function fails or if devNum is out of range.
Note:
If devNum is out of range, function will fail, possibly issuing an error to a log or console - but will not ASSERT.

Reimplemented in gadget::SimGloveGesture.

Definition at line 48 of file Digital.cpp.

References gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::stableBuffer().

00049 {
00050    SampleBuffer_t::buffer_t& stable_buffer = mDigitalSamples.stableBuffer();
00051 
00052    if ( (!stable_buffer.empty()) &&
00053         (stable_buffer.back().size() > (unsigned)devNum) )  // If Have entry && devNum in range
00054    {
00055       return stable_buffer.back()[devNum];
00056    }
00057    else        // No data or request out of range, return default value
00058    {
00059       if ( stable_buffer.empty() )
00060       {
00061          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00062             << "WARNING: [gadget::Digital::getDigitalData()] "
00063             << "Stable buffer is empty.  If this is not the first "
00064             << "read, then this is a problem.\n" << vprDEBUG_FLUSH;
00065       }
00066       else
00067       {
00068          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00069             << "WARNING: [gadget::Digital::getDigitalData()] "
00070             << "Requested devNum (" << devNum
00071             << ") is not in the range available.  "
00072             << "This is probably a configuration error.\n"
00073             << vprDEBUG_FLUSH;
00074       }
00075       return mDefaultValue;
00076    }
00077 }

void gadget::Digital::addDigitalSample ( const std::vector< DigitalData > &  digSample  )  [inline]

Helper method to add a collection of digital samples to the sample buffers.

This MUST be called by all digital devices to add new samples.

Postcondition:
The given digital samples are added to the buffers.
Parameters:
digSample A vector of DigitalData objects that represent the newest samples taken.

Definition at line 124 of file Digital.h.

00125       {
00126          // Locks and then swaps the indices.
00127          mDigitalSamples.lock();
00128          mDigitalSamples.addSample(digSample);
00129          mDigitalSamples.unlock();
00130       }

void gadget::Digital::swapDigitalBuffers (  )  [inline]

Swaps the digital data buffers.

Postcondition:
If the ready queue has values, then those values are copied from the ready queue to the stable queue. If not, then stable queue is not changed.

Definition at line 139 of file Digital.h.

00140       {
00141          mDigitalSamples.swapBuffers();
00142       }

const SampleBuffer_t::buffer_t& gadget::Digital::getDigitalDataBuffer (  )  [inline]

Returns the current stable sample buffers for this device.

Definition at line 147 of file Digital.h.

00148       {
00149          return mDigitalSamples.stableBuffer();
00150       }

virtual std::string gadget::Digital::getInputTypeName (  )  [inline, virtual]

Reimplemented in gadget::InputMixer< gadget::InputMixer< gadget::SimInput, gadget::Input >, gadget::Digital >.

Definition at line 151 of file Digital.h.

Referenced by readObject(), and writeObject().

00152       {
00153          return std::string("Digital");
00154       }

vpr::ReturnStatus gadget::Digital::writeObject ( vpr::ObjectWriter *  writer  )  [virtual]

Serializes this object.

Reimplemented in gadget::InputMixer< gadget::InputMixer< gadget::SimInput, gadget::Input >, gadget::Digital >.

Definition at line 79 of file Digital.cpp.

References gadget::tokens::BufferSampleLenAttrib(), gadget::tokens::BufferSampleTag(), gadget::tokens::DataTypeAttrib(), gadget::tokens::DigitalValue(), getInputTypeName(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::lock(), gadget::MSG_DATA_DIGITAL, gadget::tokens::SampleBufferLenAttrib(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::stableBuffer(), gadget::tokens::TimeStamp(), and gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::unlock().

00080 {
00081    writer->beginTag(Digital::getInputTypeName());
00082    //std::cout << "[Remote Input Manager] In Digital write" << std::endl;
00083    SampleBuffer_t::buffer_t& stable_buffer = mDigitalSamples.stableBuffer();
00084    writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00085       writer->writeUint16(MSG_DATA_DIGITAL);                               // Write out the data type so that we can assert if reading in wrong place
00086    writer->endAttribute();
00087 
00088    writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00089       writer->writeUint16(stable_buffer.size());                           // Write the # of vectors in the stable buffer
00090    writer->endAttribute();
00091 
00092    if ( !stable_buffer.empty() )
00093    {
00094       mDigitalSamples.lock();
00095       for ( unsigned j=0;j<stable_buffer.size();j++ )                               // For each vector in the stable buffer
00096       {
00097          writer->beginTag(gadget::tokens::BufferSampleTag);
00098          writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00099             writer->writeUint16(stable_buffer[j].size());                           // Write the # of DigitalDatas in the vector
00100          writer->endAttribute();
00101          for ( unsigned i=0;i<stable_buffer[j].size();i++ )                         // For each DigitalData in the vector
00102          {
00103             writer->beginTag(gadget::tokens::DigitalValue);
00104             writer->beginAttribute(gadget::tokens::TimeStamp);
00105                writer->writeUint64(stable_buffer[j][i].getTime().usec());           // Write Time Stamp vpr::Uint64
00106             writer->endAttribute();
00107             writer->writeUint32((vpr::Uint32)stable_buffer[j][i].getDigital());  // Write Digital Data(int)
00108             writer->endTag();
00109          }
00110          writer->endTag();
00111       }
00112       mDigitalSamples.unlock();
00113    }
00114    writer->endTag();
00115 
00116    return vpr::ReturnStatus::Succeed;
00117 }

vpr::ReturnStatus gadget::Digital::readObject ( vpr::ObjectReader *  reader  )  [virtual]

De-serializes this object.

Reimplemented in gadget::InputMixer< gadget::InputMixer< gadget::SimInput, gadget::Input >, gadget::Digital >.

Definition at line 119 of file Digital.cpp.

References gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::addSample(), gadget::tokens::BufferSampleLenAttrib(), gadget::tokens::BufferSampleTag(), gadget::tokens::DataTypeAttrib(), gadget::tokens::DigitalValue(), getInputTypeName(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::lock(), gadget::MSG_DATA_DIGITAL, gadget::tokens::SampleBufferLenAttrib(), gadget::DigitalData::setDigital(), gadget::InputData::setTime(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::swapBuffers(), gadget::tokens::TimeStamp(), and gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::unlock().

00120 {
00121       //std::cout << "[Remote Input Manager] In Digital read" << std::endl;
00122    vprASSERT(reader->attribExists("rim.timestamp.delta"));
00123    vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00124 
00125       // ASSERT if this data is really not Digital Data
00126    reader->beginTag(Digital::getInputTypeName());
00127    reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00128       vpr::Uint16 temp = reader->readUint16();
00129    reader->endAttribute();
00130 
00131    // XXX: Should there be error checking for the case when vprASSERT()
00132    // is compiled out?  -PH 8/21/2003
00133    vprASSERT(temp==MSG_DATA_DIGITAL && "[Remote Input Manager]Not Digital Data");
00134    boost::ignore_unused_variable_warning(temp);
00135 
00136    std::vector<DigitalData> dataSample;
00137 
00138    unsigned numDigitalDatas;
00139    vpr::Uint32 value;
00140    vpr::Uint64 timeStamp;
00141    DigitalData temp_digital_data;
00142 
00143    reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00144       unsigned numVectors = reader->readUint16();
00145    reader->endAttribute();
00146 
00147    //std::cout << "Stable Digital Buffer Size: "  << numVectors << std::endl;
00148    mDigitalSamples.lock();
00149    for ( unsigned i=0;i<numVectors;i++ )
00150    {
00151       reader->beginTag(gadget::tokens::BufferSampleTag);
00152       reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00153          numDigitalDatas = reader->readUint16();
00154       reader->endAttribute();
00155 
00156       dataSample.clear();
00157       for ( unsigned j=0;j<numDigitalDatas;j++ )
00158       {
00159          reader->beginTag(gadget::tokens::DigitalValue);
00160          reader->beginAttribute(gadget::tokens::TimeStamp);
00161             timeStamp = reader->readUint64();    // read Time Stamp vpr::Uint64
00162          reader->endAttribute();
00163          value = reader->readUint32();           // read Digital Data(int)
00164          reader->endTag();
00165 
00166          temp_digital_data.setDigital(value);
00167          temp_digital_data.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00168          dataSample.push_back(temp_digital_data);
00169       }
00170       mDigitalSamples.addSample(dataSample);
00171       reader->endTag();
00172    }
00173    mDigitalSamples.unlock();
00174    mDigitalSamples.swapBuffers();
00175 
00176    reader->endTag();
00177 
00178    return vpr::ReturnStatus::Succeed;
00179 }

void gadget::Digital::operator= ( const gadget::Digital  )  [inline, protected]

Definition at line 165 of file Digital.h.

00165 {;}


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