Updated cli example, cleaned up code

This commit is contained in:
G2-Games 2023-12-18 12:18:47 -06:00
parent 278ba2e8bd
commit 5e226075aa
3 changed files with 37 additions and 32 deletions

View file

@ -11,7 +11,7 @@ license = "AGPL-3.0"
[dependencies]
hex = "0.4.3"
translit = "0.5.0"
webusb = "0.5.0"
yusb = "0.1.2"
[dependencies.minidisc-rs]
path = "minidisc-rs"

View file

@ -13,8 +13,8 @@ const BULK_WRITE_ENDPOINT: u8 = 0x02;
const BULK_READ_ENDPOINT: u8 = 0x81;
pub static DEVICE_IDS: Lazy<Box<[DeviceId]>> = Lazy::new(|| {
nofmt::pls! {Box::new(
[
nofmt::pls! {
Box::new([
DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))},
DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))},
DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))},
@ -94,7 +94,7 @@ pub struct NetMD {
impl NetMD {
const READ_REPLY_RETRY_INTERVAL: u32 = 10;
/// Creates a new `NetMD` struct
/// Creates a new interface to a NetMD device
pub fn new(device: Device) -> Result<Self, Box<dyn Error>> {
let descriptor = device.device_descriptor()?;
@ -125,17 +125,17 @@ impl NetMD {
})
}
/// Gets the device name from the struct
/// Gets the device name, this is limited to the devices in the list
pub fn device_name(&self) -> &Option<String> {
&self.model.name
}
/// Gets the vendor id from the struct
/// Gets the vendor id
pub fn vendor_id(&self) -> &u16 {
&self.model.vendor_id
}
/// Gets the product id from the struct
/// Gets the product id
pub fn product_id(&self) -> &u16 {
&self.model.product_id
}

View file

@ -1,49 +1,54 @@
use std::thread::sleep;
use std::collections::BTreeSet;
use minidisc_rs::netmd::interface;
use webusb;
use yusb;
fn main() {
let webusb_context = webusb::Context::init().unwrap();
let webusb_context = yusb::Context::new().unwrap();
for mut device in webusb_context.devices().unwrap() {
match device.open() {
Ok(device) => device,
Err(_) => break,
for device in webusb_context.devices().unwrap() {
let handle = match device.open() {
Ok(handle) => handle,
Err(_) => continue,
};
device.claim_interface(0).unwrap();
let descriptor = device.device_descriptor().unwrap();
println!(
"Connected to {} {}; VID: {:04x}, PID: {:04x}",
device.manufacturer_name.clone().unwrap_or("".to_string()),
device.product_name.clone().unwrap_or("".to_string()),
device.vendor_id,
device.product_id
"Connected to VID: {:04x}, PID: {:04x}",
descriptor.vendor_id(),
descriptor.product_id(),
);
// Ensure the player is a minidisc player and not some other random device
let mut player_controller = match interface::NetMDInterface::new(device) {
Ok(player) => player,
Err(_) => continue
Err(_) => continue,
};
println!("Player Model: {}", player_controller.net_md_device.device_name().clone().unwrap());
println!(
"Player Model: {}",
player_controller
.net_md_device
.device_name()
.clone()
.unwrap()
);
let now = std::time::Instant::now();
println!("Disc Title: {} | {}",
player_controller.disc_title(false).unwrap_or("".to_string()),
player_controller.disc_title(true).unwrap_or("".to_string())
println!(
"Disc Title: {} | {}",
player_controller
.disc_title(false)
.unwrap_or("".to_string()),
player_controller.disc_title(true).unwrap_or("".to_string())
);
let track_count = player_controller.track_count().unwrap();
let track_titles = player_controller.track_titles((0..track_count).collect(), false).unwrap();
let track_count = player_controller.track_count().unwrap();
let track_titles = player_controller.track_titles((0..track_count).collect(), false).unwrap();
let track_titlesw = player_controller.track_titles((0..track_count).collect(), true).unwrap();
let track_lengths = player_controller.track_lengths((0..track_count).collect()).unwrap();
for (i, track) in track_titles.iter().enumerate() {
println!("Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
track_titlesw[i],
track_lengths[i]
println!(
"Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
track_titlesw[i], track_lengths[i]
);
}
println!("{:?}", now.elapsed());