UNPKG

@blackmagic-controller/node

Version:

An npm module for interfacing with the Blackmagic usb/bluetooth controllers in node

39 lines 1.26 kB
import { EventEmitter } from 'eventemitter3'; /** * The wrapped node-hid HIDDevice. * This translates it into the common format expected by @blackmagic-controller/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)); } 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, }; } } //# sourceMappingURL=hid-device.js.map