Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/shims/node-hid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {
ConnectedDevice,
WebVIADevice,
} from '../types/types';

var lastWriteTimestamp = Date.now();
// This is a bit cray
const globalBuffer: {
[path: string]: {currTime: number; message: Uint8Array}[];
Expand Down Expand Up @@ -143,7 +145,7 @@ const ExtendedHID = {
}

read(fn: (err?: Error, data?: ArrayBuffer) => void) {
this.fastForwardGlobalBuffer(Date.now());
this.fastForwardGlobalBuffer(lastWriteTimestamp);
if (globalBuffer[this.path].length > 0) {
// this should be a noop normally
fn(undefined, globalBuffer[this.path].shift()?.message as any);
Expand Down Expand Up @@ -172,6 +174,7 @@ const ExtendedHID = {
async write(arr: number[]) {
await this.openPromise;
const data = new Uint8Array(arr.slice(1));
lastWriteTimestamp = Date.now();
await this._hidDevice?._device.sendReport(0, data);
}
},
Expand Down