Skip to content

Commit

Permalink
Palette cycling fix.
Browse files Browse the repository at this point in the history
Updated getPaletteCount() to return count of all available palettes, including custom ones.
  • Loading branch information
blazoncek committed Mar 20, 2024
1 parent dab4dc3 commit b031fa1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ class WS2812FX { // 96 bytes
inline uint8_t getSegmentsNum(void) { return _segments.size(); } // returns currently present segments
inline uint8_t getCurrSegmentId(void) { return _segment_index; } // returns current segment index (only valid while strip.isServicing())
inline uint8_t getMainSegmentId(void) { return _mainSegment; } // returns main segment index
inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; } // will only return built-in palette count
inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT + customPalettes.size(); }
inline uint8_t getTargetFps() { return _targetFps; } // returns rough FPS value for las 2s interval
inline uint8_t getModeCount() { return _modeCount; } // returns number of registered modes/effects

Expand Down
11 changes: 8 additions & 3 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,19 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
getVal(elem["ix"], &seg.intensity);

uint8_t pal = seg.palette;
last = strip.getPaletteCount();
if (!elem["pal"].isNull() && elem["pal"].is<const char*>()) {
const char *tmp = elem["pal"].as<const char *>();
if (strlen(tmp) > 3 && (strchr(tmp,'r') || strchr(tmp,'~') != strrchr(tmp,'~'))) last = 0; // we have "X~Y(r|[w]~[-])" form
}
if (seg.getLightCapabilities() & 1) { // ignore palette for White and On/Off segments
if (getVal(elem["pal"], &pal)) seg.setPalette(pal);
if (getVal(elem["pal"], &pal, 0, last)) seg.setPalette(pal);
}

getVal(elem["c1"], &seg.custom1);
getVal(elem["c2"], &seg.custom2);
uint8_t cust3 = seg.custom3;
getVal(elem["c3"], &cust3); // we can't pass reference to bitfield
getVal(elem["c3"], &cust3, 0, 31); // we can't pass reference to bitfield
seg.custom3 = constrain(cust3, 0, 31);

seg.check1 = getBoolVal(elem["o1"], seg.check1);
Expand Down Expand Up @@ -850,8 +855,8 @@ void serializePalettes(JsonObject root, int page)
int itemPerPage = 8;
#endif

int palettesCount = strip.getPaletteCount();
int customPalettes = strip.customPalettes.size();
int palettesCount = strip.getPaletteCount() - customPalettes;

int maxPage = (palettesCount + customPalettes -1) / itemPerPage;
if (page > maxPage) page = maxPage;
Expand Down

0 comments on commit b031fa1

Please sign in to comment.