Select Git revision
system.js 5.94 KiB
class System {
constructor() {
this.connection = "unknown";
this.power = "unknown";
this.health = "unknown";
this.projector = new Projector();
this.projector.system = this;
this.ahm = new Ahm16();
this.ahm.system = this;
this.kramer = new KramerVs411X();
this.status_display = null;
// Store previous states
this.pconnection = this.connection;
this.ppower = this.power;
this.phealth = this.health;
this.pdante = null;
// Callback functions
this.onPowerChange = ()=>{};
this.onPowerOn = ()=>{};
this.onPowerOff = ()=>{};
this.onPowerShuttingDown = ()=>{};
this.onPowerStartingUp = ()=>{};
this.onPowerUnknown = ()=>{};
this.onPowerRequestedUp = ()=>{};
this.onPowerRequestedDown = ()=>{};
this.onHealthChange = ()=>{};
this.onHealthOk = ()=>{};
this.onHealthProblematic = ()=>{};
this.onHealthCritical = ()=>{};
this.onHealthUnknown = ()=>{};
}
updateFromStatus(status) {
if (status === undefined) {
console.error(`status in method system.updateFromStatus(status) was undefined`);
return;
}
if (! 'system' in status) {
console.error(`Key "system" not found in status in method system.updateFromStatus(status). Could not update system status`);
return;
}
let system_status = status["system"];
// console.log(status);
// Update Projector and DSP-subsystems as well
if ('projector' in status) { this.projector.updateFromStatus(status); }
if ('ahm' in status) { this.ahm.updateFromStatus(status); }
if ('kramer' in status) { this.kramer.updateFromStatus(status); }
// Power States and Callbacks
if ('power' in system_status) {
this.power = system_status['power'];
if (this.ppower != this.power) {
this.onPowerChange(this);
if (this.power == "on") {
this.onPowerOn(this);
updateStatus(this.status_display, "on", "on");
}
if (this.power == "off") {
this.onPowerOff(this);
updateStatus(this.status_display, "off", "off");
let uptime_display = document.getElementById("uptime-display");
uptime_display.classList.add("hidden");
}
if (this.power == "unknown") {
this.onPowerUnknown(this);
updateStatus(this.status_display, "unknown", "unknown");
}
if (this.power == "shutting down") {
this.onPowerShuttingDown(this);
updateStatus(this.status_display, "stopping", "stopping");
}
if (this.power == "starting up") {
this.onPowerStartingUp(this);
updateStatus(this.status_display, "starting", "starting");
}
if (this.power == "requested powerup") {
this.onPowerRequestedUp(this);
updateStatus(this.status_display, "starting...", "starting...");
}
if (this.power == "requested powerdown") {
this.onPowerRequestedDown(this);
updateStatus(this.status_display, "stopping...", "stopping...");
}
}
// Update the Uptime if the system is on
if (this.power == "on" && 'power-time' in system_status) {
let uptime_display = document.getElementById("uptime-display");
uptime_display.classList.remove("hidden");
let power_up = Date.parse(system_status['power-time']);
let now = new Date();
let t = now - power_up;
let seconds = Math.round(t/1000, 0);
let minutes = Math.round(t/1000/60, 0);
if (minutes < 1) {
uptime_display.innerHTML = `on for ${seconds} s`;
} else if (minutes < 240) {
uptime_display.innerHTML = `on for ${minutes} min`;
} else {
let hours = Math.round(t/1000/60/60, 1);
uptime_display.innerHTML = `on for ${hours} h`;
}
}
};
// Health Changes
if ('health' in system_status) {
this.health = system_status['health'];
if (this.phealth != this.health) {
this.onHealthChange(this);
if (this.health == "ok") { this.onHealthOk(this); }
if (this.health == "problematic") { this.onHealthProblematic(this); }
if (this.health == "critical") { this.onHealthCritical(this); }
if (this.health == "unknown") { this.onHealthUnknown(this); }
}
};
// Power States and Callbacks
if ('dante-on' in status) {
this.dante = status['dante-on'];
if (this.pdante != this.dante) {
let button = document.getElementById("toggle-button-dante_active_button");
if (button !== null) {
if (this.dante) {
button.toggle_button.setInactive();
console.log("Dante activated");
main.classList.add("dante");
} else {
button.toggle_button.setActive();
console.log("Dante deactivated");
main.classList.remove("dante");
}
}
}
this.pdante = this.dante;
};
// Store previous values
this.pconnection = this.connection;
this.ppower = this.power;
this.phealth = this.health;
this.pstatus = status;
}
}