Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions data/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,45 @@ input, button, textarea{ font-family: inherit; color: inherit; }
}
.jack-input:disabled{ opacity: 0.4; }

/* <select> wearing the jack-input skin: drop the native chrome, keep a chevron. */
.jack-select{
appearance: none;
-webkit-appearance: none;
cursor: pointer;
padding-right: 30px;
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23E8DEC9' stroke-opacity='0.55' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 14px 14px;
}
:root[data-theme="light"] .jack-select{
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23232017' stroke-opacity='0.6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
}
.jack-select option{
background: var(--c-panel);
color: var(--c-text);
}

/* "Restart to apply" strip — shown only while the persisted strip settings
differ from what the running firmware is bound to. */
.hw-apply{
display: none;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-top: 4px;
padding: 10px 12px;
border: var(--hair) dashed var(--c-amber-dim);
border-radius: var(--radius-ctl);
}
.hw-apply.show{ display: flex; }
.hw-apply-note{
font-family: var(--font-mono);
font-size: 11px;
color: var(--c-amber);
}

.jack-eye{
position: absolute;
right: 10px;
Expand Down
81 changes: 80 additions & 1 deletion data/assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,89 @@ function renderSettingsFromState() {
$("#sacnLed").classList.toggle("on", !!config.sacnEnabled);
}
if (config.sacnUniverse) $("#sacnUniverse").value = config.sacnUniverse;
renderLedHardware(config);
}

renderTuningFromState();
}

/* ---------------------------------------------------------------------
Strip hardware — chipset / colour order / data pin. The option lists come
from the device (config.ledOptions) so the UI never hardcodes what a given
firmware/chip can drive. Persisted values bind at boot; while they differ
from what the running firmware reports (config.ledActive) the "restart to
apply" strip is shown.
-------------------------------------------------------------------- */

function fillSelect(sel, items, current) {
// Rebuild only when the option set changed (keeps focus/scroll otherwise).
const sig = items.map((i) => i.value).join(",");
if (sel.dataset.sig !== sig) {
sel.innerHTML = "";
for (const it of items) {
const o = document.createElement("option");
o.value = it.value;
o.textContent = it.label;
sel.appendChild(o);
}
sel.dataset.sig = sig;
}
if (current != null && document.activeElement !== sel) sel.value = String(current);
}

function renderLedHardware(config) {
const opts = config.ledOptions;
if (opts) {
const strapping = new Set(opts.strappingPins || []);
fillSelect($("#ledType"), (opts.types || []).map((t) => ({ value: t.id, label: t.name })), config.ledType);
fillSelect($("#ledColorOrder"), (opts.colorOrders || []).map((o) => ({ value: o, label: o })), config.ledColorOrder);
fillSelect($("#ledPin"), (opts.pins || []).map((p) => ({
value: p, label: "GPIO " + p + (strapping.has(p) ? " · strapping" : "")
})), config.ledPin);
}

// Pending-restart notice: persisted vs bound. ledCount rides along since it
// binds at boot too.
const active = config.ledActive;
const pending = [];
if (active) {
if (config.ledType != null && config.ledType !== active.ledType) pending.push("strip type");
if (config.ledColorOrder != null && config.ledColorOrder !== active.ledColorOrder) pending.push("color order");
if (config.ledPin != null && +config.ledPin !== +active.ledPin) pending.push("data pin");
if (config.ledCount != null && +config.ledCount !== +active.ledCount) pending.push("LED count");
}
const strip = $("#ledHwApply");
strip.classList.toggle("show", pending.length > 0);
if (pending.length) $("#ledHwApplyNote").textContent = "Restart to apply: " + pending.join(", ");
}

function saveLedHardware(field, value, label) {
const body = {};
body[field] = value;
engine.saveConfig(body).then((res) => {
if (res.ok) {
showToast(label + " saved — restart to apply");
renderSettingsFromState();
} else {
showToast("Device rejected the " + label.toLowerCase());
engine.getConfig().then(renderSettingsFromState); // snap the select back
}
});
}
$("#ledType").addEventListener("change", (e) => saveLedHardware("ledType", e.target.value, "Strip type"));
$("#ledColorOrder").addEventListener("change", (e) => saveLedHardware("ledColorOrder", e.target.value, "Color order"));
$("#ledPin").addEventListener("change", (e) => saveLedHardware("ledPin", +e.target.value, "Data pin"));

$("#ledRestart").addEventListener("click", () => {
if (!window.confirm("Restart the device now? LEDs go dark for a few seconds while it reboots.")) return;
engine.restart().then((res) => {
showToast(res.ok ? "Restarting… back in a few seconds" : "Failed to restart");
// The status poll re-syncs when the device is back; refresh the pending
// notice then (ledActive catches up to the persisted values).
if (res.ok) setTimeout(() => engine.getConfig().then(renderSettingsFromState), 8000);
});
});

/* ---------------------------------------------------------------------
Feel / Tuning — reflects the current durations (engine.TRANSITION,
client-side + persisted) and gamma (device config). Populated whenever
Expand Down Expand Up @@ -1132,7 +1210,8 @@ $("#ledCount").addEventListener("change", (e) => {
const v = clamp(Math.round(+e.target.value) || 1, 1, 1000);
e.target.value = v;
engine.saveConfig({ ledCount: v }).then((res) => {
showToast(res.ok ? "LED count saved" : "Failed to save LED count");
showToast(res.ok ? "LED count saved — restart to apply" : "Failed to save LED count");
renderSettingsFromState(); // refresh the "restart to apply" notice
});
});

Expand Down
20 changes: 20 additions & 0 deletions data/assets/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,17 @@
];
state.selectedId = 0;
state.info = { firmware: { name: "LUME", version: "demo", buildHash: "demo" }, limits: { maxLeds: 1000, maxSegments: 8 }, features: {} };
state.config = {
ledCount: 300, ledType: "WS2812B", ledColorOrder: "GRB", ledPin: 2,
ledActive: { ledCount: 300, ledType: "WS2812B", ledColorOrder: "GRB", ledPin: 2 },
ledOptions: {
types: [{ id: "WS2812B", name: "WS2812B / WS2812 (800 kHz)" }, { id: "WS2811", name: "WS2811 (800 kHz, 12 V)" },
{ id: "SK6812", name: "SK6812 (RGB)" }, { id: "SK6812_RGBW", name: "SK6812 RGBW", rgbw: true }],
colorOrders: ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"],
pins: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 21, 38, 45, 46, 47, 48],
strappingPins: [0, 3, 45, 46]
}
};
}

/* ---- bootstrap ---- */
Expand Down Expand Up @@ -798,6 +809,14 @@
}

/* ---- config (settings view) ---- */
// Reboot the device (POST /api/restart). Boot-time settings — strip type /
// colour order / data pin and ledCount — only take effect on the way back
// up; nothing else needs this. Resolves { ok } like saveConfig.
function restart() {
if (state.demo) return Promise.resolve({ ok: true, demo: true });
return writeJson("/api/restart", "POST", {}).then(function () { return { ok: true }; },
function (err) { return { ok: false, status: err.status }; });
}
function getConfig() {
return apiFetch("/api/config").then(function (c) { state.config = c; notify(); return c; },
function () { return null; });
Expand Down Expand Up @@ -954,6 +973,7 @@
sendPrompt: sendPrompt,
getConfig: getConfig,
saveConfig: saveConfig,
restart: restart,
getGamma: getGamma,
setGamma: setGamma,
getWarmth: getWarmth,
Expand Down
27 changes: 27 additions & 0 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,33 @@
<input type="number" class="jack-input" id="ledCount" value="300" min="1" max="1000" />
</div>
</div>
<!-- Strip hardware: chipset / colour order / data pin. Options come from
GET /api/config (ledOptions) so the list always matches this
firmware + chip. All three (and LED Count) bind at boot. -->
<div class="jack-field">
<span class="jack-label">Strip Type</span>
<div class="jack-input-wrap">
<select class="jack-input jack-select" id="ledType" aria-label="LED strip type"></select>
</div>
</div>
<div class="row-2">
<div class="jack-field">
<span class="jack-label">Color Order</span>
<div class="jack-input-wrap">
<select class="jack-input jack-select" id="ledColorOrder" aria-label="LED color order"></select>
</div>
</div>
<div class="jack-field">
<span class="jack-label">Data Pin</span>
<div class="jack-input-wrap">
<select class="jack-input jack-select" id="ledPin" aria-label="LED data pin"></select>
</div>
</div>
</div>
<div class="hw-apply" id="ledHwApply">
<span class="hw-apply-note" id="ledHwApplyNote">Strip settings apply after a restart</span>
<button class="btn" id="ledRestart" type="button">Restart device</button>
</div>
<div class="row-3">
<div class="readout-cell">
<div class="rl">Firmware</div>
Expand Down
50 changes: 47 additions & 3 deletions docs/API_V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,15 @@ Lightweight metadata for UIs to discover firmware details and capability limits.
"aiPrompts": true,
"ota": true
},
"controller": { "ledCount": 160, "power": true }
"controller": { "ledCount": 160, "ledType": "WS2812B", "ledColorOrder": "GRB", "ledPin": 2, "power": true }
}
```

`limits.maxLeds` is the compile-time `MAX_LED_COUNT` (default 1000). `features.sacn` and
`features.mqtt` reflect the current config (whether each is enabled), not just build support.
`controller.ledType` / `ledColorOrder` / `ledPin` are the strip hardware the output driver is
**bound to this boot**; the persisted selection (which may differ until a restart) is in
`GET /api/config`.

---

Expand Down Expand Up @@ -416,6 +419,17 @@ Get device configuration (passwords/API keys masked).
{
"wifiSSID": "MyNetwork",
"ledCount": 160,
"ledType": "WS2812B",
"ledColorOrder": "GRB",
"ledPin": 2,
"ledActive": { "ledType": "WS2812B", "ledColorOrder": "GRB", "ledPin": 2, "ledCount": 160 },
"ledOptions": {
"types": [ { "id": "WS2812B", "name": "WS2812B / WS2812 (800 kHz)" },
{ "id": "SK6812_RGBW", "name": "SK6812 RGBW", "rgbw": true }, "..." ],
"colorOrders": [ "RGB", "RBG", "GRB", "GBR", "BRG", "BGR" ],
"pins": [ 0, 1, 2, "..." ],
"strappingPins": [ 0, 3, 45, 46 ]
},
"aiApiKey": "****",
"aiApiKeySet": true,
"aiModel": "claude-haiku-4-5",
Expand All @@ -426,6 +440,23 @@ Get device configuration (passwords/API keys masked).
}
```

**LED hardware** — the strip chipset, colour byte order and data pin are runtime settings
(persisted in NVS, no reflash):

- `ledType` — one of `ledOptions.types[].id`: `WS2812B` (also WS2812 / WS2852 / GS1903),
`WS2811`, `WS2813`, `WS2815`, `SK6812`, `SK6812_RGBW`, `SK6822` (also APA106),
`WS2811_400`, `UCS1903`, `UCS1904`, `SM16703`, `TM1809`, `PL9823`. Bit timings mirror FastLED's
`chipsets.h`. `rgbw: true` entries drive 4-byte pixels; white is derived from RGB
(FastLED's default Rgbw mode) — the pipeline is RGB-only upstream.
- `ledColorOrder` — the byte order on the wire (`GRB` for WS2812B, `RGB` for most WS2811).
- `ledPin` — must be one of `ledOptions.pins`: the GPIOs this chip may drive, excluding the
flash/PSRAM bus, the native-USB pair and unbonded numbers. Strapping pins are listed (they
work once booted) and flagged in `strappingPins`.
- `ledActive` — what the running firmware is **actually bound to**; differs from the persisted
values above until the next restart (`POST /api/restart`).
- `ledOptions` is per build/chip (the S3 and C3 pin lists differ). A UI should populate its
controls from it rather than hardcoding.

### POST /api/config

Update device configuration.
Expand All @@ -436,6 +467,9 @@ Update device configuration.
"wifiSSID": "NewNetwork",
"wifiPassword": "newpass",
"ledCount": 160,
"ledType": "SK6812",
"ledColorOrder": "GRB",
"ledPin": 4,
"aiApiKey": "sk-ant-...",
"aiModel": "claude-haiku-4-5",
"sacnEnabled": true,
Expand All @@ -448,8 +482,18 @@ Update device configuration.
- Omit password fields to leave unchanged.
- Protocol changes (sACN/MQTT) are re-applied through the bus via a `ReconfigureProtocols`
command on the render loop — not live from the web task.
- `ledCount` changes are deferred and take effect on reboot (P0.8). WiFi changes restart the
device.
- `ledCount`, `ledType`, `ledColorOrder` and `ledPin` are deferred and take effect on reboot
(P0.8 — the output driver binds pins/peripherals once, at boot). Use `POST /api/restart`.
WiFi changes make the device try the new network immediately.
- An unknown `ledType`/`ledColorOrder`, or a `ledPin` outside `ledOptions.pins`, is rejected
with **400** `{"error": "ledPin: not a usable LED data pin on this chip"}` before *any*
field of the request is applied.

### POST /api/restart

Reboot the device so boot-time settings (LED hardware, `ledCount`) take effect. Requires auth
when a token is configured. Replies **202** `{"status":"restarting"}` first; the reboot runs
from the loop task ~250 ms later (a pending segment-layout save is flushed on the way out).

### POST /api/pixels

Expand Down
Loading
Loading