mirror of
https://github.com/G2-Games/cross-usb.git
synced 2025-04-19 21:32:53 -05:00
Bumped version of nusb, improved docs
This commit is contained in:
parent
0ffcbeee5f
commit
d9bf9a6a75
3 changed files with 35 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cross_usb"
|
name = "cross_usb"
|
||||||
version = "0.1.0"
|
version = "0.1.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"
|
||||||
|
@ -46,6 +46,9 @@ features = [
|
||||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||||
nusb = "0.1.5"
|
nusb = "0.1.5"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
futures-lite = "1.13.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,8 @@ use wasm_bindgen::prelude::*;
|
||||||
use js_sys::{Array, Object, Promise, Uint8Array};
|
use js_sys::{Array, Object, Promise, Uint8Array};
|
||||||
use wasm_bindgen_futures::JsFuture;
|
use wasm_bindgen_futures::JsFuture;
|
||||||
use web_sys::{
|
use web_sys::{
|
||||||
console, UsbControlTransferParameters, UsbDevice as WasmUsbDevice,
|
console, UsbControlTransferParameters, UsbDevice as WasmUsbDevice, UsbDeviceRequestOptions,
|
||||||
UsbDeviceRequestOptions, UsbInTransferResult,
|
UsbInTransferResult, UsbOutTransferResult, UsbRecipient, UsbRequestType,
|
||||||
UsbOutTransferResult, UsbRecipient, UsbRequestType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Crate stuff
|
// Crate stuff
|
||||||
|
|
29
src/lib.rs
29
src/lib.rs
|
@ -1,3 +1,32 @@
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
//! Cross USB is a USB library which works seamlessly across native and WASM targets.
|
||||||
|
//!
|
||||||
|
//! The idea is the user only has to write one way to access USB devices, which can be compiled
|
||||||
|
//! to both WASM and native targets without any conditional compilation or configuration.
|
||||||
|
//!
|
||||||
|
//! ## Example:
|
||||||
|
//! ```no_run
|
||||||
|
//! use cross_usb::usb::{Device, Recipient, ControlType, ControlIn};
|
||||||
|
//!
|
||||||
|
//! // Obtain a device using its VendorID and ProductID
|
||||||
|
//! let device = cross_usb::get_device(0x054c, 0x0186).await.expect("");
|
||||||
|
//!
|
||||||
|
//! // Obtain an interface of the device
|
||||||
|
//! let interface = usb_device.open_interface(0).await.expect("Failed to open interface");
|
||||||
|
//!
|
||||||
|
//! // Send a Control transfer to the device, obtaining
|
||||||
|
//! // the result and storing it in `result`, and you're done!
|
||||||
|
//! let result = match interface.control_in(ControlIn {
|
||||||
|
//! control_type: ControlType::Vendor,
|
||||||
|
//! recipient: Recipient::Interface,
|
||||||
|
//! request: 0x01,
|
||||||
|
//! value: 0,
|
||||||
|
//! index: 0,
|
||||||
|
//! length: 4,
|
||||||
|
//! })
|
||||||
|
//! .await
|
||||||
|
//! .expect("Sending control transfer failed");
|
||||||
|
//! ```
|
||||||
pub mod usb;
|
pub mod usb;
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
|
Loading…
Reference in a new issue