feat(led-tool): browser settings editor with Web Serial
Add static editor, host_ports filtering, Flask /editor and REST APIs for ports and led-cli read/write; document standalone and embedded use. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
209
static/settings_editor.html
Normal file
209
static/settings_editor.html
Normal file
@@ -0,0 +1,209 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>LED device settings</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--text: #e5e7eb;
|
||||
--muted: #9ca3af;
|
||||
--border: #374151;
|
||||
--accent: #3b82f6;
|
||||
--danger: #f87171;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: system-ui, sans-serif;
|
||||
background: #0b1020;
|
||||
color: var(--text);
|
||||
padding: 1rem;
|
||||
}
|
||||
h1 { font-size: 1.15rem; margin: 0 0 0.35rem; }
|
||||
.muted { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
|
||||
.card {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
background: #111827;
|
||||
}
|
||||
label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
|
||||
input, select, textarea {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--border);
|
||||
background: #1f2937;
|
||||
color: var(--text);
|
||||
margin-bottom: 0.65rem;
|
||||
}
|
||||
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
|
||||
.row > * { flex: 1; min-width: 10rem; }
|
||||
.btn {
|
||||
padding: 0.45rem 0.85rem;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
background: #4b5563;
|
||||
color: #fff;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.btn-primary { background: var(--accent); }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
|
||||
gap: 0 0.5rem;
|
||||
}
|
||||
#status { font-size: 0.85rem; margin-top: 0.5rem; }
|
||||
#status.error { color: var(--danger); }
|
||||
.flash {
|
||||
display: none;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 0.75rem;
|
||||
background: #14532d;
|
||||
color: #86efac;
|
||||
}
|
||||
.flash.error { background: #5e1b1b; color: #fca5a5; }
|
||||
.flash.show { display: block; }
|
||||
[hidden] { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body data-api-base="/led-tool">
|
||||
<h1>Device settings (USB)</h1>
|
||||
<p class="muted">Edit <code>settings.json</code> via <strong>Web Serial</strong> (USB on this computer) or <strong>host serial</strong> (Pi running <code>led-cli</code>). Use <strong>Connect</strong> for your transport, then <strong>Download</strong> or <strong>Upload</strong>.</p>
|
||||
<div id="flash" class="flash"></div>
|
||||
|
||||
<div class="card" id="webserial-wrap" hidden>
|
||||
<h2 style="font-size:1rem;margin:0 0 0.5rem;">Web Serial</h2>
|
||||
<div class="row">
|
||||
<button type="button" class="btn btn-primary" id="webserial-connect">Connect USB</button>
|
||||
<button type="button" class="btn" id="webserial-disconnect" hidden>Disconnect</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" id="host-serial-wrap">
|
||||
<h2 style="font-size:1rem;margin:0 0 0.5rem;">Host serial</h2>
|
||||
<label for="host-port">Port</label>
|
||||
<select id="host-port"><option value="">Select port</option></select>
|
||||
<div class="row">
|
||||
<button type="button" class="btn btn-primary" id="host-connect">Connect</button>
|
||||
<button type="button" class="btn" id="host-disconnect" hidden>Disconnect</button>
|
||||
<button type="button" class="btn" id="btn-refresh-ports">Refresh ports</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="row" style="margin-bottom:0.75rem;">
|
||||
<button type="button" class="btn btn-primary" id="btn-download">Download</button>
|
||||
<button type="button" class="btn btn-primary" id="btn-upload">Upload & reset</button>
|
||||
<button type="button" class="btn" id="btn-from-json">JSON → form</button>
|
||||
<button type="button" class="btn" id="btn-to-json">Form → JSON</button>
|
||||
</div>
|
||||
<p id="status">Ready</p>
|
||||
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="name">Name</label>
|
||||
<input id="name" data-setting="name" type="text" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="num_leds">Num LEDs</label>
|
||||
<input id="num_leds" data-setting="num_leds" type="number" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="led_pin">LED pin</label>
|
||||
<input id="led_pin" data-setting="led_pin" type="number" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="brightness">Brightness</label>
|
||||
<input id="brightness" data-setting="brightness" type="number" min="0" max="255" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="color_order">Colour order</label>
|
||||
<select id="color_order" data-setting="color_order">
|
||||
<option value=""></option>
|
||||
<option value="rgb">rgb</option>
|
||||
<option value="rbg">rbg</option>
|
||||
<option value="grb">grb</option>
|
||||
<option value="gbr">gbr</option>
|
||||
<option value="brg">brg</option>
|
||||
<option value="bgr">bgr</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="transport_type">Transport</label>
|
||||
<select id="transport_type" data-setting="transport_type">
|
||||
<option value=""></option>
|
||||
<option value="espnow">espnow</option>
|
||||
<option value="wifi">wifi</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ssid">WiFi SSID</label>
|
||||
<input id="ssid" data-setting="ssid" type="text" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="password">WiFi password</label>
|
||||
<input id="password" data-setting="password" type="password" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="wifi_channel">WiFi channel</label>
|
||||
<input id="wifi_channel" data-setting="wifi_channel" type="number" min="1" max="11" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="default">Default preset</label>
|
||||
<input id="default" data-setting="default" type="text" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="id">Device id (ESP-NOW)</label>
|
||||
<input id="id" data-setting="id" type="number" min="0" max="255" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="debug">Debug</label>
|
||||
<select id="debug" data-setting="debug">
|
||||
<option value=""></option>
|
||||
<option value="False">False</option>
|
||||
<option value="True">True</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<label for="raw_json">Raw settings.json</label>
|
||||
<textarea id="raw_json" rows="14" spellcheck="false">{}</textarea>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
const api =
|
||||
document.body.getAttribute('data-api-base') ??
|
||||
(location.pathname.includes('/led-tool') ? '/led-tool' : '');
|
||||
const prefix = api + '/static';
|
||||
function loadScript(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const s = document.createElement('script');
|
||||
s.src = url;
|
||||
s.onload = () => resolve();
|
||||
s.onerror = () => reject(new Error('Failed to load ' + url));
|
||||
document.body.appendChild(s);
|
||||
});
|
||||
}
|
||||
loadScript(prefix + '/web_serial.js')
|
||||
.then(() => loadScript(prefix + '/settings_editor.js'))
|
||||
.catch((e) => {
|
||||
const el = document.getElementById('flash');
|
||||
if (el) {
|
||||
el.textContent = e.message;
|
||||
el.className = 'flash error show';
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user