add some automation to pi side

This commit is contained in:
legop3
2025-11-11 21:04:04 -05:00
parent 3bc2921f25
commit 74a460a980
11 changed files with 278 additions and 17 deletions
+19
View File
@@ -4,6 +4,7 @@ const roverSelect = document.getElementById('roverSelect');
const sensorToggleBtn = document.getElementById('sensorToggle');
const motorsStopBtn = document.getElementById('motorsStop');
const sensorOutput = document.getElementById('sensorOutput');
const alertsEl = document.getElementById('alerts');
const mediaRestartBtn = document.getElementById('mediaRestart');
let selectedRover = null;
let sensorEnabled = false;
@@ -53,6 +54,24 @@ socket.on('commandAck', ({ roverId, status, error }) => {
}
});
socket.on('roverEvent', ({ roverId, event, ts, data }) => {
if (!alertsEl) return;
const div = document.createElement('div');
div.className = 'alert';
const when = ts ? new Date(ts).toLocaleTimeString() : new Date().toLocaleTimeString();
const details = data && data.error ? ` (${data.error})` : '';
div.textContent = `[${when}] ${roverId}: ${event}${details}`;
alertsEl.prepend(div);
while (alertsEl.children.length > 5) {
alertsEl.removeChild(alertsEl.lastChild);
}
setTimeout(() => {
if (div.parentElement === alertsEl) {
alertsEl.removeChild(div);
}
}, 15000);
});
roverSelect.addEventListener('change', (e) => {
selectedRover = e.target.value;
});
+3
View File
@@ -10,6 +10,8 @@
#sensorOutput { font-family: monospace; height: 320px; overflow: auto; border: 1px solid #999; padding: 8px; }
button { margin: 4px; }
.row { margin-bottom: 8px; }
#alerts { margin-top: 12px; max-width: 600px; }
.alert { background: #fff1d2; border: 1px solid #f0b651; padding: 6px 8px; margin-bottom: 6px; font-size: 0.9rem; }
</style>
</head>
<body>
@@ -38,6 +40,7 @@
<h3>Sensor Frames</h3>
<pre id="sensorOutput"></pre>
<p>Use WASD keys to drive the selected rover. Shift increases speed.</p>
<div id="alerts"></div>
</div>
</div>
<script src="/socket.io/socket.io.js"></script>