E-Stop Log

This commit is contained in:
chk
2026-06-12 18:47:28 +02:00
parent e5ec78ae1e
commit 3e3023fa63
7 changed files with 79 additions and 16 deletions

View File

@@ -175,7 +175,7 @@ document.addEventListener('DOMContentLoaded', function() {
// ── Emergency Stop Panel ─────────────────────────────────────────────
// SVG-Button: Farbe + Text + Click-Handler je nach armed-Zustand wechseln.
// SVG-Button: Farbe + Text je nach armed-Zustand.
// armed=true → rot "EMERGENCY STOP" → POST /api/emergency-stop
// armed=false → grün "START ROBOT" → POST /api/power-on
let _lastArmed = null;
@@ -184,7 +184,7 @@ document.addEventListener('DOMContentLoaded', function() {
if (armed === _lastArmed) return;
_lastArmed = armed;
const stops = document.querySelectorAll('#estopGrad stop');
const stops = document.querySelectorAll('#estopGrad stop');
const textPath = document.querySelector('#emergency-stop textPath');
const btnInner = document.querySelector('#emergency-stop circle:last-of-type');
const label = document.getElementById('armed-status');
@@ -198,7 +198,7 @@ document.addEventListener('DOMContentLoaded', function() {
if (textPath) textPath.textContent = 'EMERGENCY STOP';
if (label) { label.textContent = '● Bestromt'; label.className = 'estop-armed-label armed'; }
} else {
// Grün: Strom AUS → Klick = Strom einschalten (Start Robot)
// Grün: Strom AUS → Klick = Strom einschalten
if (stops[0]) stops[0].setAttribute('stop-color', '#88ff99');
if (stops[1]) stops[1].setAttribute('stop-color', '#00aa44');
if (stops[2]) stops[2].setAttribute('stop-color', '#005522');
@@ -206,24 +206,59 @@ document.addEventListener('DOMContentLoaded', function() {
if (textPath) textPath.textContent = 'START ROBOT';
if (label) { label.textContent = '○ Kein Strom'; label.className = 'estop-armed-label disarmed'; }
}
}
const div = document.getElementById('emergency-stop');
if (div) {
div.onclick = armed
? () => fetch('/api/emergency-stop', { method: 'POST' })
: () => fetch('/api/power-on', { method: 'POST' });
// ── Click-Handler (einmalig registriert, liest _lastArmed dynamisch) ─────────
//
// Zeigt Lade-/Erfolgs-/Fehlerstatus unter dem Button.
// Schreibt console.warn ⚠️ für den Browser-Dev-Tools-Log.
async function handleEstopClick() {
const armed = _lastArmed;
const url = armed ? '/api/emergency-stop' : '/api/power-on';
const action = armed ? 'EmergencyStop' : 'PowerOn';
const statusEl = document.getElementById('estop-action-status');
if (statusEl) { statusEl.textContent = '⏳ …'; statusEl.className = 'estop-status'; }
console.warn(`⚠️ [${action}] wird ausgeführt …`);
try {
const res = await fetch(url, { method: 'POST' });
const data = await res.json();
const ok = data.ok || (data.results || []).every(r => r.ok || r.skipped);
if (ok) {
if (statusEl) { statusEl.textContent = `${action} OK`; statusEl.className = 'estop-status ok'; }
console.warn(`⚠️ [${action}] OK`);
} else {
const failed = (data.results || [])
.filter(r => !r.ok && !r.skipped)
.map(r => `${r.name}(${r.error || '?'})`)
.join(', ');
if (statusEl) { statusEl.textContent = `⚠️ Teilfehler: ${failed}`; statusEl.className = 'estop-status err'; }
console.warn(`⚠️ [${action}] Teilfehler — ${failed}`);
}
} catch (err) {
if (statusEl) { statusEl.textContent = `❌ Netzwerkfehler`; statusEl.className = 'estop-status err'; }
console.error(`❌ [${action}] Netzwerkfehler: ${err.message}`);
}
}
// onclick einmalig setzen — bleibt dauerhaft, Handler liest _lastArmed dynamisch.
const estopDiv = document.getElementById('emergency-stop');
if (estopDiv) estopDiv.onclick = handleEstopClick;
async function pollPowerStatus() {
try {
const res = await fetch('/api/power-status');
if (!res.ok) return;
const data = await res.json();
if (data.ok) updateEmergencyStopButton(data.armed);
// Immer aktualisieren (auch bei ok:false → disarmed als sicherer Fallback)
updateEmergencyStopButton(data.ok ? data.armed : false);
} catch { /* Netzwerkfehler → Button bleibt im letzten Zustand */ }
}
// Sofort sicheren Startzustand (grün "START ROBOT") setzen, damit der onclick
// sofort aktiv ist — noch bevor der erste Poll antwortet.
updateEmergencyStopButton(false);
pollPowerStatus();
setInterval(pollPowerStatus, 2000);

View File

@@ -105,6 +105,7 @@
</svg>
</div>
<div id="armed-status" class="estop-armed-label"></div>
<div id="estop-action-status" class="estop-status"></div>
</div>
<button id="btn-alarm-unlock" class="btn btn-unlock">