-
Notifications
You must be signed in to change notification settings - Fork 84
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
Support for monitoring of new devices #155
Comments
I think an approach for this is to use Check I haven't tested this though and I guess it can introduce race conditions if timing is tight? Maybe you can open the |
I just pushed a branch with a quick implementation on the Testing it in my app it works perfectly, although as mentioned in the libusb/hidapi#238 there are race conditions between enumerating and setting up the monitor, afaict these are unavoidable. I'll take a look at the other backends later. |
Just pushed another branch adding on the Tested by building a pre-release version of { pkgs ? import <nixpkgs> {}}:
pkgs.mkShell (with pkgs; {
nativeBuildInputs = [ pkg-config ];
buildInputs = [
udev
libusb1
(hidapi.overrideAttrs rec {
version = "connection-callback";
src = fetchFromGitHub {
owner = "libusb";
repo = "hidapi";
rev = "${version}";
sha256 = "sha256-peHXQbqNWL3XDQdRJ5piWEcglq742rez816lnja6wZA=";
};
})
];
}) And running the example with |
I have a usecase where I need to detect when new matching devices are inserted on the system. Currently I just periodically
.refresh_devices()
and re-iterate the list looking if there are any I haven't seen before, but this means there is a delay between when the device is inserted and the periodic refresh happens. It would be better ifhidapi
could monitor for changes in the device list and emit events as new devices appear (and events as they are removed could be useful too, though I already notice these when theDevice::read
returns an error).I'm not sure if this is something that is supported by the
hidapi
C backends, but it looks like it should be pretty trivial to build in thelinux-native
backend using theudev::MonitorBuilder
, and I will probably prototype it soon and could submit a PR if you'd accept it with just a single backend implementation.The text was updated successfully, but these errors were encountered: