Ran cargo fmt

This commit is contained in:
G2-Games 2024-01-29 19:44:33 -06:00
parent 1d188c335d
commit 33feb301e8
6 changed files with 345 additions and 318 deletions

View file

@ -4,7 +4,7 @@ use std::error::Error;
use std::time::Duration; use std::time::Duration;
// USB stuff // USB stuff
use nusb::transfer::{Control, ControlType, Recipient, RequestBuffer, ControlIn, ControlOut}; use nusb::transfer::{Control, ControlIn, ControlOut, ControlType, Recipient, RequestBuffer};
use nusb::{Device, DeviceInfo, Interface}; use nusb::{Device, DeviceInfo, Interface};
const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0); const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0);
@ -146,16 +146,19 @@ impl NetMD {
/// of the previous command, or the status /// of the previous command, or the status
pub async fn poll(&mut self) -> Result<(u16, [u8; 4]), Box<dyn Error>> { pub async fn poll(&mut self) -> Result<(u16, [u8; 4]), Box<dyn Error>> {
// Create an array to store the result of the poll // Create an array to store the result of the poll
let poll_result = match self.usb_interface.control_in( let poll_result = match self
ControlIn { .usb_interface
.control_in(ControlIn {
control_type: ControlType::Vendor, control_type: ControlType::Vendor,
recipient: Recipient::Interface, recipient: Recipient::Interface,
request: 0x01, request: 0x01,
value: 0, value: 0,
index: 0, index: 0,
length: 4, length: 4,
} })
).await.into_result() { .await
.into_result()
{
Ok(size) => size, Ok(size) => size,
Err(error) => return Err(error.into()), Err(error) => return Err(error.into()),
}; };
@ -198,22 +201,28 @@ impl NetMD {
true => 0xff, true => 0xff,
}; };
match self.usb_interface.control_out( match self
ControlOut { .usb_interface
.control_out(ControlOut {
control_type: ControlType::Vendor, control_type: ControlType::Vendor,
recipient: Recipient::Interface, recipient: Recipient::Interface,
request, request,
value: 0, value: 0,
index: 0, index: 0,
data: &command, data: &command,
} })
).await.into_result() { .await
.into_result()
{
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(error) => Err(error.into()), Err(error) => Err(error.into()),
} }
} }
pub async fn read_reply(&mut self, override_length: Option<i32>) -> Result<Vec<u8>, Box<dyn Error>> { pub async fn read_reply(
&mut self,
override_length: Option<i32>,
) -> Result<Vec<u8>, Box<dyn Error>> {
self._read_reply(false, override_length).await self._read_reply(false, override_length).await
} }
@ -253,16 +262,18 @@ impl NetMD {
}; };
// Create a buffer to fill with the result // Create a buffer to fill with the result
let reply = self.usb_interface.control_in( let reply = self
ControlIn { .usb_interface
.control_in(ControlIn {
control_type: ControlType::Vendor, control_type: ControlType::Vendor,
recipient: Recipient::Interface, recipient: Recipient::Interface,
request, request,
value: 0, value: 0,
index: 0, index: 0,
length, length,
} })
).await.into_result()?; .await
.into_result()?;
Ok(reply) Ok(reply)
} }
@ -292,7 +303,10 @@ impl NetMD {
done -= to_read; done -= to_read;
let buffer = RequestBuffer::new(to_read); let buffer = RequestBuffer::new(to_read);
let res = match self.usb_interface.bulk_in(BULK_READ_ENDPOINT, buffer).await let res = match self
.usb_interface
.bulk_in(BULK_READ_ENDPOINT, buffer)
.await
.into_result() .into_result()
{ {
Ok(result) => result, Ok(result) => result,
@ -306,10 +320,11 @@ impl NetMD {
} }
pub async fn write_bulk(&mut self, data: Vec<u8>) -> Result<usize, Box<dyn Error>> { pub async fn write_bulk(&mut self, data: Vec<u8>) -> Result<usize, Box<dyn Error>> {
Ok( Ok(self
self.usb_interface.bulk_out(BULK_WRITE_ENDPOINT, data).await .usb_interface
.bulk_out(BULK_WRITE_ENDPOINT, data)
.await
.into_result()? .into_result()?
.actual_length(), .actual_length())
)
} }
} }

View file

@ -346,7 +346,11 @@ impl NetMDInterface {
Ok(result) Ok(result)
} }
async fn send_command(&mut self, query: &mut Vec<u8>, test: bool) -> Result<(), Box<dyn Error>> { async fn send_command(
&mut self,
query: &mut Vec<u8>,
test: bool,
) -> Result<(), Box<dyn Error>> {
let status_byte = match test { let status_byte = match test {
true => Status::GeneralInquiry, true => Status::GeneralInquiry,
false => Status::Control, false => Status::Control,
@ -966,7 +970,11 @@ impl NetMDInterface {
} }
// Sets the title of the disc // Sets the title of the disc
pub async fn set_disc_title(&mut self, title: String, wchar: bool) -> Result<(), Box<dyn Error>> { pub async fn set_disc_title(
&mut self,
title: String,
wchar: bool,
) -> Result<(), Box<dyn Error>> {
let current_title = self.raw_disc_title(wchar).await?; let current_title = self.raw_disc_title(wchar).await?;
if current_title == title { if current_title == title {
return Err("Title is already the same".into()); return Err("Title is already the same".into());
@ -1099,7 +1107,12 @@ impl NetMDInterface {
Ok(()) Ok(())
} }
async fn raw_track_info(&mut self, track: u16, p1: i32, p2: i32) -> Result<Vec<u8>, Box<dyn Error>> { async fn raw_track_info(
&mut self,
track: u16,
p1: i32,
p2: i32,
) -> Result<Vec<u8>, Box<dyn Error>> {
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead); self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
let mut query = format_query( let mut query = format_query(
@ -1167,7 +1180,10 @@ impl NetMDInterface {
} }
/// Gets the length of a track as a `std::time::Duration` /// Gets the length of a track as a `std::time::Duration`
pub async fn track_length(&mut self, track: u16) -> Result<std::time::Duration, Box<dyn Error>> { pub async fn track_length(
&mut self,
track: u16,
) -> Result<std::time::Duration, Box<dyn Error>> {
Ok(self.track_lengths([track].into()).await?[0]) Ok(self.track_lengths([track].into()).await?[0])
} }
@ -1381,7 +1397,10 @@ impl NetMDInterface {
Ok(res[0].to_vec().unwrap()) Ok(res[0].to_vec().unwrap())
} }
pub async fn session_key_exchange(&mut self, hostnonce: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> { pub async fn session_key_exchange(
&mut self,
hostnonce: Vec<u8>,
) -> Result<Vec<u8>, Box<dyn Error>> {
if hostnonce.len() != 8 { if hostnonce.len() != 8 {
return Err("Supplied host nonce length wrong".into()); return Err("Supplied host nonce length wrong".into());
} }

View file

@ -193,7 +193,6 @@ lazy_static! {
("".to_string(), "".to_string()), ("".to_string(), "".to_string()),
("".to_string(), "".to_string()) ("".to_string(), "".to_string())
]); ]);
pub static ref MAPPINGS_RU: HashMap<String, String> = HashMap::from([ pub static ref MAPPINGS_RU: HashMap<String, String> = HashMap::from([
("а".to_string(), "a".to_string()), ("а".to_string(), "a".to_string()),
("б".to_string(), "b".to_string()), ("б".to_string(), "b".to_string()),
@ -262,7 +261,6 @@ lazy_static! {
("Ю".to_string(), "Iu".to_string()), ("Ю".to_string(), "Iu".to_string()),
("Я".to_string(), "Ia".to_string()) ("Я".to_string(), "Ia".to_string())
]); ]);
pub static ref MAPPINGS_DE: HashMap<String, String> = HashMap::from([ pub static ref MAPPINGS_DE: HashMap<String, String> = HashMap::from([
("Ä".to_string(), "Ae".to_string()), ("Ä".to_string(), "Ae".to_string()),
("ä".to_string(), "ae".to_string()), ("ä".to_string(), "ae".to_string()),
@ -272,7 +270,6 @@ lazy_static! {
("ü".to_string(), "ue".to_string()), ("ü".to_string(), "ue".to_string()),
("ß".to_string(), "ss".to_string()) ("ß".to_string(), "ss".to_string())
]); ]);
pub static ref MAPPINGS_HW: HashMap<String, String> = HashMap::from([ pub static ref MAPPINGS_HW: HashMap<String, String> = HashMap::from([
("".to_string(), "-".to_string()), ("".to_string(), "-".to_string()),
("".to_string(), "-".to_string()), ("".to_string(), "-".to_string()),
@ -553,6 +550,5 @@ lazy_static! {
("".to_string(), "".to_string()), ("".to_string(), "".to_string()),
("".to_string(), "".to_string()), ("".to_string(), "".to_string()),
]); ]);
pub static ref ALLOWED_HW_KANA: Vec<String> = MAPPINGS_HW.values().cloned().collect(); pub static ref ALLOWED_HW_KANA: Vec<String> = MAPPINGS_HW.values().cloned().collect();
} }

View file

@ -6,6 +6,6 @@
mod base; mod base;
pub mod interface; pub mod interface;
mod mappings;
mod query_utils; mod query_utils;
mod utils; mod utils;
mod mappings;

View file

@ -44,10 +44,7 @@ impl QueryValue {
} }
/// Formats a query using a standard input to send to the player /// Formats a query using a standard input to send to the player
pub fn format_query( pub fn format_query(format: String, args: Vec<QueryValue>) -> Result<Vec<u8>, Box<dyn Error>> {
format: String,
args: Vec<QueryValue>,
) -> Result<Vec<u8>, Box<dyn Error>> {
if DEBUG { if DEBUG {
println!("SENT>>> F: {}", format); println!("SENT>>> F: {}", format);
} }

View file

@ -59,9 +59,7 @@ pub fn half_width_to_full_width_range(range: &str) -> String {
.collect() .collect()
} }
pub fn get_bytes<const S: usize>( pub fn get_bytes<const S: usize>(iterator: &mut IntoIter<u8>) -> Result<[u8; S], Box<dyn Error>> {
iterator: &mut IntoIter<u8>,
) -> Result<[u8; S], Box<dyn Error>> {
let byte_vec: Vec<u8> = iterator.take(S).collect(); let byte_vec: Vec<u8> = iterator.take(S).collect();
let bytes: [u8; S] = byte_vec.try_into().unwrap(); let bytes: [u8; S] = byte_vec.try_into().unwrap();
@ -170,5 +168,7 @@ pub fn agressive_sanitize_title(title: &str) -> String {
pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration { pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration {
assert_eq!(time.len(), 4); assert_eq!(time.len(), 4);
std::time::Duration::from_micros((time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600)) std::time::Duration::from_micros(
(time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600),
)
} }