connection-callback branch cpu usage is very high
pls check it!
if (hid_init())
return;
hid_hotplug_register_callback(0x0213, 0xA22C,
HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED |
HID_API_HOTPLUG_EVENT_DEVICE_LEFT,
HID_API_HOTPLUG_ENUMERATE,
device_callback, NULL, &token2);
Let me describe it more clearly, when I don't plug in the device (0x0213, 0xA22C), the CPU usage is not high, but when I plug in the device, the CPU instantly rises to 9%~11%
Please provide more details about the device (eg: output from hidtest) and host PC configuration and OS you are using.
Please provide more details
And the source for your device_callback function.
Can you confirm that you're trying out the https://github.com/libusb/hidapi/tree/connection-callback branch on Windows?
I don't think anything abnormal is happening.
And BTW: what is the CPU usage when you plug your device, when your application isn't running at all?
On my end I only have 0.05% cpu usage when a device gets connected with the connection-callback branch and my application does a number of things at the same time. My config is Windows 11 and a 13600k cpu.
Make sure you keep your code in the callback as concise as possible. You can use a producer-consumer pattern with a FIFO to process those connections/disconnections in another thread.
@Alvazz
Any updates? Thanks.
We will close the issue if there are no responses.