Dart wrapper via dart:js
for https://wicg.github.io/webhid/
- canUseHid
- getDevices/requestDevice
- subscribeConnect/unsubscribeConnect
- subscribeDisconnect/unsubscribeDisconnect
- open/close
- sendReport
- subscribeInputReport/unsubscribeInputReport
- sendFeatureReport
bool canUse = canUseHid();
print('canUse $canUse');
List<HidDevice> getDevices = await hid.getDevices();
_device = getDevices[0];
List<HidDevice> requestDevice = await hid.requestDevice(RequestOptions(
filters: [keyboardBacklightIds],
));
_device = requestDevice[0];
https://developer.mozilla.org/en-US/docs/Web/API/HID/onconnect
final EventListener _handleConnect = allowInterop((Event event) {}
...
hid.subscribeConnect(_handleConnect);
...
hid.unsubscribeConnect(_handleConnect);
https://developer.mozilla.org/en-US/docs/Web/API/HID/ondisconnect
final EventListener _handleDisconnect = allowInterop((Event event) {}
...
hid.subscribeDisconnect(_handleDisconnect);
...
hid.unsubscribeDisconnect(_handleDisconnect);
_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');
});
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');
});
https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/oninputreport
final EventListener _handleInputReport = allowInterop((event) {}
...
_device?.subscribeInputReport(_handleInputReport);
...
_device?.unsubscribeInputReport(_handleInputReport);
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');
});
Status in Chromium: https://chromestatus.com/feature/5172464636133376