piixel
Version:
Control WS281X / NeoPixel LEDs from a Raspberry Pi using Node.js and TypeScript
201 lines (187 loc) • 4.7 kB
TypeScript
/**
* @packageDocumentation
* Control WS281X LEDs from a Raspberry Pi using TypeScript / Node.js
*/
/**
* @public
* Returns the colorwheel RGB value as an integer/hex value for the given number
*
* Based on C implementation from {@Link https://github.com/adafruit/circuitpython/blob/main/shared-module/rainbowio/__init__.c}
* @param pos - a number between 0 and 255
*
*/
export declare function colorwheel(pos: number): number
/**
* @public
* PCM_DOUT, which can be set to use GPIOs 21 and 31.
* Only 21 is available on the B+/2B/PiZero/3B, on pin 40.
* See {@link https://github.com/jgarff/rpi_ws281x?tab=readme-ov-file#pcm}
*/
export declare type PCMGpio = 21 | 31
/**
* @public
* PWM0, which can be set to use GPIOs 12, 18, 40, and 52.
* Only 12 (pin 32) and 18 (pin 12) are available on the B+/2B/3B
* See {@link https://github.com/jgarff/rpi_ws281x?tab=readme-ov-file#pwm}
*/
export declare type PWM0Gpio = 12 | 18 | 40 | 52
/**
* @public
* PWM1 which can be set to use GPIOs 13, 19, 41, 45 and 53.
* Only 13 is available on the B+/2B/PiZero/3B, on pin 33
* See {@link https://github.com/jgarff/rpi_ws281x?tab=readme-ov-file#pwm}
*/
export declare type PWM1Gpio = 13 | 19 | 41 | 45 | 53
/**
* @public
* Options for rendering pixels to the LED strip
*/
export declare interface RenderOptions {
/**
* @public
* Pixels to render to the LED strip
*/
pixels?: Uint32Array
/**
* @public
* Brightness of the LED strip (0.0 - 1.0)
*/
brightness?: number
}
/**
* @public
* Convert RGB color (e.g. 255, 255, 255) to HEX number
* @param r - red (0-255)
* @param g - green (0-255)
* @param b - blue (0-255)
*/
export declare function rgb2hex(r: number, g: number, b: number): number
/**
* @public
* SPI0-MOSI is available on GPIOs 10 and 38.
* Only GPIO 10 is available on all models.
* See {@link https://github.com/jgarff/rpi_ws281x?tab=readme-ov-file#spi}
*/
export declare type SPIGpio = 10 | 38
/**
* @public
* LED strip type identifiers
* See {@link https://github.com/jgarff/rpi_ws281x/blob/master/ws2811.h#L46}
*/
export declare enum StripType {
SK6812_STRIP_RGBW = 403703808,
SK6812_STRIP_RBGW = 403701768,
SK6812_STRIP_GRBW = 403181568,
SK6812_STRIP_GBRW = 403177488,
SK6812_STRIP_BRGW = 402657288,
SK6812_STRIP_BGRW = 402655248,
WS2811_STRIP_RGB = 1050624,
WS2811_STRIP_RBG = 1048584,
WS2811_STRIP_GRB = 528384,
WS2811_STRIP_GBR = 524304,
WS2811_STRIP_BRG = 4104,
WS2811_STRIP_BGR = 2064,
WS2812_STRIP = 528384,
SK6812_STRIP = 528384,
SK6812W_STRIP = 403181568,
}
/**
* @public
*
* Valid GPIOs to use with the Ws281x library
*/
export declare type ValidGPIO = PWM0Gpio | PWM1Gpio | PCMGpio | SPIGpio
/**
* @public
* Singleton instance of Ws281x
* @example
*
* ```typescript
* import {colorwheel, StripType, ws281x} from 'piixel'
*
* const LEDS = 16
*
* // Configure the library. Must be called before calling `render`.
* ws281x.configure({
* gpio: 18,
* leds: LEDS,
* type: StripType.WS2811_STRIP_GRB,
* })
*
* const pixels = new Uint32Array(LEDS)
* for (let i = 0; i < LEDS; i++) {
* pixels[i] = colorwheel((i * 256) / LEDS)
* }
* // Render pixels to the LED strip
* ws281x.render(pixels)
* ```
*
* See more examples here: {@link https://github.com/bjoerge/piixel/tree/main/examples}
*/
export declare const ws281x: Ws281xAPI
/**
* @public
* The Ws281x API
*/
export declare interface Ws281xAPI {
/**
* @public
* Configure the library
*
* @param options - configuration options
*/
configure(options: Ws281xConfig): void
/**
* @public
* Clear the LEDs (set all to off)
*/
clear(): void
/**
* @public
* Render the given pixels to the LED strip
*/
render(renderOptions: RenderOptions): void
/**
* @public
* Render the given pixels to the LED strip
*/
render(pixels: Uint32Array): void
/**
* @public
* Reset the library and release resources
*/
reset(): void
}
/**
* @public
* Configuration options for the Ws281x library
*/
export declare interface Ws281xConfig {
/**
* @public
* Number of LEDs to control
*/
leds: number
/**
* @public
* Set the GPIO number to communicate with the Neopixel strip (default 18, PWM0)
*/
gpio?: ValidGPIO
/**
* @public
* Reset the LEDs on process exit (default false)
*/
resetOnExit?: boolean
/**
* @public
* DMA channel to use (default 10)
* See {@link https://github.com/jgarff/rpi_ws281x/blob/master/README.md#important-warning-about-dma-channels}
*/
dma?: number
/**
* @public
* Strip type (default {@link StripType.WS2811_STRIP_GRB})
*/
type?: StripType
}
export {}