vrpn  07.33
Virtual Reality Peripheral Network
vrpn_HidInterface Class Referenceabstract

#include <vrpn_HumanInterface.h>

Inheritance diagram for vrpn_HidInterface:
Collaboration diagram for vrpn_HidInterface:

Public Member Functions

 vrpn_HidInterface (vrpn_HidAcceptor *acceptor)
 
virtual ~vrpn_HidInterface ()
 
virtual bool connected () const
 Returns true iff the last device I/O succeeded. More...
 
virtual void update ()
 Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this frequently to ensure the OS doesn't drop data. More...
 
virtual bool reconnect ()
 Tries to reconnect to an acceptable device. Call this if you suspect a hotplug event has occurred. More...
 
vrpn_uint16 vendor () const
 Returns USB vendor ID of connected device. More...
 
vrpn_uint16 product () const
 Returns USB product ID of connected device. More...
 
int interface_number () const
 Returns the USB interface number of connected device. More...
 

Protected Member Functions

virtual void on_data_received (size_t bytes, vrpn_uint8 *buffer)=0
 Derived class reimplements this callback. More...
 
void send_data (size_t bytes, const vrpn_uint8 *buffer)
 Call this to send data to the device. More...
 
void send_feature_report (size_t bytes, const vrpn_uint8 *buffer)
 Call this to send a feature report to the device - first byte must be Report ID (or 0x0 for devices without numbered reports) More...
 
int get_feature_report (size_t bytes, vrpn_uint8 *buffer)
 Call this to get a feature report from the device - first byte must be Report ID (or 0x0 for devices without numbered reports) More...
 

Protected Attributes

vrpn_HidAcceptor_acceptor
 This is the HidAcceptor we use when reconnecting. More...
 
bool _working
 
vrpn_uint16 _vendor
 
vrpn_uint16 _product
 
int _interface
 

Detailed Description

Definition at line 68 of file vrpn_HumanInterface.h.

Constructor & Destructor Documentation

◆ vrpn_HidInterface()

vrpn_HidInterface::vrpn_HidInterface ( vrpn_HidAcceptor acceptor)

Definition at line 25 of file vrpn_HumanInterface.C.

References _acceptor, reconnect(), and vrpn_HidAcceptor::reset().

Here is the call graph for this function:

◆ ~vrpn_HidInterface()

vrpn_HidInterface::~vrpn_HidInterface ( )
virtual

Definition at line 44 of file vrpn_HumanInterface.C.

Member Function Documentation

◆ connected()

bool vrpn_HidInterface::connected ( ) const
virtual

Returns true iff the last device I/O succeeded.

Definition at line 23 of file vrpn_HumanInterface.C.

References _working.

Referenced by vrpn_Analog_5dtUSB::mainloop(), vrpn_Tracker_OSVRHackerDevKit::mainloop(), vrpn_Tracker_SpacePoint::mainloop(), and vrpn_Tracker_Wintracker::mainloop().

◆ get_feature_report()

int vrpn_HidInterface::get_feature_report ( size_t  bytes,
vrpn_uint8 *  buffer 
)
protected

Call this to get a feature report from the device - first byte must be Report ID (or 0x0 for devices without numbered reports)

Returns
Number of bytes received, or -1 on error

Definition at line 229 of file vrpn_HumanInterface.C.

References _working.

◆ interface_number()

int vrpn_HidInterface::interface_number ( ) const

Returns the USB interface number of connected device.

Definition at line 20 of file vrpn_HumanInterface.C.

References _interface.

◆ on_data_received()

virtual void vrpn_HidInterface::on_data_received ( size_t  bytes,
vrpn_uint8 *  buffer 
)
protectedpure virtual

Derived class reimplements this callback.

It is called whenever a read returns some data.

WARNING! The data returned by this function differs when the device sends multiple report types and when it only has one. When it can have more than one, the report type is sent as the first byte. When it only has one, the report type is NOT included. This is the behavior of the HIDAPI library we are using. It is surprising to me, but that's how it behaves.

Implemented in vrpn_Xkeys, vrpn_Tracker_Wintracker, vrpn_Tracker_SpacePoint, vrpn_Saitek_Controller_Raw, vrpn_Retrolink, vrpn_Microsoft_Controller_Raw, vrpn_Logitech_Controller_Raw, vrpn_Griffin, vrpn_Futaba, vrpn_DreamCheeky, vrpn_Contour, vrpn_CHProducts_Controller_Raw, vrpn_Analog_5dtUSB, and vrpn_3DConnexion.

Referenced by update().

◆ product()

vrpn_uint16 vrpn_HidInterface::product ( ) const

Returns USB product ID of connected device.

Definition at line 17 of file vrpn_HumanInterface.C.

References _product.

Referenced by vrpn_Analog_5dtUSB::get_description().

◆ reconnect()

bool vrpn_HidInterface::reconnect ( )
virtual

Tries to reconnect to an acceptable device. Call this if you suspect a hotplug event has occurred.

Definition at line 55 of file vrpn_HumanInterface.C.

References _acceptor, _interface, _product, _vendor, _working, vrpn_HidAcceptor::accept(), vrpn_HIDDEVINFO::interface_number, vrpn_HIDDEVINFO::manufacturer_string, vrpn_HIDDEVINFO::product, vrpn_HIDDEVINFO::product_string, vrpn_HIDDEVINFO::serial_number, and vrpn_HIDDEVINFO::vendor.

Referenced by vrpn_Tracker_SpacePoint::on_data_received(), and vrpn_HidInterface().

Here is the call graph for this function:

◆ send_data()

void vrpn_HidInterface::send_data ( size_t  bytes,
const vrpn_uint8 *  buffer 
)
protected

◆ send_feature_report()

void vrpn_HidInterface::send_feature_report ( size_t  bytes,
const vrpn_uint8 *  buffer 
)
protected

Call this to send a feature report to the device - first byte must be Report ID (or 0x0 for devices without numbered reports)

Definition at line 203 of file vrpn_HumanInterface.C.

References _working.

◆ update()

◆ vendor()

vrpn_uint16 vrpn_HidInterface::vendor ( ) const

Returns USB vendor ID of connected device.

Definition at line 14 of file vrpn_HumanInterface.C.

References _vendor.

Member Data Documentation

◆ _acceptor

vrpn_HidAcceptor* vrpn_HidInterface::_acceptor
protected

This is the HidAcceptor we use when reconnecting.

We do not take ownership of the pointer; it is the user's responsibility. Using a stack-allocated acceptor is a really good way to get a segfault when calling reconnect()–there won't be an acceptor there any longer! Thus, always use "new" to make your acceptors.

Definition at line 127 of file vrpn_HumanInterface.h.

Referenced by reconnect(), vrpn_HidInterface(), vrpn_Analog_5dtUSB::~vrpn_Analog_5dtUSB(), and vrpn_Tracker_OSVRHackerDevKit::~vrpn_Tracker_OSVRHackerDevKit().

◆ _interface

int vrpn_HidInterface::_interface
protected

Definition at line 132 of file vrpn_HumanInterface.h.

Referenced by interface_number(), and reconnect().

◆ _product

vrpn_uint16 vrpn_HidInterface::_product
protected

Definition at line 131 of file vrpn_HumanInterface.h.

Referenced by product(), and reconnect().

◆ _vendor

vrpn_uint16 vrpn_HidInterface::_vendor
protected

Definition at line 130 of file vrpn_HumanInterface.h.

Referenced by reconnect(), and vendor().

◆ _working

bool vrpn_HidInterface::_working
protected

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