peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
rnr::HIDInput Class Referenceabstract

Input Human Interface Device Abstract Base Class. More...

#include <HID.h>

Inheritance diagram for rnr::HIDInput:
rnr::HIDXbox360

Public Types

typedef std::map< int, int > FeatMap_T
 device feature id - mnemonic map More...
 

Public Member Functions

 HIDInput (HIDClass eHIDClass=HIDClassUnknown)
 Default initialization constructor. More...
 
virtual ~HIDInput ()
 Destructor. More...
 
virtual int open ()=0
 Open connection to HID. More...
 
virtual int close ()=0
 Close connection to HID. More...
 
virtual int update (uint_t uMSec=T_UPDATE_DFT)=0
 Read device and update HID state. More...
 
virtual HIDClass getHIDClass ()
 Get the HID class. More...
 
virtual bool isConnected ()
 Query if HID is connected. More...
 
virtual bool isLinked ()
 Query if HID is linked. More...
 
virtual int assocFeature (int iFeatId, int iMnem)
 Associate user mnemonic to the device feature (e.g. button) id. More...
 
virtual int getFeatureVal (int iMnem)=0
 Get the value associated with the mapped user mnemonic. More...
 
virtual int setFeatureVal (int iMnem, int nVal)=0
 Set the value associated with the mapped user mnemonic. More...
 
virtual int getFeatureProp (int iMnem, HIDFeatType &eFeatType, int &nDir, int &nMin, int &nMax, int &nStep)=0
 Get the feature properties. More...
 
virtual void * getCurrentState ()
 Get the current full state of the device. More...
 
virtual bool ping ()
 Ping device if it is connected and is responding. More...
 
virtual bool isFatal () const
 Test to see if HID is in a fatal errored state. More...
 
virtual int getError () const
 Get the last HID-specific error number. More...
 
virtual const char * getStrError (int nError) const
 Get the string associated with the error number. More...
 
virtual std::string getProdName ()
 Get HID product name. More...
 

Static Public Attributes

static const int MNEM_START = 1024
 user mapped mnemonic starting index More...
 
static const int T_UPDATE_DFT = 33
 default update timeout (msec) More...
 

Protected Member Functions

virtual void setConnectionState (bool bNewState)
 Set connection state. More...
 
virtual void setLinkState (bool bNewState)
 Set new link state. More...
 

Protected Attributes

HIDClass m_eHIDClass
 actual HID class More...
 
std::string m_strProdName
 product name More...
 
bool m_bIsConnected
 HID is [not] physically connected. More...
 
bool m_bIsLinked
 HID is [not] linked and communicating. More...
 
int m_nError
 last error number (HID specific) More...
 
bool m_bFatal
 HID is [not] in a fatal condition. More...
 
FeatMap_T m_featMap
 feature-userid association map More...
 

Detailed Description

Input Human Interface Device Abstract Base Class.

Definition at line 100 of file HID.h.

Member Typedef Documentation

typedef std::map<int, int> rnr::HIDInput::FeatMap_T

device feature id - mnemonic map

Definition at line 106 of file HID.h.

Constructor & Destructor Documentation

rnr::HIDInput::HIDInput ( HIDClass  eHIDClass = HIDClassUnknown)
inline

Default initialization constructor.

Parameters
eHIDClassActual input HID class.

Definition at line 113 of file HID.h.

114  : m_eHIDClass(eHIDClass),
115  m_bIsConnected(false),
116  m_bIsLinked(false),
117  m_nError(0),
118  m_bFatal(false)
119  {
120  }
int m_nError
last error number (HID specific)
Definition: HID.h:299
bool m_bIsLinked
HID is [not] linked and communicating.
Definition: HID.h:298
HIDClass m_eHIDClass
actual HID class
Definition: HID.h:295
bool m_bFatal
HID is [not] in a fatal condition.
Definition: HID.h:300
bool m_bIsConnected
HID is [not] physically connected.
Definition: HID.h:297
virtual rnr::HIDInput::~HIDInput ( )
inlinevirtual

Destructor.

Definition at line 125 of file HID.h.

References close(), open(), and update().

125 { }

Member Function Documentation

virtual int rnr::HIDInput::assocFeature ( int  iFeatId,
int  iMnem 
)
inlinevirtual

Associate user mnemonic to the device feature (e.g. button) id.

Parameters
iFeatIdDevice-specific feature id (or previous mnemonic).
iMnemUser-specific mnemonic.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 184 of file HID.h.

References getFeatureProp(), getFeatureVal(), m_featMap, and setFeatureVal().

Referenced by testXboxInput(), testXboxLED(), and testXboxRumble().

185  {
186  FeatMap_T::iterator pos;
187  int iFeatIdFixed;
188 
189  if( (pos = m_featMap.find(iFeatId)) != m_featMap.end() )
190  {
191  iFeatIdFixed = pos->second;
192  m_featMap.erase(pos);
193  m_featMap[iMnem] = iFeatIdFixed;
194  return OK;
195  }
196  else
197  {
198  return RC_ERROR;
199  }
200  }
FeatMap_T m_featMap
feature-userid association map
Definition: HID.h:301
virtual int rnr::HIDInput::close ( )
pure virtual

Close connection to HID.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in rnr::HIDXbox360.

Referenced by ~HIDInput().

virtual void* rnr::HIDInput::getCurrentState ( )
inlinevirtual

Get the current full state of the device.

Returns
Return pointer to the device-specific input state.

Reimplemented in rnr::HIDXbox360.

Definition at line 247 of file HID.h.

247 { return NULL; }
virtual int rnr::HIDInput::getError ( ) const
inlinevirtual

Get the last HID-specific error number.

Errors are < 0, no error is 0.

Returns
Returns HID-specific error number.

Definition at line 270 of file HID.h.

References m_nError.

270 { return m_nError; }
int m_nError
last error number (HID specific)
Definition: HID.h:299
virtual int rnr::HIDInput::getFeatureProp ( int  iMnem,
HIDFeatType eFeatType,
int &  nDir,
int &  nMin,
int &  nMax,
int &  nStep 
)
pure virtual

Get the feature properties.

Parameters
iMnemUser-specific mnemonic.
[out]eFeatTypeFeature property type.
[out]nDirFeature is an input (HID_FEAT_INPUT) to host and/or an output (HID_FEAT_OUTPUT) to device.
[out]nMinFeature minimum value.
[out]nMaxFeature maximum value.
[out]nStepFeature step size between [min,max]
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in rnr::HIDXbox360.

Referenced by assocFeature().

virtual int rnr::HIDInput::getFeatureVal ( int  iMnem)
pure virtual

Get the value associated with the mapped user mnemonic.

Parameters
iMnemUser-specific mnemonic.
Returns
Feature current value.

Implemented in rnr::HIDXbox360.

Referenced by assocFeature().

virtual HIDClass rnr::HIDInput::getHIDClass ( )
inlinevirtual

Get the HID class.

Returns
Returns HIDClass

Definition at line 160 of file HID.h.

References m_eHIDClass.

160 { return m_eHIDClass; }
HIDClass m_eHIDClass
actual HID class
Definition: HID.h:295
virtual std::string rnr::HIDInput::getProdName ( )
inlinevirtual

Get HID product name.

Returns
String.

Definition at line 289 of file HID.h.

References m_strProdName.

290  {
291  return m_strProdName;
292  }
std::string m_strProdName
product name
Definition: HID.h:296
virtual const char* rnr::HIDInput::getStrError ( int  nError) const
inlinevirtual

Get the string associated with the error number.

Parameters
nErrorHID-specific error number.
Returns
Null-terminated error string.

Reimplemented in rnr::HIDXbox360.

Definition at line 279 of file HID.h.

280  {
281  return nError < 0? "Error": "";
282  }
virtual bool rnr::HIDInput::isConnected ( )
inlinevirtual

Query if HID is connected.

Returns
Returns true if (physically) connected, else false.

Definition at line 167 of file HID.h.

References m_bIsConnected.

Referenced by main(), testXboxSanity(), and rnr::HIDXbox360::updateThread().

167 { return m_bIsConnected; }
bool m_bIsConnected
HID is [not] physically connected.
Definition: HID.h:297
virtual bool rnr::HIDInput::isFatal ( ) const
inlinevirtual

Test to see if HID is in a fatal errored state.

Returns
Returns true if fatal, else false.

Definition at line 261 of file HID.h.

References m_bFatal.

261 { return m_bFatal; }
bool m_bFatal
HID is [not] in a fatal condition.
Definition: HID.h:300
virtual bool rnr::HIDInput::isLinked ( )
inlinevirtual

Query if HID is linked.

Returns
Returns true if linked and responding, else false.

Definition at line 174 of file HID.h.

References m_bIsLinked.

174 { return m_bIsLinked; }
bool m_bIsLinked
HID is [not] linked and communicating.
Definition: HID.h:298
virtual int rnr::HIDInput::open ( )
pure virtual

Open connection to HID.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in rnr::HIDXbox360.

Referenced by ~HIDInput().

virtual bool rnr::HIDInput::ping ( )
inlinevirtual

Ping device if it is connected and is responding.

Returns
Returns true if the HID is responding, else false.

Reimplemented in rnr::HIDXbox360.

Definition at line 254 of file HID.h.

254 { return false; }
virtual void rnr::HIDInput::setConnectionState ( bool  bNewState)
inlineprotectedvirtual

Set connection state.

Parameters
bNewStateNew connection state.

Definition at line 308 of file HID.h.

References setLinkState().

Referenced by rnr::HIDXbox360::close(), rnr::HIDXbox360::open(), rnr::HIDXbox360::transferCallbackInput(), rnr::HIDXbox360::transferCallbackLED(), and rnr::HIDXbox360::transferCallbackRumble().

309  {
310  if( bNewState != m_bIsConnected )
311  {
312  LOGDIAG3("HID is %s.", (bNewState? "connected": "not connected"));
313  }
314  m_bIsConnected = bNewState;
315  if( !m_bIsConnected )
316  {
317  setLinkState(false);
318  }
319  }
bool m_bIsConnected
HID is [not] physically connected.
Definition: HID.h:297
virtual void setLinkState(bool bNewState)
Set new link state.
Definition: HID.h:326
virtual int rnr::HIDInput::setFeatureVal ( int  iMnem,
int  nVal 
)
pure virtual

Set the value associated with the mapped user mnemonic.

Parameters
iMnemUser-specific mnemonic.
[in]nValNew input HID output value (e.g.LED). Meaning is specific to input.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in rnr::HIDXbox360.

Referenced by assocFeature().

virtual void rnr::HIDInput::setLinkState ( bool  bNewState)
inlineprotectedvirtual

Set new link state.

Parameters
bNewStateNew link state.

Reimplemented in rnr::HIDXbox360.

Definition at line 326 of file HID.h.

Referenced by setConnectionState(), and rnr::HIDXbox360::setLinkState().

327  {
328  if( bNewState != m_bIsLinked )
329  {
330  LOGDIAG3("HID is %s.", (bNewState? "linked": "not linked"));
331  }
332  m_bIsLinked = bNewState;
333  }
bool m_bIsLinked
HID is [not] linked and communicating.
Definition: HID.h:298
virtual int rnr::HIDInput::update ( uint_t  uMSec = T_UPDATE_DFT)
pure virtual

Read device and update HID state.

Parameters
uMSecBlock wait at most the given milliseconds for events.
If zero, then update() will handle any already-pending events and then immediately return (non-blocking).
Otherwise, if no events are currently pending, update() will block waiting for events for up specified timeout. If an event arrives update() will return early.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Implemented in rnr::HIDXbox360.

Referenced by ~HIDInput().

Member Data Documentation

bool rnr::HIDInput::m_bFatal
protected

HID is [not] in a fatal condition.

Definition at line 300 of file HID.h.

Referenced by rnr::HIDXbox360::close(), rnr::HIDXbox360::HIDXbox360(), isFatal(), and rnr::HIDXbox360::open().

bool rnr::HIDInput::m_bIsConnected
protected

HID is [not] physically connected.

Definition at line 297 of file HID.h.

Referenced by isConnected(), rnr::HIDXbox360::update(), and rnr::HIDXbox360::~HIDXbox360().

HIDClass rnr::HIDInput::m_eHIDClass
protected

actual HID class

Definition at line 295 of file HID.h.

Referenced by getHIDClass().

FeatMap_T rnr::HIDInput::m_featMap
protected
std::string rnr::HIDInput::m_strProdName
protected

product name

Definition at line 296 of file HID.h.

Referenced by getProdName().

const int rnr::HIDInput::MNEM_START = 1024
static

user mapped mnemonic starting index

Definition at line 103 of file HID.h.

Referenced by testXboxInput(), testXboxLED(), and testXboxRumble().

const int rnr::HIDInput::T_UPDATE_DFT = 33
static

default update timeout (msec)

Definition at line 104 of file HID.h.

Referenced by rnr::HIDXbox360::getStrError().


The documentation for this class was generated from the following file: