mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 03:32:53 -05:00
Updated example to work again, fixed crash in interface.rs
This commit is contained in:
parent
1f740509c4
commit
d0e42076d8
4 changed files with 15 additions and 22 deletions
|
@ -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"
|
||||
|
|
|
@ -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<Self, Box<dyn Error>> {
|
||||
pub fn new(device_info: &DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
||||
let mut model = DeviceId {
|
||||
vendor_id: device_info.vendor_id(),
|
||||
product_id: device_info.product_id(),
|
||||
|
|
|
@ -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<Self, Box<dyn Error>> {
|
||||
let net_md_device = base::NetMD::new(device).unwrap();
|
||||
pub fn new(device: &nusb::DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
||||
let net_md_device = base::NetMD::new(device)?;
|
||||
Ok(NetMDInterface { net_md_device })
|
||||
}
|
||||
|
||||
|
|
27
src/main.rs
27
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
|
||||
|
|
Loading…
Reference in a new issue