diff --git a/Cargo.toml b/Cargo.toml index 0875fa3..5587ca2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ license = "AGPL-3.0" [dependencies] hex = "0.4.3" +nusb = "0.1.4" translit = "0.5.0" -yusb = "0.1.2" [dependencies.minidisc-rs] path = "minidisc-rs" diff --git a/minidisc-rs/src/netmd/base.rs b/minidisc-rs/src/netmd/base.rs index 07bdc6b..3a4de06 100644 --- a/minidisc-rs/src/netmd/base.rs +++ b/minidisc-rs/src/netmd/base.rs @@ -9,7 +9,7 @@ use nusb::{Device, DeviceInfo, Interface}; use futures_lite::future::block_on; -const DEFAULT_TIMEOUT: Duration = Duration::new(9999999, 0); +const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0); const BULK_WRITE_ENDPOINT: u8 = 0x02; const BULK_READ_ENDPOINT: u8 = 0x81; @@ -98,7 +98,7 @@ impl NetMD { const READ_REPLY_RETRY_INTERVAL: u32 = 10; /// Creates a new interface to a NetMD device - pub fn new(device_info: DeviceInfo) -> Result> { + pub fn new(device_info: &DeviceInfo) -> Result> { let mut model = DeviceId { vendor_id: device_info.vendor_id(), product_id: device_info.product_id(), diff --git a/minidisc-rs/src/netmd/interface.rs b/minidisc-rs/src/netmd/interface.rs index a126059..a168f0d 100644 --- a/minidisc-rs/src/netmd/interface.rs +++ b/minidisc-rs/src/netmd/interface.rs @@ -202,8 +202,8 @@ impl NetMDInterface { const MAX_INTERIM_READ_ATTEMPTS: u8 = 4; const INTERIM_RESPONSE_RETRY_INTERVAL: u32 = 100; - pub fn new(device: nusb::DeviceInfo) -> Result> { - let net_md_device = base::NetMD::new(device).unwrap(); + pub fn new(device: &nusb::DeviceInfo) -> Result> { + let net_md_device = base::NetMD::new(device)?; Ok(NetMDInterface { net_md_device }) } diff --git a/src/main.rs b/src/main.rs index fd1c02f..bcece72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,22 @@ use minidisc_rs::netmd::interface; -use yusb; +use nusb; fn main() { - let webusb_context = yusb::Context::new().unwrap(); - - for device in webusb_context.devices().unwrap() { - let handle = match device.open() { - Ok(handle) => handle, - Err(_) => continue, - }; - - let descriptor = device.device_descriptor().unwrap(); - - println!( - "Connected to VID: {:04x}, PID: {:04x}", - descriptor.vendor_id(), - descriptor.product_id(), - ); + let devices = nusb::list_devices().unwrap(); + for device in devices { // Ensure the player is a minidisc player and not some other random device - let mut player_controller = match interface::NetMDInterface::new(device) { + let mut player_controller = match interface::NetMDInterface::new(&device) { Ok(player) => player, Err(_) => continue, }; + println!( + "Connected to VID: {:04x}, PID: {:04x}", + device.vendor_id(), + device.product_id(), + ); + println!( "Player Model: {}", player_controller