Skip to content

Latest commit

 

History

History
131 lines (99 loc) · 2.94 KB

README.md

File metadata and controls

131 lines (99 loc) · 2.94 KB

Dart wrapper via dart:js for https://wicg.github.io/webhid/

Features

Usage

canUseHid

bool canUse = canUseHid();
print('canUse $canUse');

getDevices/requestDevice

List<HidDevice> getDevices = await hid.getDevices();
_device = getDevices[0];
List<HidDevice> requestDevice = await hid.requestDevice(RequestOptions(
  filters: [keyboardBacklightIds],
));
_device = requestDevice[0];

subscribeConnect/unsubscribeConnect

https://developer.mozilla.org/en-US/docs/Web/API/HID/onconnect

hid.subscribeConnect((event){
  print('HID connected: ${event.device.productName}');
});
...
hid.unsubscribeConnect((){
  print('hid.unsubscribeConnect finish');
});

subscribeDisconnect/unsubscribeDisconnect

https://developer.mozilla.org/en-US/docs/Web/API/HID/ondisconnect

hid.subscribeDisconnect((event){
  print('HID disconnected: ${event.device.productName}');
});
...
hid.unsubscribeDisconnect((){
  print('hid.unsubscribeDisconnect finish');
});

open/close

_device?.open().then((value) {
  print('device.open success');
}).catchError((error) {
  print('device.open $error');
});
_device?.close().then((value) {
  print('device.close success');
}).catchError((error) {
  print('device.close $error');
});

sendReport

https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/sendReport

_device?.sendReport(0, blockBytes).then((value) {
  print('device.sendReport success');
}).catchError((error) {
  print('device.sendReport $error');
});

subscribeInputReport/unsubscribeInputReport

https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/oninputreport

_device?.subscribeInputReport((event) {
  print('_device?.subscribeInputReport receive');
});
...
_device?.unsubscribeInputReport((){
  print('_device?.unsubscribeInputReport finish');
});

sendFeatureReport

https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/sendFeatureReport

_device?.sendFeatureReport(1, Uint32List.fromList([1, 0])).then((value) {
  print('device.sendFeatureReport 0 success');
}).catchError((error) {
  print('device.sendFeatureReport $error');
});

Additional information

Status in Chromium: https://chromestatus.com/feature/5172464636133376