vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
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, vrpn_uint16 vendor=0, vrpn_uint16 product=0, hid_device *device=NULL)
 Constructor If we already have a HID device from some other source, it can be passed and we'll take ownership: still need the acceptor for reconnect, we just won't do it right away.
 
 vrpn_HidInterface (vrpn_HidAcceptor *acceptor, hid_device *device)
 Simplified constructor that just takes an acceptor and an underlying HID device (both non-optional).
 
 vrpn_HidInterface (const char *device_path, vrpn_HidAcceptor *acceptor, vrpn_uint16 vendor=0, vrpn_uint16 product=0)
 Constructor If we already know the path to the device we want, we can pass it in and open it directly: still need the acceptor for reconnect enumeration, we just won't do it right away.
 
virtual ~vrpn_HidInterface ()
 
virtual bool connected () const
 Returns true iff the last device I/O succeeded.
 
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.
 
virtual bool reconnect ()
 Tries to reconnect to an acceptable device. Call this if you suspect a hotplug event has occurred.
 
vrpn_uint16 vendor () const
 Returns USB vendor ID of connected device May not contain valid if an already-open device was provided to the constructor.
 
vrpn_uint16 product () const
 Returns USB product ID of connected device May not contain valid if an already-open device was provided to the constructor.
 
int interface_number () const
 Returns the USB interface number of connected device May not contain valid information on all platforms or if an already-open device was provided to the constructor.
 

Protected Member Functions

virtual void on_data_received (size_t bytes, vrpn_uint8 *buffer)=0
 Derived class reimplements this callback.
 
void send_data (size_t bytes, const vrpn_uint8 *buffer)
 Call this to send data to the device.
 
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)
 
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)
 

Protected Attributes

vrpn_HidAcceptorm_acceptor
 This is the HidAcceptor we use when reconnecting.
 
bool m_working
 
vrpn_uint16 m_vendor
 
vrpn_uint16 m_product
 
int m_interface
 
vrpn_uint16 m_vendor_sought
 What vendor we want.
 
vrpn_uint16 m_product_sought
 What product we want.
 

Detailed Description

Definition at line 70 of file vrpn_HumanInterface.h.

Constructor & Destructor Documentation

◆ vrpn_HidInterface() [1/3]

vrpn_HidInterface::vrpn_HidInterface ( vrpn_HidAcceptor * acceptor,
vrpn_uint16 vendor = 0,
vrpn_uint16 product = 0,
hid_device * device = NULL )

Constructor If we already have a HID device from some other source, it can be passed and we'll take ownership: still need the acceptor for reconnect, we just won't do it right away.

Not given an already-open device.

Parameters
acceptorDetermines which device we want
vendorDefault vendor is "any"
productDefault product is "any"
deviceOptional underlying HID device to manage and take ownership of

Definition at line 50 of file vrpn_HumanInterface.C.

References m_acceptor, m_interface, m_product, m_product_sought, m_vendor, m_vendor_sought, m_working, product(), reconnect(), and vendor().

Referenced by vrpn_3DConnexion::vrpn_3DConnexion(), vrpn_Analog_5dtUSB::vrpn_Analog_5dtUSB(), vrpn_CHProducts_Controller_Raw::vrpn_CHProducts_Controller_Raw(), vrpn_Contour::vrpn_Contour(), vrpn_DreamCheeky::vrpn_DreamCheeky(), vrpn_Futaba::vrpn_Futaba(), vrpn_Griffin::vrpn_Griffin(), vrpn_Laputa::vrpn_Laputa(), vrpn_Logitech_Controller_Raw::vrpn_Logitech_Controller_Raw(), vrpn_Microsoft_Controller_Raw::vrpn_Microsoft_Controller_Raw(), vrpn_nVidia_shield::vrpn_nVidia_shield(), vrpn_Oculus::vrpn_Oculus(), vrpn_Retrolink::vrpn_Retrolink(), vrpn_Saitek_Controller_Raw::vrpn_Saitek_Controller_Raw(), vrpn_Tracker_OSVRHackerDevKit::vrpn_Tracker_OSVRHackerDevKit(), vrpn_Tracker_OSVRHackerDevKit::vrpn_Tracker_OSVRHackerDevKit(), vrpn_Tracker_SpacePoint::vrpn_Tracker_SpacePoint(), vrpn_Tracker_Wintracker::vrpn_Tracker_Wintracker(), vrpn_Vality::vrpn_Vality(), and vrpn_Xkeys::vrpn_Xkeys().

Here is the call graph for this function:

◆ vrpn_HidInterface() [2/3]

vrpn_HidInterface::vrpn_HidInterface ( vrpn_HidAcceptor * acceptor,
hid_device * device )

Simplified constructor that just takes an acceptor and an underlying HID device (both non-optional).

Designed for passing in a device (May look at you funny if you pass a NULL device, but will work just as if you had called the other constructor with a null device) but handles NULL devices just fine.

Not given an already-open device, hmm.

Parameters
acceptorDetermines which device we want
deviceUnderlying HID device to manage and take ownership of

Definition at line 25 of file vrpn_HumanInterface.C.

References m_acceptor, m_interface, m_product, m_product_sought, m_vendor, m_vendor_sought, m_working, and reconnect().

Here is the call graph for this function:

◆ vrpn_HidInterface() [3/3]

vrpn_HidInterface::vrpn_HidInterface ( const char * device_path,
vrpn_HidAcceptor * acceptor,
vrpn_uint16 vendor = 0,
vrpn_uint16 product = 0 )

Constructor If we already know the path to the device we want, we can pass it in and open it directly: still need the acceptor for reconnect enumeration, we just won't do it right away.

Given a null/empty path.

Parameters
device_pathPlatform-specific device path, suitable to be passed to HIDAPI's hid_open_path
acceptorDetermines which device we want
vendorDefault vendor is "any"
productDefault product is "any"

Definition at line 76 of file vrpn_HumanInterface.C.

References m_acceptor, m_interface, m_product, m_product_sought, m_vendor, m_vendor_sought, m_working, product(), reconnect(), and vendor().

Here is the call graph for this function:

◆ ~vrpn_HidInterface()

vrpn_HidInterface::~vrpn_HidInterface ( )
virtual

Definition at line 115 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 m_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 307 of file vrpn_HumanInterface.C.

References m_working.

Referenced by on_data_received().

◆ interface_number()

int vrpn_HidInterface::interface_number ( ) const

Returns the USB interface number of connected device May not contain valid information on all platforms or if an already-open device was provided to the constructor.

Definition at line 20 of file vrpn_HumanInterface.C.

References m_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_3DConnexion, vrpn_Analog_5dtUSB, vrpn_CHProducts_Controller_Raw, vrpn_Contour, vrpn_DreamCheeky, vrpn_Futaba, vrpn_Griffin, vrpn_Logitech_Controller_Raw, vrpn_Microsoft_Controller_Raw, vrpn_nVidia_shield, vrpn_Retrolink, vrpn_Saitek_Controller_Raw, vrpn_Tracker_SpacePoint, vrpn_Tracker_Wintracker, vrpn_Vality, and vrpn_Xkeys.

References get_feature_report(), send_data(), and send_feature_report().

Referenced by update().

Here is the call graph for this function:

◆ product()

◆ reconnect()

◆ send_data()

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

Call this to send data to the device.

Definition at line 275 of file vrpn_HumanInterface.C.

References m_working.

Referenced by on_data_received(), vrpn_Xkeys_v1::setLEDs(), vrpn_Xkeys_v2::setLEDs(), and vrpn_Tracker_Wintracker::vrpn_Tracker_Wintracker().

◆ 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 288 of file vrpn_HumanInterface.C.

References m_working.

Referenced by on_data_received(), vrpn_Oculus_DK1::writeKeepAlive(), and vrpn_Oculus_DK2::writeKeepAlive().

◆ update()

void vrpn_HidInterface::update ( )
virtual

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.

Definition at line 239 of file vrpn_HumanInterface.C.

References m_working, and on_data_received().

Referenced by vrpn_3DConnexion::mainloop(), vrpn_Analog_5dtUSB::mainloop(), vrpn_CHProducts_Fighterstick_USB::mainloop(), vrpn_Contour_ShuttlePROv2::mainloop(), vrpn_Contour_ShuttleXpress::mainloop(), vrpn_DreamCheeky_Drum_Kit::mainloop(), vrpn_Futaba_InterLink_Elite::mainloop(), vrpn_Griffin_PowerMate::mainloop(), vrpn_Laputa::mainloop(), vrpn_Logitech_Extreme_3D_Pro::mainloop(), vrpn_Microsoft_Controller_Raw_Xbox_360_base::mainloop(), vrpn_Microsoft_Controller_Raw_Xbox_S::mainloop(), vrpn_Microsoft_SideWinder::mainloop(), vrpn_Microsoft_SideWinder_Precision_2::mainloop(), vrpn_nVidia_shield_stealth_USB::mainloop(), vrpn_nVidia_shield_USB::mainloop(), vrpn_Oculus::mainloop(), vrpn_Retrolink_GameCube::mainloop(), vrpn_Retrolink_Genesis::mainloop(), vrpn_Saitek_ST290_Pro::mainloop(), vrpn_Tracker_OSVRHackerDevKit::mainloop(), vrpn_Tracker_SpacePoint::mainloop(), vrpn_Tracker_Wintracker::mainloop(), vrpn_Vality_vGlass::mainloop(), vrpn_Xkeys_Desktop::mainloop(), vrpn_Xkeys_Jog_And_Shuttle12::mainloop(), vrpn_Xkeys_Jog_And_Shuttle68::mainloop(), vrpn_Xkeys_Jog_And_Shuttle::mainloop(), vrpn_Xkeys_Joystick12::mainloop(), vrpn_Xkeys_Joystick::mainloop(), vrpn_Xkeys_Pro::mainloop(), and vrpn_Xkeys_XK3::mainloop().

Here is the call graph for this function:

◆ vendor()

Member Data Documentation

◆ m_acceptor

vrpn_HidAcceptor* vrpn_HidInterface::m_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 175 of file vrpn_HumanInterface.h.

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

◆ m_interface

int vrpn_HidInterface::m_interface
protected

◆ m_product

vrpn_uint16 vrpn_HidInterface::m_product
protected

◆ m_product_sought

vrpn_uint16 vrpn_HidInterface::m_product_sought
protected

What product we want.

Definition at line 191 of file vrpn_HumanInterface.h.

Referenced by reconnect(), vrpn_HidInterface(), vrpn_HidInterface(), and vrpn_HidInterface().

◆ m_vendor

vrpn_uint16 vrpn_HidInterface::m_vendor
protected

◆ m_vendor_sought

vrpn_uint16 vrpn_HidInterface::m_vendor_sought
protected

What vendor we want.

Definition at line 190 of file vrpn_HumanInterface.h.

Referenced by reconnect(), vrpn_HidInterface(), vrpn_HidInterface(), and vrpn_HidInterface().

◆ m_working

bool vrpn_HidInterface::m_working
protected

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