UNPKG

@logitech-mx-creative-console/node

Version:

An npm module for interfacing with the Logitech MX Creative Console in node

37 lines 1.3 kB
import { EventEmitter } from 'eventemitter3'; /** * The wrapped node-hid HIDDevice. * This translates it into the common format expected by @logitech-mx-creative-console/core */ export class NodeHIDDevice extends EventEmitter { device; constructor(device) { super(); this.device = device; this.device.on('error', (error) => this.emit('error', error)); this.device.on('data', (data) => { this.emit('input', data[0], data.subarray(1)); }); } 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, serialNumber: info.serialNumber }; } } //# sourceMappingURL=hid-device.js.map