Skip to content

Commit 9b44cd7

Browse files
committed
hidtest: print Bus Name
1 parent 45a4ba5 commit 9b44cd7

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

hidtest/test.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
5252
#endif
5353
//
5454

55+
const char *hid_bus_name(hid_bus_type bus_type) {
56+
static const char *const HidBusTypeName[] = {
57+
"Unknown",
58+
"USB",
59+
"Bluetooth",
60+
"I2C",
61+
"SPI",
62+
};
63+
64+
if ((int)bus_type < 0)
65+
bus_type = HID_API_BUS_UNKNOWN;
66+
if ((int)bus_type >= (int)(sizeof(HidBusTypeName) / sizeof(HidBusTypeName[0])))
67+
bus_type = HID_API_BUS_UNKNOWN;
68+
69+
return HidBusTypeName[bus_type];
70+
}
71+
5572
void print_device(struct hid_device_info *cur_dev) {
5673
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
5774
printf("\n");
@@ -60,7 +77,7 @@ void print_device(struct hid_device_info *cur_dev) {
6077
printf(" Release: %hx\n", cur_dev->release_number);
6178
printf(" Interface: %d\n", cur_dev->interface_number);
6279
printf(" Usage (page): 0x%hx (0x%hx)\n", cur_dev->usage, cur_dev->usage_page);
63-
printf(" Bus type: %d\n", cur_dev->bus_type);
80+
printf(" Bus type: %d (%s)\n", cur_dev->bus_type, hid_bus_name(cur_dev->bus_type));
6481
printf("\n");
6582
}
6683

0 commit comments

Comments
 (0)