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


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_t & | getDigitalDataBuffer () |
| 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 &) |
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.
Definition at line 66 of file Digital.h.
Enum for the state of the digital buttons.
Used in DigitalProxy.
Definition at line 76 of file Digital.h.
00077 { 00078 OFF = 0, 00079 ON = 1, 00080 TOGGLE_ON = 2, 00082 TOGGLE_OFF = 3 00084 };
| gadget::Digital::Digital | ( | ) | [inline] |
| virtual gadget::Digital::~Digital | ( | ) | [inline, virtual] |
| gadget::Digital::Digital | ( | const gadget::Digital & | d | ) | [inline, protected] |
| 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().
| const DigitalData gadget::Digital::getDigitalData | ( | int | devNum = 0 |
) |
Gets the digital data for the given devNum.
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.
| 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.
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().
| 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] |
1.5.1