* Make blocking APIs optionally async `DeviceInfo::open`, `Device::from_fd`, `Device::set_configuration`, `Device::reset`, `Interface::set_alt_setting`, `Interface::clear_halt` all perform IO but are currently blocking because the underlying OS APIs are blocking. `list_devices`,`list_buses`, `Device::claim_interface` `Device::detach_and_claim_interface` theoretically don't perform IO, but are also included here because they need to be async on WebUSB. The `MaybeFuture` trait allows deferring these actions to the thread pool from the `blocking` crate when used asynchronously with `.await` / `IntoFuture`, or directly runs the blocking syscall synchronously with a `.wait()` method.
17 lines
531 B
Rust
17 lines
531 B
Rust
//! Detach the kernel driver for an FTDI device and then reattach it.
|
|
use std::{thread::sleep, time::Duration};
|
|
|
|
use nusb::MaybeFuture;
|
|
fn main() {
|
|
env_logger::init();
|
|
let di = nusb::list_devices()
|
|
.wait()
|
|
.unwrap()
|
|
.find(|d| d.vendor_id() == 0x0403 && d.product_id() == 0x6001)
|
|
.expect("device should be connected");
|
|
|
|
let device = di.open().wait().unwrap();
|
|
device.detach_kernel_driver(0).unwrap();
|
|
sleep(Duration::from_secs(10));
|
|
device.attach_kernel_driver(0).unwrap();
|
|
}
|