53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.NodeHIDDevice = void 0;
|
|
const eventemitter3_1 = require("eventemitter3");
|
|
/**
|
|
* The wrapped node-hid HIDDevice.
|
|
* This translates it into the common format expected by @elgato-stream-deck/core
|
|
*/
|
|
class NodeHIDDevice extends eventemitter3_1.EventEmitter {
|
|
device;
|
|
constructor(device) {
|
|
super();
|
|
this.device = device;
|
|
this.device.on('error', (error) => this.emit('error', error));
|
|
this.device.on('data', (data) => {
|
|
// Button press
|
|
if (data[0] === 0x01) {
|
|
const keyData = data.subarray(1);
|
|
this.emit('input', keyData);
|
|
}
|
|
});
|
|
}
|
|
async close() {
|
|
await this.device.close();
|
|
}
|
|
async sendFeatureReport(data) {
|
|
await this.device.sendFeatureReport(Buffer.from(data)); // Future: avoid re-wrap
|
|
}
|
|
async getFeatureReport(reportId, reportLength) {
|
|
return this.device.getFeatureReport(reportId, reportLength);
|
|
}
|
|
async sendReports(buffers) {
|
|
const ps = [];
|
|
for (const data of buffers) {
|
|
ps.push(this.device.write(Buffer.from(data))); // Future: avoid re-wrap
|
|
}
|
|
await Promise.all(ps);
|
|
}
|
|
async getDeviceInfo() {
|
|
const info = await this.device.getDeviceInfo();
|
|
return {
|
|
path: info.path,
|
|
productId: info.productId,
|
|
vendorId: info.vendorId,
|
|
};
|
|
}
|
|
async getChildDeviceInfo() {
|
|
// Not supported
|
|
return null;
|
|
}
|
|
}
|
|
exports.NodeHIDDevice = NodeHIDDevice;
|
|
//# sourceMappingURL=hid-device.js.map
|