multiple buttons

This commit is contained in:
2026-06-16 21:00:39 +10:00
parent f0cd430eb9
commit 411864dab8
3 changed files with 63 additions and 12 deletions
+24 -2
View File
@@ -243,7 +243,8 @@
</select>
</div>
<button class="danger" onclick="doReset()" title="Pulse the target reset line">Reset</button>
<button onclick="doButton()" title="Pulse the target button / wake line">Button</button>
<button onclick="doButton()" title="Momentary press of the target button / wake line">Button</button>
<button id="holdBtn" onclick="toggleHold()" title="Latch the button line held down (force-on) / release">Hold: off</button>
<button onclick="clearTerminal()">Clear</button>
<button onclick="reconnect()">Reconnect</button>
<button id="logBtn" onclick="toggleLog()">Log: --</button>
@@ -308,6 +309,7 @@
// Terminal setup
const term = new Terminal({
cursorBlink: true,
convertEol: true, // target sends bare '\n'; treat it as CRLF so lines don't staircase
fontSize: 14,
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
theme: {
@@ -434,6 +436,7 @@
updateStatus('btStatus', msg.btConnected);
document.getElementById('heap').textContent = `Heap: ${msg.freeHeap}`;
updateLogUi(msg);
updateButtonUi(msg);
// Show WiFi info
const wifiInfo = document.getElementById('wifiInfo');
@@ -600,7 +603,26 @@
.catch(() => term.writeln(`\r\n\x1b[31m[${label} failed]\x1b[0m`));
}
function doReset() { pulseLine('/api/reset', 'reset'); }
function doButton() { pulseLine('/api/button', 'button'); }
function doButton() {
fetch('/api/button?ms=200').then(r => r.json()).then(s => {
updateButtonUi(s);
term.writeln('\r\n\x1b[33m[button] pulsed\x1b[0m');
}).catch(() => term.writeln('\r\n\x1b[31m[button failed]\x1b[0m'));
}
let holdOn = false;
function toggleHold() {
fetch('/api/button?latch=' + (holdOn ? 'off' : 'on')).then(r => r.json()).then(s => {
updateButtonUi(s);
term.writeln(`\r\n\x1b[33m[button] hold ${holdOn ? 'ON' : 'off'}\x1b[0m`);
}).catch(() => term.writeln('\r\n\x1b[31m[hold failed]\x1b[0m'));
}
function updateButtonUi(s) {
if (typeof s.buttonLatch === 'undefined') return;
holdOn = !!s.buttonLatch;
const b = document.getElementById('holdBtn');
b.textContent = 'Hold: ' + (holdOn ? 'ON' : 'off');
b.classList.toggle('danger', holdOn);
}
// ---- SD logging controls ----
let logOn = false;