Skip to content
Draft
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
4 changes: 4 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
getStringFromJson(alexaInvocationName, id[F("inv")], 33);
#endif
CJSON(simplifiedUI, id[F("sui")]);
CJSON(powerButtonOnPreset, id[F("pon")]);
CJSON(powerButtonOffPreset, id[F("pof")]);

JsonObject nw = doc["nw"];
#ifndef WLED_DISABLE_ESPNOW
Expand Down Expand Up @@ -853,6 +855,8 @@ void serializeConfig(JsonObject root) {
id[F("inv")] = alexaInvocationName;
#endif
id[F("sui")] = simplifiedUI;
id[F("pon")] = powerButtonOnPreset;
id[F("pof")] = powerButtonOffPreset;

JsonObject nw = root.createNestedObject("nw");
#ifndef WLED_DISABLE_ESPNOW
Expand Down
7 changes: 7 additions & 0 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ function parseInfo(i) {
d.title = name;
simplifiedUI = i.simplifiedui;
ledCount = i.leds.count;
if (typeof i.pon === "number") cfg.comp.on = i.pon;
if (typeof i.pof === "number") cfg.comp.off = i.pof;
try {
localStorage.setItem('wledUiCfg', JSON.stringify(cfg));
} catch (e) {
// ignore localStorage failures
}
//syncTglRecv = i.str;
maxSeg = i.leds.maxseg;
pmt = i.fs.pmt;
Expand Down
35 changes: 27 additions & 8 deletions wled00/data/settings_ui.htm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>UI Settings</title>
<style> html { visibility: hidden; } </style> <!-- prevent white & ugly display while loading, unhidden in loadResources() -->
<script>
var initial_ds, initial_st, initial_su, oldUrl;
var oldUrl;
var sett = null;
// load common.js with retry on error
(function loadFiles() {
Expand Down Expand Up @@ -131,7 +131,22 @@
gId('lserr').style.display = "inline";
gId('lserr').innerHTML = "&#9888; Settings JSON parsing failed. (" + e + ")";
}
if (!sett.comp) sett.comp = {};
if (d.Sf.ON && d.Sf.ON.value !== "") {
var serverOn = parseInt(d.Sf.ON.value, 10);
if (!Number.isNaN(serverOn) && sett.comp.on !== serverOn) sett.comp.on = serverOn;
}
if (d.Sf.OF && d.Sf.OF.value !== "") {
var serverOff = parseInt(d.Sf.OF.value, 10);
if (!Number.isNaN(serverOff) && sett.comp.off !== serverOff) sett.comp.off = serverOff;
}
genForm(sett);
// sync local storage silently with server values for ON/OFF overrides
try {
localStorage.setItem('wledUiCfg', JSON.stringify(sett));
} catch (e) {
// ignore write errors; localStorage may be unavailable
}
gId('dm').checked = (gId('theme_base').value === 'light');
}

Expand All @@ -144,6 +159,14 @@
set(e.id, sett, val);
console.log(`${e.id} set to ${val}`);
}
if (d.Sf.ON && d.Sf.ON.value !== "") {
if (!sett.comp) sett.comp = {};
sett.comp.on = parseInt(d.Sf.ON.value, 10) || 0;
}
if (d.Sf.OF && d.Sf.OF.value !== "") {
if (!sett.comp) sett.comp = {};
sett.comp.off = parseInt(d.Sf.OF.value, 10) || 0;
}
try {
localStorage.setItem('wledUiCfg', JSON.stringify(sett));
gId('lssuc').style.display = "inline";
Expand All @@ -164,15 +187,11 @@

function Save() {
SetLS();
if (d.Sf.DS.value != initial_ds || /*d.Sf.ST.checked != initial_st ||*/ d.Sf.SU.checked != initial_su) d.Sf.submit();
d.Sf.submit(); // always submit: ON/OF are server-backed fields that always need saving
}

function S() {
getLoc();
loadJS(getURL('/settings/s.js?p=3'), false, undefined, ()=>{
initial_ds = d.Sf.DS.value;
//initial_st = d.Sf.ST.checked;
initial_su = d.Sf.SU.checked;
GetLS();
}); // If we set async false, file is loaded and executed, then next statement is processed
if (loc) d.Sf.action = getURL('/settings/ui');
Expand Down Expand Up @@ -247,8 +266,8 @@ <h3>UI Appearance</h3>
<span class="l"></span>: <input type="checkbox" id="comp_segpwr" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_segexp" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_fxdef" class="agi cb"><br>
<span class="l"></span>: <input type="number" min=0 max=250 step=1 id="comp_on" class="agi"><br>
<span class="l"></span>: <input type="number" min=0 max=250 step=1 id="comp_off" class="agi"><br>
<span class="l"></span>: <input type="number" min=0 max=250 step=1 id="comp_on" name="ON" class="agi"><br>
<span class="l"></span>: <input type="number" min=0 max=250 step=1 id="comp_off" name="OF" class="agi"><br>
I hate dark mode: <input type="checkbox" id="dm" onchange="UI()"><br>
<span id="idonthateyou" style="display:none"><i>Why would you? </i>&#x1F97A;<br></span>
<span class="l"></span>: <input type="number" min=0.0 max=1.0 step=0.01 id="theme_alpha_tab" class="agi"><br>
Expand Down
2 changes: 2 additions & 0 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ void serializeInfo(JsonObject root)
root[F("name")] = serverDescription;
root[F("udpport")] = udpPort;
root[F("simplifiedui")] = simplifiedUI;
root[F("pon")] = powerButtonOnPreset;
root[F("pof")] = powerButtonOffPreset;
root["live"] = (bool)realtimeMode;
root[F("liveseg")] = useMainSegmentOnly ? strip.getMainSegmentId() : -1; // if using main segment only for live

Expand Down
2 changes: 2 additions & 0 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ WLED_GLOBAL char serverDescription[33] _INIT("WLED"); // Name of module - use d
WLED_GLOBAL char serverDescription[33] _INIT(SERVERNAME); // use predefined name
#endif
WLED_GLOBAL bool simplifiedUI _INIT(false); // enable simplified UI
WLED_GLOBAL byte powerButtonOnPreset _INIT(0); // override preset for power-on
WLED_GLOBAL byte powerButtonOffPreset _INIT(0); // override preset for power-off
WLED_GLOBAL byte cacheInvalidate _INIT(0); // used to invalidate browser cache

// Sync CONFIG
Expand Down
2 changes: 2 additions & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ void getSettingsJS(byte subPage, Print& settingsScript)
{
printSetFormValue(settingsScript,PSTR("DS"),serverDescription);
printSetFormCheckbox(settingsScript,PSTR("SU"),simplifiedUI);
printSetFormValue(settingsScript,PSTR("ON"),powerButtonOnPreset);
printSetFormValue(settingsScript,PSTR("OF"),powerButtonOffPreset);
}

if (subPage == SUBPAGE_SYNC)
Expand Down
Loading