Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: WIP: Add ability to register device connection/disconnection callback #299

Merged
merged 5 commits into from
May 1, 2023

Conversation

DJm00n
Copy link
Contributor

@DJm00n DJm00n commented Jul 5, 2021

I have implemented two new methods:

typedef int hid_hotplug_callback_handle;

typedef enum {
	HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED = (1 << 0),
	HID_API_HOTPLUG_EVENT_DEVICE_LEFT = (1 << 1)
} hid_hotplug_event;

typedef enum {
	HID_API_HOTPLUG_ENUMERATE = (1 << 0)
} hid_hotplug_flag;

typedef int (HID_API_CALL *hid_hotplug_callback_fn)(
	hid_hotplug_callback_handle callback_handle,
	struct hid_device_info *device,
	hid_hotplug_event event,
	void *user_data);

int HID_API_EXPORT HID_API_CALL hid_hotplug_register_callback(unsigned short vendor_id, unsigned short product_id, int events, int flags, hid_hotplug_callback_fn callback, void *user_data, hid_hotplug_callback_handle *callback_handle)

int HID_API_EXPORT HID_API_CALL hid_hotplug_deregister_callback(hid_hotplug_callback_handle callback_handle)

These could be used to receive notification about HID device connection or disconnection.
I did implement it only for Windows via CM_Register_Notification that is available since Windows 8. Not sure about other platforms.

Any comments/objections are welcomed.

@DJm00n DJm00n changed the title RFC: Add ability to register device connection/disconnection callback RFC: WIP: Add ability to register device connection/disconnection callback Jul 5, 2021
@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 5, 2021

There is some things to do:

  • add some mutex to make interface_notify_callback() device add/remove thread safe.
  • clean notify_context on hid_exit()
  • add more error checking

@Youw
Copy link
Member

Youw commented Jul 5, 2021

Lets make it for the feature branch: https://github.com/libusb/hidapi/tree/connection-callback

@mcuee mcuee added the enhancement New feature or request label Jul 7, 2021
@mcuee
Copy link
Member

mcuee commented Jul 7, 2021

This is linked to hotplug support: #238

@DJm00n DJm00n force-pushed the device_notify branch 2 times, most recently from 785c8ab to 69fb610 Compare July 13, 2021 09:38
@mcuee
Copy link
Member

mcuee commented Jul 14, 2021

The function names may need some discussion. Maybe hid_device_callback can be named as hid_device_hotplug_callback. And hid_register_callback can be named as hid_register_hotplug_callback.

@DJm00n DJm00n force-pushed the device_notify branch 2 times, most recently from 142a6a4 to 2ee430b Compare July 15, 2021 10:59
@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 15, 2021

@mcuee I did some renames:

  • hid_device_callback -> hid_hotplug_callback_fn
  • hid_register_callback -> hid_hotplug_register_callback
  • hid_unregister_callback -> hid_hotplug_deregister_callback
    Now it looks much more like libusb hotplug notifications implementation.

@DJm00n DJm00n force-pushed the device_notify branch 2 times, most recently from 81fcc79 to e006c76 Compare July 15, 2021 13:30
@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 15, 2021

I have added dynamic load of CM_Register_Notification/CM_Unregister_Notification from cfgmgr32.dll since MinGW-w64 doesn't have them it in its headers: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-headers/include/cfgmgr32.h

@mcuee
Copy link
Member

mcuee commented Jul 18, 2021

First test seems to be positive. With hotplug of my Microchip PICkit 2 programmer (single HID device as seen by HIDAPI) and Logitech USB Receiver (6 HID devices as seen by HIDAPI)

click for full run log

C:\work\hid\hidapi_devnotify\windows\x64\Release [device_notify ≡]> .\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&383a3a17&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 c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&383a3a17&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: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&383a3a17&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: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&383a3a17&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&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: 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: 046d c534
  path: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&383a3a17&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: 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: 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: 04d8 0033
  path: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

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: 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: 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&1c54b96&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: 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: 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: 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)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&383a3a17&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&383a3a17&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&383a3a17&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&383a3a17&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#dell091a&col01#5&99b72d3&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 0488 121f
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#intc816&col01#3&36a7043c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 8087 0a1e
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xc (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_044e&pid_1212&col01&col02#7&290aacae&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 044e 1212
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&383a3a17&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#intc816&col02#3&36a7043c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 8087 0a1e
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_044e&pid_1212&col01&col01#7&290aacae&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 044e 1212
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#dell091a&col02#5&99b72d3&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 0488 121f
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x5 (0xd)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 04d8 0033
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#converteddevice&col02#5&379854aa&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#converteddevice&col03#5&379854aa&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#dell091a&col03#5&99b72d3&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 0488 121f
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff01)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_00#7&1c54b96&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#dell091a&col04#5&99b72d3&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 0488 121f
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0x1 (0xff02)

Handle 0000016097C74B80: New device is connected: \\?\hid#dell091a&col05#5&99b72d3&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 0488 121f
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      40d
  Interface:    -1
  Usage (page): 0xe (0xd)

Handle 0000016097C74B80: New device is connected: \\?\hid#converteddevice&col01#5&379854aa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 04d8 0033
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 04d8 0033
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 04d8 0033
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_04d8&pid_0033#e&bd5b18b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 04d8 0033
  serial_number: pk2new
  Manufacturer: Microchip Technology Inc.
  Product:      PICkit 2 Microcontroller Programmer
  Release:      2
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_00#7&1c54b96&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&383a3a17&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&383a3a17&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&383a3a17&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&383a3a17&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&383a3a17&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col02#7&383a3a17&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col03#7&383a3a17&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col04#7&383a3a17&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col05#7&383a3a17&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_00#7&1c54b96&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#vid_046d&pid_c534&mi_01&col01#7&383a3a17&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c534
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    1
  Usage (page): 0x2 (0x1)

@mcuee
Copy link
Member

mcuee commented Jul 18, 2021

Then I tested with a Bluetooth Mouse (Logitech M557 Mouse) and it seems to work fine as well. It will show up as 6 HID devices as well by hidapi.

click to expand
Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col02#8&1cf1c1b9&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col03#8&1cf1c1b9&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col04#8&1cf1c1b9&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col06#8&1cf1c1b9&0&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col01#8&1cf1c1b9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col05#8&1cf1c1b9&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col01#8&1cf1c1b9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col02#8&1cf1c1b9&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col03#8&1cf1c1b9&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col04#8&1cf1c1b9&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col05#8&1cf1c1b9&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

Handle 0000016097C74B80: Device was disconnected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col06#8&1cf1c1b9&0&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col02#8&1cf1c1b9&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col03#8&1cf1c1b9&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col04#8&1cf1c1b9&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0xff00)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col06#8&1cf1c1b9&0&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col01#8&1cf1c1b9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 0000016097C74B80: New device is connected: \\?\hid#{00001124-0000-1000-8000-00805f9b34fb}_vid&0002046d_pid&b010&col05#8&1cf1c1b9&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d b010
  serial_number: 34885dab0c12
  Manufacturer: Logitech
  Product:      Logitech Bluetooth Wireless Mouse
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

@mcuee
Copy link
Member

mcuee commented Jul 18, 2021

@DJm00n This seems to work pretty well under Windows. Just wondering if you can add for other backend as well (eg: Linux hidraw, libusb or macOS). I have the systems to test for these platforms (Windows laptop, Raspberry Pi 400 Linux and Mac Mini M1 macOS).

@mcuee mcuee mentioned this pull request Jul 18, 2021
@mcuee mcuee added Core Related to common codes like hidapi.h hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend labels Jul 18, 2021
@DJm00n DJm00n force-pushed the device_notify branch 3 times, most recently from 83feedb to e91f905 Compare July 19, 2021 11:06
@DJm00n
Copy link
Contributor Author

DJm00n commented Jul 19, 2021

Related libusb issue: libusb/libusb#86

@Youw
Copy link
Member

Youw commented Jul 28, 2021

This is a large (even though important) change.
Please target it agains https://github.com/libusb/hidapi/tree/connection-callback branch, instead of master, for now.

@DJm00n
Copy link
Contributor Author

DJm00n commented Apr 18, 2023

@andyvorld thank you for your work. I have manually rebased my changes under current upstream/master branch and also cherry-picked your b864213 fix.
Also, your 80e3e01 change was a bit broken - so I did proper changes instead while rebasing.

I've done this to avoid unnecessary noise in the git history.

@DJm00n DJm00n force-pushed the device_notify branch 2 times, most recently from 650dfc6 to cd0a4c9 Compare April 18, 2023 16:03
@Youw
Copy link
Member

Youw commented Apr 18, 2023

@DJm00n could you explicitly merge libusb:connection-callback branch into your libusb:connection-callback (with a merge commit)? otherwise the diff on Github is not what is should be

@mcuee
Copy link
Member

mcuee commented Apr 19, 2023

github action for macos-cmake and ubuntu-cmake failed due to compiler warning treated as error. Interestingly macos-automake passed.

@mcuee
Copy link
Member

mcuee commented Apr 19, 2023

Run log under Windows. I run hidtest.exe. Then I unplug the Logitech USB Receiver and then plug it back in.

@DJm00n
I am thinking that for the first run the devices should not be considered as newly plug-in. In fact for this Acer laptop, only the Microsoft Bluetooth Mouse and the Logitech USB Receiver are external devices.

PS C:\work\libusb\hidapi_pr299> msbuild .\windows\hidapi.sln
...
PS C:\work\libusb\hidapi_pr299> .\windows\Debug\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.13.1, runtime version 0.13.1.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col01#9&1937f32c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col02#9&1937f32c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col03#9&1937f32c&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

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)
  Bus type: 0

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

Handle 1: New device is connected: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col01#9&1937f32c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0916
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 1: New device is connected: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col02#9&1937f32c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0916
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col03#9&1937f32c&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0916
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#intc816#3&d2322f2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 8087 0a1e
  serial_number:
  Manufacturer:
  Product:
  Release:      200
  Interface:    -1
  Usage (page): 0xd (0x1)

Handle 1: New device is connected: \\?\hid#syna7dab&col01#5&2f64dfea&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 06cb cd40
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      501
  Interface:    -1
  Usage (page): 0x2 (0x1)

Handle 1: New device is connected: \\?\hid#syna7dab&col02#5&2f64dfea&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 06cb cd40
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      501
  Interface:    -1
  Usage (page): 0x5 (0xd)

Handle 1: New device is connected: \\?\hid#syna7dab&col03#5&2f64dfea&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 06cb cd40
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      501
  Interface:    -1
  Usage (page): 0xe (0xd)

Handle 1: New device is connected: \\?\hid#syna7dab&col04#5&2f64dfea&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 06cb cd40
  serial_number: 9999
  Manufacturer: Microsoft
  Product:      HIDI2C Device
  Release:      501
  Interface:    -1
  Usage (page): 0x1 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 1: New device is connected: \\?\hid#converteddevice&col02#5&32cf90e6&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#converteddevice&col03#5&32cf90e6&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x80 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 1: New device is connected: \\?\hid#10251229#3&9d5d338&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: deed feed
  serial_number:
  Manufacturer: Acer Inc
  Product:      Acer Airplane Mode Controller
  Release:      101
  Interface:    -1
  Usage (page): 0xc (0x1)

Handle 1: New device is connected: \\?\hid#converteddevice&col01#5&32cf90e6&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 045e 0000
  serial_number:
  Manufacturer:
  Product:
  Release:      0
  Interface:    -1
  Usage (page): 0x6 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

@mcuee
Copy link
Member

mcuee commented Apr 19, 2023

Related libusb issue: libusb/libusb#86

BTW, the above is talking about the lack of hotplug feature for libusb Windows backend. Since we only use libusb under Linux and BSDs but not Windows, the above libusb issue does not really matter.

@andyvorld
Copy link

Run log under Windows. I run hidtest.exe. Then I unplug the Logitech USB Receiver and then plug it back in.

@DJm00n I am thinking that for the first run the devices should not be considered as newly plug-in. In fact for this Acer laptop, only the Microsoft Bluetooth Mouse and the Logitech USB Receiver are external devices.

...

I think there is a flag on hid_hotplug_register_callback, the basic test program has HID_API_HOTPLUG_ENUMERATE on it. Setting it to 0 seems to not enumerate already connected devices.

@mcuee
Copy link
Member

mcuee commented Apr 19, 2023

I think there is a flag on hid_hotplug_register_callback, the basic test program has HID_API_HOTPLUG_ENUMERATE on it. Setting it to 0 seems to not enumerate already connected devices.

Thanks. Yes this is the one.

PS C:\work\libusb\hidapi_pr299> git diff
diff --git a/hidtest/test.c b/hidtest/test.c
index 4c0988e..dfb1b52 100644
--- a/hidtest/test.c
+++ b/hidtest/test.c
@@ -135,8 +135,8 @@ int main(int argc, char* argv[])
        print_devices(devs);
        hid_free_enumeration(devs);

-       hid_hotplug_register_callback(0, 0, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED | HID_API_HOTPLUG_EVENT_DEVICE_LEFT, HID_API_HOTPLUG_ENUMERATE, device_callback, NULL, &token1);
-       hid_hotplug_register_callback(0x054c, 0x0ce6, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED | HID_API_HOTPLUG_EVENT_DEVICE_LEFT, HID_API_HOTPLUG_ENUMERATE, device_callback, NULL, &token2);
+       hid_hotplug_register_callback(0, 0, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED | HID_API_HOTPLUG_EVENT_DEVICE_LEFT, 0, device_callback, NULL, &token1);
+       hid_hotplug_register_callback(0x046d, 0xc52b, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED | HID_API_HOTPLUG_EVENT_DEVICE_LEFT, 0, device_callback, NULL, &token2);

        while (1)
        {
PS C:\work\libusb\hidapi_pr299> .\windows\Debug\hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.13.1, runtime version 0.13.1.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col01#9&1937f32c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x2 (0x1)
  Bus type: 2

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col02#9&1937f32c&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

Device Found
  type: 045e 0916
  path: \\?\hid#{00001812-0000-1000-8000-00805f9b34fb}_dev_vid&02045e_pid&0916_rev&0110_f338080e09c4&col03#9&1937f32c&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
  serial_number: f338080e09c4
  Manufacturer: Microsoft
  Product:      BluetoothMouse3600
  Release:      110
  Interface:    -1
  Usage (page): 0x1 (0xc)
  Bus type: 2

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)
  Bus type: 0

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 3

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 0

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)
  Bus type: 0

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

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)
  Bus type: 1

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 1: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 2: Device was disconnected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col02#7&1119bfb4&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x1 (0xc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col03#7&1119bfb4&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x80 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col04#7&1119bfb4&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x88 (0xffbc)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col01#7&12bd7e0e&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x1 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col02#7&12bd7e0e&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x2 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_02&col03#7&12bd7e0e&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x4 (0xff00)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_00#7&34f0fd76&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Handle 1: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

Handle 2: New device is connected: \\?\hid#vid_046d&pid_c52b&mi_01&col01#7&1119bfb4&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}.
type: 046d c52b
  serial_number:
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x2 (0x1)

@Youw
Copy link
Member

Youw commented Apr 19, 2023

Interestingly macos-automake passed.

Yeah, it is not only a compiler - we explicitly set "more warnings and warnings-as-errors" only for CMake builds for our CI.

@DJm00n
Copy link
Contributor Author

DJm00n commented Apr 19, 2023

Run log under Windows. I run hidtest.exe. Then I unplug the Logitech USB Receiver and then plug it back in.
@DJm00n I am thinking that for the first run the devices should not be considered as newly plug-in. In fact for this Acer laptop, only the Microsoft Bluetooth Mouse and the Logitech USB Receiver are external devices.
...

I think there is a flag on hid_hotplug_register_callback, the basic test program has HID_API_HOTPLUG_ENUMERATE on it. Setting it to 0 seems to not enumerate already connected devices.

Yup.

/** Arm the callback and fire it for all matching currently attached devices. */
HID_API_HOTPLUG_ENUMERATE = (1 << 0)

@mini-ninja-64
Copy link

Happy to see progress on this 😍
Once merged to the feature branch i can open a MacOS implementation PR against it.

What's remaining before the merge to feature branch?

@DJm00n
Copy link
Contributor Author

DJm00n commented Apr 25, 2023

@mini-ninja-64 its missing some mutex protection of the callback list on register/unregister/notify

windows/hid.c Outdated Show resolved Hide resolved
@Youw
Copy link
Member

Youw commented May 1, 2023

As promised - merged into dev branch, so the community may work on the implementation for other backends.

I've opened a separate ticket for the "mutex problem".

andyvorld pushed a commit to andyvorld/hidapi that referenced this pull request Nov 15, 2023
…back (libusb#299)

- initial API;
- Windows backend implementation;
@DJm00n DJm00n deleted the device_notify branch November 23, 2023 14:03
k1-801 pushed a commit to k1-801/hidapi that referenced this pull request Mar 9, 2024
…back (libusb#299)

- initial API;
- Windows backend implementation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to common codes like hidapi.h enhancement New feature or request hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants