| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| 2 | |
| 3 | use nusbrust-analyzer cargo nusb 0.1.13 crate/::{descriptorsrust-analyzer cargo nusb 0.1.13 descriptors/::language_idrust-analyzer cargo nusb 0.1.13 descriptors/language_id/::US_ENGLISHrust-analyzer cargo nusb 0.1.13 descriptors/language_id/US_ENGLISH., DeviceInforust-analyzer cargo nusb 0.1.13 enumeration/DeviceInfo#}; |
| 4 | |
| 5 | fn mainrust-analyzer cargo nusb 0.1.13 main().() { |
| 6 | env_loggerrust-analyzer cargo env_logger 0.11.11 crate/::initrust-analyzer cargo env_logger 0.11.11 logger/init().(); |
| 7 | for dev in nusbrust-analyzer cargo nusb 0.1.13 crate/::list_devicesrust-analyzer cargo nusb 0.1.13 list_devices().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() { |
| 8 | inspect_devicerust-analyzer cargo nusb 0.1.13 inspect_device().(dev); |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | fn inspect_devicerust-analyzer cargo nusb 0.1.13 inspect_device().(dev: DeviceInforust-analyzer cargo nusb 0.1.13 enumeration/DeviceInfo#) { |
| 13 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 14 | "Device {:03}.{:03} ({:04x}:{:04x}) {} {}", |
| 15 | dev.bus_numberrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]bus_number().(), |
| 16 | dev.device_addressrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]device_address().(), |
| 17 | dev.vendor_idrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]vendor_id().(), |
| 18 | dev.product_idrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]product_id().(), |
| 19 | dev.manufacturer_stringrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]manufacturer_string().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(""), |
| 20 | dev.product_stringrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]product_string().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("") |
| 21 | ); |
| 22 | let dev = match dev.openrust-analyzer cargo nusb 0.1.13 enumeration/impl#[DeviceInfo]open().() { |
| 23 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(dev) => dev, |
| 24 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 25 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Failed to open device: {}", e); |
| 26 | return; |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | let timeout = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100); |
| 31 | |
| 32 | let dev_descriptor = dev.get_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_descriptor().(0x01, 0, 0, timeout).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 33 | if dev_descriptor.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().18 |
| 34 | || dev_descriptor[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().dev_descriptor.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 35 | || dev_descriptor[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0x01 |
| 36 | { |
| 37 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Invalid device descriptor: {dev_descriptor:?}"); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | let languages: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16> = dev |
| 42 | .get_string_descriptor_supported_languagesrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor_supported_languages().(timeout) |
| 43 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|i| i.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 44 | .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().(); |
| 45 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Languages: {languages:02x?}"); |
| 46 | |
| 47 | let language = languages.firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(US_ENGLISHrust-analyzer cargo nusb 0.1.13 descriptors/language_id/US_ENGLISH.); |
| 48 | |
| 49 | let i_manufacturer = dev_descriptor[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().14]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 50 | if i_manufacturer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 51 | let s = dev.get_string_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor().(i_manufacturer, language, timeout); |
| 52 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Manufacturer({i_manufacturer}): {s:?}"); |
| 53 | } |
| 54 | |
| 55 | let i_product = dev_descriptor[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().15]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 56 | if i_product rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 57 | let s = dev.get_string_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor().(i_product, language, timeout); |
| 58 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Product({i_product}): {s:?}"); |
| 59 | } |
| 60 | |
| 61 | let i_serial = dev_descriptor[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().16]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 62 | if i_serial rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 63 | let s = dev.get_string_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor().(i_serial, language, timeout); |
| 64 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Serial({i_serial}): {s:?}"); |
| 65 | } |
| 66 | |
| 67 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(""); |
| 68 | } |