Skip to content

Commit

Permalink
Merge pull request #85 from tuna-f1sh/win-hub-devices
Browse files Browse the repository at this point in the history
Windows: include hub devices in list like other platforms
  • Loading branch information
kevinmehall authored Oct 19, 2024
2 parents 8092280 + 785e89a commit b3097f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 6 additions & 0 deletions src/platform/windows_winusb/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)?;
Expand Down

0 comments on commit b3097f5

Please sign in to comment.