Skip to content

Commit

Permalink
Merge pull request #7 from istornz/rework/readme
Browse files Browse the repository at this point in the history
♻️ Rework readme + Upgrade deps
  • Loading branch information
v-apparence committed Apr 12, 2023
2 parents 4f48d6b + b216f29 commit dadccd2
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 532 deletions.
140 changes: 98 additions & 42 deletions README.md
@@ -1,60 +1,116 @@
<p align="center">
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-purple.svg" alt="License: MIT"></a>
<a href="https://pub.dev/packages/bart"><img src="https://img.shields.io/pub/v/usb_device" alt="pub dev webusb"></a>
<img src="https://github.com/Apparence-io/webUSB_plugin/raw/master/assets/img/logo.jpg" alt="web usb logo" />
</p>
<br><br>

# **WebUSB plugin**
<a href="https://en.apparence.io"><img src="https://github.com/Apparence-io/bart/raw/master/.github/img/logo.png" alt="Apparence.io logo"></a>
<p><small>Developed with 💙 &nbsp;by Apparence.io</small></p>
<p align="center">
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-purple.svg" alt="License: MIT"></a>
<a href="https://pub.dev/packages/usb_device"><img src="https://img.shields.io/pub/v/usb_device" alt="pub dev usb_device"></a>
</p>
<br>
<hr>
<br>

## 🚀&nbsp; Overview

**WebUSB** plugin provide access to USB devices from Flutter Web 💙 by using [**web usb official API**](https://wicg.github.io/webusb/).

This plugin provide access to USB devices from web pages with WebUSB.
- 📱 Get device info with configuration.
- 🔌 Pair a device with filter.
- 📤 Send data to USB device.
- 📥 Receive data from USB device.
- 🎛️ Change USB device configuration.

## Platform Support
## 💻&nbsp; Platform Support

| Android | iOS | MacOS | Web | Linux | Windows |
| :-----: | :-: | :---: | :-: | :---: | :----: |
|| || ✔️ |||
|||| ✔️ |||

## 📖&nbsp; Installation

## Usage
### Install the package

```sh
flutter pub add usb_device
```

### Import the package

```dart
import 'package:usb_device/usb_device.dart';
```

## 🚀&nbsp; Get started

- Import & instanciate the plugin.

```dart
import 'package:usb_device/usb_device.dart';
final UsbDevice usbDevice = UsbDevice();
```

- Common used methods.

var pairedDevices = await usbDevice.pairedDevices; // get paired devices
var pairedDevice = await usbDevice.requestDevices([DeviceFilter(vendorId : 0x00, productId: 0x00)]); // par a device
List<USBConfiguration> availableConfigurations = await usbDevice.getAvailableConfigurations(pairedDevice); // get device's configurations
USBDeviceInfo deviceInfo = await usbDevice.getPairedDeviceInfo(pairedDevice); // get device's info
await usbDevice.open(pairedDevice); // start session
await usbDevice.close(pairedDevice); // close session
```dart
// get paired devices
final pairedDevices = await usbDevice.pairedDevices;
// pair a device
final pairedDevice = await usbDevice.requestDevices([DeviceFilter(vendorId : 0x00, productId: 0x00)]);
// get device's configurations
List<USBConfiguration> availableConfigurations = await usbDevice.getAvailableConfigurations(pairedDevice);
// get device's info
USBDeviceInfo deviceInfo = await usbDevice.getPairedDeviceInfo(pairedDevice);
// start session
await usbDevice.open(pairedDevice);
// close session
await usbDevice.close(pairedDevice);
```

## Implementation

### USB

- [x] getDevices() : Get paired attached devices
- [x] requestDevice(filters): pair a device with filter or not

### USBDevice

- [x] Get device info with configuration
- [x] open(): *Start session*
- [x] close(): *Close session*
- [x] selectConfiguration(configurationValue): *Select a specified configuration*
- [x] claimInterface(interfaceNumber): *Claim an interface for exclusive access*
- [x] releaseInterface(interfaceNumber): *Release a claimed interface*
- [x] controlTransferIn(setup, length): *Return result of a command*
- [x] controlTransferOut(setup, data) : *Send a command to device*
- [x] transferIn(): *Return data from device*
- [x] transferOut(): *Send data to device*
- [x] clearHalt()
- [x] reset(): *Reset device*
- [x] isochronousTransferIn()
- [x] isochronousTransferOut()

### Events
- [x] OnConnect
- [x] OnDisconnect
## 📚&nbsp; Methods

## USB

| Name | Description | Returned value |
| ------------------------------------------ | ---------------------------------------------------- | ------------------------------ |
| `pairedDevices` | Get paired attached devices | `Future<List<dynamic>>` |
| `requestDevice(List<DeviceFilter> filters)` | Pair a device with filter or not | `Future<dynamic>` |
| `isSupported()` | Pair a device with filter or not | `Future<bool>` |
| `open()` | Start a session | `Future` |
| `close()` | Close a session | `Future` |
| `claimInterface(dynamic device, int interfaceNumber)` | Claim an interface for exclusive access | `Future` |
| `releaseInterface(dynamic device, int interfaceNumber)` | Release a claimed interface | `Future` |
| `reset(dynamic device)` | Reset device | `Future` |
| `selectConfiguration(dynamic device, int configurationValue)` | Select a specified configuration | `Future` |
| `clearHalt(dynamic device, String direction, int endpointNumber)` | Returns a promise that resolves when a halt condition is cleared | `Future` |
| `controlTransferIn(dynamic device, SetupParam setup, {int? length})` | Return result of a command | `Future<USBInTransferResult>` |
| `controlTransferOut(dynamic device, SetupParam setup, {dynamic data})` | Send a command to device | `Future<USBOutTransferResult>` |
| `transferIn(dynamic device, int endpointNumber, int length)` | Return data from device | `Future<USBInTransferResult>` |
| `transferOut(dynamic device, int endpointNumber, dynamic data)` | Send data to device | `Future<USBOutTransferResult>` |
| `isochronousTransferIn(dynamic device, int endpointNumber, List<int> packetLengths)` | Resolves with a USBIsochronousInTransferResult when time sensitive information has been transmitted to (received by) the USB device | `Future<USBIsochronousInTransferResult>` |
| `isochronousTransferOut(dynamic device, int endpointNumber, List<int> packetLengths)` | Resolves with a USBIsochronousOutTransferResult when time sensitive information has been transmitted from the USB device | `Future<USBIsochronousOutTransferResult>` |
| `setOnConnectCallback(Function(dynamic) onConnect)` | Connect callback | `Future` |
| `setOnDisconnectCallback(Function(dynamic) onDisconnect)` | Disconnect callback | `Future` |
| `getSelectedConfiguration(dynamic pairedDevice)` | Get the selected configuration | `Future<USBConfiguration?>` |
| `getAvailableConfigurations(dynamic pairedDevice)` | Get available device's configurations | `Future<List<USBConfiguration>>` |
| `getPairedDeviceInfo(dynamic pairedDevice)` | Get info of paired device | `Future<USBDeviceInfo>` |

## 📣&nbsp; Sponsor

<img src="https://github.com/Apparence-io/bart/raw/master/.github/img/apparence_logo.png" alt="logo apparence io" />
<br />
<br />

[Initiated and sponsored by Apparence.io.](https://apparence.io)

## 👥&nbsp; Contribution

Contributions are welcome.
Contribute by creating a PR or create an issue 🎉.
Binary file added assets/img/logo.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"


Expand Down
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down
8 changes: 8 additions & 0 deletions usb_device/example/linux/flutter/generated_plugins.cmake
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
194 changes: 0 additions & 194 deletions usb_device/example/pubspec.lock

This file was deleted.

0 comments on commit dadccd2

Please sign in to comment.