@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
49 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LedGroup = void 0;
const color_input_to_rgb_tuple_1 = require("../utils/colors/color-input-to-rgb-tuple");
const node_buffer_1 = require("node:buffer");
function prepareBuffer(buffer, red, green, blue) {
for (let i = 0; i < buffer.length; i = (i + 3) | 0) {
buffer.writeUInt8(green & 0xff, i); // G
buffer.writeUInt8(red & 0xff, i + 1); // R
buffer.writeUInt8(blue & 0xff, i + 2); // B
}
}
/**
* Class to control a group of LEDs on a Blinkstick device.
* Currently, it supports only "all LEDs" mode, but it can be extended to support more complex patterns.
* @category Implementation details
*/
class LedGroup {
constructor(blinkstick) {
this.blinkstick = blinkstick;
this.blinkstick = blinkstick;
this.buffer = node_buffer_1.Buffer.alloc(blinkstick.ledCount * 3);
}
/**
* @summary Sets the color of all LEDs
* @param color
*/
async setColor(color) {
const [r, g, b] = (0, color_input_to_rgb_tuple_1.colorInputToRgbTuple)(color);
prepareBuffer(this.buffer, r, g, b);
return await this.blinkstick.setColors(0, this.buffer);
}
/**
* @deprecated
*/
async setColorAndForget(color) {
const [r, g, b] = (0, color_input_to_rgb_tuple_1.colorInputToRgbTuple)(color);
prepareBuffer(this.buffer, r, g, b);
return await this.blinkstick.setColors(0, this.buffer);
}
/**
* @summary Turns off all LEDs by setting their color to black (0, 0, 0).
*/
async turnOff() {
return await this.setColor([0, 0, 0]);
}
}
exports.LedGroup = LedGroup;
//# sourceMappingURL=led-group.js.map