60 #define LOG(...) fprintf(stderr, __VA_ARGS__)
69 #define DETACH_KERNEL_DRIVER
82 #define INVASIVE_GET_USAGE
126 static libusb_context *usb_context = NULL;
129 static int return_data(
hid_device *dev,
unsigned char *
data,
size_t length);
136 pthread_mutex_init(&dev->
mutex, NULL);
137 pthread_cond_init(&dev->
condition, NULL);
138 pthread_barrier_init(&dev->
barrier, NULL, 2);
146 pthread_barrier_destroy(&dev->
barrier);
148 pthread_mutex_destroy(&dev->
mutex);
162 #ifdef INVASIVE_GET_USAGE
165 static uint32_t get_bytes(uint8_t *rpt,
size_t len,
size_t num_bytes,
size_t cur)
168 if (cur + num_bytes >=
len)
173 else if (num_bytes == 1)
177 else if (num_bytes == 2)
179 return (rpt[cur + 2] * 256 + rpt[cur + 1]);
181 else if (num_bytes == 4)
183 return (rpt[cur + 4] * 0x01000000 + rpt[cur + 3] * 0x00010000 + rpt[cur + 2] * 0x00000100 +
184 rpt[cur + 1] * 0x00000001);
194 static int get_usage(uint8_t *report_descriptor,
size_t size,
unsigned short *usage_page,
unsigned short *usage)
198 int data_len, key_size;
199 int usage_found = 0, usage_page_found = 0;
203 int key = report_descriptor[i];
204 int key_cmd =
key & 0xfc;
208 if ((key & 0xf0) == 0xf0)
215 data_len = report_descriptor[i + 1];
227 size_code =
key & 0x3;
233 data_len = size_code;
248 *usage_page = get_bytes(report_descriptor, size, data_len, i);
249 usage_page_found = 1;
254 *usage = get_bytes(report_descriptor, size, data_len, i);
259 if (usage_page_found && usage_found)
263 i += data_len + key_size;
272 static uint16_t get_first_language(libusb_device_handle *dev)
278 len = libusb_get_string_descriptor(dev, 0x0,
280 (
unsigned char *)buf,
sizeof(buf));
287 static int is_language_supported(libusb_device_handle *dev, uint16_t lang)
294 len = libusb_get_string_descriptor(dev, 0x0,
296 (
unsigned char *)buf,
sizeof(buf));
302 for (i = 1; i <
len; i++)
314 static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
332 if (!is_language_supported(dev, lang))
333 lang = get_first_language(dev);
336 len = libusb_get_string_descriptor(dev, idx, lang, (
unsigned char *)buf,
sizeof(buf));
344 ic = iconv_open(
"WCHAR_T",
"UTF-16LE");
345 if (ic == (iconv_t)-1)
347 LOG(
"iconv_open() failed\n");
355 outptr = (
char *)wbuf;
356 outbytes =
sizeof(wbuf);
357 res = iconv(ic, &inptr, &inbytes, &outptr, &outbytes);
358 if (res == (
size_t)-1)
360 LOG(
"iconv() failed\n");
365 wbuf[
sizeof(wbuf) /
sizeof(wbuf[0]) - 1] = 0x00000000;
366 if (outbytes >=
sizeof(wbuf[0]))
367 *((
wchar_t *)outptr) = 0x00000000;
378 static char *make_path(libusb_device *dev,
int interface_number)
381 snprintf(str,
sizeof(str),
"%04x:%04x:%02x", libusb_get_bus_number(dev), libusb_get_device_address(dev),
383 str[
sizeof(str) - 1] =
'\0';
395 if (libusb_init(&usb_context))
399 locale = indi_setlocale(LC_CTYPE, NULL);
411 libusb_exit(usb_context);
420 libusb_device **devs;
422 libusb_device_handle *handle;
433 num_devs = libusb_get_device_list(usb_context, &devs);
437 while ((dev = devs[i++]) != NULL)
439 struct libusb_device_descriptor desc;
440 struct libusb_config_descriptor *conf_desc = NULL;
442 int interface_num = 0;
444 int res = libusb_get_device_descriptor(dev, &desc);
445 unsigned short dev_vid = desc.idVendor;
446 unsigned short dev_pid = desc.idProduct;
449 if (desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE)
452 res = libusb_get_active_config_descriptor(dev, &conf_desc);
454 libusb_get_config_descriptor(dev, 0, &conf_desc);
457 for (j = 0; j < conf_desc->bNumInterfaces; j++)
459 const struct libusb_interface *intf = &conf_desc->interface[j];
460 for (k = 0; k < intf->num_altsetting; k++)
462 const struct libusb_interface_descriptor *intf_desc;
463 intf_desc = &intf->altsetting[k];
464 if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID)
466 interface_num = intf_desc->bInterfaceNumber;
469 if ((vendor_id == 0x0 && product_id == 0x0) || (vendor_id == dev_vid && product_id == dev_pid))
486 cur_dev->
next = NULL;
487 cur_dev->
path = make_path(dev, interface_num);
489 res = libusb_open(dev, &handle);
494 if (desc.iSerialNumber > 0)
495 cur_dev->
serial_number = get_usb_string(handle, desc.iSerialNumber);
498 if (desc.iManufacturer > 0)
500 if (desc.iProduct > 0)
503 #ifdef INVASIVE_GET_USAGE
519 unsigned char data[256];
520 #ifdef DETACH_KERNEL_DRIVER
523 res = libusb_kernel_driver_active(handle, interface_num);
526 res = libusb_detach_kernel_driver(handle, interface_num);
528 LOG(
"Couldn't detach kernel driver, even though a kernel driver was attached.");
533 res = libusb_claim_interface(handle, interface_num);
537 res = libusb_control_transfer(
538 handle, LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE,
539 LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8) | interface_num, 0, data,
543 unsigned short page = 0,
usage = 0;
546 get_usage(data, res, &page, &
usage);
551 LOG(
"libusb_control_transfer() for getting the HID report failed with %d\n",
555 res = libusb_release_interface(handle, interface_num);
557 LOG(
"Can't release the interface.\n");
560 LOG(
"Can't claim interface %d\n", res);
561 #ifdef DETACH_KERNEL_DRIVER
565 res = libusb_attach_kernel_driver(handle, interface_num);
567 LOG(
"Couldn't re-attach kernel driver.\n");
573 libusb_close(handle);
588 libusb_free_config_descriptor(conf_desc);
592 libusb_free_device_list(devs, 1);
615 const char *path_to_open = NULL;
628 path_to_open = cur_dev->
path;
634 path_to_open = cur_dev->
path;
638 cur_dev = cur_dev->
next;
652 static void read_callback(
struct libusb_transfer *transfer)
657 if (transfer->status == LIBUSB_TRANSFER_COMPLETED)
660 rpt->
data = malloc(transfer->actual_length);
661 memcpy(rpt->
data, transfer->buffer, transfer->actual_length);
662 rpt->
len = transfer->actual_length;
665 pthread_mutex_lock(&dev->
mutex);
679 while (cur->
next != NULL)
691 return_data(dev, NULL, 0);
694 pthread_mutex_unlock(&dev->
mutex);
696 else if (transfer->status == LIBUSB_TRANSFER_CANCELLED)
701 else if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE)
706 else if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT)
716 res = libusb_submit_transfer(transfer);
724 static void *read_thread(
void *param)
731 buf = malloc(length);
732 dev->
transfer = libusb_alloc_transfer(0);
738 libusb_submit_transfer(dev->
transfer);
741 pthread_barrier_wait(&dev->
barrier);
747 res = libusb_handle_events(usb_context);
754 if (res != LIBUSB_ERROR_BUSY && res != LIBUSB_ERROR_TIMEOUT && res != LIBUSB_ERROR_OVERFLOW &&
755 res != LIBUSB_ERROR_INTERRUPTED)
764 if (libusb_cancel_transfer(dev->
transfer) == 0)
767 libusb_handle_events(usb_context);
775 pthread_mutex_lock(&dev->
mutex);
777 pthread_mutex_unlock(&dev->
mutex);
794 dev = new_hid_device();
796 libusb_device **devs;
797 libusb_device *usb_dev;
805 num_devs = libusb_get_device_list(usb_context, &devs);
809 while ((usb_dev = devs[d++]) != NULL)
811 struct libusb_device_descriptor desc;
812 struct libusb_config_descriptor *conf_desc = NULL;
814 libusb_get_device_descriptor(usb_dev, &desc);
816 if (libusb_get_active_config_descriptor(usb_dev, &conf_desc) < 0)
818 for (j = 0; j < conf_desc->bNumInterfaces; j++)
820 const struct libusb_interface *intf = &conf_desc->interface[j];
821 for (k = 0; k < intf->num_altsetting; k++)
823 const struct libusb_interface_descriptor *intf_desc;
824 intf_desc = &intf->altsetting[k];
825 if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID)
827 char *dev_path = make_path(usb_dev, intf_desc->bInterfaceNumber);
828 if (!strcmp(dev_path, path))
841 #ifdef DETACH_KERNEL_DRIVER
844 if (libusb_kernel_driver_active(dev->
device_handle, intf_desc->bInterfaceNumber) == 1)
846 res = libusb_detach_kernel_driver(dev->
device_handle, intf_desc->bInterfaceNumber);
857 res = libusb_claim_interface(dev->
device_handle, intf_desc->bInterfaceNumber);
860 LOG(
"can't claim interface %d: %d %s\n", intf_desc->bInterfaceNumber, res,
libusb_error_name(res));
873 dev->
interface = intf_desc->bInterfaceNumber;
877 for (i = 0; i < intf_desc->bNumEndpoints; i++)
879 const struct libusb_endpoint_descriptor *ep = &intf_desc->endpoint[i];
884 (ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_INTERRUPT;
885 int is_output = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT;
886 int is_input = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN;
902 pthread_create(&dev->
thread, NULL, read_thread, dev);
905 pthread_barrier_wait(&dev->
barrier);
911 libusb_free_config_descriptor(conf_desc);
914 libusb_free_device_list(devs, 1);
924 free_hid_device(dev);
932 int report_number = data[0];
933 int skipped_report_id = 0;
935 if (report_number == 0x0)
939 skipped_report_id = 1;
946 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
947 0x09 , (2 << 8) | report_number, dev->
interface,
948 (
unsigned char *)data, length, 1000 );
953 if (skipped_report_id)
963 &actual_length, 1000);
968 if (skipped_report_id)
971 return actual_length;
977 static int return_data(
hid_device *dev,
unsigned char *data,
size_t length)
982 size_t len = (length < rpt->
len) ? length : rpt->
len;
991 static void cleanup_mutex(
void *param)
994 pthread_mutex_unlock(&dev->
mutex);
999 volatile int bytes_read = 0;
1004 LOG(
"transferred: %d\n", transferred);
1008 pthread_mutex_lock(&dev->
mutex);
1009 pthread_cleanup_push(&cleanup_mutex, dev);
1015 bytes_read = return_data(dev,
data, length);
1027 if (milliseconds == -1)
1036 bytes_read = return_data(dev,
data, length);
1039 else if (milliseconds > 0)
1044 clock_gettime(CLOCK_REALTIME, &ts);
1045 ts.tv_sec += milliseconds / 1000;
1046 ts.tv_nsec += (milliseconds % 1000) * 1000000;
1047 if (ts.tv_nsec >= 1000000000L)
1050 ts.tv_nsec -= 1000000000L;
1060 bytes_read = return_data(dev, data, length);
1068 else if (res == ETIMEDOUT)
1089 pthread_mutex_unlock(&dev->
mutex);
1090 pthread_cleanup_pop(0);
1110 int skipped_report_id = 0;
1111 int report_number = data[0];
1113 if (report_number == 0x0)
1117 skipped_report_id = 1;
1121 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
1122 0x09 , (3 << 8) | report_number, dev->
interface,
1123 (
unsigned char *)data, length, 1000 );
1129 if (skipped_report_id)
1138 int skipped_report_id = 0;
1139 int report_number = data[0];
1141 if (report_number == 0x0)
1147 skipped_report_id = 1;
1150 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN,
1151 0x01 , (3 << 8) | report_number, dev->
interface,
1152 (
unsigned char *)data, length, 1000 );
1157 if (skipped_report_id)
1170 libusb_cancel_transfer(dev->
transfer);
1173 pthread_join(dev->
thread, NULL);
1177 libusb_free_transfer(dev->
transfer);
1186 pthread_mutex_lock(&dev->
mutex);
1189 return_data(dev, NULL, 0);
1191 pthread_mutex_unlock(&dev->
mutex);
1193 free_hid_device(dev);
1218 wcsncpy(
string, str, maxlen);
1219 string[maxlen - 1] = L
'\0';
1240 #define LANG(name, code, usb_code) \
1242 name, code, usb_code \
1245 LANG(
"Afrikaans",
"af", 0x0436),
1246 LANG(
"Albanian",
"sq", 0x041C),
1247 LANG(
"Arabic - United Arab Emirates",
"ar_ae", 0x3801),
1248 LANG(
"Arabic - Bahrain",
"ar_bh", 0x3C01),
1249 LANG(
"Arabic - Algeria",
"ar_dz", 0x1401),
1250 LANG(
"Arabic - Egypt",
"ar_eg", 0x0C01),
1251 LANG(
"Arabic - Iraq",
"ar_iq", 0x0801),
1252 LANG(
"Arabic - Jordan",
"ar_jo", 0x2C01),
1253 LANG(
"Arabic - Kuwait",
"ar_kw", 0x3401),
1254 LANG(
"Arabic - Lebanon",
"ar_lb", 0x3001),
1255 LANG(
"Arabic - Libya",
"ar_ly", 0x1001),
1256 LANG(
"Arabic - Morocco",
"ar_ma", 0x1801),
1257 LANG(
"Arabic - Oman",
"ar_om", 0x2001),
1258 LANG(
"Arabic - Qatar",
"ar_qa", 0x4001),
1259 LANG(
"Arabic - Saudi Arabia",
"ar_sa", 0x0401),
1260 LANG(
"Arabic - Syria",
"ar_sy", 0x2801),
1261 LANG(
"Arabic - Tunisia",
"ar_tn", 0x1C01),
1262 LANG(
"Arabic - Yemen",
"ar_ye", 0x2401),
1263 LANG(
"Armenian",
"hy", 0x042B),
1264 LANG(
"Azeri - Latin",
"az_az", 0x042C),
1265 LANG(
"Azeri - Cyrillic",
"az_az", 0x082C),
1266 LANG(
"Basque",
"eu", 0x042D),
1267 LANG(
"Belarusian",
"be", 0x0423),
1268 LANG(
"Bulgarian",
"bg", 0x0402),
1269 LANG(
"Catalan",
"ca", 0x0403),
1270 LANG(
"Chinese - China",
"zh_cn", 0x0804),
1271 LANG(
"Chinese - Hong Kong SAR",
"zh_hk", 0x0C04),
1272 LANG(
"Chinese - Macau SAR",
"zh_mo", 0x1404),
1273 LANG(
"Chinese - Singapore",
"zh_sg", 0x1004),
1274 LANG(
"Chinese - Taiwan",
"zh_tw", 0x0404),
1275 LANG(
"Croatian",
"hr", 0x041A),
1276 LANG(
"Czech",
"cs", 0x0405),
1277 LANG(
"Danish",
"da", 0x0406),
1278 LANG(
"Dutch - Netherlands",
"nl_nl", 0x0413),
1279 LANG(
"Dutch - Belgium",
"nl_be", 0x0813),
1280 LANG(
"English - Australia",
"en_au", 0x0C09),
1281 LANG(
"English - Belize",
"en_bz", 0x2809),
1282 LANG(
"English - Canada",
"en_ca", 0x1009),
1283 LANG(
"English - Caribbean",
"en_cb", 0x2409),
1284 LANG(
"English - Ireland",
"en_ie", 0x1809),
1285 LANG(
"English - Jamaica",
"en_jm", 0x2009),
1286 LANG(
"English - New Zealand",
"en_nz", 0x1409),
1287 LANG(
"English - Phillippines",
"en_ph", 0x3409),
1288 LANG(
"English - Southern Africa",
"en_za", 0x1C09),
1289 LANG(
"English - Trinidad",
"en_tt", 0x2C09),
1290 LANG(
"English - Great Britain",
"en_gb", 0x0809),
1291 LANG(
"English - United States",
"en_us", 0x0409),
1292 LANG(
"Estonian",
"et", 0x0425),
1293 LANG(
"Farsi",
"fa", 0x0429),
1294 LANG(
"Finnish",
"fi", 0x040B),
1295 LANG(
"Faroese",
"fo", 0x0438),
1296 LANG(
"French - France",
"fr_fr", 0x040C),
1297 LANG(
"French - Belgium",
"fr_be", 0x080C),
1298 LANG(
"French - Canada",
"fr_ca", 0x0C0C),
1299 LANG(
"French - Luxembourg",
"fr_lu", 0x140C),
1300 LANG(
"French - Switzerland",
"fr_ch", 0x100C),
1301 LANG(
"Gaelic - Ireland",
"gd_ie", 0x083C),
1302 LANG(
"Gaelic - Scotland",
"gd", 0x043C),
1303 LANG(
"German - Germany",
"de_de", 0x0407),
1304 LANG(
"German - Austria",
"de_at", 0x0C07),
1305 LANG(
"German - Liechtenstein",
"de_li", 0x1407),
1306 LANG(
"German - Luxembourg",
"de_lu", 0x1007),
1307 LANG(
"German - Switzerland",
"de_ch", 0x0807),
1308 LANG(
"Greek",
"el", 0x0408),
1309 LANG(
"Hebrew",
"he", 0x040D),
1310 LANG(
"Hindi",
"hi", 0x0439),
1311 LANG(
"Hungarian",
"hu", 0x040E),
1312 LANG(
"Icelandic",
"is", 0x040F),
1313 LANG(
"Indonesian",
"id", 0x0421),
1314 LANG(
"Italian - Italy",
"it_it", 0x0410),
1315 LANG(
"Italian - Switzerland",
"it_ch", 0x0810),
1316 LANG(
"Japanese",
"ja", 0x0411),
1317 LANG(
"Korean",
"ko", 0x0412),
1318 LANG(
"Latvian",
"lv", 0x0426),
1319 LANG(
"Lithuanian",
"lt", 0x0427),
1320 LANG(
"F.Y.R.O. Macedonia",
"mk", 0x042F),
1321 LANG(
"Malay - Malaysia",
"ms_my", 0x043E),
1322 LANG(
"Malay - Brunei",
"ms_bn", 0x083E),
1323 LANG(
"Maltese",
"mt", 0x043A),
1324 LANG(
"Marathi",
"mr", 0x044E),
1325 LANG(
"Norwegian - Bokml",
"no_no", 0x0414),
1326 LANG(
"Norwegian - Nynorsk",
"no_no", 0x0814),
1327 LANG(
"Polish",
"pl", 0x0415),
1328 LANG(
"Portuguese - Portugal",
"pt_pt", 0x0816),
1329 LANG(
"Portuguese - Brazil",
"pt_br", 0x0416),
1330 LANG(
"Raeto-Romance",
"rm", 0x0417),
1331 LANG(
"Romanian - Romania",
"ro", 0x0418),
1332 LANG(
"Romanian - Republic of Moldova",
"ro_mo", 0x0818),
1333 LANG(
"Russian",
"ru", 0x0419),
1334 LANG(
"Russian - Republic of Moldova",
"ru_mo", 0x0819),
1335 LANG(
"Sanskrit",
"sa", 0x044F),
1336 LANG(
"Serbian - Cyrillic",
"sr_sp", 0x0C1A),
1337 LANG(
"Serbian - Latin",
"sr_sp", 0x081A),
1338 LANG(
"Setsuana",
"tn", 0x0432),
1339 LANG(
"Slovenian",
"sl", 0x0424),
1340 LANG(
"Slovak",
"sk", 0x041B),
1341 LANG(
"Sorbian",
"sb", 0x042E),
1342 LANG(
"Spanish - Spain (Traditional)",
"es_es", 0x040A),
1343 LANG(
"Spanish - Argentina",
"es_ar", 0x2C0A),
1344 LANG(
"Spanish - Bolivia",
"es_bo", 0x400A),
1345 LANG(
"Spanish - Chile",
"es_cl", 0x340A),
1346 LANG(
"Spanish - Colombia",
"es_co", 0x240A),
1347 LANG(
"Spanish - Costa Rica",
"es_cr", 0x140A),
1348 LANG(
"Spanish - Dominican Republic",
"es_do", 0x1C0A),
1349 LANG(
"Spanish - Ecuador",
"es_ec", 0x300A),
1350 LANG(
"Spanish - Guatemala",
"es_gt", 0x100A),
1351 LANG(
"Spanish - Honduras",
"es_hn", 0x480A),
1352 LANG(
"Spanish - Mexico",
"es_mx", 0x080A),
1353 LANG(
"Spanish - Nicaragua",
"es_ni", 0x4C0A),
1354 LANG(
"Spanish - Panama",
"es_pa", 0x180A),
1355 LANG(
"Spanish - Peru",
"es_pe", 0x280A),
1356 LANG(
"Spanish - Puerto Rico",
"es_pr", 0x500A),
1357 LANG(
"Spanish - Paraguay",
"es_py", 0x3C0A),
1358 LANG(
"Spanish - El Salvador",
"es_sv", 0x440A),
1359 LANG(
"Spanish - Uruguay",
"es_uy", 0x380A),
1360 LANG(
"Spanish - Venezuela",
"es_ve", 0x200A),
1361 LANG(
"Southern Sotho",
"st", 0x0430),
1362 LANG(
"Swahili",
"sw", 0x0441),
1363 LANG(
"Swedish - Sweden",
"sv_se", 0x041D),
1364 LANG(
"Swedish - Finland",
"sv_fi", 0x081D),
1365 LANG(
"Tamil",
"ta", 0x0449),
1366 LANG(
"Tatar",
"tt", 0X0444),
1367 LANG(
"Thai",
"th", 0x041E),
1368 LANG(
"Turkish",
"tr", 0x041F),
1369 LANG(
"Tsonga",
"ts", 0x0431),
1370 LANG(
"Ukrainian",
"uk", 0x0422),
1371 LANG(
"Urdu",
"ur", 0x0420),
1372 LANG(
"Uzbek - Cyrillic",
"uz_uz", 0x0843),
1373 LANG(
"Uzbek - Latin",
"uz_uz", 0x0443),
1374 LANG(
"Vietnamese",
"vi", 0x042A),
1375 LANG(
"Xhosa",
"xh", 0x0434),
1376 LANG(
"Yiddish",
"yi", 0x043D),
1377 LANG(
"Zulu",
"zu", 0x0435),
1378 LANG(NULL, NULL, 0x0),
1384 char search_string[64];
1388 locale = indi_setlocale(0, NULL);
1393 strncpy(search_string, locale,
sizeof(search_string));
1394 search_string[
sizeof(search_string) - 1] =
'\0';
1397 ptr = search_string;
1400 *ptr = tolower(*ptr);
1422 ptr = search_string;
1425 *ptr = tolower(*ptr);
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
Read an Input report from a HID device.
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_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.
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 hid_device_info HID_API_EXPORT * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
#define HID_API_EXPORT_CALL
const char *LIBUSB_CALL libusb_error_name(int errcode)
@ key
the parser read a key of a value in an object
pthread_barrier_t barrier
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