blinkstick-ts
Version:
BlinkStick TypeScript implementation
283 lines (282 loc) • 8.89 kB
TypeScript
/**
* Provides access to BlinkStick devices
*
* @module blinkstick
*/
/// <reference types="node" />
import * as usb from 'node-hid';
import { BlinkStickChannel } from './blinkstick-channel';
import { IBlinkStick } from './blinkstick.interface';
import { Color } from './color';
export declare class BlinkStick implements IBlinkStick {
readonly device: usb.HID;
/**
* 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
*/
readonly serial?: string;
readonly manufacturer?: string;
readonly product?: string;
/** inverse mode for IKEA DIODER in conjunction with BlinkStick v1.0 */
private inverse;
private requiresSoftwareColorPatch;
/**
* Initialize new BlinkStick device
*
* @class BlinkStick
* @constructor
* @param {Object} device The USB device as returned from "usb" package.
* @param {String} [serialNumber] Serial number of the device. Used only in Windows.
* @param {String} [manufacturer] Manufacturer of the device. Used only in Windows.
* @param {String} [product] Product name of the device. Used only in Windows.
*/
constructor(device: any, serialNumber?: string, manufacturer?: string, product?: string);
/**
* Close BlinkStick device and stop all animations
*
* @method close
*/
close(): void;
/**
* Get the major version from serial number
*
* @method getVersionMajor
* @return {Number} Major version number from serial
*/
get versionMajor(): number | undefined;
/**
* Get the minor version from serial number
*
* @method getVersionMinor
* @return {Number} Minor version number from serial
*/
get versionMinor(): number | undefined;
setRandomColor(): void;
sendColorInternal(color: Color, channel: number, index: number): void;
/**
* Set the color of LEDs
*
* @example
* //Available overloads
* setColor(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity
*
* setColor(color, [options], [callback]); // use '#rrggbb' format
*
* setColor(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names
*
* @method setColor
* @param {Color} index The index to set
* @param {Color} color The color to set
* @param {Object} [options] additional options {"channel": 0, "index": 0}. Channel is represented as 0=R, 1=G, 2=B
* @param {Function} [callback] Callback, called when complete.
*/
setColor(color: Color, index?: number, channel?: number): void;
/**
* Set mode for BlinkStick Pro
*
* - 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
*
* @method setMode
* @param {Number} mode Set the desired mode for BlinkStick Pro
*/
setMode(mode: number): void;
/**
* Get mode for BlinkStick Pro
*
* - 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
*
* Usage:
*
* @example
* getMode(function(err, data) {
* console.log(data);
* });
*
* @method getMode
*/
getMode(): Promise<number | undefined>;
/**
* Get the current color visible on BlinkStick
*
* Function supports the following overloads:
*
* @example
* //Available overloads
* getColor(callback); //index defaults to 0
*
* getColor(index, callback);
*
* @example
* getColor(0, function(err, r, g, b) {
* console.log(r, g, b);
* });
*
* @method getColor
* @param {Number=0} index The index of the LED
* @param {Function} callback Callback to which to pass the color values.
* @return {Number, Number, Number} Callback returns three numbers: R, G and B [0..255].
*/
getColor(index?: number, channel?: number): Color;
/**
* Get the current color frame on BlinkStick Pro
*
* @method getColors
* @param {Number} index Where to start
* @param {Number} count How many LEDs should return
* @return {Array} Callback returns an array of LED data in the following format: [g0, r0, b0, g1, r1, b1...]
*/
getColors(count: number, index?: number, channel?: number): Color[];
/**
* Set the color frame on BlinkStick Pro
*
* @example
* var data = [255, 0, 0, 0, 255, 0];
*
* setColors(0, data, function(err) {
* });
*
* @method setColors
* @param {Number} channel Channel is represented as 0=R, 1=G, 2=B
* @param {Array} data LED data in the following format: [g0, r0, b0, g1, r1, b1...]
* @param {Function} callback Callback when the operation completes
*/
setColors(data: Color[], channel?: number): void;
getChannel(channel?: number): BlinkStickChannel;
/**
* Get an infoblock from a device.
*
* @private
* @static
* @method getInfoBlock
* @param {BlinkStick} device Device from which to get the value.
* @param {Number} location Address to seek the data.
* @param {Function} callback Callback to which to pass the value.
*/
private getInfoBlock;
/**
* 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.
*
* Usage:
*
* @example
* getInfoBlock1(function(err, data) {
* console.log(data);
* });
*
* @method getInfoBlock1
* @param {Function} callback Callback to which to pass the value.
*/
getInfoBlock1(): string;
/**
* Get the infoblock2 of the device.
* This is a 32 byte array that can contain any data.
*
* Usage:
*
* @example
* getInfoBlock2(function(err, data) {
* console.log(data);
* });
*
* @method getInfoBlock2
* @param {Function} callback Callback to which to pass the value.
*/
getInfoBlock2(): string;
/**
* Sets an infoblock on a device.
*
* @private
* @static
* @method setInfoBlock
* @param {BlinkStick} device Device on which to set the value.
* @param {Number} location Address to seek the data.
* @param {String} data The value to push to the device. Should be <= 32 chars.
* @param {Function} callback Callback to which to pass the value.
*/
private setInfoBlock;
/**
* Sets the infoblock1 with specified string.
* It fills the rest of bytes with zeros.
*
* Usage:
*
* @example
* setInfoBlock1("abcdefg", function(err) {
* });
*
* @method setInfoBlock1
* @param {String} data Data value for InfoBlock
* @param {Function} callback Callback when the operation completes
*/
setInfoBlock1(data: string): void;
/**
* Sets the infoblock2 with specified string.
* It fills the rest of bytes with zeros.
*
* Usage:
*
* @example
* setInfoBlock2("abcdefg", function(err) {
* });
*
* @method setInfoBlock2
* @param {String} data Data value for InfoBlock
* @param {Function} callback Callback when the operation completes
*/
setInfoBlock2(data: string): void;
/**
* Turns the LED off.
*
* @method turnOff
*/
turnOff(): void;
/**
* Determines report ID and number of LEDs for the report
*
* @private
* @method determineReportId
* @return {object} data.reportId and data.ledCount
*/
private determineReportId;
/**
* Set feature report to the device.
*
* @method setFeatureReport
* @param {Number} reportId Report ID to receive
* @param {Array} data Data to send to the device
* @param {Function} callback Function called when report sent
*/
setFeatureReport(reportId: number, data: number[] | Buffer): number;
/**
* Get feature report from the device.
*
* @method getFeatureReport
* @param {Number} reportId Report ID to receive
* @param {Number} length Expected length of the report
*/
getFeatureReport(reportId: number, length: number): number[];
}