Try all interfaces

This commit is contained in:
Lennard Kittner
2026-04-19 19:08:31 +02:00
parent b6f9b94ea8
commit 5a9934487d

View File

@@ -80,34 +80,34 @@ pub fn connect_compatible_device() -> Result<Box<dyn Device>, DeviceError> {
debug_println!("Found device selecting handler"); debug_println!("Found device selecting handler");
// On Linux and MacOS we can just take the first // On Linux and MacOS we can just take the first
#[cfg(not(target_os = "windows"))] // #[cfg(not(target_os = "windows"))]
{ // {
let state = states // let state = states
.into_iter() // .into_iter()
.next() // .next()
.ok_or(DeviceError::NoDeviceFound())?; // .ok_or(DeviceError::NoDeviceFound())?;
println!( // println!(
"Connecting to {}", // "Connecting to {}",
state // state
.device_properties // .device_properties
.device_name // .device_name
.clone() // .clone()
.unwrap_or("???".to_string()) // .unwrap_or("???".to_string())
); // );
let entry = DEVICE_REGISTER // let entry = DEVICE_REGISTER
.iter() // .iter()
.find(|e| { // .find(|e| {
e.vendor_ids.contains(&state.device_properties.vendor_id) // e.vendor_ids.contains(&state.device_properties.vendor_id)
&& e.product_ids.contains(&state.device_properties.product_id) // && e.product_ids.contains(&state.device_properties.product_id)
}) // })
.ok_or(DeviceError::NoDeviceFound())?; // .ok_or(DeviceError::NoDeviceFound())?;
//
let mut device = (entry.factory)(state); // let mut device = (entry.factory)(state);
device.init_capabilities(); // device.init_capabilities();
Ok(device) // Ok(device)
} // }
// On Windows we have to check which interface can be used // On Windows we have to check which interface can be used
#[cfg(target_os = "windows")] // #[cfg(target_os = "windows")]
{ {
let mut device = None; let mut device = None;
for state in states { for state in states {
@@ -133,7 +133,7 @@ pub fn connect_compatible_device() -> Result<Box<dyn Device>, DeviceError> {
let probe_packet = test_device let probe_packet = test_device
.get_query_packets() .get_query_packets()
.into_iter() .into_iter()
.next() .nth(2)
.expect("Why is there a device without packets ???"); .expect("Why is there a device without packets ???");
test_device.prepare_write(); test_device.prepare_write();
@@ -144,6 +144,16 @@ pub fn connect_compatible_device() -> Result<Box<dyn Device>, DeviceError> {
debug_println!("Failed to open: {_e:?}"); debug_println!("Failed to open: {_e:?}");
continue; continue;
} else { } else {
std::thread::sleep(RESPONSE_DELAY);
if let Some(events) = test_device.wait_for_updates(Duration::from_secs(1)) {
for event in events {
debug_println!("got response {event:?}");
}
} else {
continue;
}
device = Some(test_device); device = Some(test_device);
break; break;
} }