Skip to content

Commit ef9e16c

Browse files
committed
Bugfixes in palette enumeration, fixed AR palette adding
enumeration was wrong, last normal palette was not loaded into UI gradient. updated the enumeration to hopefully be more readable/clear. AR palettes are now also added if there are more than 10 custom palettes
1 parent 1644e8a commit ef9e16c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

usermods/audioreactive/audio_reactive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ void AudioReactive::createAudioPalettes(void) {
19811981
if (palettes) return;
19821982
DEBUG_PRINTLN(F("Adding audio palettes."));
19831983
for (int i=0; i<MAX_PALETTES; i++)
1984-
if (customPalettes.size() < 10) {
1984+
if (customPalettes.size() < WLED_MAX_CUSTOM_PALETTES) {
19851985
customPalettes.push_back(CRGBPalette16(CRGB(BLACK)));
19861986
palettes++;
19871987
DEBUG_PRINTLN(palettes);

wled00/FX_fcn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
223223
// then come the custom palettes (255,254,...) growing downwards from 255 (255 being 1st custom palette)
224224
// palette 0 is a varying palette depending on effect and may be replaced by segment's color if so
225225
// instructed in color_from_palette()
226-
if (pal > FIXED_PALETTE_COUNT && pal < 255-customPalettes.size()+1) pal = 0; // out of bounds palette
226+
if (pal > FIXED_PALETTE_COUNT && pal <= 255-customPalettes.size()) pal = 0; // out of bounds palette
227227
//default palette. Differs depending on effect
228228
if (pal == 0) pal = _default_palette; // _default_palette is set in setMode()
229229
switch (pal) {

wled00/json.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void serializePalettes(JsonObject root, int page)
933933
#endif
934934

935935
int customPalettesCount = customPalettes.size();
936-
int palettesCount = getPaletteCount() - customPalettesCount;
936+
int palettesCount = getPaletteCount() - customPalettesCount; // palettesCount is number of palettes, not palette index
937937

938938
int maxPage = (palettesCount + customPalettesCount -1) / itemPerPage;
939939
if (page > maxPage) page = maxPage;
@@ -945,8 +945,8 @@ void serializePalettes(JsonObject root, int page)
945945
root[F("m")] = maxPage; // inform caller how many pages there are
946946
JsonObject palettes = root.createNestedObject("p");
947947

948-
for (int i = start; i < end; i++) {
949-
JsonArray curPalette = palettes.createNestedArray(String(i>=palettesCount ? 255 - i + palettesCount : i));
948+
for (int i = start; i <= end; i++) {
949+
JsonArray curPalette = palettes.createNestedArray(String(i<=palettesCount ? i : 255 - (i - (palettesCount + 1))));
950950
switch (i) {
951951
case 0: //default palette
952952
setPaletteColors(curPalette, PartyColors_p);
@@ -975,8 +975,8 @@ void serializePalettes(JsonObject root, int page)
975975
curPalette.add("c1");
976976
break;
977977
default:
978-
if (i >= palettesCount)
979-
setPaletteColors(curPalette, customPalettes[i - palettesCount]);
978+
if (i > palettesCount)
979+
setPaletteColors(curPalette, customPalettes[i - (palettesCount + 1)]);
980980
else if (i < 13) // palette 6 - 12, fastled palettes
981981
setPaletteColors(curPalette, *fastledPalettes[i-6]);
982982
else {

0 commit comments

Comments
 (0)