ws2801-alexa
Version:
An alexa connector for the WS2801-Pi module.
36 lines (35 loc) • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LedController = void 0;
const ws2801_pi_1 = __importDefault(require("ws2801-pi"));
const config_1 = require("./config/config");
class LedController {
constructor(ledController, config) {
config = config ? config : config_1.defaultConfig;
this.ledController = ledController ? ledController : new ws2801_pi_1.default(config.ledAmount);
this.setLastLedStripState();
}
async on() {
for (let ledIndex = 0; ledIndex < this.lastLedStripState.length; ledIndex++) {
this.ledController.setLed(ledIndex, this.lastLedStripState[ledIndex]);
}
await this.ledController.show();
}
async off() {
this.setLastLedStripState();
await this.ledController.clearLeds().show();
}
async setBrightness(brightness) {
await this.ledController.setBrightness(brightness).show();
}
async setColor(color) {
await this.ledController.fillLeds(color).show();
}
setLastLedStripState() {
this.lastLedStripState = this.ledController.getLedStrip();
}
}
exports.LedController = LedController;