60#define LOG(...) fprintf(stderr, __VA_ARGS__)
68#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
69#define DETACH_KERNEL_DRIVER
82#define INVASIVE_GET_USAGE
129static libusb_context *usb_context = NULL;
132static int return_data(
hid_device *dev,
unsigned char *
data,
size_t length);
139 pthread_mutex_init(&dev->
mutex, NULL);
140 pthread_cond_init(&dev->
condition, NULL);
141 pthread_barrier_init(&dev->
barrier, NULL, 2);
149 pthread_barrier_destroy(&dev->
barrier);
151 pthread_mutex_destroy(&dev->
mutex);
165#ifdef INVASIVE_GET_USAGE
168static uint32_t get_bytes(uint8_t *rpt,
size_t len,
size_t num_bytes,
size_t cur)
171 if (cur + num_bytes >=
len)
176 else if (num_bytes == 1)
180 else if (num_bytes == 2)
182 return (rpt[cur + 2] * 256 + rpt[cur + 1]);
184 else if (num_bytes == 4)
186 return (rpt[cur + 4] * 0x01000000 + rpt[cur + 3] * 0x00010000 + rpt[cur + 2] * 0x00000100 +
187 rpt[cur + 1] * 0x00000001);
197static int get_usage(uint8_t *report_descriptor,
size_t size,
unsigned short *usage_page,
unsigned short *
usage)
201 int data_len, key_size;
202 int usage_found = 0, usage_page_found = 0;
206 int key = report_descriptor[i];
207 int key_cmd =
key & 0xfc;
211 if ((key & 0xf0) == 0xf0)
218 data_len = report_descriptor[i + 1];
230 size_code =
key & 0x3;
236 data_len = size_code;
251 *usage_page = get_bytes(report_descriptor, size, data_len, i);
252 usage_page_found = 1;
257 *
usage = get_bytes(report_descriptor, size, data_len, i);
262 if (usage_page_found && usage_found)
266 i += data_len + key_size;
275static uint16_t get_first_language(libusb_device_handle *dev)
281 len = libusb_get_string_descriptor(dev, 0x0,
283 (
unsigned char *)buf,
sizeof(buf));
290static int is_language_supported(libusb_device_handle *dev, uint16_t lang)
297 len = libusb_get_string_descriptor(dev, 0x0,
299 (
unsigned char *)buf,
sizeof(buf));
305 for (i = 1; i <
len; i++)
317static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
335 if (!is_language_supported(dev, lang))
336 lang = get_first_language(dev);
339 len = libusb_get_string_descriptor(dev, idx, lang, (
unsigned char *)buf,
sizeof(buf));
347 ic = iconv_open(
"WCHAR_T",
"UTF-16LE");
348 if (ic == (iconv_t)-1)
350 LOG(
"iconv_open() failed\n");
358 outptr = (
char *)wbuf;
359 outbytes =
sizeof(wbuf);
360 res = iconv(ic, &inptr, &inbytes, &outptr, &outbytes);
361 if (res == (
size_t)-1)
363 LOG(
"iconv() failed\n");
368 wbuf[
sizeof(wbuf) /
sizeof(wbuf[0]) - 1] = 0x00000000;
369 if (outbytes >=
sizeof(wbuf[0]))
370 *((
wchar_t *)outptr) = 0x00000000;
381static char *make_path(libusb_device *dev,
int interface_number)
384 snprintf(str,
sizeof(str),
"%04x:%04x:%02x", libusb_get_bus_number(dev), libusb_get_device_address(dev),
386 str[
sizeof(str) - 1] =
'\0';
398 if (libusb_init(&usb_context))
402 locale = indi_setlocale(LC_CTYPE, NULL);
414 libusb_exit(usb_context);
423 libusb_device **devs;
425 libusb_device_handle *handle;
436 num_devs = libusb_get_device_list(usb_context, &devs);
440 while ((dev = devs[i++]) != NULL)
442 struct libusb_device_descriptor desc;
443 struct libusb_config_descriptor *conf_desc = NULL;
445 int interface_num = 0;
447 int res = libusb_get_device_descriptor(dev, &desc);
448 unsigned short dev_vid = desc.idVendor;
449 unsigned short dev_pid = desc.idProduct;
452 if (desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE)
455 res = libusb_get_active_config_descriptor(dev, &conf_desc);
457 libusb_get_config_descriptor(dev, 0, &conf_desc);
460 for (j = 0; j < conf_desc->bNumInterfaces; j++)
462 const struct libusb_interface *intf = &conf_desc->interface[j];
463 for (k = 0; k < intf->num_altsetting; k++)
465 const struct libusb_interface_descriptor *intf_desc;
466 intf_desc = &intf->altsetting[k];
467 if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID)
469 interface_num = intf_desc->bInterfaceNumber;
472 if ((vendor_id == 0x0 && product_id == 0x0) || (vendor_id == dev_vid && product_id == dev_pid))
489 cur_dev->
next = NULL;
490 cur_dev->
path = make_path(dev, interface_num);
492 res = libusb_open(dev, &handle);
497 if (desc.iSerialNumber > 0)
498 cur_dev->
serial_number = get_usb_string(handle, desc.iSerialNumber);
501 if (desc.iManufacturer > 0)
503 if (desc.iProduct > 0)
506#ifdef INVASIVE_GET_USAGE
522 unsigned char data[256];
523#ifdef DETACH_KERNEL_DRIVER
526 res = libusb_kernel_driver_active(handle, interface_num);
529 res = libusb_detach_kernel_driver(handle, interface_num);
531 LOG(
"Couldn't detach kernel driver, even though a kernel driver was attached.");
536 res = libusb_claim_interface(handle, interface_num);
540 res = libusb_control_transfer(
541 handle, LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE,
542 LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8) | interface_num, 0, data,
546 unsigned short page = 0,
usage = 0;
549 get_usage(data, res, &page, &
usage);
554 LOG(
"libusb_control_transfer() for getting the HID report failed with %d\n",
558 res = libusb_release_interface(handle, interface_num);
560 LOG(
"Can't release the interface.\n");
563 LOG(
"Can't claim interface %d\n", res);
564#ifdef DETACH_KERNEL_DRIVER
568 res = libusb_attach_kernel_driver(handle, interface_num);
570 LOG(
"Couldn't re-attach kernel driver.\n");
576 libusb_close(handle);
591 libusb_free_config_descriptor(conf_desc);
595 libusb_free_device_list(devs, 1);
618 const char *path_to_open = NULL;
631 path_to_open = cur_dev->
path;
637 path_to_open = cur_dev->
path;
641 cur_dev = cur_dev->
next;
655static void read_callback(
struct libusb_transfer *transfer)
660 if (transfer->status == LIBUSB_TRANSFER_COMPLETED)
663 rpt->
data = malloc(transfer->actual_length);
664 memcpy(rpt->
data, transfer->buffer, transfer->actual_length);
665 rpt->
len = transfer->actual_length;
668 pthread_mutex_lock(&dev->
mutex);
682 while (cur->
next != NULL)
694 return_data(dev, NULL, 0);
697 pthread_mutex_unlock(&dev->
mutex);
699 else if (transfer->status == LIBUSB_TRANSFER_CANCELLED)
705 else if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE)
711 else if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT)
729 res = libusb_submit_transfer(transfer);
738static void *read_thread(
void *param)
745 buf = malloc(length);
746 dev->
transfer = libusb_alloc_transfer(0);
752 if (libusb_submit_transfer(dev->
transfer) != 0)
759 pthread_barrier_wait(&dev->
barrier);
765 res = libusb_handle_events(usb_context);
772 if (res != LIBUSB_ERROR_BUSY && res != LIBUSB_ERROR_TIMEOUT && res != LIBUSB_ERROR_OVERFLOW &&
773 res != LIBUSB_ERROR_INTERRUPTED)
785 libusb_cancel_transfer(dev->
transfer);
794 pthread_mutex_lock(&dev->
mutex);
796 pthread_mutex_unlock(&dev->
mutex);
813 dev = new_hid_device();
815 libusb_device **devs;
816 libusb_device *usb_dev;
824 num_devs = libusb_get_device_list(usb_context, &devs);
828 while ((usb_dev = devs[d++]) != NULL)
830 struct libusb_device_descriptor desc;
831 struct libusb_config_descriptor *conf_desc = NULL;
833 libusb_get_device_descriptor(usb_dev, &desc);
835 if (libusb_get_active_config_descriptor(usb_dev, &conf_desc) < 0)
837 for (j = 0; j < conf_desc->bNumInterfaces; j++)
839 const struct libusb_interface *intf = &conf_desc->interface[j];
840 for (k = 0; k < intf->num_altsetting; k++)
842 const struct libusb_interface_descriptor *intf_desc;
843 intf_desc = &intf->altsetting[k];
844 if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID)
846 char *dev_path = make_path(usb_dev, intf_desc->bInterfaceNumber);
847 if (!strcmp(dev_path, path))
860#ifdef DETACH_KERNEL_DRIVER
863 if (libusb_kernel_driver_active(dev->
device_handle, intf_desc->bInterfaceNumber) == 1)
865 res = libusb_detach_kernel_driver(dev->
device_handle, intf_desc->bInterfaceNumber);
876 res = libusb_claim_interface(dev->
device_handle, intf_desc->bInterfaceNumber);
879 LOG(
"can't claim interface %d: %d %s\n", intf_desc->bInterfaceNumber, res,
libusb_error_name(res));
892 dev->
interface = intf_desc->bInterfaceNumber;
896 for (i = 0; i < intf_desc->bNumEndpoints; i++)
898 const struct libusb_endpoint_descriptor *ep = &intf_desc->endpoint[i];
903 (ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_INTERRUPT;
904 int is_output = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT;
905 int is_input = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN;
921 pthread_create(&dev->
thread, NULL, read_thread, dev);
924 pthread_barrier_wait(&dev->
barrier);
930 libusb_free_config_descriptor(conf_desc);
933 libusb_free_device_list(devs, 1);
943 free_hid_device(dev);
951 int report_number = data[0];
952 int skipped_report_id = 0;
954 if (report_number == 0x0)
958 skipped_report_id = 1;
965 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
966 0x09 , (2 << 8) | report_number, dev->
interface,
967 (
unsigned char *)data, length, 1000 );
972 if (skipped_report_id)
982 &actual_length, 1000);
987 if (skipped_report_id)
990 return actual_length;
996static int return_data(
hid_device *dev,
unsigned char *data,
size_t length)
1001 size_t len = (length < rpt->
len) ? length : rpt->
len;
1010static void cleanup_mutex(
void *param)
1013 pthread_mutex_unlock(&dev->
mutex);
1018 volatile int bytes_read = 0;
1023 LOG(
"transferred: %d\n", transferred);
1027 pthread_mutex_lock(&dev->
mutex);
1028 pthread_cleanup_push(&cleanup_mutex, dev);
1034 bytes_read = return_data(dev,
data, length);
1046 if (milliseconds == -1)
1055 bytes_read = return_data(dev,
data, length);
1058 else if (milliseconds > 0)
1063 clock_gettime(CLOCK_REALTIME, &ts);
1064 ts.tv_sec += milliseconds / 1000;
1065 ts.tv_nsec += (milliseconds % 1000) * 1000000;
1066 if (ts.tv_nsec >= 1000000000L)
1069 ts.tv_nsec -= 1000000000L;
1079 bytes_read = return_data(dev, data, length);
1087 else if (res == ETIMEDOUT)
1108 pthread_mutex_unlock(&dev->
mutex);
1109 pthread_cleanup_pop(0);
1129 int skipped_report_id = 0;
1130 int report_number = data[0];
1132 if (report_number == 0x0)
1136 skipped_report_id = 1;
1140 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
1141 0x09 , (3 << 8) | report_number, dev->
interface,
1142 (
unsigned char *)data, length, 1000 );
1148 if (skipped_report_id)
1157 int skipped_report_id = 0;
1158 int report_number = data[0];
1160 if (report_number == 0x0)
1166 skipped_report_id = 1;
1169 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN,
1170 0x01 , (3 << 8) | report_number, dev->
interface,
1171 (
unsigned char *)data, length, 1000 );
1176 if (skipped_report_id)
1189 libusb_cancel_transfer(dev->
transfer);
1192 pthread_join(dev->
thread, NULL);
1196 libusb_free_transfer(dev->
transfer);
1205 pthread_mutex_lock(&dev->
mutex);
1208 return_data(dev, NULL, 0);
1210 pthread_mutex_unlock(&dev->
mutex);
1212 free_hid_device(dev);
1237 wcsncpy(
string, str, maxlen);
1238 string[maxlen - 1] = L
'\0';
1259#define LANG(name, code, usb_code) \
1261 name, code, usb_code \
1264 LANG(
"Afrikaans",
"af", 0x0436),
1265 LANG(
"Albanian",
"sq", 0x041C),
1266 LANG(
"Arabic - United Arab Emirates",
"ar_ae", 0x3801),
1267 LANG(
"Arabic - Bahrain",
"ar_bh", 0x3C01),
1268 LANG(
"Arabic - Algeria",
"ar_dz", 0x1401),
1269 LANG(
"Arabic - Egypt",
"ar_eg", 0x0C01),
1270 LANG(
"Arabic - Iraq",
"ar_iq", 0x0801),
1271 LANG(
"Arabic - Jordan",
"ar_jo", 0x2C01),
1272 LANG(
"Arabic - Kuwait",
"ar_kw", 0x3401),
1273 LANG(
"Arabic - Lebanon",
"ar_lb", 0x3001),
1274 LANG(
"Arabic - Libya",
"ar_ly", 0x1001),
1275 LANG(
"Arabic - Morocco",
"ar_ma", 0x1801),
1276 LANG(
"Arabic - Oman",
"ar_om", 0x2001),
1277 LANG(
"Arabic - Qatar",
"ar_qa", 0x4001),
1278 LANG(
"Arabic - Saudi Arabia",
"ar_sa", 0x0401),
1279 LANG(
"Arabic - Syria",
"ar_sy", 0x2801),
1280 LANG(
"Arabic - Tunisia",
"ar_tn", 0x1C01),
1281 LANG(
"Arabic - Yemen",
"ar_ye", 0x2401),
1282 LANG(
"Armenian",
"hy", 0x042B),
1283 LANG(
"Azeri - Latin",
"az_az", 0x042C),
1284 LANG(
"Azeri - Cyrillic",
"az_az", 0x082C),
1285 LANG(
"Basque",
"eu", 0x042D),
1286 LANG(
"Belarusian",
"be", 0x0423),
1287 LANG(
"Bulgarian",
"bg", 0x0402),
1288 LANG(
"Catalan",
"ca", 0x0403),
1289 LANG(
"Chinese - China",
"zh_cn", 0x0804),
1290 LANG(
"Chinese - Hong Kong SAR",
"zh_hk", 0x0C04),
1291 LANG(
"Chinese - Macau SAR",
"zh_mo", 0x1404),
1292 LANG(
"Chinese - Singapore",
"zh_sg", 0x1004),
1293 LANG(
"Chinese - Taiwan",
"zh_tw", 0x0404),
1294 LANG(
"Croatian",
"hr", 0x041A),
1295 LANG(
"Czech",
"cs", 0x0405),
1296 LANG(
"Danish",
"da", 0x0406),
1297 LANG(
"Dutch - Netherlands",
"nl_nl", 0x0413),
1298 LANG(
"Dutch - Belgium",
"nl_be", 0x0813),
1299 LANG(
"English - Australia",
"en_au", 0x0C09),
1300 LANG(
"English - Belize",
"en_bz", 0x2809),
1301 LANG(
"English - Canada",
"en_ca", 0x1009),
1302 LANG(
"English - Caribbean",
"en_cb", 0x2409),
1303 LANG(
"English - Ireland",
"en_ie", 0x1809),
1304 LANG(
"English - Jamaica",
"en_jm", 0x2009),
1305 LANG(
"English - New Zealand",
"en_nz", 0x1409),
1306 LANG(
"English - Phillippines",
"en_ph", 0x3409),
1307 LANG(
"English - Southern Africa",
"en_za", 0x1C09),
1308 LANG(
"English - Trinidad",
"en_tt", 0x2C09),
1309 LANG(
"English - Great Britain",
"en_gb", 0x0809),
1310 LANG(
"English - United States",
"en_us", 0x0409),
1311 LANG(
"Estonian",
"et", 0x0425),
1312 LANG(
"Farsi",
"fa", 0x0429),
1313 LANG(
"Finnish",
"fi", 0x040B),
1314 LANG(
"Faroese",
"fo", 0x0438),
1315 LANG(
"French - France",
"fr_fr", 0x040C),
1316 LANG(
"French - Belgium",
"fr_be", 0x080C),
1317 LANG(
"French - Canada",
"fr_ca", 0x0C0C),
1318 LANG(
"French - Luxembourg",
"fr_lu", 0x140C),
1319 LANG(
"French - Switzerland",
"fr_ch", 0x100C),
1320 LANG(
"Gaelic - Ireland",
"gd_ie", 0x083C),
1321 LANG(
"Gaelic - Scotland",
"gd", 0x043C),
1322 LANG(
"German - Germany",
"de_de", 0x0407),
1323 LANG(
"German - Austria",
"de_at", 0x0C07),
1324 LANG(
"German - Liechtenstein",
"de_li", 0x1407),
1325 LANG(
"German - Luxembourg",
"de_lu", 0x1007),
1326 LANG(
"German - Switzerland",
"de_ch", 0x0807),
1327 LANG(
"Greek",
"el", 0x0408),
1328 LANG(
"Hebrew",
"he", 0x040D),
1329 LANG(
"Hindi",
"hi", 0x0439),
1330 LANG(
"Hungarian",
"hu", 0x040E),
1331 LANG(
"Icelandic",
"is", 0x040F),
1332 LANG(
"Indonesian",
"id", 0x0421),
1333 LANG(
"Italian - Italy",
"it_it", 0x0410),
1334 LANG(
"Italian - Switzerland",
"it_ch", 0x0810),
1335 LANG(
"Japanese",
"ja", 0x0411),
1336 LANG(
"Korean",
"ko", 0x0412),
1337 LANG(
"Latvian",
"lv", 0x0426),
1338 LANG(
"Lithuanian",
"lt", 0x0427),
1339 LANG(
"F.Y.R.O. Macedonia",
"mk", 0x042F),
1340 LANG(
"Malay - Malaysia",
"ms_my", 0x043E),
1341 LANG(
"Malay - Brunei",
"ms_bn", 0x083E),
1342 LANG(
"Maltese",
"mt", 0x043A),
1343 LANG(
"Marathi",
"mr", 0x044E),
1344 LANG(
"Norwegian - Bokml",
"no_no", 0x0414),
1345 LANG(
"Norwegian - Nynorsk",
"no_no", 0x0814),
1346 LANG(
"Polish",
"pl", 0x0415),
1347 LANG(
"Portuguese - Portugal",
"pt_pt", 0x0816),
1348 LANG(
"Portuguese - Brazil",
"pt_br", 0x0416),
1349 LANG(
"Raeto-Romance",
"rm", 0x0417),
1350 LANG(
"Romanian - Romania",
"ro", 0x0418),
1351 LANG(
"Romanian - Republic of Moldova",
"ro_mo", 0x0818),
1352 LANG(
"Russian",
"ru", 0x0419),
1353 LANG(
"Russian - Republic of Moldova",
"ru_mo", 0x0819),
1354 LANG(
"Sanskrit",
"sa", 0x044F),
1355 LANG(
"Serbian - Cyrillic",
"sr_sp", 0x0C1A),
1356 LANG(
"Serbian - Latin",
"sr_sp", 0x081A),
1357 LANG(
"Setsuana",
"tn", 0x0432),
1358 LANG(
"Slovenian",
"sl", 0x0424),
1359 LANG(
"Slovak",
"sk", 0x041B),
1360 LANG(
"Sorbian",
"sb", 0x042E),
1361 LANG(
"Spanish - Spain (Traditional)",
"es_es", 0x040A),
1362 LANG(
"Spanish - Argentina",
"es_ar", 0x2C0A),
1363 LANG(
"Spanish - Bolivia",
"es_bo", 0x400A),
1364 LANG(
"Spanish - Chile",
"es_cl", 0x340A),
1365 LANG(
"Spanish - Colombia",
"es_co", 0x240A),
1366 LANG(
"Spanish - Costa Rica",
"es_cr", 0x140A),
1367 LANG(
"Spanish - Dominican Republic",
"es_do", 0x1C0A),
1368 LANG(
"Spanish - Ecuador",
"es_ec", 0x300A),
1369 LANG(
"Spanish - Guatemala",
"es_gt", 0x100A),
1370 LANG(
"Spanish - Honduras",
"es_hn", 0x480A),
1371 LANG(
"Spanish - Mexico",
"es_mx", 0x080A),
1372 LANG(
"Spanish - Nicaragua",
"es_ni", 0x4C0A),
1373 LANG(
"Spanish - Panama",
"es_pa", 0x180A),
1374 LANG(
"Spanish - Peru",
"es_pe", 0x280A),
1375 LANG(
"Spanish - Puerto Rico",
"es_pr", 0x500A),
1376 LANG(
"Spanish - Paraguay",
"es_py", 0x3C0A),
1377 LANG(
"Spanish - El Salvador",
"es_sv", 0x440A),
1378 LANG(
"Spanish - Uruguay",
"es_uy", 0x380A),
1379 LANG(
"Spanish - Venezuela",
"es_ve", 0x200A),
1380 LANG(
"Southern Sotho",
"st", 0x0430),
1381 LANG(
"Swahili",
"sw", 0x0441),
1382 LANG(
"Swedish - Sweden",
"sv_se", 0x041D),
1383 LANG(
"Swedish - Finland",
"sv_fi", 0x081D),
1384 LANG(
"Tamil",
"ta", 0x0449),
1385 LANG(
"Tatar",
"tt", 0X0444),
1386 LANG(
"Thai",
"th", 0x041E),
1387 LANG(
"Turkish",
"tr", 0x041F),
1388 LANG(
"Tsonga",
"ts", 0x0431),
1389 LANG(
"Ukrainian",
"uk", 0x0422),
1390 LANG(
"Urdu",
"ur", 0x0420),
1391 LANG(
"Uzbek - Cyrillic",
"uz_uz", 0x0843),
1392 LANG(
"Uzbek - Latin",
"uz_uz", 0x0443),
1393 LANG(
"Vietnamese",
"vi", 0x042A),
1394 LANG(
"Xhosa",
"xh", 0x0434),
1395 LANG(
"Yiddish",
"yi", 0x043D),
1396 LANG(
"Zulu",
"zu", 0x0435),
1397 LANG(NULL, NULL, 0x0),
1403 char search_string[64];
1407 locale = indi_setlocale(0, NULL);
1412 strncpy(search_string, locale,
sizeof(search_string));
1413 search_string[
sizeof(search_string) - 1] =
'\0';
1416 ptr = search_string;
1419 *ptr = tolower(*ptr);
1441 ptr = search_string;
1444 *ptr = tolower(*ptr);
hid_device * 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.
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
int HID_API_EXPORT hid_init(void)
Initialize the HIDAPI library.
void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
Get a string from a HID device, based on its string index.
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
Read an Input report from a HID device with timeout.
uint16_t get_usb_code_for_current_locale(void)
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
Get a feature report from a HID device.
hid_device *HID_API_EXPORT hid_open_path(const char *path)
Open a HID device by its path name.
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
void HID_API_EXPORT hid_close(hid_device *dev)
Close a HID device.
struct hid_device_info HID_API_EXPORT * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
Send a Feature report to the device.
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *dev)
Get a string describing the last error which occurred.
int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
Set the device handle to be non-blocking.
int HID_API_EXPORT hid_exit(void)
Finalize the HIDAPI library.
#define LANG(name, code, usb_code)
struct pthread_barrier pthread_barrier_t
#define HID_API_EXPORT_CALL
struct hid_device_ hid_device
const char *LIBUSB_CALL libusb_error_name(int errcode)
pthread_barrier_t barrier
int transfer_loop_finished
libusb_device_handle * device_handle
int input_ep_max_packet_size
struct input_report * input_reports
struct libusb_transfer * transfer
unsigned short product_id
struct hid_device_info * next
wchar_t * manufacturer_string
unsigned short release_number
unsigned short usage_page