howard/usbtools.c

87 lines
2.3 KiB
C
Raw Permalink Normal View History

2021-11-27 16:58:52 +11:00
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <hidapi.h>
#define MAX_STR 255
int main(int argc, char* argv[])
{
//unsigned char buf[65];
//wchar_t wstr[MAX_STR];
//hid_device *handle;
struct hid_device_info *alldevs, *dev;
if (hid_init()) {
printf("Error initialising hidapi.");
exit(1);
}
alldevs = hid_enumerate(0x0, 0x0);
for (dev=alldevs; dev; dev = dev->next) {
printf("path: %s\n", dev->path);
printf(" Manufacturer: %ls\n", dev->manufacturer_string);
printf(" Vendor ID: %04hx\n", dev->vendor_id);
printf(" Product: %ls (%04hx)\n", dev->product_string, dev->product_id);
printf(" Serial: %ls\n", dev->serial_number);
printf(" Release: %hx\n", dev->release_number);
printf(" Interface: %d\n", dev->interface_number);
printf(" Usage (page): 0x%hx (0x%hx)\n", dev->usage, dev->usage_page);
printf("\n");
}
hid_exit();
return 0;
}
/*
// Initialize the hidapi library
res = hid_init();
// Open the device using the VID, PID,
// and optionally the Serial number.
handle = hid_open(0x4d8, 0x3f, NULL);
// Read the Manufacturer String
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
wprintf(L"Manufacturer String: %s\n", wstr);
// Read the Product String
res = hid_get_product_string(handle, wstr, MAX_STR);
wprintf(L"Product String: %s\n", wstr);
// Read the Serial Number String
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);
// Read Indexed String 1
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
wprintf(L"Indexed String 1: %s\n", wstr);
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
buf[0] = 0x0;
buf[1] = 0x80;
res = hid_write(handle, buf, 65);
// Request state (cmd 0x81). The first byte is the report number (0x0).
buf[0] = 0x0;
buf[1] = 0x81;
res = hid_write(handle, buf, 65);
// Read requested state
res = hid_read(handle, buf, 65);
// Print out the returned buffer.
for (i = 0; i < 4; i++)
printf("buf[%d]: %d\n", i, buf[i]);
// Close the device
hid_close(handle);
// Finalize the hidapi library
res = hid_exit();
*/