Linux Hotplug: connection-callback implementation for libusb backend #645

Merged
k1-801 merged 10 commits from connection-callback-libusb into connection-callback 2024-04-06 05:17:26 -05:00
k1-801 commented 2023-11-20 17:35:26 -06:00 (Migrated from github.com)
No description provided.
Youw commented 2023-11-21 03:35:13 -06:00 (Migrated from github.com)

Before looking into this - lets finish with #646 - probably some comments are applicable here as well

Before looking into this - lets finish with #646 - probably some comments are applicable here as well
k1-801 commented 2023-11-21 15:57:28 -06:00 (Migrated from github.com)

Agreed. Going to squash all the commits into one so it's a little less messy, then will try to check for similar macro check related issues.

Agreed. Going to squash all the commits into one so it's a little less messy, then will try to check for similar macro check related issues.
k1-801 commented 2023-11-21 16:02:28 -06:00 (Migrated from github.com)

For now, my biggest concern is the match_libusb_to_info function. It is the only way I found to match the devices, yet it itself relies on some features that may be unavailable for a device that has already left.

For now, my biggest concern is the `match_libusb_to_info` function. It is the only way I found to match the devices, yet it itself relies on some features that may be unavailable for a device that has already left.
k1-801 commented 2023-11-21 23:23:01 -06:00 (Migrated from github.com)

Attempted to adjust the code-style to the current style of the library, it only ended up messing some other locations where indentation is done with both tabs AND spaces :(

Attempted to adjust the code-style to the current style of the library, it only ended up messing some other locations where indentation is done with both tabs AND spaces :(
k1-801 commented 2023-11-23 03:54:50 -06:00 (Migrated from github.com)

Added some changes to list management during device removal.

Added some changes to list management during device removal.
mcuee commented 2023-12-04 21:59:14 -06:00 (Migrated from github.com)

Ubuntu-cmake and Arch Linux github action build are still failing.

Ubuntu-cmake and Arch Linux github action build are still failing.
mcuee commented 2023-12-04 22:01:44 -06:00 (Migrated from github.com)

Ubuntu-cmake and Arch Linux github action build are still failing.

Ubuntu-cmake and Arch Linux github action build are still failing.
k1-801 commented 2023-12-05 00:50:01 -06:00 (Migrated from github.com)

Ubuntu-cmake and Arch Linux github action build are still failing.

Interesting. I will see to it right away.
UPD: It is just some warnings for unused parameters, treated as errors. Easy to fix.

> Ubuntu-cmake and Arch Linux github action build are still failing. Interesting. I will see to it right away. UPD: It is just some warnings for unused parameters, treated as errors. Easy to fix.
k1-801 commented 2023-12-05 02:20:48 -06:00 (Migrated from github.com)

Ubuntu-cmake and Arch Linux github action build are still failing.

Addressed the issue, should be fine now

> Ubuntu-cmake and Arch Linux github action build are still failing. Addressed the issue, should be fine now
mcuee commented 2024-03-05 23:17:38 -06:00 (Migrated from github.com)

Not so sure how to re-run the github actions as there were build error previously.
However, previous Windows CMake error has nothing to do with this PR. So it should still be okay.

Not so sure how to re-run the github actions as there were build error previously. However, previous Windows CMake error has nothing to do with this PR. So it should still be okay.
mcuee commented 2024-03-05 23:19:51 -06:00 (Migrated from github.com)

I will test this under Linux later.

I will test this under Linux later.
mcuee commented 2024-03-07 19:42:54 -06:00 (Migrated from github.com)

This may be a bit tricky to test under Linux as we need to detach the kernel HID driver in order to use hidapi-libusb.

BTW, libusb currently only supports hotplug under Linux and macOS. There is a PR for Windows.

FreeBSD has its own libusb implementation and it supports hotplug. I will also test this PR under FreeBSD.
https://man.freebsd.org/cgi/man.cgi?query=libusb

This may be a bit tricky to test under Linux as we need to detach the kernel HID driver in order to use hidapi-libusb. BTW, libusb currently only supports hotplug under Linux and macOS. There is a PR for Windows. FreeBSD has its own libusb implementation and it supports hotplug. I will also test this PR under FreeBSD. https://man.freebsd.org/cgi/man.cgi?query=libusb
k1-801 commented 2024-03-11 09:30:28 -05:00 (Migrated from github.com)

I just rebased this onto the updated connection-callback branch. There were quite a few significant conflicts, there might even be compilation errors, will ensure it builds later today.

I just rebased this onto the updated `connection-callback` branch. There were quite a few significant conflicts, there might even be compilation errors, will ensure it builds later today.
mcuee commented 2024-03-12 07:44:32 -05:00 (Migrated from github.com)

@k1-801
It does not seem to work under Ubuntu Linux 20.04.
No issues with PR #647 with the same system (Acer Laptop, dual boot Windows 11 and Ubuntu 20.04).

  1. Unplug and plug of Logitech USB Receiver

I have tried to detached kernel usbhid driver (same results if I do not detach the kernel driver).
https://lwn.net/Articles/143397/

root@UbuntuSwift3:/home/mcuee# tree /sys/bus/usb/drivers/usbhid/
/sys/bus/usb/drivers/usbhid/
├── 3-1:1.0 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0
├── 3-1:1.1 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.1
├── 3-2.1:1.3 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1:1.3
├── 3-3:1.0 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0
├── bind
├── module -> ../../../../module/usbhid
├── new_id
├── remove_id
├── uevent
└── unbind

root@UbuntuSwift3:/home/mcuee# echo -n "3-1:1.0" > /sys/bus/usb/drivers/usbhid/unbind
root@UbuntuSwift3:/home/mcuee# echo -n "3-1:1.1" > /sys/bus/usb/drivers/usbhid/unbind
root@UbuntuSwift3:/home/mcuee# lsusb -t
/:  Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/1p, 480M
/:  Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/4p, 5000M
/:  Bus 003.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/12p, 480M
    |__ Port 001: Dev 017, If 0, Class=Human Interface Device, Driver=[none], 12M
    |__ Port 001: Dev 017, If 1, Class=Human Interface Device, Driver=[none], 12M
    |__ Port 002: Dev 003, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 001: Dev 018, If 0, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 001: Dev 018, If 1, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 001: Dev 018, If 2, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 001: Dev 018, If 3, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 003: Dev 004, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 005: Dev 005, If 0, Class=Video, Driver=uvcvideo, 480M
    |__ Port 005: Dev 005, If 1, Class=Video, Driver=uvcvideo, 480M
    |__ Port 007: Dev 006, If 0, Class=Vendor Specific Class, Driver=[none], 480M
    |__ Port 010: Dev 007, 12M
/:  Bus 004.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M

hidapi test/example tool. Compiled with hidapi version 0.14.0, runtime version 0.14.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 1ea7 0064
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      2.4G Mouse
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: (105 bytes)
0x06, 0xb5, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, 0xb5, 0x09, 
0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x07, 
0x81, 0x02, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 
0x08, 0x95, 0x07, 0x91, 0x02, 0xc0, 0x05, 0x01, 0x09, 0x02, 
0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 
0x19, 0x01, 0x29, 0x08, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 
0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 
0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 
0x81, 0x06, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 
0x95, 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x95, 
0x01, 0x81, 0x06, 0xc0, 0xc0, 
Device Found
  type: 047f c056
  path: 3-2.1:1.3
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: (373 bytes)
0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x01, 0x15, 0x00, 
0x25, 0x01, 0x09, 0xe9, 0x09, 0xea, 0x75, 0x01, 0x95, 0x02, 
0x81, 0x06, 0x95, 0x06, 0x81, 0x01, 0x85, 0x02, 0x05, 0x0c, 
0x09, 0x00, 0x95, 0x10, 0x81, 0x02, 0x85, 0x04, 0x09, 0x00, 
0x75, 0x08, 0x95, 0x24, 0x91, 0x02, 0x85, 0x05, 0x09, 0x00, 
0x95, 0x20, 0x81, 0x02, 0x85, 0x06, 0x09, 0x00, 0x95, 0x24, 
0x91, 0x02, 0x85, 0x07, 0x09, 0x00, 0x95, 0x20, 0x81, 0x02, 
0xc0, 0x05, 0x0b, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x08, 0x15, 
0x00, 0x25, 0x01, 0x09, 0x2f, 0x75, 0x01, 0x95, 0x01, 0x81, 
0x06, 0x09, 0x20, 0x09, 0x21, 0x75, 0x01, 0x95, 0x02, 0x81, 
0x22, 0x95, 0x05, 0x81, 0x01, 0x05, 0x08, 0x85, 0x09, 0x09, 
0x09, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 
0x17, 0x09, 0x17, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 
0x01, 0x85, 0x18, 0x09, 0x18, 0x95, 0x01, 0x91, 0x22, 0x95, 
0x07, 0x91, 0x01, 0x85, 0x1e, 0x09, 0x1e, 0x95, 0x01, 0x91, 
0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x20, 0x09, 0x20, 0x95, 
0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x2a, 0x09, 
0x2a, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0xc0, 
0x06, 0xa0, 0xff, 0x09, 0x03, 0xa1, 0x01, 0x85, 0x03, 0x09, 
0x30, 0x75, 0x08, 0x95, 0x20, 0x91, 0x02, 0x85, 0x03, 0x09, 
0x30, 0x75, 0x08, 0x95, 0x20, 0x81, 0x02, 0x85, 0x14, 0x09, 
0xb1, 0x09, 0xb2, 0x09, 0xb5, 0x09, 0xb7, 0x09, 0xb3, 0x15, 
0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x05, 0x81, 0x06, 0x95, 
0x03, 0x81, 0x01, 0x85, 0x15, 0x09, 0x8c, 0x15, 0x00, 0x27, 
0xff, 0xff, 0x00, 0x00, 0x75, 0x10, 0x95, 0x01, 0x81, 0x22, 
0x85, 0x19, 0x09, 0x8d, 0x09, 0x8f, 0x09, 0x9e, 0x09, 0xdc, 
0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x22, 
0x09, 0xd2, 0x09, 0xd9, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 
0x95, 0x02, 0x91, 0x06, 0x95, 0x02, 0x91, 0x01, 0x85, 0x1a, 
0x09, 0xb5, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 
0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x1b, 0x09, 0xcf, 
0x09, 0xb5, 0x75, 0x01, 0x95, 0x02, 0xb1, 0x22, 0x09, 0xde, 
0x75, 0x01, 0x95, 0x01, 0xb1, 0x23, 0x09, 0xd8, 0x95, 0x01, 
0xb1, 0x22, 0x95, 0x04, 0xb1, 0x01, 0x09, 0x09, 0x09, 0x17, 
0x09, 0x18, 0x09, 0x1e, 0x09, 0x20, 0x09, 0x2a, 0x75, 0x01, 
0x95, 0x06, 0xb1, 0x22, 0x95, 0x02, 0xb1, 0x01, 0x85, 0x1f, 
0x09, 0x9c, 0x75, 0x01, 0x95, 0x01, 0x81, 0x06, 0x95, 0x07, 
0x81, 0x01, 0xc0, 
Device Found
  type: 046d c534
  path: 3-1:1.0
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: (59 bytes)
0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, 0x07, 0x19, 0xe0, 
0x29, 0xe7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 
0x81, 0x02, 0x81, 0x03, 0x95, 0x05, 0x05, 0x08, 0x19, 0x01, 
0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x01, 
0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x26, 0xa4, 0x00, 0x05, 
0x07, 0x19, 0x00, 0x2a, 0xa4, 0x00, 0x81, 0x00, 0xc0, 
Device Found
  type: 046d c534
  path: 3-1:1.1
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: (177 bytes)
0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, 
0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x10, 0x15, 0x00, 
0x25, 0x01, 0x95, 0x10, 0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 
0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 
0x09, 0x30, 0x09, 0x31, 0x81, 0x06, 0x15, 0x81, 0x25, 0x7f, 
0x75, 0x08, 0x95, 0x01, 0x09, 0x38, 0x81, 0x06, 0x05, 0x0c, 
0x0a, 0x38, 0x02, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0, 0x05, 
0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x75, 0x10, 0x95, 
0x02, 0x15, 0x01, 0x26, 0x8c, 0x02, 0x19, 0x01, 0x2a, 0x8c, 
0x02, 0x81, 0x00, 0xc0, 0x05, 0x01, 0x09, 0x80, 0xa1, 0x01, 
0x85, 0x04, 0x75, 0x02, 0x95, 0x01, 0x15, 0x01, 0x25, 0x03, 
0x09, 0x82, 0x09, 0x81, 0x09, 0x83, 0x81, 0x60, 0x75, 0x06, 
0x81, 0x03, 0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 
0x85, 0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff, 
0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00, 0xc0, 
0x06, 0x00, 0xff, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x11, 0x75, 
0x08, 0x95, 0x13, 0x15, 0x00, 0x26, 0xff, 0x00, 0x09, 0x02, 
0x81, 0x00, 0x09, 0x02, 0x91, 0x00, 0xc0, 
Handle 1: New device is connected: 3-3:1.0.
type: 1ea7 0064
  serial_number: (null)
  Manufacturer: (null)
  Product:      2.4G Mouse
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2.1:1.3.
type: 047f c056
  serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
  Manufacturer: Plantronics
  Product:      Plantronics Blackwire 3220 Series
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.0.
type: 046d c534
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.1.
type: 046d c534
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x0 (0x0)

@k1-801 It does not seem to work under Ubuntu Linux 20.04. No issues with PR #647 with the same system (Acer Laptop, dual boot Windows 11 and Ubuntu 20.04). * #647 1) Unplug and plug of Logitech USB Receiver I have tried to detached kernel usbhid driver (same results if I do not detach the kernel driver). https://lwn.net/Articles/143397/ ``` root@UbuntuSwift3:/home/mcuee# tree /sys/bus/usb/drivers/usbhid/ /sys/bus/usb/drivers/usbhid/ ├── 3-1:1.0 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0 ├── 3-1:1.1 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.1 ├── 3-2.1:1.3 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1:1.3 ├── 3-3:1.0 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 ├── bind ├── module -> ../../../../module/usbhid ├── new_id ├── remove_id ├── uevent └── unbind root@UbuntuSwift3:/home/mcuee# echo -n "3-1:1.0" > /sys/bus/usb/drivers/usbhid/unbind root@UbuntuSwift3:/home/mcuee# echo -n "3-1:1.1" > /sys/bus/usb/drivers/usbhid/unbind root@UbuntuSwift3:/home/mcuee# lsusb -t /: Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/1p, 480M /: Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/4p, 5000M /: Bus 003.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/12p, 480M |__ Port 001: Dev 017, If 0, Class=Human Interface Device, Driver=[none], 12M |__ Port 001: Dev 017, If 1, Class=Human Interface Device, Driver=[none], 12M |__ Port 002: Dev 003, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 001: Dev 018, If 0, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 001: Dev 018, If 1, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 001: Dev 018, If 2, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 001: Dev 018, If 3, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 003: Dev 004, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 005: Dev 005, If 0, Class=Video, Driver=uvcvideo, 480M |__ Port 005: Dev 005, If 1, Class=Video, Driver=uvcvideo, 480M |__ Port 007: Dev 006, If 0, Class=Vendor Specific Class, Driver=[none], 480M |__ Port 010: Dev 007, 12M /: Bus 004.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M ``` <details> ``` hidapi test/example tool. Compiled with hidapi version 0.14.0, runtime version 0.14.0. Compile-time version matches runtime version of hidapi. Device Found type: 1ea7 0064 path: 3-3:1.0 serial_number: (null) Manufacturer: (null) Product: 2.4G Mouse Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: (105 bytes) 0x06, 0xb5, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, 0xb5, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x07, 0x81, 0x02, 0x09, 0x02, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x07, 0x91, 0x02, 0xc0, 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0, Device Found type: 047f c056 path: 3-2.1:1.3 serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3 Manufacturer: Plantronics Product: Plantronics Blackwire 3220 Series Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: (373 bytes) 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x01, 0x15, 0x00, 0x25, 0x01, 0x09, 0xe9, 0x09, 0xea, 0x75, 0x01, 0x95, 0x02, 0x81, 0x06, 0x95, 0x06, 0x81, 0x01, 0x85, 0x02, 0x05, 0x0c, 0x09, 0x00, 0x95, 0x10, 0x81, 0x02, 0x85, 0x04, 0x09, 0x00, 0x75, 0x08, 0x95, 0x24, 0x91, 0x02, 0x85, 0x05, 0x09, 0x00, 0x95, 0x20, 0x81, 0x02, 0x85, 0x06, 0x09, 0x00, 0x95, 0x24, 0x91, 0x02, 0x85, 0x07, 0x09, 0x00, 0x95, 0x20, 0x81, 0x02, 0xc0, 0x05, 0x0b, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x08, 0x15, 0x00, 0x25, 0x01, 0x09, 0x2f, 0x75, 0x01, 0x95, 0x01, 0x81, 0x06, 0x09, 0x20, 0x09, 0x21, 0x75, 0x01, 0x95, 0x02, 0x81, 0x22, 0x95, 0x05, 0x81, 0x01, 0x05, 0x08, 0x85, 0x09, 0x09, 0x09, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x17, 0x09, 0x17, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x18, 0x09, 0x18, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x1e, 0x09, 0x1e, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x20, 0x09, 0x20, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x2a, 0x09, 0x2a, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0xc0, 0x06, 0xa0, 0xff, 0x09, 0x03, 0xa1, 0x01, 0x85, 0x03, 0x09, 0x30, 0x75, 0x08, 0x95, 0x20, 0x91, 0x02, 0x85, 0x03, 0x09, 0x30, 0x75, 0x08, 0x95, 0x20, 0x81, 0x02, 0x85, 0x14, 0x09, 0xb1, 0x09, 0xb2, 0x09, 0xb5, 0x09, 0xb7, 0x09, 0xb3, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x05, 0x81, 0x06, 0x95, 0x03, 0x81, 0x01, 0x85, 0x15, 0x09, 0x8c, 0x15, 0x00, 0x27, 0xff, 0xff, 0x00, 0x00, 0x75, 0x10, 0x95, 0x01, 0x81, 0x22, 0x85, 0x19, 0x09, 0x8d, 0x09, 0x8f, 0x09, 0x9e, 0x09, 0xdc, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x22, 0x09, 0xd2, 0x09, 0xd9, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x02, 0x91, 0x06, 0x95, 0x02, 0x91, 0x01, 0x85, 0x1a, 0x09, 0xb5, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x91, 0x22, 0x95, 0x07, 0x91, 0x01, 0x85, 0x1b, 0x09, 0xcf, 0x09, 0xb5, 0x75, 0x01, 0x95, 0x02, 0xb1, 0x22, 0x09, 0xde, 0x75, 0x01, 0x95, 0x01, 0xb1, 0x23, 0x09, 0xd8, 0x95, 0x01, 0xb1, 0x22, 0x95, 0x04, 0xb1, 0x01, 0x09, 0x09, 0x09, 0x17, 0x09, 0x18, 0x09, 0x1e, 0x09, 0x20, 0x09, 0x2a, 0x75, 0x01, 0x95, 0x06, 0xb1, 0x22, 0x95, 0x02, 0xb1, 0x01, 0x85, 0x1f, 0x09, 0x9c, 0x75, 0x01, 0x95, 0x01, 0x81, 0x06, 0x95, 0x07, 0x81, 0x01, 0xc0, Device Found type: 046d c534 path: 3-1:1.0 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 2901 Interface: 0 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: (59 bytes) 0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, 0x07, 0x19, 0xe0, 0x29, 0xe7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x81, 0x03, 0x95, 0x05, 0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x26, 0xa4, 0x00, 0x05, 0x07, 0x19, 0x00, 0x2a, 0xa4, 0x00, 0x81, 0x00, 0xc0, Device Found type: 046d c534 path: 3-1:1.1 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 2901 Interface: 1 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: (177 bytes) 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x10, 0x15, 0x00, 0x25, 0x01, 0x95, 0x10, 0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 0x16, 0x01, 0xf8, 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x09, 0x30, 0x09, 0x31, 0x81, 0x06, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x09, 0x38, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x95, 0x01, 0x81, 0x06, 0xc0, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x75, 0x10, 0x95, 0x02, 0x15, 0x01, 0x26, 0x8c, 0x02, 0x19, 0x01, 0x2a, 0x8c, 0x02, 0x81, 0x00, 0xc0, 0x05, 0x01, 0x09, 0x80, 0xa1, 0x01, 0x85, 0x04, 0x75, 0x02, 0x95, 0x01, 0x15, 0x01, 0x25, 0x03, 0x09, 0x82, 0x09, 0x81, 0x09, 0x83, 0x81, 0x60, 0x75, 0x06, 0x81, 0x03, 0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff, 0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00, 0xc0, 0x06, 0x00, 0xff, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x11, 0x75, 0x08, 0x95, 0x13, 0x15, 0x00, 0x26, 0xff, 0x00, 0x09, 0x02, 0x81, 0x00, 0x09, 0x02, 0x91, 0x00, 0xc0, Handle 1: New device is connected: 3-3:1.0. type: 1ea7 0064 serial_number: (null) Manufacturer: (null) Product: 2.4G Mouse Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2.1:1.3. type: 047f c056 serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3 Manufacturer: Plantronics Product: Plantronics Blackwire 3220 Series Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.0. type: 046d c534 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 2901 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.1. type: 046d c534 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 2901 Interface: 1 Usage (page): 0x0 (0x0) ``` </details>
k1-801 commented 2024-03-12 07:48:09 -05:00 (Migrated from github.com)

It does not seem to work under Ubuntu Linux 20.04

Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself.

> It does not seem to work under Ubuntu Linux 20.04 Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself.
mcuee commented 2024-03-12 07:53:18 -05:00 (Migrated from github.com)

It does not seem to work under Ubuntu Linux 20.04

Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself.

Thanks.

FYI: libusb hotplug works fine.

mcuee@UbuntuSwift3 ~/build/libusb/libusb/build (master)$ sudo ./examples/hotplugtest 
Device detached: 046d:c534
Device attached: 046d:c534
Device detached: 046d:c534
Device attached: 046d:c534
^C
> > It does not seem to work under Ubuntu Linux 20.04 > > Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself. Thanks. FYI: libusb hotplug works fine. ``` mcuee@UbuntuSwift3 ~/build/libusb/libusb/build (master)$ sudo ./examples/hotplugtest Device detached: 046d:c534 Device attached: 046d:c534 Device detached: 046d:c534 Device attached: 046d:c534 ^C ```
k1-801 commented 2024-03-12 11:29:33 -05:00 (Migrated from github.com)

FYI: libusb hotplug works fine.

It took me some time to track the issue, but I found it. Turns out that, despite the documentation foe libusb NEVER explicitly stating so, the hotplug system actually does NOT start it's own background thread and requires a call to any variation libusb_handle_events this is actually described in the documentation, but the explanation is not super clear.

In turn, calling libusb_handle_events in a seprate thread, according to the documentation, may or may not cause issues with the read thread and it's own call to libusb_handle_events. I don't really understand how multiple read_thread's for multiple devices don't interfere with one another.
The way I see it, the best solution here would be to have a separate libusb context dedicated to the hotplug events. Will test and report my findings in 2 hours.

> FYI: libusb hotplug works fine. It took me some time to track the issue, but I found it. ~~Turns out that, despite the documentation foe libusb NEVER explicitly stating so, the hotplug system actually does NOT start it's own background thread and requires a call to any variation `libusb_handle_events`~~ this is actually described in the documentation, but the explanation is not super clear. In turn, calling `libusb_handle_events` in a seprate thread, according to the documentation, may or may not cause issues with the `read thread` and it's own call to `libusb_handle_events`. I don't really understand how multiple `read_thread`'s for multiple devices don't interfere with one another. The way I see it, the best solution here would be to have a separate libusb context dedicated to the hotplug events. Will test and report my findings in 2 hours.
k1-801 commented 2024-03-12 12:23:04 -05:00 (Migrated from github.com)

I managed to get the events going (there is some debug output in the printout below that will not be present in the real tests), BUT, the device info is always empty. So far, it's definitely an impovement.

I don't know why the fields are empty or how to fix them, get_usb_string keeps returning NULL. But, as long as we have the events firing, as long as the paths are not empty and as long as we still get VID/PID pairs, I assume the patch does it's job.

Maybe it is related to the fact that I used a second libusb context, but the documentation states they should not interfere with one another, and the processing code never mentions the context at all.

UPD: every call to libusb_get_string_descriptor returns error -6, which is LIBUSB_ERROR_BUSY, and that's why no strings are returned.

UPD2: https://github.com/libusb/libusb/issues/408 - it is impossible to retrieve any strings while in the libusb's hotplug callback. Will think of a workaround, but this is really becoming complicated. I can imagine it running two threads, one for libusb running it's event processing, in which the events would be put on a queue. The other would be actually processing the queue and calling the callbacks registered in hidapi.

Handle 1: New device is connected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-3:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-3:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

libusb callback fired! Event: out
Handle 1: Device was disconnected: 3-3:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-3:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-3:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

libusb callback fired! Event: in
Handle 1: New device is connected: 3-3:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-3:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-3:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

libusb callback fired! Event: out
Handle 1: Device was disconnected: 3-3:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-3:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-3:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

libusb callback fired! Event: in
Handle 1: New device is connected: 3-2:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

I managed to get the events going (there is some debug output in the printout below that will not be present in the real tests), BUT, the device info is always empty. So far, it's definitely an impovement. I don't know why the fields are empty or how to fix them, `get_usb_string` keeps returning NULL. But, as long as we have the events firing, as long as the paths are not empty and as long as we still get VID/PID pairs, I assume the patch does it's job. Maybe it is related to the fact that I used a second libusb context, but the documentation states they should not interfere with one another, and the processing code never mentions the context at all. UPD: every call to `libusb_get_string_descriptor` returns error -6, which is LIBUSB_ERROR_BUSY, and that's why no strings are returned. UPD2: https://github.com/libusb/libusb/issues/408 - it is impossible to retrieve any strings while in the libusb's hotplug callback. Will think of a workaround, but this is really becoming complicated. I can imagine it running two threads, one for libusb running it's event processing, in which the events would be put on a queue. The other would be actually processing the queue and calling the callbacks registered in hidapi. <details> Handle 1: New device is connected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-3:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-3:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 2 Usage (page): 0x0 (0x0) libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-3:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-3:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 2 Usage (page): 0x0 (0x0) libusb callback fired! Event: in Handle 1: New device is connected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-3:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-3:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 2 Usage (page): 0x0 (0x0) libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-3:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-3:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 2 Usage (page): 0x0 (0x0) libusb callback fired! Event: in Handle 1: New device is connected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: (null) Release: 110 Interface: 2 Usage (page): 0x0 (0x0) </detais>
k1-801 commented 2024-03-12 15:39:23 -05:00 (Migrated from github.com)

Implemented a two-thread queue processing. Will push in a moment, needs some indentation cleanup.

Handle 1: New device is connected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-2:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-2:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-2:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.1.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 1
Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2:1.2.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 2
Usage (page): 0x0 (0x0)

Implemented a two-thread queue processing. Will push in a moment, needs some indentation cleanup. <details> Handle 1: New device is connected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 2 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-2:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-2:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 2 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.1. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2:1.2. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 2 Usage (page): 0x0 (0x0) </details>
k1-801 commented 2024-03-12 15:43:46 -05:00 (Migrated from github.com)

@mcuee this monstrocity is now more or less ready to be tested, reviewed and insulted.

@mcuee this monstrocity is now more or less ready to be tested, reviewed ~~and insulted~~.
k1-801 commented 2024-03-12 16:00:25 -05:00 (Migrated from github.com)

Forgot a call to trigger the pthread_condition...
Does not affect the funcction, but the event is delayed for up to 5ms. Going to fix later. done.

Forgot a call to trigger the pthread_condition... Does not affect the funcction, but the event is delayed for up to 5ms. ~~Going to fix later.~~ done.
mcuee commented 2024-03-12 18:51:21 -05:00 (Migrated from github.com)

Now this works fine. Thanks. And yes it is not requird to detach kernel driver for event.

Tested under Ubuntu Linux 20.04.

Unplug and plug of Platronics USB headset
Unplug and plug of a USB mouse receiver
Unplug and plug of another USB mouse receiver

mcuee@UbuntuSwift3 ~/build/hid/hidapi_hotplug_libusb (connection-callback-libusb)$ ./hidtest/hidtest-libusb 
hidapi test/example tool. Compiled with hidapi version 0.14.0, runtime version 0.14.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 1ea7 0064
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: Unable to open device by path
Device Found
  type: 047f c056
  path: 3-2.1:1.3
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: Unable to open device by path
Device Found
  type: 1ea7 0066
  path: 3-1:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: Unable to open device by path
Device Found
  type: 1ea7 0066
  path: 3-1:1.1
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    1
  Usage (page): 0x0 (0x0)
  Bus type: 1 (USB)

  Report Descriptor: Unable to open device by path
Handle 1: New device is connected: 3-3:1.0.
type: 1ea7 0064
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2.1:1.3.
type: 047f c056
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.0.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.1.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    1
  Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-2.1:1.3.
type: 047f c056
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-2.1:1.3.
type: 047f c056
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      210
  Interface:    3
  Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-1:1.0.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-1:1.1.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    1
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.0.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-1:1.1.
type: 1ea7 0066
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    1
  Usage (page): 0x0 (0x0)

Handle 1: Device was disconnected: 3-3:1.0.
type: 1ea7 0064
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

Handle 1: New device is connected: 3-3:1.0.
type: 1ea7 0064
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      200
  Interface:    0
  Usage (page): 0x0 (0x0)

^C
Now this works fine. Thanks. And yes it is not requird to detach kernel driver for event. Tested under Ubuntu Linux 20.04. Unplug and plug of Platronics USB headset Unplug and plug of a USB mouse receiver Unplug and plug of another USB mouse receiver <details> ``` mcuee@UbuntuSwift3 ~/build/hid/hidapi_hotplug_libusb (connection-callback-libusb)$ ./hidtest/hidtest-libusb hidapi test/example tool. Compiled with hidapi version 0.14.0, runtime version 0.14.0. Compile-time version matches runtime version of hidapi. Device Found type: 1ea7 0064 path: 3-3:1.0 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: Unable to open device by path Device Found type: 047f c056 path: 3-2.1:1.3 serial_number: (null) Manufacturer: (null) Product: (null) Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: Unable to open device by path Device Found type: 1ea7 0066 path: 3-1:1.0 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: Unable to open device by path Device Found type: 1ea7 0066 path: 3-1:1.1 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 1 Usage (page): 0x0 (0x0) Bus type: 1 (USB) Report Descriptor: Unable to open device by path Handle 1: New device is connected: 3-3:1.0. type: 1ea7 0064 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2.1:1.3. type: 047f c056 serial_number: (null) Manufacturer: (null) Product: (null) Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.0. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.1. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-2.1:1.3. type: 047f c056 serial_number: (null) Manufacturer: (null) Product: (null) Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-2.1:1.3. type: 047f c056 serial_number: (null) Manufacturer: (null) Product: (null) Release: 210 Interface: 3 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-1:1.0. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-1:1.1. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.0. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-1:1.1. type: 1ea7 0066 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 1 Usage (page): 0x0 (0x0) Handle 1: Device was disconnected: 3-3:1.0. type: 1ea7 0064 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) Handle 1: New device is connected: 3-3:1.0. type: 1ea7 0064 serial_number: (null) Manufacturer: (null) Product: (null) Release: 200 Interface: 0 Usage (page): 0x0 (0x0) ^C ``` </details>
Youw (Migrated from github.com) reviewed 2024-04-06 05:04:03 -05:00
Youw (Migrated from github.com) commented 2024-04-06 05:04:03 -05:00
		        rpt[cur+3] * 0x00010000 +
		        rpt[cur+2] * 0x00000100 +
		        rpt[cur+1] * 0x00000001);
```suggestion rpt[cur+3] * 0x00010000 + rpt[cur+2] * 0x00000100 + rpt[cur+1] * 0x00000001); ```
Youw (Migrated from github.com) reviewed 2024-04-06 05:12:56 -05:00
Youw (Migrated from github.com) commented 2024-04-06 05:12:55 -05:00
	     intf_desc->bInterfaceProtocol == xb360w_iface_protocol)) {
```suggestion intf_desc->bInterfaceProtocol == xb360w_iface_protocol)) { ```
Youw (Migrated from github.com) approved these changes 2024-04-06 05:15:57 -05:00
Youw (Migrated from github.com) left a comment

I've fixed some formatting concerns of mine, but still don't have enough time to go thru all of the code.
But I trust the community to review it properly and fix if anything needs to be fixed.
That said, I will not block the PR from getting into a feature branch.

I've fixed some formatting concerns of mine, but still don't have enough time to go thru all of the code. But I trust the community to review it properly and fix if anything needs to be fixed. That said, I will not block the PR from getting into a feature branch.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!645
No description provided.