mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 13:22: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]
|
[package]
|
||||||
name = "cross_usb"
|
name = "cross_usb"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
authors = ["G2-Games <ke0bhogsg@gmail.com>"]
|
authors = ["G2-Games <ke0bhogsg@gmail.com>"]
|
||||||
repository = "https://github.com/G2-Games/cross-usb"
|
repository = "https://github.com/G2-Games/cross-usb"
|
||||||
documentation = "https://docs.rs/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() {
|
let device = match device_info.open() {
|
||||||
Ok(dev) => dev,
|
Ok(dev) => dev,
|
||||||
Err(_) => return Err(UsbError::CommunicationError)
|
Err(_) => return Err(UsbError::CommunicationError),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(UsbDevice {
|
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(
|
pub async fn get_device_filter(device_filter: Vec<DeviceFilter>) -> Result<UsbDevice, UsbError> {
|
||||||
device_filter: Vec<DeviceFilter>,
|
|
||||||
) -> Result<UsbDevice, UsbError> {
|
|
||||||
let devices = nusb::list_devices().unwrap();
|
let devices = nusb::list_devices().unwrap();
|
||||||
|
|
||||||
let mut device_info = None;
|
let mut device_info = None;
|
||||||
for prelim_dev_inf in devices {
|
for prelim_dev_inf in devices {
|
||||||
// See if the device exists in the list
|
// See if the device exists in the list
|
||||||
if device_filter.iter().position(|info|
|
if device_filter
|
||||||
{
|
.iter()
|
||||||
|
.position(|info| {
|
||||||
let mut result = false;
|
let mut result = false;
|
||||||
|
|
||||||
if info.vendor_id.is_some() {
|
if info.vendor_id.is_some() {
|
||||||
|
@ -96,8 +95,9 @@ pub async fn get_device_filter(
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
})
|
||||||
).is_some() {
|
.is_some()
|
||||||
|
{
|
||||||
device_info = Some(prelim_dev_inf)
|
device_info = Some(prelim_dev_inf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,8 @@ impl<'a> Interface<'a> for UsbInterface {
|
||||||
.interface
|
.interface
|
||||||
.bulk_in(endpoint, request_buffer)
|
.bulk_in(endpoint, request_buffer)
|
||||||
.await
|
.await
|
||||||
.into_result() {
|
.into_result()
|
||||||
|
{
|
||||||
Ok(res) => Ok(res),
|
Ok(res) => Ok(res),
|
||||||
Err(_) => Err(UsbError::TransferError),
|
Err(_) => Err(UsbError::TransferError),
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,9 @@ pub async fn get_device_filter(
|
||||||
for js_device in device_list {
|
for js_device in device_list {
|
||||||
let device: WasmUsbDevice = js_device.into();
|
let device: WasmUsbDevice = js_device.into();
|
||||||
|
|
||||||
if device_filter.iter().position(|info|
|
if device_filter
|
||||||
{
|
.iter()
|
||||||
|
.position(|info| {
|
||||||
let mut result = false;
|
let mut result = false;
|
||||||
|
|
||||||
if info.vendor_id.is_some() {
|
if info.vendor_id.is_some() {
|
||||||
|
@ -139,8 +140,9 @@ pub async fn get_device_filter(
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
})
|
||||||
).is_some() {
|
.is_some()
|
||||||
|
{
|
||||||
return Ok(UsbDevice { device });
|
return Ok(UsbDevice { device });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,9 +294,11 @@ impl<'a> Interface<'a> for UsbInterface {
|
||||||
&self
|
&self
|
||||||
.device
|
.device
|
||||||
.control_transfer_out_with_buffer_source(¶ms, array_obj),
|
.control_transfer_out_with_buffer_source(¶ms, array_obj),
|
||||||
)).await {
|
))
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(res) => res.into(),
|
Ok(res) => res.into(),
|
||||||
Err(_) => return Err(UsbError::TransferError)
|
Err(_) => return Err(UsbError::TransferError),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(result.bytes_written() as usize)
|
Ok(result.bytes_written() as usize)
|
||||||
|
|
Loading…
Reference in a new issue