UNPKG

@elgato-stream-deck/core

Version:

An npm module for interfacing with the Elgato Stream Deck

75 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GalleonK100EncoderLedService = void 0; class GalleonK100EncoderLedService { #device; #encoderControls; constructor(device, allControls) { this.#device = device; this.#encoderControls = allControls.filter((control) => control.type === 'encoder'); } async clearAll() { const ps = []; for (const control of this.#encoderControls) { if (control.ledRingSteps > 0) ps.push(this.setEncoderRingSingleColor(control.index, 0, 0, 0)); } await Promise.all(ps); } async setEncoderColor(encoder, _red, _green, _blue) { const control = this.#encoderControls.find((c) => c.index === encoder); if (!control) throw new Error(`Invalid encoder index ${encoder}`); throw new Error('Encoder does not have an LED'); } async setEncoderRingSingleColor(encoder, red, green, blue) { const control = this.#encoderControls.find((c) => c.index === encoder); if (!control) throw new Error(`Invalid encoder index ${encoder}`); if (control.ledRingSteps <= 0) throw new Error('Encoder does not have an LED ring'); // Assume them all the same number of steps const offset = (1 - encoder) * control.ledRingSteps; const ps = []; for (let i = 0; i < control.ledRingSteps; i++) { ps.push(this.#sendEncoderPixelColor(offset + i, red, green, blue)); } await Promise.all(ps); } async setEncoderRingColors(encoder, colors) { const control = this.#encoderControls.find((c) => c.index === encoder); if (!control) throw new Error(`Invalid encoder index ${encoder}`); if (control.ledRingSteps <= 0) throw new Error('Encoder does not have an LED ring'); if (colors.length !== control.ledRingSteps * 3) throw new Error('Invalid colors length'); let colorsArray = colors instanceof Uint8Array ? Array.from(colors) : colors; // If there is an offset, repack the buffer to change the start point if (control.lcdRingOffset) { const oldColorsArray = colorsArray; colorsArray = []; colorsArray.push(...oldColorsArray.slice(control.lcdRingOffset * 3)); colorsArray.push(...oldColorsArray.slice(0, control.lcdRingOffset * 3)); } // Assume them all the same number of steps const offset = (1 - encoder) * control.ledRingSteps; const ps = []; for (let i = 0; i < control.ledRingSteps; i++) { ps.push(this.#sendEncoderPixelColor(offset + i, colorsArray[i * 3], colorsArray[i * 3 + 1], colorsArray[i * 3 + 2])); } await Promise.all(ps); } async #sendEncoderPixelColor(index, red, green, blue) { const buffer = new Uint8Array(6); buffer[0] = 0x03; buffer[1] = 0x24; buffer[2] = index; buffer[3] = red; buffer[4] = green; buffer[5] = blue; await this.#device.sendFeatureReport(buffer); } } exports.GalleonK100EncoderLedService = GalleonK100EncoderLedService; //# sourceMappingURL=galleonK100.js.map