@ros2jsguy/node-blink1-async
Version:
Asynchronous TypeScript api for the node-blink1 package
183 lines (182 loc) • 7.26 kB
TypeScript
export declare enum Blink1_LEDN {
ALL = 0,
LEDA = 1,
LEDB = 2
}
export declare type RGBData = {
r: number;
g: number;
b: number;
};
export declare type PatternLineData = {
r: number;
g: number;
b: number;
fadeMillis: number;
};
export declare enum BlinkRate {
SLOW = 1000,
MED = 500,
FAST = 250,
VERY_FAST = 100
}
/**
* An asynchronous api for controlling blink(1) USB LED devices.
*/
export declare class Blink1 {
private _blink1;
private _isClosed;
private _timeout;
/**
* Find all connected blink(1) devices.
* @returns Array of found blink(1) serial numbers.
*/
static devices(): Array<string>;
/**
* Utility method that a sender can await on from an async function or method
* to create a delay-like execution experience.
* @param [millis=1000] - delay period in milliseconds, if millis <= 0 then 2^31
* @returns A Promise that the sender can await on to simulate a delay
*/
static delay(millis?: number): Promise<void>;
/**
* Create a high-level reference to a blink(1) HID device.
* @param [serialNumber] The serial number of the device to reference (see devices()).
* When undefined choose the first blink(1) device found.
* @param [enableDegamma=true] Enablement for degamma color correction (crappy name)
*/
constructor(serialNumber?: string, enableDegamma?: boolean);
/**
* Get the degamma setting.
* Default value is true
* @returns degamma enabled flag
*/
get enableDegamma(): boolean;
/**
* Update the degamma setting.
* @param enabled The new enabled or disabled value
*/
set enableDegamma(enabled: boolean);
/**
* Return the version number of the blink(1) HID device.
* @returns Promise<number> with version string to await for completion
*/
version(): Promise<number>;
/**
* Close the underlying HID device.
* @returns Promise<void> to await for completion
*/
close(): Promise<void>;
isClosed(): boolean;
/**
* Transition one or both LEDs to a new RGB color.
* @param fadeMillis The milliseconds for the transition.
* @param [red=0] The red color value [0-255].
* @param [green=0] The green color value [0-255].
* @param [blue=0] The blue color value [0-255].
* @param [led=Blink1_LEDN.ALL] Led(s) to update.
* @returns Promise<void> to await for completion
*/
fadeToRGB(fadeMillis: number, red?: number, green?: number, blue?: number, led?: Blink1_LEDN): Promise<void>;
/**
* Access the device current RGB value.
* @param led The led to read the RGB value from.
* @returns A promise that resolves to the current RGB values.
*/
rgb(led: Blink1_LEDN): Promise<RGBData>;
/**
* Immediately output an RGB color. For mk2 devices both LEDs will
* present the RGB color.
* @param [red=0] The red color value [0-255].
* @param [green=0] The green color value [0-255].
* @param [blue=0] The blue color value [0-255].
* @returns Promise<void> to await for completion
*/
setRGB(red?: number, green?: number, blue?: number): Promise<void>;
/**
* Immediately disable output.
* @returns Promise<void> to await for completion
*/
off(): Promise<void>;
/**
* Animate the sequence of color patterns in RAM beginning at a specific index in the sequence.
* @param startPosition The index [0-31] into the sequence of color patterns.
* @returns Promise<void> to await for completion
*/
play(startPosition?: number): Promise<void>;
/**
* Repeatedly animate a range of color patterns in RAM
* beginning at start index in the sequence to an end index
* the sequence.
* @param [startIndex=0] The start index [0-31] in the sequence of color patterns
* @param [endIndex=0] The end index [0-31] in the sequence of color patterns
* @param [count=1] The number of times to loop, 0 = loop infinitely
* @returns Promise<void> to await for completion
*/
playLoop(startPosition?: number, endPosition?: number, count?: number): Promise<void>;
/**
* Immediately stop presenting color patterns from RAM.
* @returns Promise<void> to await for completion
*/
stop(): Promise<void>;
/**
* Return the color pattern data at position in RAM.
* @param [position=0] The index [0-31] into the sequence of color patterns
* @returns Promise<string> returnin the pattern line read
*/
readPatternLine(position?: number): Promise<string>;
/**
* Insert a new color pattern into the sequence of color patterns in RAM.
* @param fadeMillis The duration in milliseconds for the transition from the current color to the new RGB colors of this pattern
* @param [red=0] The red color value [0-255].
* @param [green=0] The green color value [0-255].
* @param [blue=0] The blue color value [0-255].
* @param [position=0] The position [0-31] in the color sequence to insert this pattern.
* @returns Promise<void> to await for completion
*/
writePatternLine(fadeMillis: number, red?: number, green?: number, blue?: number, position?: number): Promise<void>;
/**
* Save all patterns in to Blink(1) non-volatile memory.
* @returns Promise<void> to await for completion
*/
savePattern(): Promise<void>;
/**
* Clear all pattern data from Blink(1) non-volatile memory.
* @returns Promise<void> to await for completion
*/
clearPattern(): Promise<void>;
/**
* Set the led to which future writePattern() calls will apply.
* @param led The led to make default
* @returns Promise<void> to await for completion
*/
setLedN(led?: Blink1_LEDN): Promise<void>;
/**
* Enable the ServerDown feature that will trigger a display pattern
* @param triggerMillis
* @returns Promise<void> to await for completion
*/
enableServerDown(triggerMillis?: number): Promise<unknown>;
/**
* Disable the ServerDown feature.
* @returns A promise to await on.
*/
disableServerDown(): Promise<unknown>;
/**
* Continuously play an alternating pattern of the rgb color parameter in an on/off sequence.
* Senders should call stop() or off() to cancel the blink loop.
*
* @param [red=0] The red color value [0-255].
* @param [green=0] The green color value [0-255].
* @param [blue=0] The blue color value [0-255].
* @returns Promise<void> to await for completion
*/
blink(red?: number, green?: number, blue?: number, rate?: BlinkRate): Promise<void>;
/**
* Send an array of PatternLineData to a blink(1) device.
* @param patterns The array of PatternLineData
* @param [startPos=0] Start writing patternLineData at this line
* @returns Promise<void> to await for completion
*/
writePattern(patterns: Array<PatternLineData>, startPos?: number): Promise<void>;
}