SDL  2.0
hid.cpp File Reference
#include "../hidapi/hidapi.h"
#include "../../../public/tier1/utlvector.h"
#include "../../../public/tier1/utlhashmap.h"
+ Include dependency graph for hid.cpp:

Go to the source code of this file.

Macros

#define NAMESPACE   HIDRAW
 
#define NAMESPACE   HIDUSB
 

Enumerations

enum  EHIDAPIType {
  k_EHIDAPIUnknown,
  k_EHIDAPIRAW,
  k_EHIDAPIUSB
}
 

Functions

template<class T >
void CopyHIDDeviceInfo (T *pSrc, struct hid_device_info *pDst)
 
static EHIDAPIType GetAPIForDevice (hid_device *pDevice)
 
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate (unsigned short vendor_id, unsigned short product_id)
 Enumerate the HID Devices. More...
 
void HID_API_EXPORT HID_API_CALL hid_free_enumeration (struct hid_device_info *devs)
 Free an enumeration Linked List. More...
 
HID_API_EXPORT hid_device *HID_API_CALL hid_open (unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
 Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number. More...
 
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path (const char *path, int bExclusive)
 Open a HID device by its path name. More...
 
int HID_API_EXPORT HID_API_CALL hid_write (hid_device *device, const unsigned char *data, size_t length)
 Write an Output report to a HID device. More...
 
int HID_API_EXPORT HID_API_CALL hid_read_timeout (hid_device *device, unsigned char *data, size_t length, int milliseconds)
 Read an Input report from a HID device with timeout. More...
 
int HID_API_EXPORT HID_API_CALL hid_read (hid_device *device, unsigned char *data, size_t length)
 Read an Input report from a HID device. More...
 
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking (hid_device *device, int nonblock)
 Set the device handle to be non-blocking. More...
 
int HID_API_EXPORT HID_API_CALL hid_send_feature_report (hid_device *device, const unsigned char *data, size_t length)
 Send a Feature report to the device. More...
 
int HID_API_EXPORT HID_API_CALL hid_get_feature_report (hid_device *device, unsigned char *data, size_t length)
 Get a feature report from a HID device. More...
 
void HID_API_EXPORT HID_API_CALL hid_close (hid_device *device)
 Close a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_manufacturer_string (hid_device *device, wchar_t *string, size_t maxlen)
 Get The Manufacturer String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_product_string (hid_device *device, wchar_t *string, size_t maxlen)
 Get The Product String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_serial_number_string (hid_device *device, wchar_t *string, size_t maxlen)
 Get The Serial Number String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_indexed_string (hid_device *device, int string_index, wchar_t *string, size_t maxlen)
 Get a string from a HID device, based on its string index. More...
 
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error (hid_device *device)
 Get a string describing the last error which occurred. More...
 

Variables

static CUtlHashMap< uintptr_t, EHIDAPITypes_hashDeviceToAPI
 

Macro Definition Documentation

◆ NAMESPACE [1/2]

#define NAMESPACE   HIDRAW

Definition at line 18 of file hid.cpp.

◆ NAMESPACE [2/2]

#define NAMESPACE   HIDUSB

Definition at line 18 of file hid.cpp.

Enumeration Type Documentation

◆ EHIDAPIType

Enumerator
k_EHIDAPIUnknown 
k_EHIDAPIRAW 
k_EHIDAPIUSB 

Definition at line 48 of file hid.cpp.

Function Documentation

◆ CopyHIDDeviceInfo()

template<class T >
void CopyHIDDeviceInfo ( T pSrc,
struct hid_device_info pDst 
)

Definition at line 30 of file hid.cpp.

References hid_device_info::interface_number, hid_device_info::manufacturer_string, hid_device_info::next, NULL, hid_device_info::path, hid_device_info::product_id, hid_device_info::product_string, hid_device_info::release_number, hid_device_info::serial_number, hid_device_info::usage, hid_device_info::usage_page, and hid_device_info::vendor_id.

Referenced by hid_enumerate().

31 {
32  pDst->path = pSrc->path ? strdup( pSrc->path ) : NULL;
33  pDst->vendor_id = pSrc->vendor_id;
34  pDst->product_id = pSrc->product_id;
35  pDst->serial_number = pSrc->serial_number ? wcsdup( pSrc->serial_number ) : NULL;
36  pDst->release_number = pSrc->release_number;
37  pDst->manufacturer_string = pSrc->manufacturer_string ? wcsdup( pSrc->manufacturer_string ) : NULL;
38  pDst->product_string = pSrc->product_string ? wcsdup( pSrc->product_string ) : NULL;
39  pDst->usage_page = pSrc->usage_page;
40  pDst->usage = pSrc->usage;
41  pDst->interface_number = pSrc->interface_number;
42  pDst->next = NULL;
43 }
int interface_number
Definition: hidapi.h:79
wchar_t * manufacturer_string
Definition: hidapi.h:66
char * path
Definition: hidapi.h:55
struct hid_device_info * next
Definition: hidapi.h:82
unsigned short product_id
Definition: hidapi.h:59
wchar_t * serial_number
Definition: hidapi.h:61
unsigned short vendor_id
Definition: hidapi.h:57
wchar_t * product_string
Definition: hidapi.h:68
unsigned short usage
Definition: hidapi.h:74
#define NULL
Definition: begin_code.h:164
unsigned short usage_page
Definition: hidapi.h:71
unsigned short release_number
Definition: hidapi.h:64

◆ GetAPIForDevice()

static EHIDAPIType GetAPIForDevice ( hid_device *  pDevice)
static

Definition at line 57 of file hid.cpp.

References k_EHIDAPIUnknown.

Referenced by hid_close(), hid_error(), hid_get_feature_report(), hid_get_indexed_string(), hid_get_manufacturer_string(), hid_get_product_string(), hid_get_serial_number_string(), hid_read(), hid_read_timeout(), hid_send_feature_report(), hid_set_nonblocking(), and hid_write().

58 {
59  int iIndex = s_hashDeviceToAPI.Find( (uintptr_t)pDevice );
60  if ( iIndex != -1 )
61  {
62  return s_hashDeviceToAPI[ iIndex ];
63  }
64  return k_EHIDAPIUnknown;
65 }
unsigned int uintptr_t
static CUtlHashMap< uintptr_t, EHIDAPIType > s_hashDeviceToAPI
Definition: hid.cpp:55

Variable Documentation

◆ s_hashDeviceToAPI

CUtlHashMap<uintptr_t, EHIDAPIType> s_hashDeviceToAPI
static

Definition at line 55 of file hid.cpp.