From a57bd328dbdfb38e766ad0474139d8543c2d6252 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 26 Jul 2024 12:40:36 +0200 Subject: [PATCH] Only enumerate Wooting HID devices (#74) * Use HidApi::new_without_enumerate since refresh_device is called afterwards anyway * Only enumerate Wooting HID devices --- Cargo.lock | 78 ++++++++++++++++++++++++++++++-- wooting-analog-plugin/Cargo.toml | 2 +- wooting-analog-plugin/src/lib.rs | 14 ++++-- 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1b6a54..862295d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,13 +1260,15 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "hidapi" -version = "1.4.1" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b1717343691998deb81766bfcd1dce6df0d5d6c37070b5a3de2bb6d39f7822" +checksum = "830eccace7c861211d0ad04288e5dad690d6711b0db152084da58882ee7a840a" dependencies = [ "cc", + "cfg-if 1.0.0", "libc", "pkg-config", + "windows-sys 0.48.0", ] [[package]] @@ -3778,7 +3780,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", ] [[package]] @@ -3787,21 +3798,42 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" @@ -3814,6 +3846,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.36.1" @@ -3826,6 +3864,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.36.1" @@ -3838,6 +3882,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" @@ -3850,12 +3900,24 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" @@ -3868,6 +3930,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "winit" version = "0.26.1" diff --git a/wooting-analog-plugin/Cargo.toml b/wooting-analog-plugin/Cargo.toml index 0328e3e..62c07dc 100644 --- a/wooting-analog-plugin/Cargo.toml +++ b/wooting-analog-plugin/Cargo.toml @@ -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" diff --git a/wooting-analog-plugin/src/lib.rs b/wooting-analog-plugin/src/lib.rs index 6ea6755..5dfcf55 100644 --- a/wooting-analog-plugin/src/lib.rs +++ b/wooting-analog-plugin/src/lib.rs @@ -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> = vec![ Box::new(WootingOne()), Box::new(WootingTwo()), @@ -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 @@ -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);