Skip to content

Commit 2c4ed42

Browse files
authored
New custom palettes editor (#5010)
* full refactoring, added live preview, better minifying in cdata.js * update main UI buttons, support for gaps in cpal files, cpal UI cleanup * fixed some layout issues, added un-ordered cpal deletion * changed to tab indentation, paste button border color now holds stored color * fix preview to work properly and some other fixes in UI * always unfreeze * new approach to loading iro.js, add harmonic random palette, many fixes. * decoupling iro.j, update UI of cpal.htm - load iro.js sequentially - no parallel requests in cpal.htm - update UI buttons - fix showing sequential loading of palettes (using opacity) - better UX for mobile (larger markers, larger editor) - various fixes * small change to buttons * load iro.js dynamically, remove iro.js from index.htm, revert changes to cdata.js * improved visibility for very dark/black palettes and markers
1 parent f19d29c commit 2c4ed42

10 files changed

Lines changed: 964 additions & 676 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ wled-update.sh
2525
/wled00/Release
2626
/wled00/wled00.ino.cpp
2727
/wled00/html_*.h
28+
/wled00/js_*.h

tools/cdata.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const packageJson = require("../package.json");
2626
// Export functions for testing
2727
module.exports = { isFileNewerThan, isAnyFileInFolderNewerThan };
2828

29-
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_edit.h", "wled00/html_pxmagic.h", "wled00/html_pixelforge.h", "wled00/html_settings.h", "wled00/html_other.h"]
29+
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_edit.h", "wled00/html_pxmagic.h", "wled00/html_pixelforge.h", "wled00/html_settings.h", "wled00/html_other.h", "wled00/js_iro.h"]
3030

3131
// \x1b[34m is blue, \x1b[36m is cyan, \x1b[0m is reset
3232
const wledBanner = `
@@ -257,6 +257,19 @@ writeHtmlGzipped("wled00/data/pxmagic/pxmagic.htm", "wled00/html_pxmagic.h", 'px
257257
writeHtmlGzipped("wled00/data/pixelforge/pixelforge.htm", "wled00/html_pixelforge.h", 'pixelforge', false); // do not inline css
258258
//writeHtmlGzipped("wled00/data/edit.htm", "wled00/html_edit.h", 'edit');
259259

260+
writeChunks(
261+
"wled00/data/",
262+
[
263+
{
264+
file: "iro.js",
265+
name: "JS_iro",
266+
method: "gzip",
267+
filter: "plain", // no minification, it is already minified
268+
mangle: (s) => s.replace(/^\/\*![\s\S]*?\*\//, '') // remove license comment at the top
269+
}
270+
],
271+
"wled00/js_iro.h"
272+
);
260273

261274
writeChunks(
262275
"wled00/data",

usermods/audioreactive/audio_reactive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,14 +1742,14 @@ class AudioReactive : public Usermod {
17421742
}
17431743
#endif
17441744
}
1745-
if (root.containsKey(F("rmcpal")) && root[F("rmcpal")].as<bool>()) {
1745+
if (palettes > 0 && root.containsKey(F("rmcpal"))) {
17461746
// handle removal of custom palettes from JSON call so we don't break things
17471747
removeAudioPalettes();
17481748
}
17491749
}
17501750

17511751
void onStateChange(uint8_t callMode) override {
1752-
if (initDone && enabled && addPalettes && palettes==0 && customPalettes.size()<10) {
1752+
if (initDone && enabled && addPalettes && palettes==0 && customPalettes.size()<WLED_MAX_CUSTOM_PALETTES) {
17531753
// if palettes were removed during JSON call re-add them
17541754
createAudioPalettes();
17551755
}

wled00/colors.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,13 @@ void loadCustomPalettes() {
249249
byte tcp[72]; //support gradient palettes with up to 18 entries
250250
CRGBPalette16 targetPalette;
251251
customPalettes.clear(); // start fresh
252+
StaticJsonDocument<1536> pDoc; // barely enough to fit 72 numbers -> TODO: current format uses 214 bytes max per palette, why is this buffer so large?
253+
unsigned emptyPaletteGap = 0; // count gaps in palette files to stop looking for more (each exists() call takes ~5ms)
252254
for (int index = 0; index < WLED_MAX_CUSTOM_PALETTES; index++) {
253255
char fileName[32];
254256
sprintf_P(fileName, PSTR("/palette%d.json"), index);
255-
256-
StaticJsonDocument<1536> pDoc; // barely enough to fit 72 numbers
257257
if (WLED_FS.exists(fileName)) {
258+
emptyPaletteGap = 0; // reset gap counter if file exists
258259
DEBUGFX_PRINTF_P(PSTR("Reading palette from %s\n"), fileName);
259260
if (readObjectFromFile(fileName, nullptr, &pDoc)) {
260261
JsonArray pal = pDoc[F("palette")];
@@ -288,7 +289,8 @@ void loadCustomPalettes() {
288289
}
289290
}
290291
} else {
291-
break;
292+
emptyPaletteGap++;
293+
if (emptyPaletteGap > WLED_MAX_CUSTOM_PALETTE_GAP) break; // stop looking for more palettes
292294
}
293295
}
294296
}

wled00/const.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ constexpr size_t FIXED_PALETTE_COUNT = DYNAMIC_PALETTE_COUNT + FASTLED_PALETTE_C
1515
#else
1616
#define WLED_MAX_CUSTOM_PALETTES 10 // ESP8266: limit custom palettes to 10
1717
#endif
18+
#define WLED_MAX_CUSTOM_PALETTE_GAP 20 // max number of empty palette files in a row before stopping to look for more (20 takes 100ms)
1819

1920
// You can define custom product info from build flags.
2021
// This is useful to allow API consumer to identify what type of WLED version

0 commit comments

Comments
 (0)