hidapi
hidapi copied to clipboard
Add hid_get_device_info
Resolves: #431 Closes: #164 Closes: #163
I don't like the signature of get_device_info_for_device
in linux, and Im unsure about fill_device_info_for_device
in libusb.
The mac, linux and libusb implementations appear to work fine with hidtest. I havent tested the other backends yet
lets have it against a feature branch for now: https://github.com/libusb/hidapi/tree/hid_get_device_info
This could replace #164, as it will be possible to get the path from the device_info struct. I can see there you were wondering about lazily initialising the path. Would you want that to be done here? It doesnt look like it would be too hard to do for most backends. It looks like the only extra data some backends may need is the path. Nothing too bad to persist until the device_info is generated
Would you want that to be done here?
Yes, lazy initialization of the device info should be beneficial, specially for those who never use it.
Would you want that to be done here?
Yes, lazy initialization of the device info should be beneficial, specially for those who never use it.
The calls to get the serial number and other strings are now all copying off the device_info, so I would guess it to be rare that it won't get loaded, but I have no problem making it lazy and caching it
Rebase to master, when you have a chance - got some conflicting changes in there.
Mac Mini M1 (macOS 12.4) output. The output seems to be fine.
mcuee@mcuees-Mac-mini hidapi_pr432 % ./build_darwin/hidtest/hidtest
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 0000 0000
path: DevSrvsID:4294969138
serial_number:
Manufacturer: Apple
Product:
Release: 0
Interface: -1
Usage (page): 0xff (0xff00)
Device Found
type: 1915 1025
path: DevSrvsID:4294969659
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 3
Usage (page): 0x2 (0x1)
Device Found
type: 1915 1025
path: DevSrvsID:4294969659
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 3
Usage (page): 0x1 (0x1)
Device Found
type: 1915 1025
path: DevSrvsID:4294969659
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 3
Usage (page): 0x1 (0xc)
Device Found
type: 1915 1025
path: DevSrvsID:4294969659
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 3
Usage (page): 0x80 (0x1)
Device Found
type: 1915 1025
path: DevSrvsID:4294969659
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 3
Usage (page): 0x0 (0xff00)
Device Found
type: 1915 1025
path: DevSrvsID:4294969661
serial_number:
Manufacturer: ZY.Ltd
Product: ZY Control Mic
Release: 173
Interface: 2
Usage (page): 0x6 (0x1)
Device Found
type: 045e 082f
path: DevSrvsID:4294969867
serial_number: 734762612322
Manufacturer: Microsoft
Product: Microsoft Bluetooth Mouse
Release: 212
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 045e 082f
path: DevSrvsID:4294969867
serial_number: 734762612322
Manufacturer: Microsoft
Product: Microsoft Bluetooth Mouse
Release: 212
Interface: -1
Usage (page): 0x1 (0x1)
Device Found
type: 045e 082f
path: DevSrvsID:4294969867
serial_number: 734762612322
Manufacturer: Microsoft
Product: Microsoft Bluetooth Mouse
Release: 212
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 045e 082f
path: DevSrvsID:4294969867
serial_number: 734762612322
Manufacturer: Microsoft
Product: Microsoft Bluetooth Mouse
Release: 212
Interface: -1
Usage (page): 0x212 (0xff07)
Device Found
type: 046d b33d
path: DevSrvsID:4294969883
serial_number: f4-73-35-4b-c5-aa
Manufacturer: Unknown
Product: Keyboard K480
Release: 2803
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 046d b33d
path: DevSrvsID:4294969883
serial_number: f4-73-35-4b-c5-aa
Manufacturer: Unknown
Product: Keyboard K480
Release: 2803
Interface: -1
Usage (page): 0x1 (0xc)
Device Found
type: 046d b33d
path: DevSrvsID:4294969883
serial_number: f4-73-35-4b-c5-aa
Manufacturer: Unknown
Product: Keyboard K480
Release: 2803
Interface: -1
Usage (page): 0x80 (0x1)
Device Found
type: 046d b33d
path: DevSrvsID:4294969883
serial_number: f4-73-35-4b-c5-aa
Manufacturer: Unknown
Product: Keyboard K480
Release: 2803
Interface: -1
Usage (page): 0x1 (0xff00)
Device Found
type: 046d b33d
path: DevSrvsID:4294969883
serial_number: f4-73-35-4b-c5-aa
Manufacturer: Unknown
Product: Keyboard K480
Release: 2803
Interface: -1
Usage (page): 0x2 (0xff00)
Device Found
type: 0000 0000
path: DevSrvsID:4294968515
serial_number:
Manufacturer: Apple
Product: Headset
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Device Found
type: 0000 0000
path: DevSrvsID:4294968878
serial_number:
Manufacturer: APPL
Product: BTM
Release: 0
Interface: -1
Usage (page): 0x48 (0xff00)
unable to open device
Windows MSYS2 mingw64 output. Seems to be fine.
MINGW64 /c/work/libusb/hidapi_pr432
$ ./build_mingw64/hidtest/hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 8087 0a1e
path: \\?\HID#INTC816#3&d2322f2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 200
Interface: -1
Usage (page): 0xd (0x1)
Device Found
type: 06cb cd40
path: \\?\HID#SYNA7DAB&Col01#5&2f64dfea&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 501
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 06cb cd40
path: \\?\HID#SYNA7DAB&Col02#5&2f64dfea&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 501
Interface: -1
Usage (page): 0x5 (0xd)
Device Found
type: 06cb cd40
path: \\?\HID#SYNA7DAB&Col03#5&2f64dfea&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 501
Interface: -1
Usage (page): 0xe (0xd)
Device Found
type: 06cb cd40
path: \\?\HID#SYNA7DAB&Col04#5&2f64dfea&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 501
Interface: -1
Usage (page): 0x1 (0xff00)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_01&Col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x2 (0x1)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col02#5&32cf90e6&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_01&Col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x1 (0xc)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col03#5&32cf90e6&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x80 (0x1)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_01&Col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x80 (0x1)
Device Found
type: deed feed
path: \\?\HID#10251229#3&9d5d338&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Acer Inc
Product: Acer Airplane Mode Controller
Release: 101
Interface: -1
Usage (page): 0xc (0x1)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col01#5&32cf90e6&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_01&Col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x88 (0xffbc)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_02&Col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x1 (0xff00)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_02&Col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x2 (0xff00)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_02&Col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x4 (0xff00)
Device Found
type: 046d c52b
path: \\?\HID#VID_046D&PID_C52B&MI_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x6 (0x1)
unable to open device
@Julusian do you consider this as still a draft?
Sorry, I got distracted on other things Yeah I am happy with this. I havent made it lazy initialize yet though
@mcuee you haven't really tested my changes much there. You have for the refactoring, but the unable to open device
at the end means that it didnt open a device and use the new method
Sorry, I got distracted on other things Yeah I am happy with this. I havent made it lazy initialize yet though
@mcuee you haven't really tested my changes much there. You have for the refactoring, but the
unable to open device
at the end means that it didnt open a device and use the new method
I see. Unfortunately the one used in hidtest is not a common device but rather a modified Microchip generic HID FW example from Alan Ott. So maybe I need to use other codes to test this pull request.
Will hidapitester be good enought?
I see. Unfortunately the one used in hidtest is not a common device but rather a modified Microchip generic HID FW example from Alan Ott. So maybe I need to use other programms to test this pull request.
I have been changing the ids to be for a device I have, then stopping the application when it starts on the read/write tests
I see. Unfortunately the one used in hidtest is not a common device but rather a modified Microchip generic HID FW example from Alan Ott. So maybe I need to use other programms to test this pull request.
I have been changing the ids to be for a device I have, then stopping the application when it starts on the read/write tests
This is the output from my Microchip Custom Demo (original Microchip FW). It is probably good enough for this testing.
...
PS C:\work\libusb\hidapi_pr432> .\build_mingw64\hidtest\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
....
...
...
Device Found
type: 04d8 003f
path: \\?\HID#VID_04D8&PID_003F#7&aebbb81&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: -1
Usage (page): 0x1 (0xff00)
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (0)
Device Found
type: 04d8 003f
path: \\?\HID#VID_04D8&PID_003F#7&aebbb81&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: -1
Usage (page): 0x1 (0xff00)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report.
Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.Data read:
81 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Press any key to continue . . .
Output under Linux.
mcuee@UbuntuSwift3:~/build/hidapi_pr432$ sudo ./build_linux/hidtest/hidtest_hidraw
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 04d8 003f
path: /dev/hidraw3
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
....
....
....
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (0)
Device Found
type: 04d8 003f
path: /dev/hidraw3
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Unable to read indexed string 1
Indexed String 1:
Unable to send a feature report.
Unable to get a feature report.
ioctl (GFEATURE): Broken pipewaiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
^C
mcuee@UbuntuSwift3:~/build/hidapi_pr432$ sudo ./build_linux/hidtest/hidtest_libusb
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.1
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.2
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x0 (0x0)
Device Found
type: 04d8 003f
path: 3-2.3:1.0
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x0 (0x0)
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (1033)
Device Found
type: 04d8 003f
path: 3-2.3:1.0
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x0 (0x0)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report.
hid_error is not implemented yetwaiting...
waiting...
waiting...
waiting...
waiting...
^C
Output under macOS 12.4 (Mac Mini M1 2020).
mcuee@mcuees-Mac-mini hidapi_pr432 % ./build_darwin/hidtest/hidtest
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
...
...
Device Found
type: 04d8 003f
path: DevSrvsID:4294969665
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
...
...
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (0)
Device Found
type: 04d8 003f
path: DevSrvsID:4294969665
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Indexed String 1:
Unable to send a feature report.
Unable to get a feature report.
hid_error is not implemented yetwaiting...
waiting...
waiting...
waiting...
waiting...
waiting...
^C
I have been changing the ids to be for a device I have, then stopping the application when it starts on the read/write tests
Good idea. So I just modified test.c to open different device.
Here is the output for Logitech Bluetooth mouse.
...
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col02#8&1cf1c1b9&5&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Manufacturer String: Logitech
Product String: Logitech Bluetooth Wireless Mouse
Serial Number String: (51) 34885dab0c12
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col03#8&1cf1c1b9&5&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x1 (0xff00)
Indexed String 1: Bluetooth Mouse
Press any key to continue . . .
For Logitech USB Receiver:
C:\work\hid\hidapi_pr432\windows\x64\Release [feat/hid_get_device_info ≡ +0 ~1 -0 !]> .\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col03#8&1cf1c1b9&5&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x1 (0xff00)
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col04#8&1cf1c1b9&5&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x2 (0xff00)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col03#7&7e9f97e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x80 (0x1)
Device Found
type: 0488 121f
path: \\?\HID#DELL091A&Col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 40d
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col05#8&1cf1c1b9&5&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col06#8&1cf1c1b9&5&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Device Found
type: 8087 0a1e
path: \\?\HID#INTC816&Col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 200
Interface: -1
Usage (page): 0xc (0x1)
Device Found
type: 044e 1212
path: \\?\HID#Vid_044E&Pid_1212&Col01&Col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 8087 0a1e
path: \\?\HID#INTC816&Col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 200
Interface: -1
Usage (page): 0xd (0x1)
Device Found
type: 044e 1212
path: \\?\HID#Vid_044E&Pid_1212&Col01&Col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col04#7&7e9f97e&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x1 (0xff00)
Device Found
type: 0488 121f
path: \\?\HID#DELL091A&Col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 40d
Interface: -1
Usage (page): 0x5 (0xd)
Device Found
type: 413c b06e
path: \\?\HID#VID_413C&PID_B06E#c&37ff1248&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 101
Interface: -1
Usage (page): 0xda (0xffda)
Device Found
type: 047f c056
path: \\?\HID#VID_047F&PID_C056&MI_03&Col01#f&39e6f119&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
Manufacturer: Plantronics
Product: Plantronics Blackwire 3220 Series
Release: 210
Interface: 3
Usage (page): 0x1 (0xc)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Device Found
type: 047f c056
path: \\?\HID#VID_047F&PID_C056&MI_03&Col02#f&39e6f119&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
Manufacturer: Plantronics
Product: Plantronics Blackwire 3220 Series
Release: 210
Interface: 3
Usage (page): 0x5 (0xb)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x80 (0x1)
Device Found
type: 047f c056
path: \\?\HID#VID_047F&PID_C056&MI_03&Col03#f&39e6f119&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
Manufacturer: Plantronics
Product: Plantronics Blackwire 3220 Series
Release: 210
Interface: 3
Usage (page): 0x3 (0xffa0)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col05#7&7e9f97e&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x2 (0xff00)
Device Found
type: 0488 121f
path: \\?\HID#DELL091A&Col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 40d
Interface: -1
Usage (page): 0x1 (0xff01)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_00#7&32158c2f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 0
Usage (page): 0x6 (0x1)
Device Found
type: 413c 2107
path: \\?\HID#VID_413C&PID_2107#e&1de7f0c0&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer: DELL
Product: Dell USB Entry Keyboard
Release: 178
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 0488 121f
path: \\?\HID#DELL091A&Col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 40d
Interface: -1
Usage (page): 0x1 (0xff02)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col01#7&7e9f97e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x2 (0x1)
Device Found
type: 046d c077
path: \\?\HID#VID_046D&PID_C077#e&fde55df&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Optical Mouse
Release: 7200
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 0488 121f
path: \\?\HID#DELL091A&Col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 9999
Manufacturer: Microsoft
Product: HIDI2C Device
Release: 40d
Interface: -1
Usage (page): 0xe (0xd)
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col01#8&1cf1c1b9&5&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x2 (0x1)
Device Found
type: 413c b06f
path: \\?\HID#VID_413C&PID_B06F#d&3624b04c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer:
Product:
Release: 101
Interface: -1
Usage (page): 0xda (0xffda)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col02#7&7e9f97e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x1 (0xc)
Device Found
type: 045e 0000
path: \\?\HID#ConvertedDevice&Col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\KBD
serial_number:
Manufacturer:
Product:
Release: 0
Interface: -1
Usage (page): 0x6 (0x1)
Device Found
type: 046d b010
path: \\?\HID#{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b010&Col02#8&1cf1c1b9&5&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number: 34885dab0c12
Manufacturer: Logitech
Product: Logitech Bluetooth Wireless Mouse
Release: 0
Interface: -1
Usage (page): 0x1 (0xc)
Manufacturer String: Logitech
Product String: USB Receiver
Serial Number String: (0)
Device Found
type: 046d c534
path: \\?\HID#VID_046D&PID_C534&MI_01&Col03#7&7e9f97e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x80 (0x1)
Indexed String 1: Logitech
Press any key to continue . . .
@Youw I think I am done on this now. I have made it lazy-load the device_info struct on linux&mac backends, both libusb and windows use some additional properties which arent persisted on the struct.
I'll have to find some time to go over it again to review. I'll try to do so shortly. Thanks for the contribution!
Windows and macOS is fine. Libusb and Hidraw - I see multuple improvements to perform before it is ready as far as I can tell.
@Julusian do you feel comfortable performing all changes as part of this PR? I could make a feature branch and accept changes there iteratively instead.
I think this is as far as I feel I can go on this myself.
The remaining couple of points are ones that I think need to be experimented with to see how close it can get to what you want, and consider the cost/benefit of the result. So this would probably be better to do separately.
Updated the implementation to have lazy initialisation for libusb backend.
During the refactoring, found a bug: hidapi_initialize_device
hasn't been filling up the device_info->interface_number
field.
With new implementation such kind of issues are eliminated.
Another libusb update: sorted out the "get usage_page/usage". It has to be handled differently during the enumeration and when the device is fully opened.
Now I'm happy with libusb implementation.
Since no one complains about my latest changes - either everything works as expecter or no one had a chance to look :)
@Youw The hidraw backend seems to have some issues with my Microchip Custom Demo device.
No issue with the libusb backend under Ubuntu 20.04.
mcuee@UbuntuSwift3:~/build/hidapi_pr432/build_linux$ ./hidtest/hidtest_libusb
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.1
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.2
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x0 (0x0)
Device Found
type: 04d8 003f
path: 3-2.3:1.0
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 16c0 05dc
path: 3-1:1.1
serial_number: 0001
Manufacturer: www.fischl.de
Product: USBasp
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (1033)
Device Found
type: 04d8 003f
path: 3-2.3:1.0
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report.
hid_error is not implemented yetwaiting...
waiting...
waiting...
waiting...
waiting...
^C
But there is no way to open the device using the hidraw backend. It can not even find the device after the above. Maybe it does not work with hidraw driver.
mcuee@UbuntuSwift3:~/build/hidapi_pr432/build_linux$ ./hidtest/hidtest_hidraw
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 16c0 05dc
path: /dev/hidraw1
serial_number: 0001
Manufacturer: www.fischl.de
Product: USBasp
Release: 110
Interface: 1
Usage (page): 0x1 (0xff00)
...
unable to open device
@Youw Sorry but the above is a false alarm. The libusb backend will detach the hidraw driver so that hidraw backend will not be able to find the device. There will be no issue running the hidtest-hidraw first.
mcuee@UbuntuSwift3:~/build/hidapi_pr432/build_linux$ sudo ./hidtest/hidtest_hidraw
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 16c0 05dc
path: /dev/hidraw1
serial_number: 0001
Manufacturer: www.fischl.de
Product: USBasp
Release: 110
Interface: 1
Usage (page): 0x1 (0xff00)
Device Found
type: 04d8 003f
path: /dev/hidraw4
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
...
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (0)
Device Found
type: 04d8 003f
path: /dev/hidraw4
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Unable to read indexed string 1
Indexed String 1:
Unable to send a feature report.
Unable to get a feature report.
ioctl (GFEATURE): Broken pipewaiting...
waiting...
waiting...
waiting...
waiting...
^C
Results of the Logitech USB Receiver under Linux.
mcuee@UbuntuSwift3:~/build/hidapi_pr432/build_linux$ sudo ./hidtest/hidtest_hidraw
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 16c0 05dc
path: /dev/hidraw1
serial_number: 0001
Manufacturer: www.fischl.de
Product: USBasp
Release: 110
Interface: 1
Usage (page): 0x1 (0xff00)
Device Found
type: 04d8 003f
path: /dev/hidraw4
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
...
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x1 (0xff00)
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x2 (0xff00)
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x4 (0xff00)
...
Manufacturer String: Logitech
Product String: USB Receiver
Serial Number String: (0)
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x1 (0xff00)
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x2 (0xff00)
Device Found
type: 046d c52b
path: /dev/hidraw2
serial_number:
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x4 (0xff00)
Unable to read indexed string 1
Indexed String 1:
Unable to send a feature report.
Unable to get a feature report.
ioctl (GFEATURE): Broken pipeUnable to write()
Error: Broken pipe
Unable to write() (2)
waiting...
waiting...
waiting...
waiting...
^C
mcuee@UbuntuSwift3:~/build/hidapi_pr432/build_linux$ ./hidtest/hidtest_libusb
hidapi test/example tool. Compiled with hidapi version 0.12.0, runtime version 0.12.0.
Compile-time version matches runtime version of hidapi.
Device Found
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.1
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 1
Usage (page): 0x0 (0x0)
Device Found
type: 046d c52b
path: 3-3:1.2
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 2
Usage (page): 0x0 (0x0)
Device Found
type: 04d8 003f
path: 3-2.3:1.0
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 16c0 05dc
path: 3-1:1.1
serial_number: 0001
Manufacturer: www.fischl.de
Product: USBasp
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)
Manufacturer String: Logitech
Product String: USB Receiver
Serial Number String: (1033)
Device Found
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x6 (0x1)
Indexed String 1: Logitech
Unable to send a feature report.
Unable to get a feature report.
hid_error is not implemented yetUnable to write()
Error: hid_error is not implemented yet
Unable to write() (2)
waiting...
waiting...
waiting...
waiting...
^C
The libusb backend will detach the hidraw driver so that hidraw backend will not be able to find the device.
That is actually unexpected. LIBUSB backed should have re-attach the kernel (hidraw) driver back, once the device is closed. Let me check.
Let me check.
As far as I can tell - the driver was reattached (otherwise you wouldn't be able to enumerate it with hidraw after libusb). Maybe there is adifferent issue - likely outside of this PR's scope.
There is an interesting side-effect/improvement in libusb backed:
Before this change, the only way to get (primary) usage_page/usage was to compile hidapi with INVASIVE_GET_USAGE
.
Now - it is possible to to get it with hid_get_device_info
with default compilation flags.
I.e. (default compilation flags):
hid_enumerate
:
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x0 (0x0)
hid_get_device_info
:
type: 046d c52b
path: 3-3:1.0
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 1203
Interface: 0
Usage (page): 0x6 (0x1)
~But that works only if device supports GET
LIBUSB_DT_REPORT
- which is not always true. I have several devices that do not have this usb request implemented, even though HID Report Descriptor is still present among all USB descriptors.~
UPD: see #438.