Took 59 minutes
This commit is contained in:
Tobias Hopp 2023-03-13 11:14:27 +01:00
parent 3f789d24ec
commit b7fd5f87bc
4 changed files with 90 additions and 23 deletions

View File

@ -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<void> {
return new Promise<void>(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<void> {
return new Promise<void>(() => {
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();
}
}

View File

@ -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<void> {
}
}, 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();
});
}

View File

@ -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 = `<div class="tooltip">${span.innerText}

View File

@ -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%")