Emergency Stop

This commit is contained in:
chk
2026-06-12 19:02:31 +02:00
parent f02415c23f
commit a49e54367e
3 changed files with 102 additions and 6 deletions

View File

@@ -21,11 +21,13 @@ const loginBtn = document.getElementById("login-btn");
const loginSubmit = document.getElementById("login-submit");
const loginMsg = document.getElementById("login-msg");
const nav = document.getElementById("services");
const estopBtn = document.getElementById("emergency-stop");
const usernameInput = document.getElementById("username");
const passwordInput = document.getElementById("password");
let loggedIn = false;
let armedPollInterval = null;
// ===========================
// Login anzeigen
@@ -57,6 +59,8 @@ function switchToLogout() {
// ===========================
function performLocalLogout() {
loggedIn = false;
stopArmedPolling();
estopBtn.style.display = "none";
iframe.src = "";
iframe.style.display = "none";
nav.innerHTML = "";
@@ -64,6 +68,46 @@ function performLocalLogout() {
switchToLogin();
}
// ===========================
// Armed-Status prüfen
// ===========================
async function updateArmedStatus() {
try {
const r = await fetch('https://robotDriver.server.schooltech.ch/api/power-status');
if (r.ok) {
const data = await r.json();
estopBtn.style.display = data.armed ? "block" : "none";
} else {
estopBtn.style.display = "none";
}
} catch (e) {
estopBtn.style.display = "none";
}
}
function startArmedPolling() {
updateArmedStatus();
armedPollInterval = setInterval(updateArmedStatus, 5000);
}
function stopArmedPolling() {
if (armedPollInterval) {
clearInterval(armedPollInterval);
armedPollInterval = null;
}
}
// ===========================
// Emergency Stop
// ===========================
estopBtn.addEventListener("click", async () => {
try {
await fetch('https://robotDriver.server.schooltech.ch/api/emergency-stop', { method: 'POST' });
} catch (e) {
console.error('E-Stop request failed:', e);
}
});
// ===========================
// Login-Logik
// ===========================
@@ -84,6 +128,7 @@ async function doLogin() {
loginMsg.textContent = "";
setupServiceButtons();
switchToLogout();
startArmedPolling();
} else {
loginMsg.textContent = "Login fehlgeschlagen";
}
@@ -156,6 +201,7 @@ function openService(svc) {
loggedIn = true;
setupServiceButtons();
switchToLogout();
startArmedPolling();
} else {
switchToLogin();
}