[node-hid]: add writes with Buffers for 1.2.0 (#42338)

This commit is contained in:
Julian Waller 2020-02-14 02:47:42 +01:00 committed by GitHub
parent f29cd16d7e
commit adf8a1b87a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for node-hid 0.7
// Type definitions for node-hid 1.2
// Project: https://github.com/node-hid/node-hid#readme
// Definitions by: Mohamed Hegazy <https://github.com/mhegazy>
// Robert Kiss <https://github.com/ert78gb>
@ -30,10 +30,10 @@ export class HID extends EventEmitter {
read(callback: (err: any, data: number[]) => void): void;
readSync(): number[];
readTimeout(time_out: number): number[];
sendFeatureReport(data: number[]): number;
sendFeatureReport(data: number[] | Buffer): number;
getFeatureReport(report_id: number, report_length: number): number[];
resume(): void;
write(values: number[]): number;
write(values: number[] | Buffer): number;
setNonBlocking(no_block: boolean): void;
}
export function devices(): Device[];

View File

@ -2,20 +2,24 @@ import HID = require('node-hid');
const devices = HID.devices();
let device = new HID.HID("path");
let device = new HID.HID('path');
device = new HID.HID(12, 22);
device.setNonBlocking(true);
device.on("data", data => {});
device.once("data", data => {});
device.on("error", err => {});
device.on('data', data => {});
device.once('data', data => {});
device.on('error', err => {});
device.write([0x00, 0x01, 0x01, 0x05, 0xff, 0xff]);
device.write(Buffer.from([0x00, 0x01, 0x01, 0x05, 0xff, 0xff]));
device.sendFeatureReport([0x00, 0x01, 0x01, 0x05, 0xff, 0xff]);
device.sendFeatureReport(Buffer.from([0x00, 0x01, 0x01, 0x05, 0xff, 0xff]));
device.pause();
device.resume();
device.removeListener("data", data => {});
device.removeAllListeners("data");
device.removeListener('data', data => {});
device.removeAllListeners('data');
device.close();