-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use cyme::lsusb::profiler; | ||
|
||
fn main() -> Result<(), String> { | ||
// get all system devices - this time with extra data which contain the USBConfiguration, driver data (with udev) | ||
let sp_usb = profiler::get_spusb_with_extra(false).map_err(|e| { | ||
format!("Failed to gather system USB data from libusb, Error({})", e) | ||
})?; | ||
|
||
let devices = sp_usb.flatten_devices(); | ||
|
||
// print all configurations | ||
for device in devices { | ||
device.extra.as_ref().map(|extra| { | ||
println!("Device {} has configurations:", device.name); | ||
for c in extra.configurations.iter() { | ||
println!("{:?}", c); | ||
}; | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// This example shows how to use the USBFilter to filter out devices that match a certain criteria | ||
/// | ||
/// See [`USBFilter`] docs for more information | ||
use cyme::lsusb::profiler; | ||
use cyme::usb::ClassCode; | ||
use cyme::system_profiler::USBFilter; | ||
|
||
fn main() -> Result<(), String> { | ||
// get all system devices | ||
let mut sp_usb = profiler::get_spusb(false).map_err(|e| { | ||
format!("Failed to gather system USB data from libusb, Error({})", e) | ||
})?; | ||
|
||
// if one does want the tree, use the utility | ||
let filter = USBFilter { | ||
class: Some(ClassCode::HID), | ||
..Default::default() | ||
}; | ||
|
||
// will retain only the buses that have devices that match the filter - parent devices such as hubs with a HID device will be retained | ||
filter.retain_buses(&mut sp_usb.buses); | ||
sp_usb.buses.retain(|b| b.devices.as_ref().map_or(false, |d| d.is_empty())); | ||
|
||
// if one does not care about the tree, flatten the devices and do manually | ||
// let hid_devices = sp_usb.flatten_devices().iter().filter(|d| d.class == Some(ClassCode::HID)); | ||
|
||
if sp_usb.buses.is_empty() { | ||
println!("No HID devices found"); | ||
} else { | ||
println!("Found HID devices"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use cyme::lsusb::profiler; | ||
use cyme::system_profiler::USBDevice; | ||
|
||
fn recusive_map_devices(device: &USBDevice) { | ||
// the alternate format will print with colour | ||
println!("Device: {:#}", device); | ||
device.devices.as_ref().map(|v| { | ||
for d in v { | ||
recusive_map_devices(d) | ||
} | ||
}); | ||
} | ||
|
||
fn main() -> Result<(), String> { | ||
// get all system devices | ||
let sp_usb = profiler::get_spusb(false).map_err(|e| { | ||
format!("Failed to gather system USB data from libusb, Error({})", e) | ||
})?; | ||
|
||
// SPUSBDataType contains buses... | ||
for bus in sp_usb.buses { | ||
// which may contain devices... | ||
bus.devices.as_ref().map(|devices| { | ||
// to walk all the devices, since each device can have devices attached, call a recursive function | ||
for device in devices { | ||
recusive_map_devices(device); | ||
} | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} |