From b2b344ebec8f7b55506deb0c2138a1e2b9ffeb46 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Sun, 7 Dec 2025 13:27:46 -0700 Subject: Much nicer version of the controller page. --- controller_webpage/index.html | 458 +++++++++++++++++++++++++++++------------- 1 file changed, 317 insertions(+), 141 deletions(-) diff --git a/controller_webpage/index.html b/controller_webpage/index.html index 1400956..bfa6461 100644 --- a/controller_webpage/index.html +++ b/controller_webpage/index.html @@ -1,171 +1,347 @@ - - - - - + container.appendChild(header); + container.appendChild(field); + return container; + } -

Control Josh's Christmas Tree!

+ function renderControls(data) { + state.params = data; + const controls = document.getElementById("controls"); + controls.innerHTML = ""; + Object.keys(data).forEach((attr) => { + const card = createCard(attr, data[attr]); + controls.appendChild(card); + }); + } -
-
+ async function refreshValues() { + setStatus("Loading…"); + try { + const data = await fetchJSON(`${BASE_URL}/params`); + renderControls(data); + setStatus(""); + } catch (err) { + setStatus("Failed to load params"); + console.error(err); + } + } - + async function updateValues() { + try { + const data = await fetchJSON(`${BASE_URL}/params`); + Object.keys(data).forEach((attr) => { + const value = data[attr]; + const el = document.getElementById(attr); + if (!el) return; + if (value.type === "bool") { + el.checked = value.value === "on"; + } else { + const newVal = value.type === "color" + ? (value.value.startsWith("#") ? value.value : `#${value.value}`) + : value.value; + el.value = newVal; + if (value.type === "color" && el.nextElementSibling) { + el.nextElementSibling.value = newVal; + } + } + }); + } catch (err) { + console.error(err); + } + } - + async function sendRequest(attr, param, value) { + try { + await fetch(`${BASE_URL}/${attr}?${param}=${encodeURIComponent(value)}`, { + method: "POST", + }); + updateValues(); + } catch (err) { + setStatus("Request failed"); + console.error(err); + } + } + refreshValues(); + + + -- cgit