-
-
Notifications
You must be signed in to change notification settings - Fork 138
Add generic usermod palette support, move AR palettes to usermod #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mdev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,20 @@ struct CRGBW { | |
|
|
||
| #endif | ||
|
|
||
| // WLEDMM: Palette registered by a usermod at fixed IDs (255, 254, 253... 201), growing downward from WLED_USERMOD_PALETTE_ID_BASE. | ||
| // Display name is "name: palName" (if palName non-null) or falls back to "name index" (e.g. "AudioReactive 1"), see util.cpp | ||
| // (matches upstream WLED's wled00/colors.h UsermodPalette, PR #5548) | ||
| struct UsermodPalette { | ||
| CRGBPalette16 palette; | ||
| const char *name; // PROGMEM base name string (must not be nullptr), used as identity key by removeUsermodPalettes() | ||
| uint8_t palIndex; // index of the palette for a usermod | ||
| const char *palName; // optional PROGMEM display name; "name: palName" if set, else "name index" | ||
| }; | ||
|
|
||
| // Remove all entries from usermodPalettes whose name pointer matches 'name'. Returns number of entries removed. | ||
| size_t removeUsermodPalettes(const char *name); | ||
| extern std::vector<UsermodPalette> usermodPalettes; // usermod-registered palettes (IDs 255, 254, 253...), see wled.h | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
ast-grep outline wled00 --items all --type function
rg -n -C 4 -P 'usermodPalettes\s*\.\s*(push_back|emplace_back|insert)|\busermodPalettes\s*=' .
rg -n -C 4 -P '\bgetPaletteCount\s*\(' wled00Repository: MoonModules/WLED-MM Length of output: 37542 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- colors.h ---'
cat -n wled00/colors.h | sed -n '70,105p'
printf '%s\n' '--- UsermodPalette and registry references ---'
rg -n -C 5 'UsermodPalette|usermodPalettes|getPaletteCount|USERMOD.*PALET|PALET.*USERMOD' wled00 --glob '!data/**'
printf '%s\n' '--- registration and palette consumers ---'
cat -n wled00/um_manager.cpp | sed -n '1,240p'
cat -n wled00/colors.cpp | sed -n '1,180p'
cat -n wled00/json.cpp | sed -n '330,470p'
cat -n wled00/wled.h | sed -n '1,180p'Repository: MoonModules/WLED-MM Length of output: 47499 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- all registry references and constructors ---'
rg -n -C 6 'usermodPalettes|UsermodPalette|WLED_MAX_USERMOD_PALETTES' . --glob '!wled00/data/**'
printf '%s\n' '--- candidate registration calls and direct vector writes ---'
rg -n -C 5 '\.(push_back|emplace_back|insert)\s*\(' . --glob '*.{cpp,h,hpp}' | rg -C 4 'palette|Palette|usermod|Usermod' || true
rg -n -C 4 'UsermodPalette\s*[\{\(]|std::vector<UsermodPalette>|vector<UsermodPalette>' . --glob '*.{cpp,h,hpp}' || true
printf '%s\n' '--- exact ID assignment and lookup branches ---'
cat -n wled00/const.h | sed -n '10,27p'
cat -n wled00/FX_fcn.cpp | sed -n '350,380p'
cat -n wled00/FX_fcn.cpp | sed -n '458,478p'
cat -n wled00/json.cpp | sed -n '1378,1392p'
cat -n wled00/json.cpp | sed -n '1460,1472p'
cat -n wled00/util.cpp | sed -n '292,310p'Repository: MoonModules/WLED-MM Length of output: 28678 Bound usermod palette registration to 55 entries.
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| struct CHSV32 { // 32bit HSV color with 16bit hue for more accurate conversions - credits @dedehai | ||
| union { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,26 @@ | |
| * Readability defines and their associated numerical values + compile-time constants | ||
| */ | ||
|
|
||
| #define GRADIENT_PALETTE_COUNT 62 //WLEDMM netmindz ar palette +3, ewowi Random Smooth palette +1 | ||
| constexpr size_t FASTLED_PALETTE_COUNT = 7; // 6-12 = sizeof(fastledPalettes) / sizeof(fastledPalettes[0]); | ||
| constexpr size_t GRADIENT_PALETTE_COUNT = 58; // 13-70 = sizeof(gGradientPalettes) / sizeof(gGradientPalettes[0]); | ||
| constexpr size_t DYNAMIC_PALETTE_COUNT = 6; // 0- 5 = dynamic palettes (0=default(virtual),1=random,2=primary,3=primary+secondary,4=primary+secondary+tertiary,5=primary+secondary(+tertiary if not black) | ||
| constexpr size_t WLEDMM_EXTRA_PALETTE_COUNT = 1; // 71 = "* Random Cycle" WLEDMM extra (in addition to upstream's "Random Smooth" at id 1) | ||
| constexpr size_t FIXED_PALETTE_COUNT = DYNAMIC_PALETTE_COUNT + FASTLED_PALETTE_COUNT + GRADIENT_PALETTE_COUNT + WLEDMM_EXTRA_PALETTE_COUNT; // total number of fixed palettes (=72) | ||
|
|
||
| // Palette ID space layout (palette IDs are uint8_t, 0-255): | ||
| // 0 .. FIXED_PALETTE_COUNT-1 : fixed built-in palettes (WLEDMM: includes "* Random Cycle" at 71) | ||
| // 72 .. WLED_CUSTOM_PALETTE_ID_BASE(200) : user custom palettes (index 0 = ID 200, growing downward) | ||
| // 201.. WLED_USERMOD_PALETTE_ID_BASE(255): usermod-registered palettes (index 0 = ID 255, growing downward) | ||
| constexpr uint8_t WLED_USERMOD_PALETTE_ID_BASE = 255; // highest ID for usermod palettes | ||
| constexpr uint8_t WLED_CUSTOM_PALETTE_ID_BASE = 200; // highest ID for user custom palettes | ||
| constexpr size_t WLED_MAX_USERMOD_PALETTES = WLED_USERMOD_PALETTE_ID_BASE - WLED_CUSTOM_PALETTE_ID_BASE; // 55 slots (IDs 201-255) | ||
| #ifndef ESP8266 | ||
| #define WLED_MAX_CUSTOM_PALETTES (WLED_CUSTOM_PALETTE_ID_BASE - FIXED_PALETTE_COUNT + 1) // 129 slots (IDs 72-200) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Keep
🤖 Prompt for AI Agents |
||
| #else | ||
| #define WLED_MAX_CUSTOM_PALETTES 10 // ESP8266: limit custom palettes to 10 | ||
| #endif | ||
| #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) | ||
|
|
||
|
|
||
| //Defaults | ||
| #define DEFAULT_CLIENT_SSID "Your_Network" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -986,20 +986,38 @@ function populatePalettes() | |
| ); | ||
| } | ||
| gId('pallist').innerHTML=html; | ||
| // append custom palettes (when loading for the 1st time) | ||
| if (!isEmpty(lastinfo) && lastinfo.cpalcount) { | ||
| for (let j = 0; j<lastinfo.cpalcount; j++) { | ||
| // append usermod palettes (fixed ID space: 255 down to 201) | ||
| let li = lastinfo; | ||
| if (!isEmpty(li) && li.umpalcount && li.umpalnames) { | ||
| for (let j = 0; j < li.umpalcount; j++) { | ||
| let div = d.createElement("div"); | ||
| gId('pallist').appendChild(div); | ||
| div.outerHTML = generateListItemHtml( | ||
| 'palette', | ||
| 255-j, | ||
| '~ Custom '+j+' ~', | ||
| li.umpalnames[j], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- relevant definitions and callers ---'
rg -n -C 8 'generateListItemHtml|umpalnames|outerHTML' wled00/data/index.js
printf '%s\n' '--- source range around the reported line ---'
sed -n '960,1015p' wled00/data/index.jsRepository: MoonModules/WLED-MM Length of output: 4844 🏁 Script executed: #!/bin/bash
set -eu
rg -n -C 6 'lastinfo\s*=|lastinfo\.|requestJson|json|info' wled00/data/index.js wled00/data/simple.js | head -240Repository: MoonModules/WLED-MM Length of output: 12119 🏁 Script executed: #!/bin/bash
set -eu
rg -n -C 8 'lastinfo' wled00/dataRepository: MoonModules/WLED-MM Length of output: 34861 XSS Reachability: External Encode fetched usermod palette names before HTML insertion.
🧰 Tools🪛 ast-grep (0.45.3)[warning] 994-1000: Avoid assigning untrusted data to innerHTML/outerHTML or document.write (inner-outer-html) 🤖 Prompt for AI AgentsSources: Path instructions, Linters/SAST tools |
||
| 'setPalette', | ||
| `<div class="lstIprev" style="${genPalPrevCss(255-j)}"></div>` | ||
| ); | ||
| } | ||
| } | ||
| // append user custom palettes (fixed ID space: 200 down to FIXED_PALETTE_COUNT+1) | ||
| if (!isEmpty(li) && li.cpalcount) { | ||
| for (let j = 0; j < li.cpalcount; j++) { | ||
| const id = 200 - j; | ||
| const pd = palettesData[id]; | ||
| if (pd && pd.length === 16 && pd.every(e => e[1] === 128 && e[2] === 128 && e[3] === 128)) continue; // skip gray gap-placeholder entries | ||
| let div = d.createElement("div"); | ||
| gId('pallist').appendChild(div); | ||
| div.outerHTML = generateListItemHtml( | ||
| 'palette', | ||
| id, | ||
| '~ Custom '+j+' ~', | ||
| 'setPalette', | ||
| `<div class="lstIprev" style="${genPalPrevCss(id)}"></div>` | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function redrawPalPrev() | ||
|
|
@@ -3449,7 +3467,7 @@ function loadPalettesData(callback = null) | |
| if (lsPalData) { | ||
| try { | ||
| var d = JSON.parse(lsPalData); | ||
| if (d && d.vid == d.vid) { | ||
| if (d && d.vid == lastinfo.vid && d.pcount == lastinfo.palcount) { // WLEDMM: also invalidate cache if total palette count changed (fixes upstream bug where vid alone was compared to itself) | ||
| palettesData = d.p; | ||
| if (callback) callback(); | ||
| return; | ||
|
|
@@ -3461,8 +3479,10 @@ function loadPalettesData(callback = null) | |
| getPalettesData(0, ()=>{ | ||
| localStorage.setItem(lsKey, JSON.stringify({ | ||
| p: palettesData, | ||
| vid: lastinfo.vid | ||
| vid: lastinfo.vid, | ||
| pcount: lastinfo.palcount // WLEDMM: total palette count, used to invalidate stale cache | ||
| })); | ||
|
|
||
| redrawPalPrev(); | ||
| if (callback) setTimeout(callback, 99); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a source URL for the upstream attribution.
The comments reference upstream WLED PR
#5548but do not include a GitHub or documentation link.wled00/colors.h#L79-L81: add the specific upstream source URL.wled00/colors.cpp#L508-L509: add the same specific upstream source URL.As per coding guidelines, “Document attribution of inspiration, knowledge, and sources used in code with links to GitHub repositories or documentation.”
📍 Affects 2 files
wled00/colors.h#L79-L81(this comment)wled00/colors.cpp#L508-L509🤖 Prompt for AI Agents
Source: Coding guidelines