O
OpenDeck•4w ago
thomasvs

Automatically reconnect attached streamdecks on replug/resume?

My streamdecks are plugged into a USB hub that's plugged into my laptop. If I take my laptop to work then come back home, I have to manually reconnect them clicking a button in the app. Maybe the app could listen to usb plugin events and automatically reconnect?
18 Replies
ninjadev64
ninjadev64•4w ago
I haven't found a clean way to listen for device connection events in Rust, but if you do find one, please let me know
thomasvs
thomasvsOP•4w ago
GitHub
GitHub - kbknapp/usbwatch-rs: Watch for USB events and execute acti...
Watch for USB events and execute actions from rules - kbknapp/usbwatch-rs
thomasvs
thomasvsOP•4w ago
looks like it's a command line tool but the code should serve as an example
thomasvs
thomasvsOP•4w ago
Device in udev - Rust
A structure that provides access to sysfs/kernel devices.
thomasvs
thomasvsOP•4w ago
alternatively, an easier way could be to have a SIGHUP handler (which usually is used for a daemon to reload config) and have that scan/reconnect. or USR1. then one could just add udev trigger rules to send that
ninjadev64
ninjadev64•4w ago
This one looks like it only supports Linux, and the same goes for talking to udev directly I generally only add features when they can work cross-platform (I gave the same response to the request for switching profiles when the focused window changes, until a cross-platform solution was found and then I implemented it)
thomasvs
thomasvsOP•4w ago
hm, tall order to have a cross-platform hotplug detection, but let's see
ninjadev64
ninjadev64•4w ago
sorry 😅 If you want I can add a rescan devices button, so that you can refresh the list even if you have a device connected already Of course there is the route of just polling every few seconds
thomasvs
thomasvsOP•4w ago
spoke to soon!
thomasvs
thomasvsOP•4w ago
GitHub
Hotplug events on device connect and disconnect · Issue #5 · kevinm...
Linux Typically udev Rust udev crate looks good, but wraps a C library. There's also a way to get events directly from the kernel with a NETLINK_KOBJECT_UEVENT socket Windows RegisterDeviceNoti...
thomasvs
thomasvsOP•4w ago
suggests that nusb has hotplug support cross-platform
ninjadev64
ninjadev64•4w ago
oh very cool this project seems very interesting, maybe I should have a look at adding it as a supported backend to the hidapi library that might resolve some inconsistencies between platforms as well (#Ajazz devices not functioning properly under Windows)
thomasvs
thomasvsOP•3w ago
as a temporary solution, allowing to choose to rescan every minute or so when no device is currently connected according to the app would work just fine for now
ninjadev64
ninjadev64•3w ago
@thomasvs latest commit rescans every 10 seconds seems to work fine with my Mini
thomasvs
thomasvsOP•3w ago
nice, will try, thanks! are there nightly builds or should I build and run from source to try?
ninjadev64
ninjadev64•3w ago
2.4.0 should be out by tomorrow I think
Dem
Dem•3w ago
might be late but this: https://github.com/haimgel/display-switch/blob/main/src/platform/pnp_detect_libusb.rs seems to also implement similar behaviour
GitHub
display-switch/src/platform/pnp_detect_libusb.rs at main · haimgel/...
Turn a $30 USB switch into a full-featured multi-monitor KVM switch - haimgel/display-switch
ninjadev64
ninjadev64•2w ago
Oh cool Sorry this hasn't happened yet, waiting on the resolution of a few more things Yea building from source might have been a better idea

Did you find this page helpful?