From 88996840926ce7b01ff9859289c5de3cbe8d8490 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Fri, 25 Nov 2022 17:33:29 +0100 Subject: [PATCH] Select custom palette bugfix. --- .../usermod_v2_rotary_encoder_ui_ALT.h | 2 +- wled00/FX.h | 2 +- wled00/FX_fcn.cpp | 19 +- wled00/data/index.js | 4 +- wled00/html_ui.h | 1873 ++++++++--------- wled00/ir.cpp | 2 +- wled00/json.cpp | 4 +- wled00/udp.cpp | 4 +- wled00/wled.h | 2 +- 9 files changed, 953 insertions(+), 959 deletions(-) diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h index ecc994e6..b5aed94d 100644 --- a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h +++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h @@ -191,7 +191,7 @@ private: re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT); palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount()); - palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount()); + palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount()); // only use internal palettes // How many palette names start with '*' and should not be sorted? // (Also skipping the first one, 'Default'). diff --git a/wled00/FX.h b/wled00/FX.h index 3c2d7e10..2241bf74 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -767,7 +767,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; } inline uint8_t getMainSegmentId(void) { return _mainSegment; } - inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; } + inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; } // will only return built-in palette count inline uint8_t getTargetFps() { return _targetFps; } inline uint8_t getModeCount() { return _modeCount; } diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 3b6552a5..d33e6349 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -418,12 +418,7 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) { sOpt = extractModeDefaults(fx, "mi"); if (sOpt >= 0) mirror = (bool)sOpt; // NOTE: setting this option is a risky business sOpt = extractModeDefaults(fx, "rY"); if (sOpt >= 0) reverse_y = (bool)sOpt; sOpt = extractModeDefaults(fx, "mY"); if (sOpt >= 0) mirror_y = (bool)sOpt; // NOTE: setting this option is a risky business - sOpt = extractModeDefaults(fx, "pal"); - if (sOpt >= 0 && (size_t)sOpt < strip.getPaletteCount() + strip.customPalettes.size()) { - if (sOpt != palette) { - palette = sOpt; - } - } + sOpt = extractModeDefaults(fx, "pal"); if (sOpt >= 0) setPalette(sOpt); } stateChanged = true; // send UDP/WS broadcast } @@ -431,13 +426,13 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) { } void Segment::setPalette(uint8_t pal) { - if (pal < strip.getPaletteCount()) { - if (pal != palette) { - if (strip.paletteFade) startTransition(strip.getTransition()); - palette = pal; - } + if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; // built in palettes + if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0; // custom palettes + if (pal != palette) { + if (strip.paletteFade) startTransition(strip.getTransition()); + palette = pal; + stateChanged = true; // send UDP/WS broadcast } - stateChanged = true; // send UDP/WS broadcast } // 2D matrix diff --git a/wled00/data/index.js b/wled00/data/index.js index 4cbc4924..6e2a3877 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -1535,8 +1535,8 @@ function requestJson(command=null) if (json.info) { let i = json.info; // append custom palettes (when loading for the 1st time) - if (!command && isEmpty(lastinfo) && i.leds && i.leds.cpal) { - for (let j = 0; j 2) seg.intensity = udpIn[16]; - if (version > 4 && udpIn[19] < strip.getPaletteCount()) seg.palette = udpIn[19]; + if (version > 4) seg.setPalette(udpIn[19]); } stateChanged = true; } diff --git a/wled00/wled.h b/wled00/wled.h index 249c50e8..6781cedb 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2211220 +#define VERSION 2211250 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG