Merge pull request #85 from tuna-f1sh/win-hub-devices

Windows: include hub devices in list like other platforms
This commit is contained in:
Kevin Mehall 2024-10-19 15:06:03 -06:00 committed by GitHub
commit b3097f552a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -142,9 +142,6 @@ pub type Error = io::Error;
/// .find(|dev| dev.vendor_id() == 0xAAAA && dev.product_id() == 0xBBBB)
/// .expect("device not connected");
/// ```
///
/// ### Platform-specific notes
/// * On Windows, hubs are not included in the list
pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
platform::list_devices()
}

View file

@ -29,7 +29,9 @@ use super::{
pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
let devs: Vec<DeviceInfo> = cfgmgr32::list_interfaces(GUID_DEVINTERFACE_USB_DEVICE, None)
// get USB_HUB devices as well, like other platforms. ROOT_HUBs will be dropped by probe_device
.iter()
.chain(cfgmgr32::list_interfaces(GUID_DEVINTERFACE_USB_HUB, None).iter())
.flat_map(|i| get_device_interface_property::<WCString>(i, DEVPKEY_Device_InstanceId))
.flat_map(|d| DevInst::from_instance_id(&d))
.flat_map(probe_device)
@ -49,6 +51,10 @@ pub fn list_buses() -> Result<impl Iterator<Item = BusInfo>, Error> {
pub fn probe_device(devinst: DevInst) -> Option<DeviceInfo> {
let instance_id = devinst.get_property::<OsString>(DEVPKEY_Device_InstanceId)?;
if instance_id.to_string_lossy().starts_with("USB\\ROOT_HUB") {
return None;
}
debug!("Probing device {instance_id:?}");
let parent_instance_id = devinst.get_property::<OsString>(DEVPKEY_Device_Parent)?;