| 1 | use futures_lite::future::block_on; |
| 2 | use nusb::transfer::{ControlIn, ControlOut, ControlType, Recipient}; |
| 3 | |
| 4 | fn main() { |
| 5 | env_logger::init(); |
| 6 | let di = nusb::list_devices() |
| 7 | .unwrap() |
| 8 | .find(|d| d.vendor_id() == 0x59e3 && d.product_id() == 0x0a23) |
| 9 | .expect("device should be connected"); |
| 10 | |
| 11 | println!("Device info: {di:?}"); |
| 12 | |
| 13 | let device = di.open().unwrap(); |
| 14 | |
| 15 | // Linux can make control transfers without claiming an interface |
| 16 | #[cfg(any(target_os = "linux", target_os = "macos"))] |
| 17 | { |
| 18 | let result = block_on(device.control_out(ControlOut { |
| 19 | control_type: ControlType::Vendor, |
| 20 | recipient: Recipient::Device, |
| 21 | request: 0x81, |
| 22 | value: 0x9999, |
| 23 | index: 0x9999, |
| 24 | data: &[1, 2, 3, 4], |
| 25 | })); |
| 26 | println!("{result:?}"); |
| 27 | |
| 28 | let result = block_on(device.control_in(ControlIn { |
| 29 | control_type: ControlType::Vendor, |
| 30 | recipient: Recipient::Device, |
| 31 | request: 0x81, |
| 32 | value: 0x9999, |
| 33 | index: 0x9999, |
| 34 | length: 256, |
| 35 | })); |
| 36 | println!("{result:?}"); |
| 37 | } |
| 38 | |
| 39 | // but we also provide an API on the `Interface` to support Windows |
| 40 | let interface = device.claim_interface(0).unwrap(); |
| 41 | |
| 42 | let result = block_on(interface.control_out(ControlOut { |
| 43 | control_type: ControlType::Vendor, |
| 44 | recipient: Recipient::Device, |
| 45 | request: 0x81, |
| 46 | value: 0x9999, |
| 47 | index: 0x9999, |
| 48 | data: &[1, 2, 3, 4], |
| 49 | })); |
| 50 | println!("{result:?}"); |
| 51 | |
| 52 | let result = block_on(interface.control_in(ControlIn { |
| 53 | control_type: ControlType::Vendor, |
| 54 | recipient: Recipient::Device, |
| 55 | request: 0x81, |
| 56 | value: 0x9999, |
| 57 | index: 0x9999, |
| 58 | length: 256, |
| 59 | })); |
| 60 | println!("{result:?}"); |
| 61 | } |