#include <Digital.h>
Inheritance diagram for gadget::Digital:


Public Types | |
| typedef gadget::SampleBuffer< DigitalData > | SampleBuffer_t |
| enum | State { OFF = 0, ON = 1, TOGGLE_ON = 2, TOGGLE_OFF = 3 } |
| Enum for the state of the digital buttons. More... | |
Public Methods | |
| Digital () | |
| virtual | ~Digital () |
| virtual bool | config (jccl::ConfigElementPtr e) |
| const DigitalData | getDigitalData (int devNum=0) |
| Gets the digital data for the given devNum. More... | |
| void | addDigitalSample (const std::vector< DigitalData > &digSample) |
| Helper method to add a sample to the sample buffers. More... | |
| void | swapDigitalBuffers () |
| Swap the digital data buffers. More... | |
| const SampleBuffer_t::buffer_t & | getDigitalDataBuffer () |
| virtual std::string | getBaseType () |
| virtual vpr::ReturnStatus | writeObject (vpr::ObjectWriter *writer) |
| virtual vpr::ReturnStatus | readObject (vpr::ObjectReader *reader) |
Protected Methods | |
| Digital (const gadget::Digital &d) | |
| void | operator= (const gadget::Digital &d) |
Digital is the base class that digital devices must derive from. Digital inherits from Input, so it has pure virtual function constraints from Input in the following functions: StartSampling, StopSampling, Sample, and UpdateData.
Digital adds one new pure virtual function, getDigitalData() for retreiving the digital data, similar to the addition for gadget::Position and gadget::Analog.
Definition at line 64 of file Digital.h.
|
|
|
|
|
Enum for the state of the digital buttons. Used in DigitalProxy. Definition at line 74 of file Digital.h. Referenced by gadget::DigitalProxy::getData.
00075 {
00076 OFF=0, ON=1, TOGGLE_ON=2, TOGGLE_OFF=3
00077 };
|
|
|
Definition at line 81 of file Digital.h.
00082 {
00083 //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** Digital::Digital()\n"<< vprDEBUG_FLUSH;
00084 }
|
|
|
Definition at line 86 of file Digital.h.
00087 {
00088 }
|
|
|
Definition at line 165 of file Digital.h.
00165 : vpr::SerializableObject() {;}
|
|
|
Reimplemented in gadget::SimDigital. Definition at line 90 of file Digital.h.
00091 {
00092 boost::ignore_unused_variable_warning(e);
00093 //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** Digital::config()\n"<< vprDEBUG_FLUSH;
00094 return true;
00095 }
|
|
|
Gets the digital data for the given devNum.
Reimplemented in gadget::SimGloveGesture. Definition at line 105 of file Digital.h.
00106 {
00107 SampleBuffer_t::buffer_t& stable_buffer = mDigitalSamples.stableBuffer();
00108
00109 if ( (!stable_buffer.empty()) &&
00110 (stable_buffer.back().size() > (unsigned)devNum) ) // If Have entry && devNum in range
00111 {
00112 return stable_buffer.back()[devNum];
00113 }
00114 else // No data or request out of range, return default value
00115 {
00116 if ( stable_buffer.empty() )
00117 {
00118 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Warning: Digital::getDigitalData: Stable buffer is empty. If this is not the first read, then this is a problem.\n" << vprDEBUG_FLUSH;
00119 }
00120 else
00121 {
00122 vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Warning: Digital::getDigitalData: Requested devNum " << devNum << " is not in the range available. May have configuration error\n" << vprDEBUG_FLUSH;
00123 }
00124 return mDefaultValue;
00125 }
00126 }
|
|
|
Helper method to add a sample to the sample buffers. This MUST be called by all digital devices to add a new sample. The data samples passed in will then be modified by any local filters.
Definition at line 133 of file Digital.h. Referenced by gadget::SimDigital::updateData.
00134 {
00135 // Locks and then swaps the indices.
00136 mDigitalSamples.lock();
00137 mDigitalSamples.addSample(digSample);
00138 mDigitalSamples.unlock();
00139 }
|
|
|
Swap the digital data buffers.
Definition at line 145 of file Digital.h. Referenced by gadget::SimDigital::updateData.
00146 {
00147 mDigitalSamples.swapBuffers();
00148 }
|
|
|
Definition at line 150 of file Digital.h.
00151 {
00152 return mDigitalSamples.stableBuffer();
00153 }
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Digital >. Definition at line 154 of file Digital.h.
00155 {
00156 return std::string("Digital");
00157 }
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Digital >. Definition at line 42 of file Digital.cpp. References gadget::SampleBuffer< DigitalData >::lock, gadget::MSG_DATA_DIGITAL, gadget::SampleBuffer< DigitalData >::stableBuffer, and gadget::SampleBuffer< DigitalData >::unlock.
00043 {
00044 writer->beginTag(Digital::getBaseType());
00045 //std::cout << "[Remote Input Manager] In Digital write" << std::endl;
00046 SampleBuffer_t::buffer_t& stable_buffer = mDigitalSamples.stableBuffer();
00047 writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00048 writer->writeUint16(MSG_DATA_DIGITAL); // Write out the data type so that we can assert if reading in wrong place
00049 writer->endAttribute();
00050
00051 writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00052 writer->writeUint16(stable_buffer.size()); // Write the # of vectors in the stable buffer
00053 writer->endAttribute();
00054
00055 if ( !stable_buffer.empty() )
00056 {
00057 mDigitalSamples.lock();
00058 for ( unsigned j=0;j<stable_buffer.size();j++ ) // For each vector in the stable buffer
00059 {
00060 writer->beginTag(gadget::tokens::BufferSampleTag);
00061 writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00062 writer->writeUint16(stable_buffer[j].size()); // Write the # of DigitalDatas in the vector
00063 writer->endAttribute();
00064 for ( unsigned i=0;i<stable_buffer[j].size();i++ ) // For each DigitalData in the vector
00065 {
00066 writer->beginTag(gadget::tokens::DigitalValue);
00067 writer->beginAttribute(gadget::tokens::TimeStamp);
00068 writer->writeUint64(stable_buffer[j][i].getTime().usec()); // Write Time Stamp vpr::Uint64
00069 writer->endAttribute();
00070 writer->writeUint32((vpr::Uint32)stable_buffer[j][i].getDigital()); // Write Digital Data(int)
00071 writer->endTag();
00072 }
00073 writer->endTag();
00074 }
00075 mDigitalSamples.unlock();
00076 }
00077 writer->endTag();
00078
00079 return vpr::ReturnStatus::Succeed;
00080 }
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Digital >. Definition at line 82 of file Digital.cpp. References gadget::SampleBuffer< DigitalData >::addSample, gadget::SampleBuffer< DigitalData >::lock, gadget::MSG_DATA_DIGITAL, gadget::SampleBuffer< DigitalData >::swapBuffers, and gadget::SampleBuffer< DigitalData >::unlock.
00083 {
00084 //std::cout << "[Remote Input Manager] In Digital read" << std::endl;
00085 vprASSERT(reader->attribExists("rim.timestamp.delta"));
00086 vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00087
00088 // ASSERT if this data is really not Digital Data
00089 reader->beginTag(Digital::getBaseType());
00090 reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00091 vpr::Uint16 temp = reader->readUint16();
00092 reader->endAttribute();
00093
00094 // XXX: Should there be error checking for the case when vprASSERT()
00095 // is compiled out? -PH 8/21/2003
00096 vprASSERT(temp==MSG_DATA_DIGITAL && "[Remote Input Manager]Not Digital Data");
00097 boost::ignore_unused_variable_warning(temp);
00098
00099 std::vector<DigitalData> dataSample;
00100
00101 unsigned numDigitalDatas;
00102 vpr::Uint32 value;
00103 vpr::Uint64 timeStamp;
00104 DigitalData temp_digital_data;
00105
00106 reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00107 unsigned numVectors = reader->readUint16();
00108 reader->endAttribute();
00109
00110 //std::cout << "Stable Digital Buffer Size: " << numVectors << std::endl;
00111 mDigitalSamples.lock();
00112 for ( unsigned i=0;i<numVectors;i++ )
00113 {
00114 reader->beginTag(gadget::tokens::BufferSampleTag);
00115 reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00116 numDigitalDatas = reader->readUint16();
00117 reader->endAttribute();
00118
00119 dataSample.clear();
00120 for ( unsigned j=0;j<numDigitalDatas;j++ )
00121 {
00122 reader->beginTag(gadget::tokens::DigitalValue);
00123 reader->beginAttribute(gadget::tokens::TimeStamp);
00124 timeStamp = reader->readUint64(); // read Time Stamp vpr::Uint64
00125 reader->endAttribute();
00126 value = reader->readUint32(); // read Digital Data(int)
00127 reader->endTag();
00128
00129 temp_digital_data.setDigital(value);
00130 temp_digital_data.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00131 dataSample.push_back(temp_digital_data);
00132 }
00133 mDigitalSamples.addSample(dataSample);
00134 reader->endTag();
00135 }
00136 mDigitalSamples.unlock();
00137 mDigitalSamples.swapBuffers();
00138
00139 reader->endTag();
00140
00141 return vpr::ReturnStatus::Succeed;
00142 }
|
|
|
Definition at line 166 of file Digital.h.
00166 {;}
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002