UNPKG

@logitech-mx-creative-console/webhid

Version:

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

40 lines 1.82 kB
import { MXCreativeConsoleProxy } from '@logitech-mx-creative-console/core'; /** * A MXCreativeConsole instance. * This is an extended variant of the class, to provide some more web friendly helpers, such as accepting a canvas */ export class MXCreativeConsoleWeb extends MXCreativeConsoleProxy { #hid; constructor(device, hid) { super(device); this.#hid = hid; } /** * Instruct the browser to close and forget the device. This will revoke the website's permissions to access the device. */ async forget() { await this.#hid.forget(); } async fillKeyCanvas(keyIndex, canvas) { // this.checkValidKeyIndex(keyIndex) const ctx = canvas.getContext('2d', { willReadFrequently: true }); if (!ctx) throw new Error('Failed to get canvas context'); const control = this.CONTROLS.find((control) => control.type === 'button' && control.index === keyIndex); if (!control || control.feedbackType === 'none') throw new TypeError(`Expected a valid keyIndex`); const data = ctx.getImageData(0, 0, control.pixelSize.width, control.pixelSize.height); return this.device.fillKeyBuffer(keyIndex, data.data, { format: 'rgba' }); } async fillPanelCanvas(canvas, options) { const ctx = canvas.getContext('2d', { willReadFrequently: true }); if (!ctx) throw new Error('Failed to get canvas context'); const dimensions = this.device.calculateFillPanelDimensions(options); if (!dimensions) throw new Error('Panel does not support filling'); const data = ctx.getImageData(0, 0, dimensions.width, dimensions.height); return this.device.fillPanelBuffer(data.data, { format: 'rgba' }); } } //# sourceMappingURL=wrapper.js.map