diff --git a/src/LEDHandler.ts b/src/LEDHandler.ts index 19294ca..1740ad1 100644 --- a/src/LEDHandler.ts +++ b/src/LEDHandler.ts @@ -1,20 +1,82 @@ import ws281x from "rpi-ws281x-native"; +import {Utils} from "./Utils"; export class LEDHandler { - private static channel = ws281x(10, {stripType: 'ws2812'}); - private static currentInterval: NodeJS.Timer; + private static channel = ws281x(100, {stripType: 'ws2812'}); + private static currentInterval: NodeJS.Timer | undefined; - public static waterfall() { + public static pulseBlue() { clearInterval(this.currentInterval); - this.currentInterval = setInterval(() => { + const colors = this.channel.array; + for (let i = 0; i < colors.length; i++) { + colors[i] = 0x02f5f5; + } + this.channel.brightness = 50; + ws281x.render(); + + this.currentInterval = setInterval(async () => { + for (let i = 50; i <= 255; i++) { + this.channel.brightness = i; + await Utils.sleep(10); + } + await ws281x.render(); + await Utils.sleep(300); + for (let i = 255; i >= 50; i--) { + this.channel.brightness = i; + await Utils.sleep(10); + } + }, 4500); - }, 1000); } - public static pulseGreen() { + public static doGreen() { clearInterval(this.currentInterval); - this.currentInterval = setInterval(() => { + const colors = this.channel.array; + for (let i = 0; i < colors.length; i++) { + colors[i] = 0x419822; + } + this.channel.brightness = 255; + ws281x.render(); + } - }, 1000); + + public static clear() { + clearInterval(this.currentInterval); + this.currentInterval = undefined; + } + + static init(): Promise { + return new Promise(async () => { + const options = { + dma: 10, + freq: 800000, + gpio: 18, + invert: false, + brightness: 255, + stripType: ws281x.stripType.WS2812 + }; + + this.channel = ws281x(20, options); + + setInterval(this.loop, 1000); + }); + } + + private static loop(): Promise { + return new Promise(() => { + if (this.currentInterval) + return; + + this.ambientColor(); + }); + } + + private static ambientColor() { + const colors = this.channel.array; + for (let i = 0; i < colors.length; i++) { + colors[i] = 0xd60007; + } + this.channel.brightness = 255; + ws281x.render(); } } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index f068636..a7c7542 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ import {ContainerHelper} from "./ContainerHelper"; import {ArduinoProxy} from "./ArduinoProxy"; import path from "path"; import {ErrorHandler, InternalError} from "./ErrorHandler"; +import {LEDHandler} from "./LEDHandler"; const log = debug("itender:server"); @@ -24,16 +25,15 @@ global.appRoot = path.resolve(__dirname); process.on("uncaughtException", (error) => { let iError = new InternalError("UncaughtException: " + error.message, error.stack, error.name); - ErrorHandler.sendError(iError).then().catch((e) => console.error("Error report could not been sent!\n" +e)).then(() => process.exit(255)); + ErrorHandler.sendError(iError).then().catch((e) => console.error("Error report could not been sent!\n" + e)).then(() => process.exit(255)); }); process.on("unhandledRejection", (reason, promise) => { let iError = new InternalError("UnhandledRejection: " + reason, promise.toString()); - ErrorHandler.sendError(iError).then().catch((e) => console.error("Error report could not been sent!\n" +e)).then(() => process.exit(255)); + ErrorHandler.sendError(iError).then().catch((e) => console.error("Error report could not been sent!\n" + e)).then(() => process.exit(255)); }); - (async () => { try { log("Starting..."); @@ -100,17 +100,25 @@ function init(): Promise { } }, 1000 * 15); - log("1/4"); + log("1/5"); // Containers + //await iTender.refreshContainers(); await ContainerHelper.measureContainers(); - log("2/4"); + log("2/5"); + // Drinks await iTender.refreshDrinks(); - log("3/4"); + log("3/5"); + // Start auto checkup for stuck jobs await iTender.autoCheckup(); - log("4/4"); + log("4/5"); + + // Start LED Handler + await LEDHandler.init(); + log("5/5"); + resolve(); }); } diff --git a/src/web/main.ts b/src/web/main.ts index 1624551..be3a112 100644 --- a/src/web/main.ts +++ b/src/web/main.ts @@ -61,15 +61,12 @@ document.addEventListener("DOMContentLoaded", async () => { if (pcnt < 5) { containerDiv.style.backgroundColor = "var(--danger)"; - } - else if (pcnt < 15) { + } else if (pcnt < 15) { containerDiv.style.backgroundColor = "#EF4F00"; - } - else if (pcnt < 40) { + } else if (pcnt < 40) { containerDiv.style.backgroundColor = "#FF5400"; - } - else { - containerDiv.style.backgroundColor = "#5b5b9b"; + } else { + containerDiv.style.backgroundColor = "#5B5B9B"; } containerDiv.innerHTML = `
${span.innerText} diff --git a/views/index.pug b/views/index.pug index e51e87e..6079b9d 100644 --- a/views/index.pug +++ b/views/index.pug @@ -8,7 +8,7 @@ block setup input#ledCheckbox.input(type="checkbox") div.inputGroup label GPIO-Pin - input#ledGPIO.input(type="number" value="40" style="width:15%" disabled="disabled") + input#ledGPIO.input(type="number" value="18" style="width:15%" disabled="disabled") div.inputGroup label Ambiente Farbe input#ambientColor.input(type="color" value="#05445E" style="width:15%")