Skip to content

Commit

Permalink
Only enumerate Wooting HID devices (#74)
Browse files Browse the repository at this point in the history
* Use HidApi::new_without_enumerate since refresh_device is called afterwards anyway

* Only enumerate Wooting HID devices
  • Loading branch information
Sainan authored Jul 26, 2024
1 parent 4d1ab8a commit a57bd32
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 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"

Expand Down
14 changes: 11 additions & 3 deletions wooting-analog-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,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 @@ -488,10 +496,10 @@ impl WootingPlugin {
Box::new(WootingUwU()),
Box::new(WootingUwURgb()),
];
let mut hid = match HidApi::new() {
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 @@ -532,7 +540,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 a57bd32

Please sign in to comment.