@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
304 lines • 11.2 kB
TypeScript
import type { ColorOptions, NormalizedColorOptions } from '../types/color-options';
import { MorphOptions } from '../color-change-options/morph-options';
import { SetColorOptions } from '../color-change-options/set-color-options';
import { Channel } from '../types/enums/channel';
import { interpretParameters } from '../utils/colors/interpret-parameters';
import type { BlinkStickProMode } from '../types/enums/mode';
import { AnimationRunner } from '../animations/animation-runner';
import { LedGroup } from '../led/led-group';
import { Led } from '../led/led';
import type { RgbTuple } from '../types/rgb-tuple';
import { WriteStream } from 'node:fs';
import { MinimalDeviceInfo, UsbTransport } from '../transport';
import { Buffer } from 'node:buffer';
/**
* Main class responsible for controlling BlinkStick devices.
* @category Core
*/
export declare abstract class BlinkStick<Transport extends UsbTransport = UsbTransport> {
abstract readonly isSync: boolean;
protected abortController: AbortController;
/**
* Changes the default retry count for sending feature reports.
*/
defaultRetryCount: number;
ledCount: number;
readonly requiresSoftwareColorPatch: boolean;
readonly device: Transport;
readonly serial: string;
readonly manufacturer: string;
readonly product: string;
readonly versionMajor: number;
readonly versionMinor: number;
protected _animation?: AnimationRunner;
protected _inverse: boolean;
readonly deviceDescription: import("../consts/device-descriptions").KnownDeviceInfo | null;
protected commandDebug: string | null;
protected debugWriteStream: WriteStream | null;
protected deviceInfo: MinimalDeviceInfo;
protected isLinux: boolean;
interpretParameters: typeof interpretParameters;
/**
*
* @internal This is not intended to be used outside of the library. End-users should use `find*` functions
*/
protected constructor(device: Transport);
get inverse(): boolean;
set inverse(value: boolean);
/**
* This allows BlinkStick instances to be used with explicit resource management
*/
[Symbol.asyncDispose](): Promise<void>;
/**
* Gets animation runner for the device.
* If device has unknown number of LEDs, getter will return null.
* If device is in inverse mode, getter will return null.
*/
get animation(): AnimationRunner | null;
/**
* Low-level method that directly sends a feature report to the device.
* @param data
*/
sendFeatureReport(data: number[] | Buffer): Promise<number>;
/**
* Returns the serial number of device.
*
* <pre>
* BSnnnnnn-1.0
* || | | |- Software minor version
* || | |--- Software major version
* || |-------- Denotes sequential number
* ||----------- Denotes BlinkStick device
* </pre>
*
* Software version defines the capabilities of the device
* @deprecated Use `.serial` directly
*/
getSerial(): string;
/**
* Close BlinkStick device and stop all animations
*/
close(): Promise<void>;
/**
* Stop all animations
*/
stop(): Promise<void>;
/**
* Set the color of LEDs
*
* @example
* //Available overloads
* setColor(red, green, blue, [options]); // use [0..255] ranges for intensity
*
* setColor(color, [options]); // use '#rrggbb' format
*
* setColor(color_name, [options]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names
*
*/
setColor(...options: ColorOptions<SetColorOptions>): Promise<void>;
protected sendColor(params: NormalizedColorOptions): Promise<void>;
/**
* Set inverse mode for IKEA DIODER in conjunction with BlinkStick Pro
* Seemingly, this is effectively deprecated in favor of setting mode on BlinkStick Pro directly.
*
* @param {Boolean} inverse Set true for inverse mode and false otherwise
* @deprecated Use `.inverse` directly
*/
setInverse(inverse: boolean): void;
/**
* @deprecated Use `.inverse` directly
*/
getInverse(): boolean;
/**
* Set mode for BlinkStick Pro. This will persist across reboots.
*
* - 0 = Normal
* - 1 = Inverse
* - 2 = WS2812
*
* You can read more about BlinkStick modes by following this link:
*
* http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes
*/
setMode(mode: BlinkStickProMode): Promise<void>;
/**
* Gets the current mode.
*/
getMode(): Promise<BlinkStickProMode>;
/**
* Sets the number of LEDs on "supported" devices.
* Note that unplugging and plugging the device may be necessary for the change to take effect.
* @param count
* @experimental
*/
setLedCountAtDevice(count: number): Promise<void>;
/**
* Gets the number of LEDs from the device.
* @experimental
*/
getLedCountFromDevice(): Promise<number>;
/**
* Loads the LED count from the device on "supported" devices.
* @experimental
*/
loadLedCountFromDevice(): Promise<this>;
/**
* Set a random color on BlinkStick.
* @param index The index of the LED, 0 is default
*/
setRandomColor(index?: number): Promise<void>;
/**
* Get the current color visible on BlinkStick
* @param index The index of the LED, 0 is default
*/
getColor(index?: number): Promise<RgbTuple>;
/**
* Get the current color frame on BlinkStick Pro
* @example
* .getColors(8);
* @return {Array} Callback returns an array of LED data in the following format: [g0, r0, b0, g1, r1, b1...]
* * */
getColors(count: number): Promise<Buffer>;
/**
* Set the color frame on BlinkStick Pro
* Missing colors are filled with zeros.
* Note - this method seemingly has DIFFERENT behavior on different devices.
* @param channel Channel is represented as 0=R, 1=G, 2=B
* @param data LED data in the following format: [g0, r0, b0, g1, r1, b1...]
*/
setColors(channel: Channel, data: number[] | Uint8Array | Buffer): Promise<void>;
/**
* A workaround for setting colors on Flex on Linux.
* @param channel
* @param data
*/
protected setBigColorsOnLinux(channel: Channel, data: Buffer): Promise<void>;
/**
* Get the current color as hex string.
* @param index The index of the LED, 0 is default
* @deprecated Use utils functions instead
*/
getColorString(index?: number): Promise<`#${string}`>;
/**
* Get the infoblock1 of the device.
* This is a 32 byte array that can contain any data. It's supposed to
* hold the "Name" of the device making it easier to identify rather than
* a serial number.
*/
getInfoBlock1(): Promise<Buffer>;
/**
* Sets the infoblock1 with specified string.
* It fills the rest of bytes with zeros.
*
* Usage:
*
* @example
* ```
* setInfoBlock1(Buffer.from("abcdefg", 'hex'));
* ```
* @param data
*/
setInfoBlock1(data: Buffer): Promise<void>;
/**
* Get the infoblock2 of the device.
* This is a 32 byte array that can contain any data.
*/
getInfoBlock2(): Promise<Buffer<ArrayBufferLike>>;
setInfoBlock2(data: Buffer): Promise<void>;
turnOff(index?: number): Promise<void>;
turnOffAll(): Promise<void>;
/**
* @deprecated Use Animation API instead
*/
blink(...options: ColorOptions): Promise<void>;
/**
* Set a feature report to the device, and returns read data from the device.
*
* @param reportId Report ID to receive
* @param data Data to send to the device
* @param maxRetries Maximum number of retries
*/
setFeatureReportAndRead(reportId: number, data: Buffer, maxRetries?: number): Promise<Buffer>;
/**
* Set a feature report to the device.
* @param data - First byte is report ID, the rest is data
* @param maxRetries
*/
setFeatureReport(data: Buffer, maxRetries?: number): Promise<void>;
protected getDebugWriteStream(): WriteStream;
/**
* This method is used to write debug commands to the debug stream.
* It should never be called if `commandDebug` is not set.
*/
protected writeDebugCommand(type: string, ...args: unknown[]): void;
/**
* Morphs to specified RGB color from current color.
*
* Function supports the following overloads:
*
* @example
* //Available overloads
* morph(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity
*
* morph(color, [options], [callback]); // use '#rrggbb' format
*
* morph(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names
*
* Options can contain the following parameters for object:
*
* - channel=0: Channel is represented as 0=R, 1=G, 2=B
* - index=0: The index of the LED
* - duration=1000: How long should the morph animation last in milliseconds
* - steps=50: How many steps for color changes
* @deprecated Use animation API instead
*/
morph(...args: ColorOptions<MorphOptions>): Promise<void>;
/**
* Pulses specified RGB color.
*
* Function supports the following overloads:
*
* @example
* //Available overloads
* pulse(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity
*
* pulse(color, [options], [callback]); // use '#rrggbb' format
*
* pulse(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names
*
* Options can contain the following parameters for object:
*
* - channel=0: Channel is represented as 0=R, 1=G, 2=B
* - index=0: The index of the LED
* - duration=1000: How long should the pulse animation last in milliseconds (this time is actually doubled, keeping it in-line with legacy behavior)
* - steps=50: How many steps for color changes
* @deprecated Use animation API instead
*/
pulse(...options: ColorOptions<MorphOptions>): Promise<void>;
/**
* Get a feature report from the device, retrying if necessary.
*
* @param {Number} reportId Report ID to receive
* @param {Number} length Expected length of the report
* @param {Number} maxRetries Maximum number of retries
*/
getFeatureReport(reportId: number, length: number, maxRetries?: number): Promise<Buffer>;
/**
* Gets a feature report from the device without retries.
* @param reportId
* @param length
*/
getFeatureReportRaw(reportId: number, length: number): Promise<Buffer>;
/**
* Gets API to control all LEDs on the device.
*/
leds(): LedGroup;
/**
* Gets API to control a single LED on the device.
* @param index
*/
led(index: number): Led;
getTransport(): Transport;
}
export type BlinkstickAny = BlinkStick<any>;
//# sourceMappingURL=blinkstick.d.ts.map