mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 13:22:53 -05:00
Control in/out both work
This commit is contained in:
parent
db9605fbb7
commit
3ca83e5f8c
3 changed files with 13 additions and 17 deletions
|
@ -7,10 +7,12 @@ edition = "2021"
|
|||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
# Wasm deps
|
||||
[target.'cfg(target_family = "wasm")'.dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
wasm-bindgen-futures = "0.4.39"
|
||||
js-sys = "0.3.67"
|
||||
gloo = "0.11.0"
|
||||
|
||||
[target.'cfg(target_family = "wasm")'.dependencies.web-sys]
|
||||
version = "0.3"
|
||||
|
@ -29,14 +31,12 @@ features = [
|
|||
"Storage"
|
||||
]
|
||||
|
||||
# Non-wasm deps
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
nusb = "0.1.4"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.56"
|
||||
|
||||
[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
|
||||
dwarf-debug-info = true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![cfg_attr(debug_assertions, allow(dead_code, unused_imports))]
|
||||
use std::error::Error;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use js_sys::JSON;
|
||||
use gloo::console::log;
|
||||
|
||||
use web_sys::{
|
||||
console,
|
||||
|
@ -14,7 +14,7 @@ use web_sys::{
|
|||
UsbRequestType,
|
||||
UsbDeviceRequestOptions,
|
||||
};
|
||||
use js_sys::{Array, Uint8Array, Promise};
|
||||
use js_sys::{Array, Uint8Array, Promise, Object};
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
|
||||
// Crate stuff
|
||||
|
@ -89,7 +89,6 @@ impl Device for UsbDevice {
|
|||
return Err(format!("{:?}", err).into())
|
||||
},
|
||||
};
|
||||
//let interface: WasmUsbInterface = dev_promise.await.unwrap().into();
|
||||
|
||||
Ok(UsbInterface {
|
||||
device: self.device.clone()
|
||||
|
@ -121,9 +120,9 @@ impl<'a> Interface<'a> for UsbInterface {
|
|||
let length = data.length;
|
||||
let params: UsbControlTransferParameters = data.into();
|
||||
|
||||
let promise = Promise::resolve(&self.device.control_transfer_in(¶ms, length));
|
||||
|
||||
let result = JsFuture::from(promise).await;
|
||||
let result = JsFuture::from(Promise::resolve(
|
||||
&self.device.control_transfer_in(¶ms, length)
|
||||
)).await;
|
||||
|
||||
let transfer_result: UsbInTransferResult = match result {
|
||||
Ok(res) => res.into(),
|
||||
|
@ -141,13 +140,15 @@ impl<'a> Interface<'a> for UsbInterface {
|
|||
}
|
||||
|
||||
async fn control_out(&self, data: crate::usb::ControlOut<'a>) -> Result<(), Box<dyn Error>> {
|
||||
let params = data.into();
|
||||
let promise = Promise::resolve(&self.device.control_transfer_out(¶ms));
|
||||
let array = Uint8Array::from(data.data);
|
||||
let array_obj = Object::try_from(&array).unwrap();
|
||||
let params: UsbControlTransferParameters = data.into();
|
||||
|
||||
let promise = Promise::resolve(&self.device.control_transfer_out_with_buffer_source(¶ms, &array_obj));
|
||||
let result = JsFuture::from(promise).await;
|
||||
|
||||
match result {
|
||||
Ok(_) => Ok(()),
|
||||
Ok(res) => Ok(()),
|
||||
Err(err) => Err(format!("{:?}", err).into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
#![cfg_attr(debug_assertions, allow(async_fn_in_trait))]
|
||||
use std::error::Error;
|
||||
use crate::context::UsbInterface;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UsbError {
|
||||
}
|
||||
|
||||
/// A unique USB device
|
||||
pub trait Device {
|
||||
|
|
Loading…
Reference in a new issue