added slider for led brightness

This commit is contained in:
RaffaelW 2024-12-15 00:11:37 +01:00
parent 6276b1f74b
commit 4234732631
5 changed files with 65 additions and 7 deletions

View file

@ -11,6 +11,7 @@
<script type="module" src="/networks.js" defer></script> <script type="module" src="/networks.js" defer></script>
<script type="module" src="/submit.js" defer></script> <script type="module" src="/submit.js" defer></script>
<script type="module" src="/reset.js" defer></script> <script type="module" src="/reset.js" defer></script>
<script type="module" src="/range-input.js" defer></script>
</head> </head>
<body> <body>
<main> <main>
@ -177,6 +178,23 @@
/> />
</label> </label>
</fieldset> </fieldset>
<fieldset>
<legend>Sonstiges</legend>
<label>
LED-Helligkeit
<div>
<input
type="range"
name="led-brightness"
id="led-brightness"
min="0"
max="255"
class="range"
/>
<span class="range-value"></span>
</div>
</label>
</fieldset>
<div class="buttons"> <div class="buttons">
<button type="reset">Zurücksetzen</button> <button type="reset">Zurücksetzen</button>
<button type="submit">Speichern</button> <button type="submit">Speichern</button>

14
data/range-input.js Normal file
View file

@ -0,0 +1,14 @@
document.querySelector("form").addEventListener("input", (event) => {
if (event.target.classList.contains("range")) {
updateValue(event.target);
}
});
function updateValue(slider) {
const percentage = Math.round((slider.value / slider.max) * 100);
slider.nextElementSibling.innerText = `${percentage}%`;
}
document.querySelectorAll("input[type='range'].range").forEach((element) => {
updateValue(element);
});

View file

@ -3,7 +3,7 @@
--color-on-primary: white; --color-on-primary: white;
--color-background: #222; --color-background: #222;
--color-danger: #fa2b58; --color-danger: #fa2b58;
--icon-button-size: 2.5rem; --appended-item-size: 2.5rem;
} }
body { body {
@ -50,8 +50,13 @@ label span {
} }
input, input,
select { select,
label div {
width: clamp(200px, 100%, 400px); width: clamp(200px, 100%, 400px);
}
input,
select {
background-color: var(--color-background); background-color: var(--color-background);
color: white; color: white;
border: 1px solid white; border: 1px solid white;
@ -66,8 +71,13 @@ select:focus {
border-color: var(--color-primary); border-color: var(--color-primary);
} }
select:has(+ .icon-button) { select:has(+ .icon-button),
width: calc(clamp(200px, 100%, 400px) - var(--icon-button-size) - 8px); label div input[type="range"] {
width: calc(clamp(200px, 100%, 400px) - var(--appended-item-size) - 8px);
}
input[type="range"] {
accent-color: var(--color-primary);
} }
button { button {
@ -213,8 +223,8 @@ button.reload {
.icon-button { .icon-button {
padding: 8px; padding: 8px;
font-size: 0; font-size: 0;
width: var(--icon-button-size); width: var(--appended-item-size);
height: var(--icon-button-size); height: var(--appended-item-size);
} }
.spinning { .spinning {
@ -223,3 +233,16 @@ button.reload {
animation-iteration-count: infinite; animation-iteration-count: infinite;
animation-timing-function: linear; animation-timing-function: linear;
} }
div:has(.range-value) {
display: flex;
flex-direction: row;
gap: 8px;
}
.range-value {
width: var(--appended-item-size);
height: var(--appended-item-size);
text-align: center;
line-height: var(--appended-item-size);
}

View file

@ -18,7 +18,7 @@ function parseValue(input) {
return null; return null;
} }
if (input.type === "number") { if (input.type === "number" || input.type === "range") {
const number = Number(input.value); const number = Number(input.value);
return Number.isNaN(number) ? null : number; return Number.isNaN(number) ? null : number;
} }

View file

@ -96,6 +96,7 @@ void onGetConfig(AsyncWebServerRequest *request)
doc["direction-1"] = config.getUInt("direction-1", Output); doc["direction-1"] = config.getUInt("direction-1", Output);
doc["universe-2"] = config.getUInt("universe-2", 1); doc["universe-2"] = config.getUInt("universe-2", 1);
doc["direction-2"] = config.getUInt("direction-2", Input); doc["direction-2"] = config.getUInt("direction-2", Input);
doc["led-brightness"] = config.getUInt("led-brightness", 25);
config.end(); config.end();
@ -152,6 +153,8 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
config.putUInt("universe-1", doc["universe-1"]); config.putUInt("universe-1", doc["universe-1"]);
config.putUInt("universe-2", doc["universe-2"]); config.putUInt("universe-2", doc["universe-2"]);
config.putUInt("led-brightness", doc["led-brightness"]);
config.end(); config.end();
request->send(200); request->send(200);