UNPKG

@xkeys-lib/core

Version:

NPM package to interact with the X-keys panels

182 lines 7.7 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { ButtonStates, Color, XKeysEvents, XKeysInfo } from './api'; import { Product } from './products'; import { HIDDevice } from './genericHIDDevice'; export declare interface XKeys { on<U extends keyof XKeysEvents>(event: U, listener: XKeysEvents[U]): this; emit<U extends keyof XKeysEvents>(event: U, ...args: Parameters<XKeysEvents[U]>): boolean; } export declare class XKeys extends EventEmitter { private device; private deviceInfo; private _devicePath; private product; /** All button states */ private _buttonStates; /** Analogue states, such as jog-wheels, shuttle etc */ private _analogStates; private receivedVersionResolve?; private receivedGenerateDataResolve?; private _initialized; private _firmwareVersion; private _firmwareVersionIsSet; private _unitId; private _unitIdIsSet; private _disconnected; /** Vendor id for the X-keys panels */ static get vendorId(): number; /** * Takes a HID device as input. If the HID device is NOT an X-Keys returns null, otherwise some info about it. */ static filterDevice(deviceInfo: DeviceInfo): { product: Product; productId: number; interface: number; } | null; constructor(device: HIDDevice, deviceInfo: DeviceInfo, _devicePath: string | undefined); private _setupDevice; /** Initialize the device. This ensures that the essential information from the device about its state has been received. */ init(): Promise<void>; /** Closes the device. Subsequent commands will raise errors. */ close(): Promise<void>; /** Firmware version of the device */ get firmwareVersion(): number; /** Unit id ("UID") of the device, is used to uniquely identify a certain panel, or panel type. * From factory it's set to 0, but it can be changed using this.setUnitId() */ get unitId(): number; /** Various information about the device and its capabilities */ get info(): XKeysInfo; /** * Returns an object with current Button states */ getButtons(): ButtonStates; /** * Sets the indicator-LED on the device, usually a red and green LED at the top of many X-keys * @param ledIndex the LED to set (1 = green (top), 2 = red (bottom)) * @param on boolean: on or off * @param flashing boolean: flashing or not (if on) * @returns undefined */ setIndicatorLED(ledIndex: number, on: boolean, flashing?: boolean): void; /** * Sets the backlight of a button * @param keyIndex The button of which to set the backlight color * @param color r,g,b or string (RGB, RRGGBB, #RRGGBB) * @param bankIndex number: Which LED bank (top or bottom) to set the color of. (Only applicable to RGB-based panels. ) * @param flashing boolean: flashing or not (if on) * @returns undefined */ setBacklight(keyIndex: number, /** RGB, RRGGBB, #RRGGBB */ color: Color | string | boolean | null, flashing?: boolean, bankIndex?: number): void; /** * Sets the backlight of all buttons * @param color r,g,b or string (RGB, RRGGBB, #RRGGBB) * @param bankIndex number: Which LED bank (top or bottom) to control. */ setAllBacklights(color: Color | string | boolean | null, bankIndex?: number): void; /** * On first call: Turn all backlights off * On second call: Return all backlights to their previous states */ toggleAllBacklights(): void; /** * Sets the backlight intensity of the device * @param blueIntensity 0-255 * @param redIntensity 0-255 */ setBacklightIntensity(blueIntensity: number, redIntensity?: number): void; /** * Save the current backlights. This will restore the backlights after a power cycle. * Note: EEPROM command, don't call this function too often, or you'll kill the EEPROM! * (An EEPROM only support a few thousands of write operations.) */ saveBackLights(): void; /** * Sets the flash frequency of LEDs for the entire X-keys. Flashing will always be synchronized * @param frequency 1-255, where 1 is fastest and 255 is the slowest. 255 is approximately 4 seconds between flashes. * @returns undefined */ setFrequency(frequency: number): void; /** * Sets the UID (unit Id) value in the X-keys hardware * Note: EEPROM command, don't call this function too often, or you'll kill the EEPROM! * (An EEPROM only supports a few thousands of write operations.) * @param unitId Unit id ("UID"). Allowed values: 0-255. 0 is factory default * @returns undefined */ setUnitId(unitId: number): void; /** * Reboots the device * @returns undefined */ rebootDevice(): void; /** * Sets the 2x16 LCD display * @param line 1 for top line, 2 for bottom line. * @param displayChar // string to display, empty string to clear * @param backlight 0 for off, 1 for on. * @returns undefined */ writeLcdDisplay(line: number, displayChar: string, backlight: boolean): void; /** * Writes a Buffer of data bytes to the X-keys device * Used to send custom messages to X-keys for testing and development, see documentation for valid messages * @param buffer The buffer written to the device * @returns undefined */ writeData(message: HIDMessage): void; /** * Returns a Promise that settles when all writes have been completed */ flush(): Promise<void>; /** (Internal function) Called when there has been detected that the device has been disconnected */ _handleDeviceDisconnected(): Promise<void>; /** (Internal function) Called when there has been detected that a device has been reconnected */ _handleDeviceReconnected(device: HIDDevice, deviceInfo: DeviceInfo): Promise<void>; _getHIDDevice(): HIDDevice; _getDeviceInfo(): DeviceInfo; get devicePath(): string | undefined; /** The unique id of the xkeys-panel. Note: This is only available if options.automaticUnitIdMode is set for the Watcher */ get uniqueId(): string; /** * Writes a Buffer to the X-keys device * * @param buffer The buffer written to the device * @returns undefined */ private _write; private _padMessage; private _verifyButtonIndex; private _findBtnLocation; /** * Generate data: forces the unit to send a data report with current states. Important to get the Unit ID. * @param none * @returns undefined //an input report will be generated by the X-keys with bit 2 of PS set. This is useful in determining the initial state of the device before any data has changed. */ private _generateData; /** * Gets the firmware version and UID : forces the unit to send a special data report with firmware version and Unit ID. * @param none * @returns undefined //an input report will be generated by the X-keys with byte 2 set to 214. This has the firmware version and UID. */ private _getVersion; /** Makes best effort to interpret a color */ private _interpretColor; /** Check that the .init() function has run, throw otherwise */ private ensureInitialized; /** Calculate delta value */ static calculateDelta(newValue: number, oldValue: number, overflow?: number): number; } declare type HIDMessage = (string | number)[]; interface DeviceInfo { /** Name of the panel */ product: string | undefined; vendorId: number; productId: number; interface: number | null; } export {}; //# sourceMappingURL=xkeys.d.ts.map