Compare commits

..

No commits in common. "79e8691865743635041eddba97a8c869d55a09bd" and "bbdb47add7892d3f1cce6433fb7e1a7631c547d1" have entirely different histories.

4 changed files with 21 additions and 23 deletions

View file

@ -3,5 +3,5 @@ rustflags = ["--cfg=web_sys_unstable_apis"]
[build] [build]
#just comment in the "current" target #just comment in the "current" target
#target = "x86_64-unknown-linux-gnu" target = "x86_64-unknown-linux-gnu"
target = "wasm32-unknown-unknown" #target = "wasm32-unknown-unknown"

View file

@ -16,11 +16,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup rust environment - name: Build
run: rustup target add wasm32-unknown-unknown run: cargo build --verbose
- name: Build WASM - name: Run tests
run: cargo build --verbose --target wasm32-unknown-unknown run: cargo test --verbose
- name: Build Native (Linux)
run: cargo build --verbose --target x86_64-unknown-linux-gnu
- name: Run clippy - name: Run clippy
run: cargo clippy --verbose run: cargo clippy --verbose

View file

@ -1,6 +1,6 @@
[package] [package]
name = "cross_usb" name = "cross_usb"
version = "0.3.2" version = "0.3.1"
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"

View file

@ -10,24 +10,24 @@ use web_sys::{
// Crate stuff // Crate stuff
use crate::usb::{ use crate::usb::{
ControlIn, ControlOut, ControlType, UsbDescriptor, UsbDevice, UsbInterface, Recipient, UsbError, ControlIn, ControlOut, ControlType, Descriptor, Device, Interface, Recipient, UsbError,
}; };
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug)] #[derive(Debug)]
pub struct Descriptor { pub struct UsbDescriptor {
device: WasmUsbDevice, device: WasmUsbDevice,
} }
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug)] #[derive(Debug)]
pub struct Device { pub struct UsbDevice {
device: WasmUsbDevice, device: WasmUsbDevice,
} }
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug)] #[derive(Debug)]
pub struct Interface { pub struct UsbInterface {
device: WasmUsbDevice, device: WasmUsbDevice,
_number: u8, _number: u8,
} }
@ -61,7 +61,7 @@ impl DeviceFilter {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub async fn get_device(device_filter: Vec<DeviceFilter>) -> Result<Descriptor, js_sys::Error> { pub async fn get_device(device_filter: Vec<DeviceFilter>) -> Result<UsbDescriptor, js_sys::Error> {
let window = web_sys::window().unwrap(); let window = web_sys::window().unwrap();
let navigator = window.navigator(); let navigator = window.navigator();
@ -102,7 +102,7 @@ pub async fn get_device(device_filter: Vec<DeviceFilter>) -> Result<Descriptor,
result result
}) { }) {
let _open_promise = JsFuture::from(Promise::resolve(&device.open())).await?; let _open_promise = JsFuture::from(Promise::resolve(&device.open())).await?;
return Ok(Descriptor { device }); return Ok(UsbDescriptor { device });
} }
} }
@ -161,7 +161,7 @@ pub async fn get_device(device_filter: Vec<DeviceFilter>) -> Result<Descriptor,
let _open_promise = JsFuture::from(Promise::resolve(&device.open())).await?; let _open_promise = JsFuture::from(Promise::resolve(&device.open())).await?;
Ok(Descriptor { device }) Ok(UsbDescriptor { device })
} }
/* /*
@ -273,8 +273,8 @@ pub async fn get_device_list(device_filter: Vec<DeviceFilter>) -> Result<Vec<Usb
} }
*/ */
impl UsbDescriptor for Descriptor { impl Descriptor for UsbDescriptor {
type Device = Device; type Device = UsbDevice;
async fn open(self) -> Result<Self::Device, UsbError> { async fn open(self) -> Result<Self::Device, UsbError> {
Ok(Self::Device { Ok(Self::Device {
@ -307,10 +307,10 @@ impl UsbDescriptor for Descriptor {
} }
} }
impl UsbDevice for Device { impl Device for UsbDevice {
type Interface = Interface; type Interface = UsbInterface;
async fn open_interface(&self, number: u8) -> Result<Interface, UsbError> { async fn open_interface(&self, number: u8) -> Result<UsbInterface, UsbError> {
let dev_promise = let dev_promise =
JsFuture::from(Promise::resolve(&self.device.claim_interface(number))).await; JsFuture::from(Promise::resolve(&self.device.claim_interface(number))).await;
@ -324,7 +324,7 @@ impl UsbDevice for Device {
} }
}; };
Ok(Interface { Ok(UsbInterface {
device: self.device.clone(), device: self.device.clone(),
_number: number, _number: number,
}) })
@ -381,7 +381,7 @@ impl UsbDevice for Device {
} }
} }
impl<'a> UsbInterface<'a> for Interface { impl<'a> Interface<'a> for UsbInterface {
async fn control_in(&self, data: crate::usb::ControlIn) -> Result<Vec<u8>, UsbError> { async fn control_in(&self, data: crate::usb::ControlIn) -> Result<Vec<u8>, UsbError> {
let length = data.length; let length = data.length;
let params: UsbControlTransferParameters = data.into(); let params: UsbControlTransferParameters = data.into();