diff options
Diffstat (limited to 'rust/qmk-hid-com/src/search.rs')
-rw-r--r-- | rust/qmk-hid-com/src/search.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/rust/qmk-hid-com/src/search.rs b/rust/qmk-hid-com/src/search.rs new file mode 100644 index 0000000..3c954ba --- /dev/null +++ b/rust/qmk-hid-com/src/search.rs @@ -0,0 +1,51 @@ +use hidapi::HidApi; + +pub fn search(api: &HidApi, vendor_name: String) -> anyhow::Result<()> { + for device in api.device_list() { + if let Some(string) = device.manufacturer_string() { + if string.to_lowercase().contains(&vendor_name.to_lowercase()) { + println!( + "Device matches: {} (VID) - {} (PID) {}:{} - at {} by {} via {:#?}", + device.vendor_id(), + device.product_id(), + device.usage_page(), + device.usage(), + device.path().to_str()?, + string, + device.bus_type(), + ); + + println!( + " {} (Interface {}):", + match device.product_string() { + Some(s) => s, + _ => "<COULD NOT FETCH>", + }, + device.interface_number() + ); + let mut descriptor = vec![0u8; 2048]; + match device + .open_device(api) + .and_then(|dev| dev.get_report_descriptor(&mut descriptor)) + { + Ok(length) => { + println!(" {} (descriptor)", { + &descriptor[..length] + .iter() + .map(|val| val.to_string()) + .collect::<String>() + }) + } + Err(err) => println!(" Failed to retrieve descriptor ({:?})", err), + } + println!(); + } + } else { + eprintln!( + "Device without manufacturer string ({})", + device.product_id() + ); + } + } + Ok(()) +} |