mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 11:42:53 -05:00
Updated cli example, cleaned up code
This commit is contained in:
parent
278ba2e8bd
commit
5e226075aa
3 changed files with 37 additions and 32 deletions
|
@ -11,7 +11,7 @@ license = "AGPL-3.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
translit = "0.5.0"
|
translit = "0.5.0"
|
||||||
webusb = "0.5.0"
|
yusb = "0.1.2"
|
||||||
|
|
||||||
[dependencies.minidisc-rs]
|
[dependencies.minidisc-rs]
|
||||||
path = "minidisc-rs"
|
path = "minidisc-rs"
|
||||||
|
|
|
@ -13,8 +13,8 @@ const BULK_WRITE_ENDPOINT: u8 = 0x02;
|
||||||
const BULK_READ_ENDPOINT: u8 = 0x81;
|
const BULK_READ_ENDPOINT: u8 = 0x81;
|
||||||
|
|
||||||
pub static DEVICE_IDS: Lazy<Box<[DeviceId]>> = Lazy::new(|| {
|
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: 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: 0x9013, name: Some(String::from("Sharp IM-DR400"))},
|
||||||
DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))},
|
DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))},
|
||||||
|
@ -94,7 +94,7 @@ pub struct NetMD {
|
||||||
impl NetMD {
|
impl NetMD {
|
||||||
const READ_REPLY_RETRY_INTERVAL: u32 = 10;
|
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>> {
|
pub fn new(device: Device) -> Result<Self, Box<dyn Error>> {
|
||||||
let descriptor = device.device_descriptor()?;
|
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> {
|
pub fn device_name(&self) -> &Option<String> {
|
||||||
&self.model.name
|
&self.model.name
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the vendor id from the struct
|
/// Gets the vendor id
|
||||||
pub fn vendor_id(&self) -> &u16 {
|
pub fn vendor_id(&self) -> &u16 {
|
||||||
&self.model.vendor_id
|
&self.model.vendor_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the product id from the struct
|
/// Gets the product id
|
||||||
pub fn product_id(&self) -> &u16 {
|
pub fn product_id(&self) -> &u16 {
|
||||||
&self.model.product_id
|
&self.model.product_id
|
||||||
}
|
}
|
||||||
|
|
49
src/main.rs
49
src/main.rs
|
@ -1,39 +1,44 @@
|
||||||
use std::thread::sleep;
|
|
||||||
use std::collections::BTreeSet;
|
|
||||||
|
|
||||||
use minidisc_rs::netmd::interface;
|
use minidisc_rs::netmd::interface;
|
||||||
use webusb;
|
use yusb;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let webusb_context = webusb::Context::init().unwrap();
|
let webusb_context = yusb::Context::new().unwrap();
|
||||||
|
|
||||||
for mut device in webusb_context.devices().unwrap() {
|
for device in webusb_context.devices().unwrap() {
|
||||||
match device.open() {
|
let handle = match device.open() {
|
||||||
Ok(device) => device,
|
Ok(handle) => handle,
|
||||||
Err(_) => break,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
device.claim_interface(0).unwrap();
|
let descriptor = device.device_descriptor().unwrap();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Connected to {} {}; VID: {:04x}, PID: {:04x}",
|
"Connected to VID: {:04x}, PID: {:04x}",
|
||||||
device.manufacturer_name.clone().unwrap_or("".to_string()),
|
descriptor.vendor_id(),
|
||||||
device.product_name.clone().unwrap_or("".to_string()),
|
descriptor.product_id(),
|
||||||
device.vendor_id,
|
|
||||||
device.product_id
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure the player is a minidisc player and not some other random device
|
// 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,
|
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();
|
let now = std::time::Instant::now();
|
||||||
println!("Disc Title: {} | {}",
|
println!(
|
||||||
player_controller.disc_title(false).unwrap_or("".to_string()),
|
"Disc Title: {} | {}",
|
||||||
|
player_controller
|
||||||
|
.disc_title(false)
|
||||||
|
.unwrap_or("".to_string()),
|
||||||
player_controller.disc_title(true).unwrap_or("".to_string())
|
player_controller.disc_title(true).unwrap_or("".to_string())
|
||||||
);
|
);
|
||||||
let track_count = player_controller.track_count().unwrap();
|
let track_count = player_controller.track_count().unwrap();
|
||||||
|
@ -41,9 +46,9 @@ fn main() {
|
||||||
let track_titlesw = player_controller.track_titles((0..track_count).collect(), true).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();
|
let track_lengths = player_controller.track_lengths((0..track_count).collect()).unwrap();
|
||||||
for (i, track) in track_titles.iter().enumerate() {
|
for (i, track) in track_titles.iter().enumerate() {
|
||||||
println!("Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
|
println!(
|
||||||
track_titlesw[i],
|
"Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
|
||||||
track_lengths[i]
|
track_titlesw[i], track_lengths[i]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!("{:?}", now.elapsed());
|
println!("{:?}", now.elapsed());
|
||||||
|
|
Loading…
Reference in a new issue