Skip to content

Commit

Permalink
Improve USB HID handling
Browse files Browse the repository at this point in the history
Switch `hidapi` backend from `libusb` to the linux-specific `hidapi-hidraw`.
Update `FRAME_GENERATION_COUNTER` on device hotplug, to ensure that
the device is in a known state.

References #161
  • Loading branch information
X3n0m0rph59 committed Oct 6, 2022
1 parent 8d49065 commit a8c3e8c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion eruption-debug-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ thiserror = "1.0.37"
eyre = "0.6.8"
color-eyre = "0.6.2"
hexdump = "0.1.1"
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
bitvec = "1.0.1"
byteorder = "1.4.3"
serialport = "4.2.0"
Expand Down
2 changes: 1 addition & 1 deletion eruption-hwutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ eyre = "0.6.8"
color-eyre = "0.6.2"
bitvec = "1.0.1"
byteorder = "1.4.3"
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
hexdump = "0.1.1"
serialport = "4.2.0"
crc8 = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion eruption-keymap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ eyre = "0.6.8"
color-eyre = "0.6.2"
hexdump = "0.1.1"
chrono = { version = "0.4.22", features = ["serde"] }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
#lua-src = "544.0.1"
#mlua = { version = "0.7.3", features = ["lua54", "vendored"] }
#luajit-src = "210.3.2+resty1085a4d"
Expand Down
2 changes: 1 addition & 1 deletion eruption-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ eyre = "0.6.8"
color-eyre = "0.6.2"
hexdump = "0.1.1"
chrono = { version = "0.4.22", features = ["serde"] }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
#lua-src = "544.0.1"
#mlua = { version = "0.7.3", features = ["lua54", "vendored"] }
#luajit-src = "210.3.2+resty1085a4d"
Expand Down
2 changes: 1 addition & 1 deletion eruption-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ thiserror = "1.0.37"
eyre = "0.6.8"
color-eyre = "0.6.2"
hexdump = "0.1.1"
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
udev = "0.6.3"
evdev-rs = "0.6.0"
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion eruption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ctrlc = { version = "3.2.3", features = ["termination"] }
clap = "4.0.10"
hotwatch = "0.4.6"
config = "0.13.2"
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master" }
hidapi = { git = "https://github.com/ruabmbua/hidapi-rs.git", branch = "master", default-features = false, features = ["linux-shared-hidraw"] }
udev = "0.6.3"
evdev-rs = "0.6.0"
hexdump = "0.1.1"
Expand Down
10 changes: 9 additions & 1 deletion eruption/src/dbus_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use dbus_tree::{
};
use flume::Sender;
use log::*;
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::{path::PathBuf, thread, time::Duration};

use crate::{
color_scheme::ColorScheme,
Expand Down Expand Up @@ -1020,6 +1020,14 @@ impl DbusApi {
))
.map_err(|_| error!("D-Bus error during send call"));

// this is required for hotplug to work correctly in case we didn't transfer
// data to the device for an extended period of time
script::FRAME_GENERATION_COUNTER.fetch_add(1, Ordering::SeqCst);
thread::sleep(Duration::from_millis(120));

// we need to terminate and then re-enter the main loop to update all global state
crate::REENTER_MAIN_LOOP.store(true, Ordering::SeqCst);

Ok(())
}

Expand Down
3 changes: 1 addition & 2 deletions eruption/src/hwdevices/roccat_vulcan_1xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ impl RoccatVulcan1xx {
} else if !self.is_opened {
Err(HwDeviceError::DeviceNotOpened {}.into())
} else {
// DEBUG: Does this help KVM switches to not fail to init the device?
// sleep for a short while
// This helps slow USB HUBs and KVM switches to not fail to init the device
thread::sleep(Duration::from_millis(25));

loop {
Expand Down
7 changes: 4 additions & 3 deletions eruption/src/plugins/sdk_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,10 @@ impl SdkSupportPlugin {

claim_hotplugged_devices(&hotplug_info)?;

// we need to terminate and then re-enter the main loop to update all global state
crate::REENTER_MAIN_LOOP
.store(true, Ordering::SeqCst);
// this is required for hotplug to work correctly in case we didn't transfer
// data to the device for an extended period of time
script::FRAME_GENERATION_COUNTER
.fetch_add(1, Ordering::SeqCst);

let response = protocol::Response {
response_message: Some(
Expand Down

0 comments on commit a8c3e8c

Please sign in to comment.