From 885e7508fda78bf34b49dc1d4ed740178736d4f9 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Wed, 14 Aug 2024 20:49:04 -0500 Subject: [PATCH] Updated `cross-usb` to v0.4.0 --- Cargo.toml | 2 +- src/netmd/base.rs | 8 ++++---- src/netmd/commands.rs | 4 ++-- src/netmd/interface.rs | 7 ++++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eee044a..aecea99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ nofmt = "1.0.0" once_cell = "1.18.0" unicode-normalization = "0.1.22" regex = "1.10" -cross_usb = "0.3" +cross_usb = "0.4" num-derive = "0.4.2" num-traits = "0.2.14" rand = "0.8.5" diff --git a/src/netmd/base.rs b/src/netmd/base.rs index 0c3f85c..0140d2d 100644 --- a/src/netmd/base.rs +++ b/src/netmd/base.rs @@ -6,8 +6,8 @@ use thiserror::Error; // USB stuff use cross_usb::prelude::*; -use cross_usb::usb::{ControlIn, ControlOut, ControlType, Recipient, UsbError}; -use cross_usb::{Descriptor, Interface}; +use cross_usb::usb::{ControlIn, ControlOut, ControlType, Recipient, Error}; +use cross_usb::{DeviceInfo, Interface}; use super::utils::cross_sleep; @@ -114,7 +114,7 @@ pub enum NetMDError { UnknownDevice(DeviceId), #[error("usb connection error")] - UsbError(#[from] UsbError), + UsbError(#[from] Error), } /// A low-level USB connection to a NetMD device. @@ -132,7 +132,7 @@ impl NetMD { const READ_REPLY_RETRY_INTERVAL: u32 = 10; /// Creates a new interface to a NetMD device - pub async fn new(usb_descriptor: Descriptor) -> Result { + pub async fn new(usb_descriptor: DeviceInfo) -> Result { let mut model = DeviceId { vendor_id: usb_descriptor.vendor_id().await, product_id: usb_descriptor.product_id().await, diff --git a/src/netmd/commands.rs b/src/netmd/commands.rs index 631f5a6..ad9d0ee 100644 --- a/src/netmd/commands.rs +++ b/src/netmd/commands.rs @@ -1,5 +1,5 @@ #![cfg_attr(debug_assertions, allow(dead_code))] -use cross_usb::Descriptor; +use cross_usb::DeviceInfo; use num_derive::FromPrimitive; use num_traits::FromPrimitive; use regex::Regex; @@ -278,7 +278,7 @@ pub struct NetMDContext { impl NetMDContext { /// Create a new context to control a NetMD device - pub async fn new(device: Descriptor) -> Result { + pub async fn new(device: DeviceInfo) -> Result { let interface = NetMDInterface::new(device).await?; Ok(Self { interface }) diff --git a/src/netmd/interface.rs b/src/netmd/interface.rs index eeaa3f6..6057276 100644 --- a/src/netmd/interface.rs +++ b/src/netmd/interface.rs @@ -306,11 +306,14 @@ pub struct NetMDInterface { #[allow(dead_code)] impl NetMDInterface { + /// The maximum number of times to retry after an interim response const MAX_INTERIM_READ_ATTEMPTS: u8 = 4; + + /// The amount of time to wait after an interim response (in milliseconds) const INTERIM_RESPONSE_RETRY_INTERVAL: u32 = 100; /// Get a new interface to a NetMD device - pub async fn new(device: cross_usb::Descriptor) -> Result { + pub async fn new(device: cross_usb::DeviceInfo) -> Result { let device = base::NetMD::new(device).await?; Ok(NetMDInterface { device }) } @@ -618,8 +621,6 @@ impl NetMDInterface { pub async fn disc_present(&mut self) -> Result { let status = self.status().await?; - println!("{:X?}", status); - Ok(status[4] == 0x40) }