@logitech-mx-creative-console/core
Version:
An npm module for interfacing with the Logitech MX Creative Console
93 lines • 3.54 kB
JavaScript
import { EventEmitter } from 'eventemitter3';
export class MXConsoleBase extends EventEmitter {
get CONTROLS() {
return this.deviceProperties.CONTROLS;
}
get MODEL() {
return this.deviceProperties.MODEL;
}
get PRODUCT_NAME() {
return this.deviceProperties.PRODUCT_NAME;
}
device;
deviceProperties;
// readonly #options: Readonly<Required<OpenMXConsoleOptions>>
#propertiesService;
#buttonsLcdService;
#inputService;
constructor(device, _options, services) {
super();
this.device = device;
this.deviceProperties = services.deviceProperties;
// this.#options = options
this.#propertiesService = services.properties;
this.#buttonsLcdService = services.buttonsLcd;
this.#inputService = services.inputService;
// propogate events
services.events?.listen((key, ...args) => this.emit(key, ...args));
this.device.on('input', (reportId, data) => this.#inputService.handleInput(reportId, data));
this.device.on('error', (err) => {
this.emit('error', err);
});
}
checkValidKeyIndex(keyIndex, feedbackType) {
const buttonControl = this.deviceProperties.CONTROLS.find((control) => control.type === 'button' && control.index === keyIndex);
if (!buttonControl) {
throw new TypeError(`Expected a valid keyIndex`);
}
if (feedbackType && buttonControl.feedbackType !== feedbackType) {
throw new TypeError(`Expected a keyIndex with expected feedbackType`);
}
}
calculateFillPanelDimensions(options) {
return this.#buttonsLcdService.calculateFillPanelDimensions(options);
}
async close() {
return this.device.close();
}
async getHidDeviceInfo() {
return this.device.getDeviceInfo();
}
async setBrightness(percentage) {
return this.#propertiesService.setBrightness(percentage);
}
async resetToLogo() {
return this.#propertiesService.resetToLogo();
// const finish = new Uint8Array(20)
// const finishView = uint8ArrayToDataView(finish)
// finishView.setUint8(0, 0x11)
// finishView.setUint8(1, 0xff)
// finishView.setUint8(2, 0x04)
// finishView.setUint8(3, 0x1b)
// finishView.setUint8(4, 0x0b)
// finishView.setUint8(5, 0xb8)
// await this.device.sendReports([finish])
}
// public async getFirmwareVersion(): Promise<string> {
// return this.#propertiesService.getFirmwareVersion()
// }
// public async getSerialNumber(): Promise<string> {
// return this.#propertiesService.getSerialNumber()
// }
async fillKeyColor(keyIndex, r, g, b) {
this.checkValidKeyIndex(keyIndex, null);
await this.#buttonsLcdService.fillKeyColor(keyIndex, r, g, b);
}
async fillKeyBuffer(keyIndex, imageBuffer, options) {
this.checkValidKeyIndex(keyIndex, 'lcd');
await this.#buttonsLcdService.fillKeyBuffer(keyIndex, imageBuffer, options);
}
async fillPanelBuffer(imageBuffer, options) {
await this.#buttonsLcdService.fillPanelBuffer(imageBuffer, options);
}
async clearKey(keyIndex) {
this.checkValidKeyIndex(keyIndex, null);
await this.#buttonsLcdService.clearKey(keyIndex);
}
async clearPanel() {
const ps = [];
ps.push(this.#buttonsLcdService.clearPanel());
await Promise.all(ps);
}
}
//# sourceMappingURL=base.js.map