mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 05:12:53 -05:00
v0.2.0, ran cargo fmt
This commit is contained in:
parent
847367c9a9
commit
138d642fc9
4 changed files with 25 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "cross_usb"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
authors = ["G2-Games <ke0bhogsg@gmail.com>"]
|
||||
repository = "https://github.com/G2-Games/cross-usb"
|
||||
documentation = "https://docs.rs/cross_usb"
|
||||
|
|
|
@ -54,7 +54,7 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result<UsbDevice, Us
|
|||
|
||||
let device = match device_info.open() {
|
||||
Ok(dev) => dev,
|
||||
Err(_) => return Err(UsbError::CommunicationError)
|
||||
Err(_) => return Err(UsbError::CommunicationError),
|
||||
};
|
||||
|
||||
Ok(UsbDevice {
|
||||
|
@ -63,16 +63,15 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result<UsbDevice, Us
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn get_device_filter(
|
||||
device_filter: Vec<DeviceFilter>,
|
||||
) -> Result<UsbDevice, UsbError> {
|
||||
pub async fn get_device_filter(device_filter: Vec<DeviceFilter>) -> Result<UsbDevice, UsbError> {
|
||||
let devices = nusb::list_devices().unwrap();
|
||||
|
||||
let mut device_info = None;
|
||||
for prelim_dev_inf in devices {
|
||||
// See if the device exists in the list
|
||||
if device_filter.iter().position(|info|
|
||||
{
|
||||
if device_filter
|
||||
.iter()
|
||||
.position(|info| {
|
||||
let mut result = false;
|
||||
|
||||
if info.vendor_id.is_some() {
|
||||
|
@ -96,8 +95,9 @@ pub async fn get_device_filter(
|
|||
}
|
||||
|
||||
result
|
||||
}
|
||||
).is_some() {
|
||||
})
|
||||
.is_some()
|
||||
{
|
||||
device_info = Some(prelim_dev_inf)
|
||||
}
|
||||
}
|
||||
|
@ -187,10 +187,11 @@ impl<'a> Interface<'a> for UsbInterface {
|
|||
.interface
|
||||
.bulk_in(endpoint, request_buffer)
|
||||
.await
|
||||
.into_result() {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(UsbError::TransferError),
|
||||
}
|
||||
.into_result()
|
||||
{
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(UsbError::TransferError),
|
||||
}
|
||||
}
|
||||
|
||||
async fn bulk_out(&self, endpoint: u8, data: &[u8]) -> Result<usize, UsbError> {
|
||||
|
|
|
@ -114,8 +114,9 @@ pub async fn get_device_filter(
|
|||
for js_device in device_list {
|
||||
let device: WasmUsbDevice = js_device.into();
|
||||
|
||||
if device_filter.iter().position(|info|
|
||||
{
|
||||
if device_filter
|
||||
.iter()
|
||||
.position(|info| {
|
||||
let mut result = false;
|
||||
|
||||
if info.vendor_id.is_some() {
|
||||
|
@ -139,8 +140,9 @@ pub async fn get_device_filter(
|
|||
}
|
||||
|
||||
result
|
||||
}
|
||||
).is_some() {
|
||||
})
|
||||
.is_some()
|
||||
{
|
||||
return Ok(UsbDevice { device });
|
||||
}
|
||||
}
|
||||
|
@ -292,9 +294,11 @@ impl<'a> Interface<'a> for UsbInterface {
|
|||
&self
|
||||
.device
|
||||
.control_transfer_out_with_buffer_source(¶ms, array_obj),
|
||||
)).await {
|
||||
))
|
||||
.await
|
||||
{
|
||||
Ok(res) => res.into(),
|
||||
Err(_) => return Err(UsbError::TransferError)
|
||||
Err(_) => return Err(UsbError::TransferError),
|
||||
};
|
||||
|
||||
Ok(result.bytes_written() as usize)
|
||||
|
|
|
@ -79,7 +79,7 @@ pub enum UsbError {
|
|||
#[error("device transfer failed")]
|
||||
TransferError,
|
||||
|
||||
#[error("device communication failed")]
|
||||
#[error("device communication failed")]
|
||||
CommunicationError,
|
||||
|
||||
#[error("device disconnected")]
|
||||
|
|
Loading…
Reference in a new issue