Skip to content

Commit 10dace6

Browse files
authored
Merge pull request #1 from Aircoookie/main
Pull upstream changes
2 parents 3653666 + f6e843b commit 10dace6

File tree

8 files changed

+467
-464
lines changed

8 files changed

+467
-464
lines changed

wled00/data/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ function setSeg(s)
20202020
var startY = parseInt(sY.value);
20212021
var stopY = parseInt(eY.value);
20222022
if (startY<sY.min || startY>sY.max) {sY.value=sY.min; return;} // prevent out of bounds
2023-
if (stopY<eY.min || stop>eY.max) {eY.value=eY.max; return;} // prevent out of bounds
2023+
if (stopY<eY.min || stopY>eY.max) {eY.value=eY.max; return;} // prevent out of bounds
20242024
obj.seg.startY = startY;
20252025
obj.seg.stopY = (cfg.comp.seglen?startY:0)+stopY;
20262026
}
@@ -2194,12 +2194,12 @@ function setPreset(i)
21942194
{
21952195
var obj = {"ps":i};
21962196
if (pJson && pJson[i] && (!pJson[i].win || pJson[i].win.indexOf("Please") <= 0)) {
2197-
// we will send complete preset content as to avoid delay introduced by
2198-
// async nature of applyPreset(). json.cpp has to decide wether to call applyPreset()
2199-
// or not (by looking at the JSON content, if "ps" only)
2197+
// we will send the complete preset content as to avoid delay introduced by
2198+
// async nature of applyPreset() and having to read the preset from file system.
2199+
obj = {"pd":i}; // use "pd" instead of "ps" to indicate that we are sending the preset content directly
22002200
Object.assign(obj, pJson[i]);
2201-
delete obj.ql; // no need for quick load
2202-
delete obj.n; // no need for name
2201+
delete obj.ql; // no need for quick load
2202+
delete obj.n; // no need for name
22032203
}
22042204
if (isPlaylist(i)) obj.on = true; // force on
22052205
showToast("Loading preset " + pName(i) +" (" + i + ")");

wled00/data/settings_ui.htm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
}
4444
};
4545
function gId(s) { return d.getElementById(s); }
46+
function toggle(el) { gId(el).classList.toggle("hide"); gId('No'+el).classList.toggle("hide"); }
4647
function isObject(item) {
4748
return (item && typeof item === 'object' && !Array.isArray(item));
4849
}
@@ -247,7 +248,10 @@
247248
<h2>Web Setup</h2>
248249
Server description: <input type="text" name="DS" maxlength="32"><br>
249250
Sync button toggles both send and receive: <input type="checkbox" name="ST"><br>
250-
Enable simplified UI: <input type="checkbox" name="SU"><br>
251+
<div id="NoSimple" class="hide">
252+
<em style="color:#fa0;">This firmware build does not include simplified UI support.<br></em>
253+
</div>
254+
<div id="Simple">Enable simplified UI: <input type="checkbox" name="SU"><br></div>
251255
<i>The following UI customization settings are unique both to the WLED device and this browser.<br>
252256
You will need to set them again if using a different browser, device or WLED IP address.<br>
253257
Refresh the main UI to apply changes.</i><br>

wled00/html_settings.h

Lines changed: 200 additions & 195 deletions
Large diffs are not rendered by default.

wled00/html_ui.h

Lines changed: 213 additions & 213 deletions
Large diffs are not rendered by default.

wled00/json.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,22 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
394394
handleSet(nullptr, apireq, false); // may set stateChanged
395395
}
396396

397-
// applying preset (2 cases: a) API call includes all preset values, b) API only specifies preset ID)
398-
if (!root["ps"].isNull()) {
397+
// applying preset (2 cases: a) API call includes all preset values ("pd"), b) API only specifies preset ID ("ps"))
398+
byte presetToRestore = 0;
399+
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
400+
if (!root["pd"].isNull() && stateChanged) {
401+
currentPreset = root[F("pd")] | currentPreset;
402+
if (root["win"].isNull()) presetCycCurr = currentPreset;
403+
presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after
404+
//unloadPlaylist(); // applying a preset unloads the playlist, may be needed here too?
405+
} else if (!root["ps"].isNull()) {
399406
ps = presetCycCurr;
400-
if (stateChanged) {
401-
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
402-
currentPreset = root["ps"] | currentPreset;
403-
// if preset contains HTTP API call do not change presetCycCurr
404-
if (root["win"].isNull()) presetCycCurr = currentPreset;
405-
stateChanged = false; // cancel state change update (preset was set directly by applying values stored in UI JSON array)
406-
notify(callMode);
407-
} else if (root["win"].isNull() && getVal(root["ps"], &ps, 0, 0) && ps > 0 && ps < 251 && ps != currentPreset) {
407+
if (root["win"].isNull() && getVal(root["ps"], &ps, 0, 0) && ps > 0 && ps < 251 && ps != currentPreset) {
408408
// b) preset ID only or preset that does not change state (use embedded cycling limits if they exist in getVal())
409409
presetCycCurr = ps;
410-
presetId = ps;
411-
root.remove("v"); // may be added in UI call
412-
root.remove("time"); // may be added in UI call
413-
root.remove("ps");
414-
root.remove("on"); // some external calls add "on" to "ps" call
415-
if (root.size() == 0) {
416-
unloadPlaylist(); // we need to unload playlist
417-
applyPreset(ps, callMode); // async load (only preset ID was specified)
418-
return stateResponse;
419-
}
410+
unloadPlaylist(); // applying a preset unloads the playlist
411+
applyPreset(ps, callMode); // async load from file system (only preset ID was specified)
412+
return stateResponse;
420413
}
421414
}
422415

@@ -428,6 +421,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
428421
}
429422

430423
stateUpdated(callMode);
424+
if (presetToRestore) currentPreset = presetToRestore;
431425

432426
return stateResponse;
433427
}

wled00/presets.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ static char quickLoad[9];
1616
static char saveName[33];
1717
static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false;;
1818

19-
static const char *getName(bool persist = true) {
19+
static const char *getFileName(bool persist = true) {
2020
return persist ? "/presets.json" : "/tmp.json";
2121
}
2222

2323
static void doSaveState() {
2424
bool persist = (presetToSave < 251);
25-
const char *filename = getName(persist);
25+
const char *filename = getFileName(persist);
2626

27-
if (!requestJSONBufferLock(10)) return; // will set fileDoc
27+
if (!requestJSONBufferLock(10)) return; // will set fileDoc
2828

2929
initPresetsFile(); // just in case if someone deleted presets.json using /edit
3030
JsonObject sObj = doc.to<JsonObject>();
@@ -83,7 +83,7 @@ bool getPresetName(byte index, String& name)
8383
{
8484
if (!requestJSONBufferLock(9)) return false;
8585
bool presetExists = false;
86-
if (readObjectFromFileUsingId(getName(), index, &doc))
86+
if (readObjectFromFileUsingId(getFileName(), index, &doc))
8787
{
8888
JsonObject fdo = doc.as<JsonObject>();
8989
if (fdo["n"]) {
@@ -97,12 +97,12 @@ bool getPresetName(byte index, String& name)
9797

9898
void initPresetsFile()
9999
{
100-
if (WLED_FS.exists(getName())) return;
100+
if (WLED_FS.exists(getFileName())) return;
101101

102102
StaticJsonDocument<64> doc;
103103
JsonObject sObj = doc.to<JsonObject>();
104104
sObj.createNestedObject("0");
105-
File f = WLED_FS.open(getName(), "w");
105+
File f = WLED_FS.open(getFileName(), "w");
106106
if (!f) {
107107
errorFlag = ERR_FS_GENERAL;
108108
return;
@@ -127,14 +127,14 @@ void handlePresets()
127127
return;
128128
}
129129

130+
if (presetToApply == 0 || fileDoc) return; // no preset waiting to apply, or JSON buffer is already allocated, return to loop until free
131+
130132
bool changePreset = false;
131133
uint8_t tmpPreset = presetToApply; // store temporary since deserializeState() may call applyPreset()
132134
uint8_t tmpMode = callModeToApply;
133135

134-
if (tmpPreset == 0 || (fileDoc /*&& !force*/)) return; // JSON buffer already allocated and not force apply or no preset waiting
135-
136136
JsonObject fdo;
137-
const char *filename = getName(tmpPreset < 255);
137+
const char *filename = getFileName(tmpPreset < 255);
138138

139139
// allocate buffer
140140
if (!requestJSONBufferLock(9)) return; // will also assign fileDoc
@@ -201,30 +201,28 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
201201
presetToSave = index;
202202
playlistSave = false;
203203
if (sObj[F("ql")].is<const char*>()) strlcpy(quickLoad, sObj[F("ql")].as<const char*>(), 9); // client limits QL to 2 chars, buffer for 8 bytes to allow unicode
204-
sObj.remove("v");
205-
sObj.remove("time");
206-
sObj.remove(F("error"));
207-
sObj.remove(F("psave"));
208-
if (sObj["o"].isNull()) { // "o" marks a playlist or manually entered API
204+
205+
if (sObj["o"].isNull()) { // no "o" means not a playlist or custom API call, saving of state is async (not immediately)
209206
includeBri = sObj["ib"].as<bool>() || index==255; // temporary preset needs brightness
210207
segBounds = sObj["sb"].as<bool>() || index==255; // temporary preset needs bounds
211208
selectedOnly = sObj[F("sc")].as<bool>();
212209
saveLedmap = sObj[F("ledmap")] | -1;
213-
sObj.remove("ib");
214-
sObj.remove("sb");
215-
sObj.remove(F("sc"));
216210
} else {
217-
// this is a playlist or API
218-
sObj.remove("o");
211+
// this is a playlist or API call
219212
if (sObj[F("playlist")].isNull()) {
220-
presetToSave = 0; // we will save API immediately
221-
if (index < 251 && fileDoc) {
222-
if (sObj["n"].isNull()) sObj["n"] = saveName;
223-
initPresetsFile(); // just in case if someone deleted presets.json using /edit
224-
writeObjectToFileUsingId(getName(index), index, fileDoc);
225-
presetsModifiedTime = toki.second(); //unix time
226-
updateFSInfo();
227-
}
213+
// we will save API call immediately
214+
presetToSave = 0;
215+
if (index > 250 || !fileDoc) return; // cannot save API calls to temporary preset (255)
216+
sObj.remove("o");
217+
sObj.remove("v");
218+
sObj.remove("time");
219+
sObj.remove(F("error"));
220+
sObj.remove(F("psave"));
221+
if (sObj["n"].isNull()) sObj["n"] = saveName;
222+
initPresetsFile(); // just in case if someone deleted presets.json using /edit
223+
writeObjectToFileUsingId(getFileName(index), index, fileDoc);
224+
presetsModifiedTime = toki.second(); //unix time
225+
updateFSInfo();
228226
} else {
229227
// store playlist
230228
includeBri = true; // !sObj["on"].isNull();
@@ -235,7 +233,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
235233

236234
void deletePreset(byte index) {
237235
StaticJsonDocument<24> empty;
238-
writeObjectToFileUsingId(getName(), index, &empty);
236+
writeObjectToFileUsingId(getFileName(), index, &empty);
239237
presetsModifiedTime = toki.second(); //unix time
240238
updateFSInfo();
241239
}

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2212110
11+
#define VERSION 2212130
1212

1313
//uncomment this if you have a "my_config.h" file you'd like to use
1414
//#define WLED_USE_MY_CONFIG

wled00/xml.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ void getSettingsJS(byte subPage, char* dest)
471471
sappend('c',SET_F("ST"),syncToggleReceive);
472472
#ifdef WLED_ENABLE_SIMPLE_UI
473473
sappend('c',SET_F("SU"),simplifiedUI);
474+
#else
475+
oappend(SET_F("toggle('Simple');")); // hide Simplified UI settings
474476
#endif
475477
}
476478

0 commit comments

Comments
 (0)