Files
ExoMy_Cuno/ExoMy_Software-master/gui/admin-motor-test.html
T

693 lines
37 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CUNO // Motorentest</title>
<style>
:root {
--bg: #05080F;
--pri: #0088FF;
--sec: #FF8C00;
--ok: #00ff91;
--txt: rgba(0,255,145,.8);
--txt2: rgba(0,210,130,.38);
--mono: "Consolas","Cascadia Code","Cascadia Mono","Courier New",monospace;
}
* { margin:0; padding:0; box-sizing:border-box; }
html { height:100%; }
body {
font-family:var(--mono);
background-color:var(--bg);
background-image:
linear-gradient(rgba(0,255,145,.04) 1px, transparent 1px),
linear-gradient(90deg, rgba(0,255,145,.04) 1px, transparent 1px);
background-size:32px 32px;
color:var(--txt);
display:flex; flex-direction:column; height:100%; overflow:hidden;
}
/* ── HEADER ─────────────────────────────────────── */
header {
height:52px;
background:linear-gradient(135deg, #060D1A 0%, #0C1C38 100%);
border-bottom:2px solid var(--pri);
box-shadow:0 2px 24px rgba(0,136,255,.28);
display:flex; align-items:center; padding:0 16px; gap:14px; flex-shrink:0; z-index:10;
}
.hdr-icon { width:32px; height:32px; flex-shrink:0; }
.hdr-title { font-weight:700; font-size:14px; color:#fff; letter-spacing:5px; text-transform:uppercase; white-space:nowrap; }
.hdr-title em { font-style:normal; color:var(--pri); }
.hdr-div { width:1px; height:28px; background:rgba(255,255,255,.12); flex-shrink:0; }
.hdr-badge { font-size:7px; color:var(--pri); border:1px solid rgba(0,136,255,.5); padding:2px 8px; letter-spacing:2.5px; text-transform:uppercase; white-space:nowrap; }
.hdr-gap { flex:1; }
.hdr-status { font-size:8px; color:rgba(0,255,145,.55); letter-spacing:2px; text-transform:uppercase; white-space:nowrap; }
.hdr-back { color:rgba(0,255,145,.45); text-decoration:none; font-size:8px; letter-spacing:2px; text-transform:uppercase; }
.hdr-back:hover { color:rgba(0,255,145,.8); }
.hdr-clk { display:flex; flex-direction:column; align-items:flex-end; }
.hdr-clk-lbl { font-size:7px; color:rgba(255,255,255,.35); letter-spacing:2px; text-transform:uppercase; }
.hdr-clk-val { font-weight:700; font-size:14px; color:#fff; letter-spacing:3px; line-height:1.1; }
/* ── PANEL ──────────────────────────────────────── */
.panel {
position:relative;
background:
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 0 0/14px 1px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 0 0/1px 14px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 100% 0/14px 1px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 100% 0/1px 14px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 0 100%/14px 1px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 0 100%/1px 14px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 100% 100%/14px 1px no-repeat,
linear-gradient(rgba(0,255,145,.55),rgba(0,255,145,.55)) 100% 100%/1px 14px no-repeat,
#070D18;
border:1px solid rgba(0,255,145,.1);
box-shadow:0 0 24px rgba(0,0,0,.5), inset 0 0 40px rgba(0,255,145,.018);
}
.p-hdr {
display:flex; align-items:center; gap:7px; padding:7px 12px;
border-bottom:1px solid rgba(0,255,145,.08);
background:linear-gradient(90deg, rgba(0,255,145,.05) 0%, transparent 100%);
}
.p-dot { width:5px; height:5px; border-radius:50%; background:var(--ok); box-shadow:0 0 6px var(--ok); flex-shrink:0; }
.p-lbl { font-size:8px; letter-spacing:3px; color:rgba(0,255,145,.7); text-transform:uppercase; font-weight:bold; }
.p-tag { margin-left:auto; font-size:7px; color:rgba(0,255,145,.25); letter-spacing:1px; }
/* ── STATUS ROWS ────────────────────────────────── */
.sr { display:flex; align-items:center; padding:5px 12px; gap:8px; border-bottom:1px solid rgba(0,255,145,.04); }
.sr:last-child { border-bottom:none; }
.sr-led { width:6px; height:6px; border-radius:50%; flex-shrink:0; border:1px solid rgba(0,255,145,.15); background:#0a1408; }
.sr-led.led-ok { background:#00ff91; border-color:#00ff91; box-shadow:0 0 5px #00ff91, 0 0 12px rgba(0,255,145,.55); }
.sr-led.led-blue { background:#0088FF; border-color:#0088FF; box-shadow:0 0 5px #0088FF, 0 0 12px rgba(0,136,255,.5); }
.sr-led.led-off { background:#0d1208; border-color:rgba(0,255,145,.08); }
.sr-key { font-size:7px; letter-spacing:2px; color:rgba(0,210,130,.4); text-transform:uppercase; min-width:80px; flex-shrink:0; }
.sr-val { font-size:9px; font-weight:700; letter-spacing:.8px; margin-left:auto; color:rgba(0,255,145,.85); }
.state_active { color:#00ff91; }
.state_inactive { color:#FF3333; }
.state_unknown { color:#FF8C00; }
/* ── MAIN LAYOUT ────────────────────────────────── */
.admin-main {
flex:1; min-height:0; overflow-y:auto;
display:flex; flex-direction:column; gap:12px;
padding:12px; width:100%;
}
.admin-col { display:flex; flex-direction:column; gap:12px; }
/* ── RESPONSIVE ─────────────────────────────────── */
@media (min-width:640px) {
.admin-main { flex-direction:row; overflow:hidden; max-width:1200px; margin:0 auto; }
.admin-col { flex:1; min-width:0; overflow-y:auto; min-height:0; }
.admin-col:first-child { flex:0 0 320px; }
}
@media (min-width:1024px) {
.admin-main { padding:16px; gap:16px; }
.admin-col:first-child { flex:0 0 380px; }
}
@media (max-width:479px) {
.hdr-badge, .hdr-clk { display:none; }
}
/* ── BUTTONS ────────────────────────────────────── */
.button {
font-family:var(--mono); font-size:8px; letter-spacing:1.5px; text-transform:uppercase;
padding:9px 12px; border:1px solid rgba(0,255,145,.2); background:rgba(0,255,145,.03);
color:rgba(0,255,145,.6); cursor:pointer; transition:all .15s;
}
.button:hover { background:rgba(0,255,145,.08); color:var(--ok); }
.button:disabled { opacity:.3; cursor:not-allowed; }
.buttonA { border-color:rgba(0,136,255,.4); background:rgba(0,136,255,.06); color:rgba(0,136,255,.8); }
.buttonA:hover { background:rgba(0,136,255,.14); color:#55AAFF; border-color:rgba(0,136,255,.7); }
.buttonA:disabled { opacity:.3; }
.buttonX { border-color:rgba(0,255,145,.3); background:rgba(0,255,145,.04); color:rgba(0,255,145,.7); }
.buttonX:hover { background:rgba(0,255,145,.1); color:var(--ok); }
.buttonWarm { border-color:rgba(255,140,0,.35); background:rgba(255,140,0,.04); color:rgba(255,140,0,.7); }
.buttonWarm:hover { background:rgba(255,140,0,.12); color:#FF8C00; }
.buttonWarm:disabled { opacity:.3; }
.buttonDanger { border-color:rgba(255,51,51,.35); background:rgba(255,51,51,.04); color:rgba(255,51,51,.7); }
.buttonDanger:hover { background:rgba(255,51,51,.12); color:#FF3333; }
/* ── CONTAINER CONTROL ──────────────────────────── */
.container-grid { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:10px 12px; }
.container-grid .button { padding:10px 8px; }
/* ── COPY TEXT ──────────────────────────────────── */
.copy-text { font-size:8px; color:rgba(0,210,130,.45); letter-spacing:.5px; line-height:1.6; padding:8px 12px; border-bottom:1px solid rgba(0,255,145,.05); }
/* ── TAB BAR ────────────────────────────────────── */
.tab-bar { display:flex; gap:2px; padding:10px 12px 0; }
.motor_test_tab_button {
font-family:var(--mono); font-size:8px; letter-spacing:1.5px; text-transform:uppercase;
padding:7px 16px; border:1px solid rgba(0,255,145,.15); border-bottom:none;
background:transparent; color:rgba(0,255,145,.3); cursor:pointer; transition:all .15s;
}
.motor_test_tab_button:hover { color:rgba(0,255,145,.6); border-color:rgba(0,255,145,.35); }
.motor_test_tab_button.is_active { background:rgba(0,255,145,.06); color:#00ff91; border-color:rgba(0,255,145,.4); }
.tab-content-wrap { border-top:1px solid rgba(0,255,145,.08); }
/* ── TAB PANELS ─────────────────────────────────── */
.motor_test_tab_panel { display:none; }
.motor_test_tab_panel.is_active { display:block; }
/* ── TWO-COLUMN TAB LAYOUT ──────────────────────── */
.tab-row { display:grid; grid-template-columns:1fr 1fr; gap:0; }
.tab-box { padding:12px; }
.tab-box + .tab-box { border-left:1px solid rgba(0,255,145,.06); }
.tab-box-lbl { font-size:6px; letter-spacing:4px; color:rgba(0,255,145,.35); text-transform:uppercase; margin-bottom:8px; }
/* ── WHEEL SELECTOR ─────────────────────────────── */
.wheel_selector { display:grid; grid-template-columns:1fr 1fr; gap:4px; }
.wheel_option { display:flex; align-items:center; gap:6px; cursor:pointer; padding:6px 8px; border:1px solid rgba(0,255,145,.1); background:rgba(0,255,145,.02); transition:all .12s; }
.wheel_option:hover { border-color:rgba(0,255,145,.3); background:rgba(0,255,145,.05); }
.wheel_option input[type="radio"] { accent-color:var(--ok); width:12px; height:12px; flex-shrink:0; }
.wheel_option span { font-size:8px; letter-spacing:.8px; color:rgba(0,255,145,.6); }
.wheel_option:has(input:checked) { border-color:rgba(0,255,145,.5); background:rgba(0,255,145,.07); }
.wheel_option:has(input:checked) span { color:var(--ok); }
/* ── MOTOR TEST GRID ────────────────────────────── */
.motor_test_grid { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.motor_test_grid .button { padding:12px 8px; }
/* ── NEUTRAL TOOLBAR ────────────────────────────── */
.neutral-toolbar { display:flex; gap:6px; padding:8px 12px; border-bottom:1px solid rgba(0,255,145,.05); }
.neutral-toolbar .button { padding:7px 14px; font-size:8px; }
/* ── NEUTRAL CARDS ──────────────────────────────── */
.steering_neutral_grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(130px, 1fr)); gap:6px; padding:12px; }
.steering_neutral_card { border:1px solid rgba(0,255,145,.12); background:rgba(0,255,145,.025); padding:10px; }
.steering_neutral_card.is_dirty { border-color:rgba(255,140,0,.4); background:rgba(255,140,0,.03); }
.steering_neutral_compact_row { display:flex; flex-direction:column; gap:8px; }
.steering_neutral_card_header_compact { }
.steering_neutral_title { font-size:8px; letter-spacing:1.5px; color:rgba(0,255,145,.7); text-transform:uppercase; display:block; }
.steering_neutral_value_row_compact { display:flex; align-items:center; gap:6px; }
.steering_neutral_value { font-size:14px; font-weight:700; color:rgba(0,255,145,.9); letter-spacing:2px; flex:1; text-align:center; }
.is_dirty .steering_neutral_value { color:#FF8C00; }
.steering_neutral_adjust { padding:4px 10px !important; font-size:12px !important; letter-spacing:0 !important; }
/* ── BACK LINKS ─────────────────────────────────── */
.back-row { display:flex; gap:12px; padding:10px 12px; }
.back-link { font-family:var(--mono); font-size:8px; letter-spacing:1.5px; text-transform:uppercase; color:rgba(0,255,145,.4); text-decoration:none; padding:7px 14px; border:1px solid rgba(0,255,145,.15); transition:all .15s; }
.back-link:hover { color:rgba(0,255,145,.8); border-color:rgba(0,255,145,.4); }
</style>
</head>
<body>
<header>
<svg class="hdr-icon" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="7" y="11" width="18" height="10" rx="1" fill="#0088FF" opacity=".85"/>
<rect x="11" y="7" width="10" height="4" rx="1" fill="#0088FF" opacity=".5"/>
<circle cx="9" cy="23" r="3.5" fill="none" stroke="#0088FF" stroke-width="1.5"/>
<circle cx="23" cy="23" r="3.5" fill="none" stroke="#0088FF" stroke-width="1.5"/>
<circle cx="9" cy="23" r="1.3" fill="#0088FF"/>
<circle cx="23" cy="23" r="1.3" fill="#0088FF"/>
<rect x="22" y="8" width="4" height="3" rx=".5" fill="#FF6B00" opacity=".9"/>
<line x1="16" y1="7" x2="16" y2="3" stroke="#0088FF" stroke-width="1.5"/>
<circle cx="16" cy="2.5" r="1" fill="#0088FF"/>
<rect x="3" y="14" width="4" height="2" rx="1" fill="#0088FF" opacity=".6"/>
</svg>
<span class="hdr-title">CUNO&nbsp;<em>MOTORTEST</em></span>
<div class="hdr-div"></div>
<div class="hdr-badge">Maintenance</div>
<div class="hdr-gap"></div>
<span id="motor_test_status" class="hdr-status">Bereit</span>
<div class="hdr-div"></div>
<a class="hdr-back" href="./admin.html">← Admin</a>
<div class="hdr-div"></div>
<div class="hdr-clk">
<div class="hdr-clk-lbl">UTC</div>
<div class="hdr-clk-val" id="utc-clock">--:--:--</div>
</div>
</header>
<div class="admin-main">
<div class="admin-col">
<div class="panel">
<div class="p-hdr">
<div class="p-dot"></div>
<span class="p-lbl">Testmodus</span>
<span class="p-tag">Container Control</span>
</div>
<div class="copy-text">
Stoppe zuerst den ExoMy-Container. Erst wenn der Status eindeutig auf gestoppt steht, solltest du Motoren testen oder die Servo-Mitten ausrichten.
</div>
<div class="sr">
<span class="sr-led led-blue"></span>
<span class="sr-key">Container</span>
<span class="sr-val" id="container_name">exomy_autostart</span>
</div>
<div class="sr">
<span class="sr-led led-off"></span>
<span class="sr-key">Status</span>
<strong id="container_state" class="sr-val service_state state_unknown">-</strong>
</div>
<div class="sr">
<span class="sr-led led-off"></span>
<span class="sr-key">Sicher testen</span>
<span class="sr-val" id="container_safe_state">-</span>
</div>
<div class="container-grid">
<button class="button buttonDanger" onclick="setContainerState('stop')">Container stoppen</button>
<button class="button buttonA" onclick="setContainerState('start')">Container starten</button>
</div>
</div>
</div>
<div class="admin-col">
<div class="panel">
<div class="p-hdr">
<div class="p-dot"></div>
<span class="p-lbl">Motorentest</span>
<span class="p-tag">Motor Diagnostics</span>
</div>
<div class="tab-bar" role="tablist" aria-label="Motorentest Bereiche">
<button id="tab_button_impulse" class="motor_test_tab_button is_active" role="tab" aria-selected="true" onclick="switchMotorTestTab('impulse')">Impulstest</button>
<button id="tab_button_neutral" class="motor_test_tab_button" role="tab" aria-selected="false" onclick="switchMotorTestTab('neutral')">Servo-Mitte</button>
<button id="tab_button_drive_neutral" class="motor_test_tab_button" role="tab" aria-selected="false" onclick="switchMotorTestTab('drive-neutral')">Fahr-Null</button>
</div>
<div class="tab-content-wrap">
<section id="tab_panel_impulse" class="motor_test_tab_panel is_active" role="tabpanel">
<div class="tab-row">
<div class="tab-box">
<div class="tab-box-lbl">Rad auswählen</div>
<div class="wheel_selector" role="radiogroup" aria-label="Rad auswählen">
<label class="wheel_option"><input type="radio" name="wheel" value="fl" checked><span>Vorne links</span></label>
<label class="wheel_option"><input type="radio" name="wheel" value="fr"><span>Vorne rechts</span></label>
<label class="wheel_option"><input type="radio" name="wheel" value="cl"><span>Mitte links</span></label>
<label class="wheel_option"><input type="radio" name="wheel" value="cr"><span>Mitte rechts</span></label>
<label class="wheel_option"><input type="radio" name="wheel" value="rl"><span>Hinten links</span></label>
<label class="wheel_option"><input type="radio" name="wheel" value="rr"><span>Hinten rechts</span></label>
</div>
</div>
<div class="tab-box">
<div class="tab-box-lbl">Impulstest</div>
<div class="motor_test_grid">
<button class="button buttonX" onclick="runMotorTest('steer_left')">Lenkung links</button>
<button class="button buttonX" onclick="runMotorTest('steer_right')">Lenkung rechts</button>
<button class="button buttonA" onclick="runMotorTest('drive_forward')">Vorwärts</button>
<button class="button buttonDanger" onclick="runMotorTest('drive_backward')">Rückwärts</button>
</div>
</div>
</div>
</section>
<section id="tab_panel_neutral" class="motor_test_tab_panel" role="tabpanel" hidden>
<div class="copy-text">
Mit <code>-</code> und <code>+</code> wird die aktuelle Mittelstellung direkt am jeweiligen Lenkservo angefahren. <code>Speichern</code> schreibt alle Werte dauerhaft in die <code>exomy.yaml</code>.
</div>
<div class="neutral-toolbar">
<button class="button buttonWarm" onclick="loadSteeringNeutralValues()">Neu laden</button>
<button id="neutral_save_button" class="button buttonA" onclick="saveSteeringNeutralValues()">Speichern</button>
</div>
<div id="steering_neutral_grid" class="steering_neutral_grid"></div>
</section>
<section id="tab_panel_drive_neutral" class="motor_test_tab_panel" role="tabpanel" hidden>
<div class="copy-text">
Mit <code>-</code> und <code>+</code> stellst du den Stillstands-PWM pro Fahrmotor ein. <code>Speichern</code> schreibt alle sechs Werte dauerhaft in die <code>exomy.yaml</code>.
</div>
<div class="neutral-toolbar">
<button class="button buttonWarm" onclick="loadDriveNeutralValue()">Neu laden</button>
<button id="drive_neutral_save_button" class="button buttonA" onclick="saveDriveNeutralValue()">Speichern</button>
</div>
<div id="drive_neutral_grid" class="steering_neutral_grid"></div>
</section>
</div>
<div class="back-row">
<a class="back-link" href="./admin.html">← Admin</a>
<a class="back-link" href="./index.html">← Ground Control</a>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var adminApiBase = window.location.protocol + '//' + window.location.hostname + ':8082';
var isMotorTestRunning = false;
var isContainerActionRunning = false;
var isNeutralLoading = false;
var isNeutralPreviewRunning = false;
var isNeutralSaving = false;
var isDriveNeutralLoading = false;
var isDriveNeutralPreviewRunning = false;
var isDriveNeutralSaving = false;
var lastContainerStatus = null;
var activeMotorTestTab = 'impulse';
var steeringNeutralValues = {};
var steeringNeutralSavedValues = {};
var driveNeutralValues = {};
var driveNeutralSavedValues = {};
var STEERING_NEUTRAL_STEP = 5;
var WHEEL_ORDER = ['fl', 'fr', 'cl', 'cr', 'rl', 'rr'];
function setMotorTestStatus(text) {
var status = document.getElementById('motor_test_status');
if (status) status.textContent = text;
}
function getSelectedWheel() {
var selected = document.querySelector('input[name="wheel"]:checked');
return selected ? selected.value : 'fl';
}
function setServiceState(node, value) {
if (!node) return;
node.textContent = value || '-';
node.classList.remove('state_active', 'state_inactive', 'state_unknown');
if (value === 'running' || value === 'active') { node.classList.add('state_active'); return; }
if (value === 'exited' || value === 'stopped' || value === 'inactive') { node.classList.add('state_inactive'); return; }
node.classList.add('state_unknown');
}
function renderContainerStatus(data) {
var containerStatus = data && data.container_status;
var containerName = document.getElementById('container_name');
var containerState = document.getElementById('container_state');
var containerSafeState = document.getElementById('container_safe_state');
lastContainerStatus = containerStatus || null;
if (containerName && containerStatus && containerStatus.container) containerName.textContent = containerStatus.container;
setServiceState(containerState, containerStatus && containerStatus.state);
if (containerSafeState) containerSafeState.textContent = containerStatus && containerStatus.is_safe_for_motor_test ? 'Ja' : 'Nein';
}
function shouldWarnBeforeLeaving() {
return lastContainerStatus && lastContainerStatus.is_safe_for_motor_test && !isContainerActionRunning;
}
function confirmLeaveIfNeeded() {
if (!shouldWarnBeforeLeaving()) return true;
return window.confirm('Der ExoMy-Container ist noch gestoppt. Wirklich die Motortest-Seite verlassen?');
}
function switchMotorTestTab(tabName) {
activeMotorTestTab = tabName;
var impulseButton = document.getElementById('tab_button_impulse');
var neutralButton = document.getElementById('tab_button_neutral');
var driveNeutralButton = document.getElementById('tab_button_drive_neutral');
var impulsePanel = document.getElementById('tab_panel_impulse');
var neutralPanel = document.getElementById('tab_panel_neutral');
var driveNeutralPanel = document.getElementById('tab_panel_drive_neutral');
var isImpulse = tabName === 'impulse';
var isNeutral = tabName === 'neutral';
var isDriveNeutral = tabName === 'drive-neutral';
impulseButton.classList.toggle('is_active', isImpulse);
neutralButton.classList.toggle('is_active', isNeutral);
driveNeutralButton.classList.toggle('is_active', isDriveNeutral);
impulseButton.setAttribute('aria-selected', isImpulse ? 'true' : 'false');
neutralButton.setAttribute('aria-selected', isNeutral ? 'true' : 'false');
driveNeutralButton.setAttribute('aria-selected', isDriveNeutral ? 'true' : 'false');
impulsePanel.classList.toggle('is_active', isImpulse);
neutralPanel.classList.toggle('is_active', isNeutral);
driveNeutralPanel.classList.toggle('is_active', isDriveNeutral);
impulsePanel.hidden = !isImpulse;
neutralPanel.hidden = !isNeutral;
driveNeutralPanel.hidden = !isDriveNeutral;
if (isNeutral && !Object.keys(steeringNeutralValues).length) loadSteeringNeutralValues();
if (isDriveNeutral && !Object.keys(driveNeutralValues).length) loadDriveNeutralValue();
}
function renderSteeringNeutralCards() {
var grid = document.getElementById('steering_neutral_grid');
if (!grid) return;
var html = [];
WHEEL_ORDER.forEach(function(wheel) {
var entry = steeringNeutralValues[wheel];
if (!entry) return;
var savedEntry = steeringNeutralSavedValues[wheel];
var isDirty = !savedEntry || Number(savedEntry.value) !== Number(entry.value);
html.push(
'<article class="steering_neutral_card steering_neutral_card_compact' + (isDirty ? ' is_dirty' : '') + '">' +
'<div class="steering_neutral_compact_row">' +
'<div class="steering_neutral_card_header steering_neutral_card_header_compact">' +
'<strong class="steering_neutral_title">' + entry.wheel_label + '</strong>' +
'</div>' +
'<div class="steering_neutral_value_row steering_neutral_value_row_compact">' +
'<button class="button buttonWarm steering_neutral_adjust" onclick="adjustSteeringNeutralValue(\'' + wheel + '\', -' + STEERING_NEUTRAL_STEP + ')">-</button>' +
'<strong class="steering_neutral_value">' + entry.value + '</strong>' +
'<button class="button buttonA steering_neutral_adjust" onclick="adjustSteeringNeutralValue(\'' + wheel + '\', ' + STEERING_NEUTRAL_STEP + ')">+</button>' +
'</div>' +
'</div>' +
'</article>'
);
});
grid.innerHTML = html.join('');
updateNeutralSaveButton();
}
function hasUnsavedNeutralChanges() {
return WHEEL_ORDER.some(function(wheel) {
var c = steeringNeutralValues[wheel], s = steeringNeutralSavedValues[wheel];
if (!c || !s) return false;
return Number(c.value) !== Number(s.value);
});
}
function updateNeutralSaveButton() {
var button = document.getElementById('neutral_save_button');
if (button) button.disabled = isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || !hasUnsavedNeutralChanges();
}
function renderDriveNeutralCards() {
var grid = document.getElementById('drive_neutral_grid');
if (!grid) return;
var html = [];
WHEEL_ORDER.forEach(function(wheel) {
var entry = driveNeutralValues[wheel];
if (!entry) return;
var savedEntry = driveNeutralSavedValues[wheel];
var isDirty = !savedEntry || Number(savedEntry.value) !== Number(entry.value);
html.push(
'<article class="steering_neutral_card steering_neutral_card_compact' + (isDirty ? ' is_dirty' : '') + '">' +
'<div class="steering_neutral_compact_row">' +
'<div class="steering_neutral_card_header steering_neutral_card_header_compact">' +
'<strong class="steering_neutral_title">' + entry.wheel_label + '</strong>' +
'</div>' +
'<div class="steering_neutral_value_row steering_neutral_value_row_compact">' +
'<button class="button buttonWarm steering_neutral_adjust" onclick="adjustDriveNeutralValue(\'' + wheel + '\', -' + STEERING_NEUTRAL_STEP + ')">-</button>' +
'<strong class="steering_neutral_value">' + entry.value + '</strong>' +
'<button class="button buttonA steering_neutral_adjust" onclick="adjustDriveNeutralValue(\'' + wheel + '\', ' + STEERING_NEUTRAL_STEP + ')">+</button>' +
'</div>' +
'</div>' +
'</article>'
);
});
grid.innerHTML = html.join('');
updateDriveNeutralSaveButton();
}
function hasUnsavedDriveNeutralChanges() {
return WHEEL_ORDER.some(function(wheel) {
var c = driveNeutralValues[wheel], s = driveNeutralSavedValues[wheel];
if (!c || !s) return false;
return Number(c.value) !== Number(s.value);
});
}
function updateDriveNeutralSaveButton() {
var button = document.getElementById('drive_neutral_save_button');
if (button) button.disabled = isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving || !hasUnsavedDriveNeutralChanges();
}
async function fetchMotorTestStatus() {
try {
var response = await fetch(adminApiBase + '/api/motor-test/status');
if (!response.ok) throw new Error('status ' + response.status);
renderContainerStatus(await response.json());
} catch (error) {
setMotorTestStatus('API nicht erreichbar');
}
}
async function setContainerState(action) {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
isContainerActionRunning = true;
updateNeutralSaveButton(); updateDriveNeutralSaveButton();
setMotorTestStatus(action === 'stop' ? 'Stoppe Container...' : 'Starte Container...');
try {
var response = await fetch(adminApiBase + '/api/motor-test/' + action + '-container', { method: 'POST' });
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
setMotorTestStatus(data.status || 'Fertig');
renderContainerStatus(data);
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Container-Aktion konnte nicht ausgeführt werden.');
} finally {
isContainerActionRunning = false;
updateNeutralSaveButton(); updateDriveNeutralSaveButton();
}
}
async function runMotorTest(action) {
if (isMotorTestRunning || isContainerActionRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
isMotorTestRunning = true;
updateNeutralSaveButton(); updateDriveNeutralSaveButton();
setMotorTestStatus('Teste...');
try {
var response = await fetch(adminApiBase + '/api/motor-test', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ wheel: getSelectedWheel(), action: action })
});
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
setMotorTestStatus(data.status || 'Test beendet');
renderContainerStatus(data);
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Der Motortest konnte nicht ausgeführt werden.');
} finally {
isMotorTestRunning = false;
updateNeutralSaveButton(); updateDriveNeutralSaveButton();
}
}
async function loadSteeringNeutralValues() {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
isNeutralLoading = true; updateNeutralSaveButton(); setMotorTestStatus('Lade Servo-Mitten...');
try {
var response = await fetch(adminApiBase + '/api/motor-test/steering-neutral');
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
steeringNeutralValues = data.neutral_values && data.neutral_values.values ? data.neutral_values.values : {};
steeringNeutralSavedValues = JSON.parse(JSON.stringify(steeringNeutralValues));
renderSteeringNeutralCards(); renderContainerStatus(data);
setMotorTestStatus(data.status || 'Servo-Mitten geladen');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Servo-Mitten konnten nicht geladen werden.');
} finally { isNeutralLoading = false; updateNeutralSaveButton(); }
}
async function adjustSteeringNeutralValue(wheel, delta) {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
var entry = steeringNeutralValues[wheel];
if (!entry) return;
steeringNeutralValues[wheel].value = Math.max(0, Math.min(4095, Number(entry.value) + Number(delta)));
renderSteeringNeutralCards();
isNeutralPreviewRunning = true; updateNeutralSaveButton(); setMotorTestStatus('Fahre Servo-Mitte an...');
try {
var response = await fetch(adminApiBase + '/api/motor-test/steering-neutral/preview', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ wheel: wheel, value: steeringNeutralValues[wheel].value })
});
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
renderContainerStatus(data); setMotorTestStatus(data.status || 'Servo angefahren');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Servo-Vorschau konnte nicht ausgeführt werden.');
} finally { isNeutralPreviewRunning = false; updateNeutralSaveButton(); }
}
async function saveSteeringNeutralValues() {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving || !hasUnsavedNeutralChanges()) return;
var payload = {};
WHEEL_ORDER.forEach(function(wheel) { var e = steeringNeutralValues[wheel]; if (e) payload[e.key] = Number(e.value); });
isNeutralSaving = true; updateNeutralSaveButton(); setMotorTestStatus('Speichere Servo-Mitten...');
try {
var response = await fetch(adminApiBase + '/api/motor-test/steering-neutral/save', {
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ values: payload })
});
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
steeringNeutralValues = data.neutral_values && data.neutral_values.values ? data.neutral_values.values : steeringNeutralValues;
steeringNeutralSavedValues = JSON.parse(JSON.stringify(steeringNeutralValues));
renderSteeringNeutralCards(); renderContainerStatus(data); setMotorTestStatus(data.status || 'Servo-Mitten gespeichert');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Servo-Mitten konnten nicht gespeichert werden.');
} finally { isNeutralSaving = false; updateNeutralSaveButton(); }
}
async function loadDriveNeutralValue() {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
isDriveNeutralLoading = true; updateDriveNeutralSaveButton(); setMotorTestStatus('Lade Fahr-Neutralwerte...');
try {
var response = await fetch(adminApiBase + '/api/motor-test/drive-neutral');
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
driveNeutralValues = data.drive_neutral && data.drive_neutral.values ? data.drive_neutral.values : {};
driveNeutralSavedValues = JSON.parse(JSON.stringify(driveNeutralValues));
renderDriveNeutralCards(); renderContainerStatus(data); setMotorTestStatus(data.status || 'Fahr-Neutralwerte geladen');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Fahr-Neutralwerte konnten nicht geladen werden.');
} finally { isDriveNeutralLoading = false; updateDriveNeutralSaveButton(); }
}
async function adjustDriveNeutralValue(wheel, delta) {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving) return;
var entry = driveNeutralValues[wheel];
if (!entry) return;
entry.value = Math.max(0, Math.min(4095, Number(entry.value) + Number(delta)));
renderDriveNeutralCards();
isDriveNeutralPreviewRunning = true; updateDriveNeutralSaveButton(); setMotorTestStatus('Fahre Fahr-Neutralwerte an...');
var values = {};
WHEEL_ORDER.forEach(function(k) { if (driveNeutralValues[k]) values[k] = Number(driveNeutralValues[k].value); });
try {
var response = await fetch(adminApiBase + '/api/motor-test/drive-neutral/preview', {
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ values: values })
});
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
driveNeutralValues = data.drive_neutral && data.drive_neutral.values ? data.drive_neutral.values : driveNeutralValues;
renderDriveNeutralCards(); renderContainerStatus(data); setMotorTestStatus(data.status || 'Fahr-Neutralwerte angefahren');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Fahr-Vorschau konnte nicht ausgeführt werden.');
} finally { isDriveNeutralPreviewRunning = false; updateDriveNeutralSaveButton(); }
}
async function saveDriveNeutralValue() {
if (isContainerActionRunning || isMotorTestRunning || isNeutralLoading || isNeutralPreviewRunning || isNeutralSaving || isDriveNeutralLoading || isDriveNeutralPreviewRunning || isDriveNeutralSaving || !hasUnsavedDriveNeutralChanges()) return;
isDriveNeutralSaving = true; updateDriveNeutralSaveButton(); setMotorTestStatus('Speichere Fahr-Neutralwerte...');
var values = {};
WHEEL_ORDER.forEach(function(wheel) { var e = driveNeutralValues[wheel]; if (e) values[e.key] = Number(e.value); });
try {
var response = await fetch(adminApiBase + '/api/motor-test/drive-neutral/save', {
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ values: values })
});
var data = await response.json();
if (!response.ok) throw new Error(data.status || ('status ' + response.status));
driveNeutralValues = data.drive_neutral && data.drive_neutral.values ? data.drive_neutral.values : driveNeutralValues;
driveNeutralSavedValues = JSON.parse(JSON.stringify(driveNeutralValues));
renderDriveNeutralCards(); renderContainerStatus(data); setMotorTestStatus(data.status || 'Fahr-Neutralwerte gespeichert');
} catch (error) {
setMotorTestStatus('Fehler');
alert(error.message || 'Die Fahr-Neutralwerte konnten nicht gespeichert werden.');
} finally { isDriveNeutralSaving = false; updateDriveNeutralSaveButton(); }
}
function updateClock() {
var el = document.getElementById('utc-clock');
if (el) el.textContent = new Date().toUTCString().split(' ')[4];
}
window.addEventListener('load', function() {
updateClock();
window.setInterval(updateClock, 1000);
fetchMotorTestStatus();
window.setInterval(fetchMotorTestStatus, 4000);
document.querySelectorAll('a[href]').forEach(function(link) {
link.addEventListener('click', function(event) {
if (!confirmLeaveIfNeeded()) event.preventDefault();
});
});
});
window.addEventListener('beforeunload', function(event) {
if (!shouldWarnBeforeLeaving()) return;
event.preventDefault();
event.returnValue = '';
});
</script>
</body>
</html>