SDL  2.0
hidapi API

Functions

int HID_API_EXPORT HID_API_CALL hid_init (void)
 Initialize the HIDAPI library. More...
 
int HID_API_EXPORT HID_API_CALL hid_exit (void)
 Finalize the HIDAPI library. More...
 
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...
 

Detailed Description

Function Documentation

◆ hid_close()

void HID_API_EXPORT HID_API_CALL hid_close ( hid_device *  device)

Close a HID device.

Parameters
deviceA device handle returned from hid_open().

Definition at line 1090 of file hid.cpp.

References CHIDDevice::Close(), device, FindDevice(), g_DevicesRefCountMutex, GetAPIForDevice(), hid_close(), k_EHIDAPIRAW, k_EHIDAPIUSB, LOGD, and LOGV.

Referenced by hid_close(), main(), MainWindow::onDisconnect(), and MainWindow::~MainWindow().

1091 {
1092  LOGV( "hid_close id=%d", device->m_nId );
1094  LOGD("Decrementing device %d (%p), refCount = %d\n", device->m_nId, device, device->m_nDeviceRefCount - 1);
1095  if ( --device->m_nDeviceRefCount == 0 )
1096  {
1097  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1098  if ( pDevice )
1099  {
1100  pDevice->Close( true );
1101  }
1102  else
1103  {
1104  delete device;
1105  }
1106  LOGD("Deleted device %p\n", device);
1107  }
1108 
1109 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
static pthread_mutex_t g_DevicesRefCountMutex
Definition: hid.cpp:706
static SDL_AudioDeviceID device
Definition: loopwave.c:37
void Close(bool bDeleteDevice)
Definition: hid.cpp:653
#define LOGV(...)
Definition: hid.cpp:25
#define LOGD(...)
Definition: hid.cpp:26
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_enumerate()

struct hid_device_info HID_API_EXPORT* HID_API_CALL hid_enumerate ( unsigned short  vendor_id,
unsigned short  product_id 
)

Enumerate the HID Devices.

This function returns a linked list of all the HID devices attached to the system which match vendor_id and product_id. If vendor_id is set to 0 then any vendor matches. If product_id is set to 0 then any product matches. If vendor_id and product_id are both set to 0, then all HID devices will be returned.

@param vendor_id The Vendor ID (VID) of the types of device
    to open.
@param product_id The Product ID (PID) of the types of
    device to open.
Returns
This function returns a pointer to a linked list of type struct #hid_device, containing information about the HID devices attached to the system, or NULL in the case of failure. Free this linked list by calling hid_free_enumeration().

Definition at line 961 of file hid.cpp.

References CopyHIDDeviceInfo(), g_DevicesMutex, hid_enumerate(), hid_free_enumeration(), hid_device_info::next, CHIDDevice::next, NULL, hid_device_info::product_id, and hid_device_info::vendor_id.

Referenced by hid_enumerate(), main(), and MainWindow::onRescan().

962 {
963  struct hid_device_info *root = NULL;
965  for ( hid_device_ref<CHIDDevice> pDevice = g_Devices; pDevice; pDevice = pDevice->next )
966  {
967  const hid_device_info *info = pDevice->GetDeviceInfo();
968  if ( ( vendor_id == 0 && product_id == 0 ) ||
969  ( vendor_id == info->vendor_id && product_id == info->product_id ) )
970  {
971  hid_device_info *dev = CopyHIDDeviceInfo( info );
972  dev->next = root;
973  root = dev;
974  }
975  }
976  return root;
977 }
hid_device_ref< CHIDDevice > next
Definition: hid.cpp:701
static pthread_mutex_t g_DevicesMutex
Definition: hid.cpp:705
static hid_device_ref< CHIDDevice > g_Devices
Definition: hid.cpp:707
struct hid_device_info * next
Definition: hidapi.h:82
unsigned short product_id
Definition: hidapi.h:59
unsigned short vendor_id
Definition: hidapi.h:57
static hid_device_info * CopyHIDDeviceInfo(const hid_device_info *pInfo)
Definition: hid.cpp:315
#define NULL
Definition: begin_code.h:164

◆ hid_error()

HID_API_EXPORT const wchar_t* HID_API_CALL hid_error ( hid_device *  device)

Get a string describing the last error which occurred.

Parameters
deviceA device handle returned from hid_open().
Returns
This function returns a string containing the last error which occurred or NULL if none has occurred.

Definition at line 1149 of file hid.cpp.

References GetAPIForDevice(), hid_error(), k_EHIDAPIRAW, k_EHIDAPIUSB, and NULL.

Referenced by hid_error(), main(), MainWindow::onGetFeatureReport(), MainWindow::onSendFeatureReport(), and MainWindow::onSendOutputReport().

1150 {
1151  return NULL;
1152 }
#define NULL
Definition: begin_code.h:164

◆ hid_exit()

int HID_API_EXPORT HID_API_CALL hid_exit ( void  )

Finalize the HIDAPI library.

This function frees all of the static data associated with HIDAPI. It should be called at the end of execution to avoid memory leaks.

Returns
This function returns 0 on success and -1 on error.

Definition at line 1154 of file hid.cpp.

Referenced by main(), and MainWindow::~MainWindow().

1155 {
1156  return 0;
1157 }

◆ hid_free_enumeration()

void HID_API_EXPORT HID_API_CALL hid_free_enumeration ( struct hid_device_info devs)

Free an enumeration Linked List.

This function frees a linked list created by hid_enumerate().

Parameters
devsPointer to a list of struct_device returned from hid_enumerate().

Definition at line 979 of file hid.cpp.

References free, FreeHIDDeviceInfo(), hid_device_info::manufacturer_string, hid_device_info::next, hid_device_info::path, hid_device_info::product_string, and hid_device_info::serial_number.

Referenced by hid_enumerate(), main(), and MainWindow::onRescan().

980 {
981  while ( devs )
982  {
983  struct hid_device_info *next = devs->next;
984  FreeHIDDeviceInfo( devs );
985  devs = next;
986  }
987 }
struct hid_device_info * next
Definition: hidapi.h:82
static void FreeHIDDeviceInfo(hid_device_info *pInfo)
Definition: hid.cpp:326

◆ hid_get_feature_report()

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.

Set the first byte of data[] to the Report ID of the report to be read. Make sure to allow space for this extra byte in data[]. Upon return, the first byte will still contain the Report ID, and the report data will start in data[1].

@param device A device handle returned from hid_open().
@param data A buffer to put the read data into, including
    the Report ID. Set the first byte of @p data[] to the
    Report ID of the report to be read, or set it to zero
    if your device does not use numbered reports.
@param length The number of bytes to read, including an
    extra byte for the report ID. The buffer can be longer
    than the actual report.

@returns
    This function returns the number of bytes read plus
    one for the report ID (which is still in the first
    byte), or -1 on error.

Definition at line 1078 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), CHIDDevice::GetFeatureReport(), hid_get_feature_report(), k_EHIDAPIRAW, k_EHIDAPIUSB, and LOGV.

Referenced by hid_get_feature_report(), main(), and MainWindow::onGetFeatureReport().

1079 {
1080  LOGV( "hid_get_feature_report id=%d length=%u", device->m_nId, length );
1081  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1082  if ( pDevice )
1083  {
1084  return pDevice->GetFeatureReport( data, length );
1085  }
1086  return -1; // Controller was disconnected
1087 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static SDL_AudioDeviceID device
Definition: loopwave.c:37
int GetFeatureReport(unsigned char *pData, size_t nDataLen)
Definition: hid.cpp:583
#define LOGV(...)
Definition: hid.cpp:25
GLuint GLsizei GLsizei * length
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_get_indexed_string()

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.

Parameters
deviceA device handle returned from hid_open().
string_indexThe index of the string to get.
stringA wide string buffer to put the data into.
maxlenThe length of the buffer in multiples of wchar_t.
Returns
This function returns 0 on success and -1 on error.

Definition at line 1144 of file hid.cpp.

References GetAPIForDevice(), hid_get_indexed_string(), k_EHIDAPIRAW, and k_EHIDAPIUSB.

Referenced by hid_get_indexed_string(), and main().

1145 {
1146  return -1;
1147 }

◆ hid_get_manufacturer_string()

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.

Parameters
deviceA device handle returned from hid_open().
stringA wide string buffer to put the data into.
maxlenThe length of the buffer in multiples of wchar_t.
Returns
This function returns 0 on success and -1 on error.

Definition at line 1111 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), CHIDDevice::GetDeviceInfo(), hid_get_manufacturer_string(), k_EHIDAPIRAW, k_EHIDAPIUSB, and hid_device_info::manufacturer_string.

Referenced by hid_get_manufacturer_string(), and main().

1112 {
1113  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1114  if ( pDevice )
1115  {
1116  wcsncpy( string, pDevice->GetDeviceInfo()->manufacturer_string, maxlen );
1117  return 0;
1118  }
1119  return -1;
1120 }
const hid_device_info * GetDeviceInfo()
Definition: hid.cpp:395
wchar_t * manufacturer_string
Definition: hidapi.h:66
static SDL_AudioDeviceID device
Definition: loopwave.c:37
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_get_product_string()

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.

Parameters
deviceA device handle returned from hid_open().
stringA wide string buffer to put the data into.
maxlenThe length of the buffer in multiples of wchar_t.
Returns
This function returns 0 on success and -1 on error.

Definition at line 1122 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), CHIDDevice::GetDeviceInfo(), hid_get_product_string(), k_EHIDAPIRAW, k_EHIDAPIUSB, and hid_device_info::product_string.

Referenced by hid_get_product_string(), and main().

1123 {
1124  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1125  if ( pDevice )
1126  {
1127  wcsncpy( string, pDevice->GetDeviceInfo()->product_string, maxlen );
1128  return 0;
1129  }
1130  return -1;
1131 }
const hid_device_info * GetDeviceInfo()
Definition: hid.cpp:395
static SDL_AudioDeviceID device
Definition: loopwave.c:37
wchar_t * product_string
Definition: hidapi.h:68
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_get_serial_number_string()

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.

Parameters
deviceA device handle returned from hid_open().
stringA wide string buffer to put the data into.
maxlenThe length of the buffer in multiples of wchar_t.
Returns
This function returns 0 on success and -1 on error.

Definition at line 1133 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), CHIDDevice::GetDeviceInfo(), hid_get_serial_number_string(), k_EHIDAPIRAW, k_EHIDAPIUSB, and hid_device_info::serial_number.

Referenced by hid_get_serial_number_string(), and main().

1134 {
1135  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1136  if ( pDevice )
1137  {
1138  wcsncpy( string, pDevice->GetDeviceInfo()->serial_number, maxlen );
1139  return 0;
1140  }
1141  return -1;
1142 }
const hid_device_info * GetDeviceInfo()
Definition: hid.cpp:395
static SDL_AudioDeviceID device
Definition: loopwave.c:37
wchar_t * serial_number
Definition: hidapi.h:61
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_init()

int HID_API_EXPORT HID_API_CALL hid_init ( void  )

Initialize the HIDAPI library.

This function initializes the HIDAPI library. Calling it is not strictly necessary, as it will be called automatically by hid_enumerate() and any of the hid_open_*() functions if it is needed. This function should be called at the beginning of execution however, if there is a chance of HIDAPI handles being opened by different threads simultaneously.

@returns
    This function returns 0 on success and -1 on error.

Definition at line 956 of file hid.cpp.

Referenced by main().

957 {
958  return 0;
959 }

◆ hid_open()

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.

If serial_number is NULL, the first device with the specified VID and PID is opened.

@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
                   (Optionally NULL).

@returns
    This function returns a pointer to a #hid_device object on
    success or NULL on failure.

Definition at line 989 of file hid.cpp.

References hid_open(), k_EHIDAPIRAW, k_EHIDAPIUSB, and NULL.

Referenced by hid_open(), and main().

990 {
991  // TODO: Implement
992  return NULL;
993 }
#define NULL
Definition: begin_code.h:164

◆ hid_open_path()

HID_API_EXPORT hid_device* HID_API_CALL hid_open_path ( const char *  path,
int  bExclusive 
)

Open a HID device by its path name.

The path name be determined by calling hid_enumerate(), or a platform-specific path name can be used (eg: /dev/hidraw0 on Linux).

Parameters
pathThe path name of the device to open
@returns
    This function returns a pointer to a #hid_device object on
    success or NULL on failure.

Definition at line 995 of file hid.cpp.

References CHIDDevice::BOpen(), g_DevicesMutex, g_DevicesRefCountMutex, CHIDDevice::GetDevice(), hid_open_path(), k_EHIDAPIRAW, k_EHIDAPIUSB, LOGD, LOGV, CHIDDevice::next, and NULL.

Referenced by hid_open_path(), and MainWindow::onConnect().

996 {
997  LOGV( "hid_open_path( %s )", path );
998 
1000  {
1003  for ( hid_device_ref<CHIDDevice> pCurr = g_Devices; pCurr; pCurr = pCurr->next )
1004  {
1005  if ( strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 )
1006  {
1007  hid_device *pValue = pCurr->GetDevice();
1008  if ( pValue )
1009  {
1010  ++pValue->m_nDeviceRefCount;
1011  LOGD("Incrementing device %d (%p), refCount = %d\n", pValue->m_nId, pValue, pValue->m_nDeviceRefCount);
1012  return pValue;
1013  }
1014 
1015  // Hold a shared pointer to the controller for the duration
1016  pDevice = pCurr;
1017  break;
1018  }
1019  }
1020  }
1021  if ( pDevice && pDevice->BOpen() )
1022  {
1023  return pDevice->GetDevice();
1024  }
1025  return NULL;
1026 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
hid_device_ref< CHIDDevice > next
Definition: hid.cpp:701
bool BOpen()
Definition: hid.cpp:432
hid_device * GetDevice()
Definition: hid.cpp:400
static pthread_mutex_t g_DevicesRefCountMutex
Definition: hid.cpp:706
static pthread_mutex_t g_DevicesMutex
Definition: hid.cpp:705
static hid_device_ref< CHIDDevice > g_Devices
Definition: hid.cpp:707
#define NULL
Definition: begin_code.h:164
#define LOGV(...)
Definition: hid.cpp:25
#define LOGD(...)
Definition: hid.cpp:26
GLsizei const GLchar *const * path

◆ hid_read()

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.

Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports.

@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
    multiple reports, make sure to read an extra byte for
    the report number.

@returns
    This function returns the actual number of bytes read and
    -1 on error. If no packet was available to be read and
    the handle is in non-blocking mode, this function returns 0.

Definition at line 1053 of file hid.cpp.

References GetAPIForDevice(), hid_read(), hid_read_timeout(), k_EHIDAPIRAW, k_EHIDAPIUSB, and LOGV.

Referenced by hid_read(), main(), and MainWindow::onTimeout().

1054 {
1055  LOGV( "hid_read id=%d length=%u", device->m_nId, length );
1056  return hid_read_timeout( device, data, length, 0 );
1057 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static SDL_AudioDeviceID device
Definition: loopwave.c:37
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.
Definition: hid.cpp:1040
#define LOGV(...)
Definition: hid.cpp:25
GLuint GLsizei GLsizei * length

◆ hid_read_timeout()

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.

Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports.

@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
    multiple reports, make sure to read an extra byte for
    the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.

@returns
    This function returns the actual number of bytes read and
    -1 on error. If no packet was available to be read within
    the timeout period, this function returns 0.

Definition at line 1040 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), CHIDDevice::GetInput(), hid_read_timeout(), k_EHIDAPIRAW, k_EHIDAPIUSB, and LOGV.

Referenced by hid_read(), and hid_read_timeout().

1041 {
1042 // LOGV( "hid_read_timeout id=%d length=%u timeout=%d", device->m_nId, length, milliseconds );
1043  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1044  if ( pDevice )
1045  {
1046  return pDevice->GetInput( data, length );
1047  }
1048  LOGV( "controller was disconnected" );
1049  return -1; // Controller was disconnected
1050 }
int GetInput(unsigned char *data, size_t length)
Definition: hid.cpp:509
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define LOGV(...)
Definition: hid.cpp:25
GLuint GLsizei GLsizei * length
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_send_feature_report()

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.

Feature reports are sent over the Control endpoint as a Set_Report transfer. The first byte of data[] must contain the Report ID. For devices which only support a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the Report ID is mandatory, calls to hid_send_feature_report() will always contain one more byte than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to hid_send_feature_report(): the Report ID (or 0x0, for devices which do not use numbered reports), followed by the report data (16 bytes). In this example, the length passed in would be 17.

@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
    the first byte.
@param length The length in bytes of the data to send, including
    the report number.

@returns
    This function returns the actual number of bytes written and
    -1 on error.

Definition at line 1065 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), hid_send_feature_report(), k_EHIDAPIRAW, k_EHIDAPIUSB, LOGV, and CHIDDevice::SendFeatureReport().

Referenced by hid_send_feature_report(), main(), and MainWindow::onSendFeatureReport().

1066 {
1067  LOGV( "hid_send_feature_report id=%d length=%u", device->m_nId, length );
1068  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1069  if ( pDevice )
1070  {
1071  return pDevice->SendFeatureReport( data, length );
1072  }
1073  return -1; // Controller was disconnected
1074 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
int SendFeatureReport(const unsigned char *pData, size_t nDataLen)
Definition: hid.cpp:556
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define LOGV(...)
Definition: hid.cpp:25
GLuint GLsizei GLsizei * length
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709

◆ hid_set_nonblocking()

int HID_API_EXPORT HID_API_CALL hid_set_nonblocking ( hid_device *  device,
int  nonblock 
)

Set the device handle to be non-blocking.

In non-blocking mode calls to hid_read() will return immediately with a value of 0 if there is no data to be read. In blocking mode, hid_read() will wait (block) until there is data to read before returning.

Nonblocking can be turned on and off at any time.

@param device A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
 - 1 to enable nonblocking
 - 0 to disable nonblocking.

@returns
    This function returns 0 on success and -1 on error.

Definition at line 1060 of file hid.cpp.

References GetAPIForDevice(), hid_set_nonblocking(), k_EHIDAPIRAW, and k_EHIDAPIUSB.

Referenced by hid_set_nonblocking(), main(), and MainWindow::onConnect().

1061 {
1062  return -1;
1063 }

◆ hid_write()

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.

The first byte of data[] must contain the Report ID. For devices which only support a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the Report ID is mandatory, calls to hid_write() will always contain one more byte than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to hid_write(), the Report ID (or 0x0, for devices with a single report), followed by the report data (16 bytes). In this example, the length passed in would be 17.

hid_write() will send the data on the first OUT endpoint, if one exists. If it does not, it will send the data through the Control Endpoint (Endpoint 0).

@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
    the first byte.
@param length The length in bytes of the data to send.

@returns
    This function returns the actual number of bytes written and
    -1 on error.

Definition at line 1028 of file hid.cpp.

References FindDevice(), GetAPIForDevice(), hid_write(), k_EHIDAPIRAW, k_EHIDAPIUSB, LOGV, and CHIDDevice::SendOutputReport().

Referenced by hid_write(), main(), and MainWindow::onSendOutputReport().

1029 {
1030  LOGV( "hid_write id=%d length=%u", device->m_nId, length );
1031  hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
1032  if ( pDevice )
1033  {
1034  return pDevice->SendOutputReport( data, length );
1035  }
1036  return -1; // Controller was disconnected
1037 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static SDL_AudioDeviceID device
Definition: loopwave.c:37
int SendOutputReport(const unsigned char *pData, size_t nDataLen)
Definition: hid.cpp:541
#define LOGV(...)
Definition: hid.cpp:25
GLuint GLsizei GLsizei * length
static hid_device_ref< CHIDDevice > FindDevice(int nDeviceId)
Definition: hid.cpp:709