Skip to content

Commit

Permalink
Only enumerate Wooting HID devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jan 31, 2024
1 parent 61101e5 commit 9609664
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
78 changes: 73 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wooting-analog-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ log = "^0.4"
# For dev
wooting-analog-plugin-dev = { path = "../wooting-analog-plugin-dev"}
# wooting-analog-plugin-dev = "^0.6"
hidapi = { version = "^1.2", features = ["linux-static-hidraw"], default-features = false }
hidapi = { version = "^2.5", features = ["linux-static-hidraw"], default-features = false }
env_logger = "^0.7"
objekt = "^0.1"
timer = "^0.2"
Expand Down
12 changes: 10 additions & 2 deletions wooting-analog-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ impl WootingPlugin {
}
};

let refresh_devices = |hid: &mut HidApi| -> hidapi::HidResult<()> {
hid.reset_devices()?;
hid.add_devices(WOOTING_VID, 0)?;
hid.add_devices(0x03EB, 0xFF01)?;
hid.add_devices(0x03EB, 0xFF02)?;
Ok(())
};

let device_impls: Vec<Box<dyn DeviceImplementation>> = vec![
Box::new(WootingOne()),
Box::new(WootingTwo()),
Expand All @@ -479,7 +487,7 @@ impl WootingPlugin {
let mut hid = match HidApi::new_without_enumerate() {
Ok(mut api) => {
//An attempt at trying to ensure that all the devices have been found in the initialisation of the plugins
if let Err(e) = api.refresh_devices() {
if let Err(e) = refresh_devices(&mut api) {
error!("We got error while refreshing devices. Err: {}", e);
}
api
Expand Down Expand Up @@ -516,7 +524,7 @@ impl WootingPlugin {
}
}

if let Err(e) = hid.refresh_devices() {
if let Err(e) = refresh_devices(&mut hid) {
error!("We got error while refreshing devices. Err: {}", e);
}
init_device_closure(&hid, &t_devices, &t_device_event_cb, &device_impls);
Expand Down

0 comments on commit 9609664

Please sign in to comment.