Skip to content

Commit 36987a9

Browse files
committed
Squashed commit of the following:
commit bd20c83 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Mon Jan 1 23:14:45 2024 +0100 Bugfix wled#3632 commit 48f8a45 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Sun Dec 31 18:05:21 2023 +0100 Last minute adjustments & fixes commit 680cec5 Author: Istvan Meszaros <contact.imeszaros@gmail.com> Date: Tue Dec 26 11:09:20 2023 +0100 Make palette editor mobile friendly. commit ecdc3be Author: Blaz Kristan <blaz@kristan-sp.si> Date: Sat Dec 30 11:56:21 2023 +0100 Changlog update commit 301bdf2 Merge: 1c1b67e d3be7a3 Author: Blaž Kristan <blaz@kristan-sp.si> Date: Sat Dec 30 11:00:53 2023 +0100 Merge pull request wled#3610 from Aircoookie/psram-4-json Allow PSRAM (SPI RAM) to be used for JSON buffer commit 1c1b67e Author: Blaz Kristan <blaz@kristan-sp.si> Date: Fri Dec 29 23:07:29 2023 +0100 Full per-port ABL implementation and bugfix. Update of BusManager class (static) commit d3be7a3 Merge: 7971f3c 6cd0da8 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Thu Dec 28 23:38:27 2023 +0100 Merge branch '0_15' into psram-4-json commit 6cd0da8 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Thu Dec 28 23:32:47 2023 +0100 Reduce heap fragmentation when switching ledmaps commit 6332ee6 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Wed Dec 27 19:36:25 2023 +0100 Effect buffer optimisations setMode() fix for selecting gap UI error messages commit 7971f3c Author: Blaz Kristan <blaz@kristan-sp.si> Date: Sat Dec 23 22:56:07 2023 +0100 Fix for saving config. commit 08d9f7d Author: Blaz Kristan <blaz@kristan-sp.si> Date: Sat Dec 23 21:05:01 2023 +0100 Fix for wled#2922 commit 776502e Merge: 4e10549 7af5b24 Author: Blaž Kristan <blaz@kristan-sp.si> Date: Sat Dec 23 20:27:20 2023 +0100 Merge pull request wled#3606 from WoodyLetsCode/welcome Fix bug that welcome page was not shown commit 7af5b24 Author: Woody <xaver@holzapfel.net> Date: Thu Dec 21 22:17:43 2023 +0100 Fix bug that welcome page was not shown commit 1f81fb9 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Thu Dec 21 21:30:17 2023 +0100 Implement JSON buffer in PSRAM to free up DRAM. commit 4e10549 Author: Blaz Kristan <blaz@kristan-sp.si> Date: Thu Dec 21 21:02:53 2023 +0100 Retry on failed JSON load. Throttle for ESP8266 This is a band-aid for ESP8266 JSON corruption and not a proper fix. commit abf7dd5 Merge: 6c877b6 37b8072 Author: Blaž Kristan <blaz@kristan-sp.si> Date: Thu Dec 21 20:49:44 2023 +0100 Merge pull request wled#3587 from WoodyLetsCode/search-scroll-top Scroll to first search result on search commit 6c877b6 Merge: 42dba31 86d2998 Author: Blaž Kristan <blaz@kristan-sp.si> Date: Thu Dec 21 20:43:29 2023 +0100 Merge pull request wled#3597 from WoodyLetsCode/inline Inline iro.js and rangetouch.js commit 86d2998 Author: Xaver <xaver@holzapfel.net> Date: Wed Dec 20 11:30:28 2023 +0100 Add reference to old loading of iro.js and rangetouch.js commit 201daf8 Author: Woody <xaver@holzapfel.net> Date: Tue Dec 19 22:40:24 2023 +0100 Remove /iro.js and /rangetouch.js commit 1140f5f Author: Woody <xaver@holzapfel.net> Date: Tue Dec 19 21:18:33 2023 +0100 Update version to 2312190 commit 0a91d60 Author: Woody <xaver@holzapfel.net> Date: Tue Dec 19 21:12:07 2023 +0100 add onload event to body commit 5cd8f56 Author: Woody <xaver@holzapfel.net> Date: Tue Dec 19 20:41:56 2023 +0100 Remove unused feedback function This was probably forgotten to remove in commit d6c0642 commit b2babd9 Author: Xaver <xaver@holzapfel.net> Date: Tue Dec 19 16:52:15 2023 +0100 inline iro.js and rangetouch.js commit 37b8072 Author: Woody <xaver@holzapfel.net> Date: Wed Dec 13 18:22:09 2023 +0100 Scroll to first search result on search
1 parent 7e0e0d3 commit 36987a9

39 files changed

+4523
-4497
lines changed

CHANGELOG.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
## WLED changelog
22

3-
#### Build 2309120 till build 2311120
3+
#### Build 2309120 till build 2312290
44
- WLED version 0.15.0-a0
5+
- Per port Auto Brightness Limiter (ABL)
6+
- Use PSRAM for JSON buffer (double size, larger ledmaps, up to 2k)
7+
- Reduced heap fragmentation by allocating ledmap array only once and not deallocating effect buffer
8+
- HTTP retries on failed UI load
9+
- UI Search: scroll to top (#3587 by @WoodyLetsCode)
10+
- Return to inline iro.js and rangetouch.js (#3597 by @WoodyLetsCode)
11+
- Better caching (#3591 by @WoodyLetsCode)
12+
- Do not send 404 for missing `skin.css` (#3590 by @WoodyLetsCode)
13+
- Simplified UI rework (#3511 by @WoodyLetsCode)
14+
- Domoticz device ID for PIR and Temperature usermods
15+
- Bugfix for UCS8904 `hasWhite()`
16+
- Better search in UI (#3540 by @WoodyLetsCode)
17+
- Seeding FastLED PRNG (#3552 by @TripleWhy)
18+
- WIZ Smart Button support (#3547 by @micw)
19+
- New button type (button switch, fix for #3537)
20+
- Pixel Magic Tool update (#3483 by @ajotanc)
21+
- Effect: 2D Matrix fix for gaps
22+
- Bugfix #3526, #3533, #3561
523
- Spookier Halloween Eyes (#3501)
624
- Compile time options for Multi Relay usermod (#3498)
7-
- Fix for Dissolve (#3502)
25+
- Effect: Fix for Dissolve (#3502)
826
- Better reverse proxy support (nested paths)
927
- Implement global JSON API boolean toggle (i.e. instead of "var":true or "var":false -> "var":"t").
1028
- Sort presets by ID
11-
- Fix #3496
29+
- Fix for #3496, #2922, #3593, #3514, #3522, #3578 (partial), #3606 (@WoodyLetsCode)
1230
- Improved random bg image and added random bg image options (@WoodyLetsCode, #3481)
1331
- Audio palettes (Audioreactive usermod, credit @netmindz)
1432
- Better UI tooltips (@ajotnac, #3464)
1533
- Better effect filters (filter dropdown)
16-
- Fix udp sync (fix for #3487)
34+
- UDP sync fix (for #3487)
1735
- Power button override (solves #3431)
1836
- Additional HTTP request throttling (ESP8266)
1937
- Additional UI/UX improvements

tools/cdata.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,6 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
380380
file: "favicon.ico",
381381
name: "favicon",
382382
method: "binary",
383-
},
384-
{
385-
file: "iro.js",
386-
name: "iroJs",
387-
method: "gzip"
388-
},
389-
{
390-
file: "rangetouch.js",
391-
name: "rangetouchJs",
392-
method: "gzip"
393383
}
394384
],
395385
"wled00/html_other.h"

usermods/ST7789_display/ST7789_display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class St7789DisplayUsermod : public Usermod {
307307
// Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate).
308308
tft.print("Current: ");
309309
tft.setTextColor(TFT_ORANGE);
310-
tft.print(strip.currentMilliamps);
310+
tft.print(BusManager::currentMilliamps());
311311
tft.print("mA");
312312
}
313313

usermods/quinled-an-penta/quinled-an-penta.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class QuinLEDAnPentaUsermod : public Usermod
8484
void getCurrentUsedLedPins()
8585
{
8686
for (int8_t lp = 0; lp <= 4; lp++) currentLedPins[lp] = 0;
87-
byte numBusses = busses.getNumBusses();
87+
byte numBusses = BusManager::getNumBusses();
8888
byte numUsedPins = 0;
8989

9090
for (int8_t b = 0; b < numBusses; b++) {
91-
Bus* curBus = busses.getBus(b);
91+
Bus* curBus = BusManager::getBus(b);
9292
if (curBus != nullptr) {
9393
uint8_t pins[5] = {0, 0, 0, 0, 0};
9494
currentBussesNumPins[b] = curBus->getPins(pins);
@@ -104,11 +104,11 @@ class QuinLEDAnPentaUsermod : public Usermod
104104

105105
void getCurrentLedcValues()
106106
{
107-
byte numBusses = busses.getNumBusses();
107+
byte numBusses = BusManager::getNumBusses();
108108
byte numLedc = 0;
109109

110110
for (int8_t b = 0; b < numBusses; b++) {
111-
Bus* curBus = busses.getBus(b);
111+
Bus* curBus = BusManager::getBus(b);
112112
if (curBus != nullptr) {
113113
uint32_t curPixColor = curBus->getPixelColor(0);
114114
uint8_t _data[5] = {255, 255, 255, 255, 255};

wled00/FX.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,8 +3444,8 @@ static const char _data_FX_MODE_STARBURST[] PROGMEM = "Fireworks Starburst@Chanc
34443444
uint16_t mode_exploding_fireworks(void)
34453445
{
34463446
if (SEGLEN == 1) return mode_static();
3447-
const uint16_t cols = strip.isMatrix ? SEGMENT.virtualWidth() : 1;
3448-
const uint16_t rows = strip.isMatrix ? SEGMENT.virtualHeight() : SEGMENT.virtualLength();
3447+
const uint16_t cols = SEGMENT.is2D() ? SEGMENT.virtualWidth() : 1;
3448+
const uint16_t rows = SEGMENT.is2D() ? SEGMENT.virtualHeight() : SEGMENT.virtualLength();
34493449

34503450
//allocate segment data
34513451
uint16_t maxData = FAIR_DATA_PER_SEG; //ESP8266: 256 ESP32: 640
@@ -3476,24 +3476,26 @@ uint16_t mode_exploding_fireworks(void)
34763476
if (SEGENV.aux0 < 2) { //FLARE
34773477
if (SEGENV.aux0 == 0) { //init flare
34783478
flare->pos = 0;
3479-
flare->posX = strip.isMatrix ? random16(2,cols-3) : (SEGMENT.intensity > random8()); // will enable random firing side on 1D
3479+
flare->posX = SEGMENT.is2D() ? random16(2,cols-3) : (SEGMENT.intensity > random8()); // will enable random firing side on 1D
34803480
uint16_t peakHeight = 75 + random8(180); //0-255
34813481
peakHeight = (peakHeight * (rows -1)) >> 8;
34823482
flare->vel = sqrtf(-2.0f * gravity * peakHeight);
3483-
flare->velX = strip.isMatrix ? (random8(9)-4)/32.f : 0; // no X velocity on 1D
3483+
flare->velX = SEGMENT.is2D() ? (random8(9)-4)/64.0f : 0; // no X velocity on 1D
34843484
flare->col = 255; //brightness
34853485
SEGENV.aux0 = 1;
34863486
}
34873487

34883488
// launch
34893489
if (flare->vel > 12 * gravity) {
34903490
// flare
3491-
if (strip.isMatrix) SEGMENT.setPixelColorXY(int(flare->posX), rows - uint16_t(flare->pos) - 1, flare->col, flare->col, flare->col);
3492-
else SEGMENT.setPixelColor(int(flare->posX) ? rows - int(flare->pos) - 1 : int(flare->pos), flare->col, flare->col, flare->col);
3491+
if (SEGMENT.is2D()) SEGMENT.setPixelColorXY(int(flare->posX), rows - uint16_t(flare->pos) - 1, flare->col, flare->col, flare->col);
3492+
else SEGMENT.setPixelColor((flare->posX > 0.0f) ? rows - int(flare->pos) - 1 : int(flare->pos), flare->col, flare->col, flare->col);
34933493
flare->pos += flare->vel;
3494-
flare->posX += flare->velX;
34953494
flare->pos = constrain(flare->pos, 0, rows-1);
3496-
flare->posX = constrain(flare->posX, 0, cols-strip.isMatrix);
3495+
if (SEGMENT.is2D()) {
3496+
flare->posX += flare->velX;
3497+
flare->posX = constrain(flare->posX, 0, cols-1);
3498+
}
34973499
flare->vel += gravity;
34983500
flare->col -= 2;
34993501
} else {
@@ -3516,12 +3518,12 @@ uint16_t mode_exploding_fireworks(void)
35163518
sparks[i].posX = flare->posX;
35173519
sparks[i].vel = (float(random16(20001)) / 10000.0f) - 0.9f; // from -0.9 to 1.1
35183520
sparks[i].vel *= rows<32 ? 0.5f : 1; // reduce velocity for smaller strips
3519-
sparks[i].velX = strip.isMatrix ? (float(random16(10001)) / 10000.0f) - 0.5f : 0; // from -0.5 to 0.5
3521+
sparks[i].velX = SEGMENT.is2D() ? (float(random16(20001)) / 10000.0f) - 1.0f : 0; // from -1 to 1
35203522
sparks[i].col = 345;//abs(sparks[i].vel * 750.0); // set colors before scaling velocity to keep them bright
35213523
//sparks[i].col = constrain(sparks[i].col, 0, 345);
35223524
sparks[i].colIndex = random8();
35233525
sparks[i].vel *= flare->pos/rows; // proportional to height
3524-
sparks[i].velX *= strip.isMatrix ? flare->posX/cols : 0; // proportional to width
3526+
sparks[i].velX *= SEGMENT.is2D() ? flare->posX/cols : 0; // proportional to width
35253527
sparks[i].vel *= -gravity *50;
35263528
}
35273529
//sparks[1].col = 345; // this will be our known spark
@@ -3534,11 +3536,11 @@ uint16_t mode_exploding_fireworks(void)
35343536
sparks[i].pos += sparks[i].vel;
35353537
sparks[i].posX += sparks[i].velX;
35363538
sparks[i].vel += *dying_gravity;
3537-
sparks[i].velX += strip.isMatrix ? *dying_gravity : 0;
3539+
sparks[i].velX += SEGMENT.is2D() ? *dying_gravity : 0;
35383540
if (sparks[i].col > 3) sparks[i].col -= 4;
35393541

35403542
if (sparks[i].pos > 0 && sparks[i].pos < rows) {
3541-
if (strip.isMatrix && !(sparks[i].posX >= 0 && sparks[i].posX < cols)) continue;
3543+
if (SEGMENT.is2D() && !(sparks[i].posX >= 0 && sparks[i].posX < cols)) continue;
35423544
uint16_t prog = sparks[i].col;
35433545
uint32_t spColor = (SEGMENT.palette) ? SEGMENT.color_wheel(sparks[i].colIndex) : SEGCOLOR(0);
35443546
CRGB c = CRGB::Black; //HeatColor(sparks[i].col);
@@ -3550,7 +3552,7 @@ uint16_t mode_exploding_fireworks(void)
35503552
c.g = qsub8(c.g, cooling);
35513553
c.b = qsub8(c.b, cooling * 2);
35523554
}
3553-
if (strip.isMatrix) SEGMENT.setPixelColorXY(int(sparks[i].posX), rows - int(sparks[i].pos) - 1, c.red, c.green, c.blue);
3555+
if (SEGMENT.is2D()) SEGMENT.setPixelColorXY(int(sparks[i].posX), rows - int(sparks[i].pos) - 1, c.red, c.green, c.blue);
35543556
else SEGMENT.setPixelColor(int(sparks[i].posX) ? rows - int(sparks[i].pos) - 1 : int(sparks[i].pos), c.red, c.green, c.blue);
35553557
}
35563558
}
@@ -5292,7 +5294,6 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
52925294
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
52935295

52945296
if (SEGENV.call == 0) {
5295-
memset(SEGMENT.data, 0, dataSize); // no falling spawns
52965297
SEGMENT.fill(BLACK);
52975298
SEGENV.step = 0;
52985299
}

wled00/FX.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@
6262
//#define FRAMETIME _frametime
6363
#define FRAMETIME strip.getFrameTime()
6464

65-
/* each segment uses 52 bytes of SRAM memory, so if you're application fails because of
65+
/* each segment uses 82 bytes of SRAM memory, so if you're application fails because of
6666
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
6767
#ifdef ESP8266
68-
#define MAX_NUM_SEGMENTS 16
68+
#define MAX_NUM_SEGMENTS 12
6969
/* How much data bytes all segments combined may allocate */
7070
#define MAX_SEGMENT_DATA 5120
7171
#else
7272
#ifndef MAX_NUM_SEGMENTS
7373
#define MAX_NUM_SEGMENTS 32
7474
#endif
7575
#if defined(ARDUINO_ARCH_ESP32S2)
76-
#define MAX_SEGMENT_DATA 24576
76+
#if defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
77+
#define MAX_SEGMENT_DATA MAX_NUM_SEGMENTS*1024 // 32k by default
78+
#else
79+
#define MAX_SEGMENT_DATA MAX_NUM_SEGMENTS*768 // 24k by default
80+
#endif
7781
#else
78-
#define MAX_SEGMENT_DATA 32767
82+
#define MAX_SEGMENT_DATA MAX_NUM_SEGMENTS*1280 // 40k by default
7983
#endif
8084
#endif
8185

@@ -543,9 +547,9 @@ typedef struct Segment {
543547

544548
// runtime data functions
545549
inline uint16_t dataSize(void) const { return _dataLen; }
546-
bool allocateData(size_t len);
547-
void deallocateData(void);
548-
void resetIfRequired(void);
550+
bool allocateData(size_t len); // allocates effect data buffer in heap and clears it
551+
void deallocateData(void); // deallocates (frees) effect data buffer from heap
552+
void resetIfRequired(void); // sets all SEGENV variables to 0 and clears data buffer
549553
/**
550554
* Flags that before the next effect is calculated,
551555
* the internal segment state should be reset.
@@ -559,10 +563,10 @@ typedef struct Segment {
559563
void stopTransition(void);
560564
void handleTransition(void);
561565
#ifndef WLED_DISABLE_MODE_BLEND
562-
void swapSegenv(tmpsegd_t &tmpSegD);
563-
void restoreSegenv(tmpsegd_t &tmpSegD);
566+
void swapSegenv(tmpsegd_t &tmpSegD); // copies segment data into specifed buffer, if buffer is not a transition buffer, segment data is overwritten from transition buffer
567+
void restoreSegenv(tmpsegd_t &tmpSegD); // restores segment data from buffer, if buffer is not transition buffer, changed values are copied to transition buffer
564568
#endif
565-
uint16_t progress(void); //transition progression between 0-65535
569+
uint16_t progress(void); // transition progression between 0-65535
566570
uint8_t currentBri(bool useCct = false);
567571
uint8_t currentMode(void);
568572
uint32_t currentColor(uint8_t slot);
@@ -682,10 +686,7 @@ class WS2812FX { // 96 bytes
682686
WS2812FX() :
683687
paletteFade(0),
684688
paletteBlend(0),
685-
milliampsPerLed(55),
686689
cctBlending(0),
687-
ablMilliampsMax(ABL_MILLIAMPS_DEFAULT),
688-
currentMilliamps(0),
689690
now(millis()),
690691
timebase(0),
691692
isMatrix(false),
@@ -760,7 +761,7 @@ class WS2812FX { // 96 bytes
760761
resetSegments(),
761762
makeAutoSegments(bool forceReset = false),
762763
fixInvalidSegments(),
763-
setPixelColor(int n, uint32_t c),
764+
setPixelColor(unsigned n, uint32_t c),
764765
show(void),
765766
setTargetFps(uint8_t fps),
766767
addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name), // add effect to the list; defined in FX.cpp
@@ -769,10 +770,10 @@ class WS2812FX { // 96 bytes
769770
inline void restartRuntime() { for (Segment &seg : _segments) seg.markForReset(); }
770771
inline void setTransitionMode(bool t) { for (Segment &seg : _segments) seg.startTransition(t ? _transitionDur : 0); }
771772
inline void setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setColor(slot, RGBW32(r,g,b,w)); }
772-
inline void fill(uint32_t c) { for (int i = 0; i < getLengthTotal(); i++) setPixelColor(i, c); } // fill whole strip with color (inline)
773+
inline void fill(uint32_t c) { for (unsigned i = 0; i < getLengthTotal(); i++) setPixelColor(i, c); } // fill whole strip with color (inline)
773774
// outsmart the compiler :) by correctly overloading
774-
inline void setPixelColor(int n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); }
775-
inline void setPixelColor(int n, CRGB c) { setPixelColor(n, c.red, c.green, c.blue); }
775+
inline void setPixelColor(unsigned n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); }
776+
inline void setPixelColor(unsigned n, CRGB c) { setPixelColor(n, c.red, c.green, c.blue); }
776777
inline void trigger(void) { _triggered = true; } // Forces the next frame to be computed on all active segments.
777778
inline void setShowCallback(show_callback cb) { _callback = cb; }
778779
inline void setTransition(uint16_t t) { _transitionDur = t; }
@@ -793,7 +794,6 @@ class WS2812FX { // 96 bytes
793794

794795
uint8_t
795796
paletteBlend,
796-
milliampsPerLed,
797797
cctBlending,
798798
getActiveSegmentsNum(void),
799799
getFirstSelectedSegId(void),
@@ -811,8 +811,6 @@ class WS2812FX { // 96 bytes
811811
inline uint8_t getModeCount() { return _modeCount; }
812812

813813
uint16_t
814-
ablMilliampsMax,
815-
currentMilliamps,
816814
getLengthPhysical(void),
817815
getLengthTotal(void), // will include virtual/nonexistent pixels in matrix
818816
getFps();
@@ -878,7 +876,7 @@ class WS2812FX { // 96 bytes
878876
void setUpMatrix();
879877

880878
// outsmart the compiler :) by correctly overloading
881-
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(y * Segment::maxWidth + x, c); }
879+
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor((unsigned)(y * Segment::maxWidth + x), c); }
882880
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
883881
inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); }
884882

wled00/FX_2Dfcn.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@
3636
// so matrix should disable regular ledmap processing
3737
void WS2812FX::setUpMatrix() {
3838
#ifndef WLED_DISABLE_2D
39-
// erase old ledmap, just in case.
40-
if (customMappingTable != nullptr) delete[] customMappingTable;
41-
customMappingTable = nullptr;
42-
customMappingSize = 0;
43-
4439
// isMatrix is set in cfg.cpp or set.cpp
4540
if (isMatrix) {
46-
// calculate width dynamically because it will have gaps
41+
// calculate width dynamically because it may have gaps
4742
Segment::maxWidth = 1;
4843
Segment::maxHeight = 1;
4944
for (size_t i = 0; i < panel.size(); i++) {
@@ -68,15 +63,17 @@ void WS2812FX::setUpMatrix() {
6863
return;
6964
}
7065

71-
customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
66+
customMappingSize = 0; // prevent use of mapping if anything goes wrong
67+
68+
if (customMappingTable == nullptr) customMappingTable = new uint16_t[getLengthTotal()];
7269

7370
if (customMappingTable != nullptr) {
74-
customMappingSize = Segment::maxWidth * Segment::maxHeight;
71+
customMappingSize = getLengthTotal();
7572

7673
// fill with empty in case we don't fill the entire matrix
77-
for (size_t i = 0; i< customMappingSize; i++) {
78-
customMappingTable[i] = (uint16_t)-1;
79-
}
74+
unsigned matrixSize = Segment::maxWidth * Segment::maxHeight;
75+
for (unsigned i = 0; i<matrixSize; i++) customMappingTable[i] = 0xFFFFU;
76+
for (unsigned i = matrixSize; i<getLengthTotal(); i++) customMappingTable[i] = i; // trailing LEDs for ledmap (after matrix) if it exist
8077

8178
// we will try to load a "gap" array (a JSON file)
8279
// the array has to have the same amount of values as mapping array (or larger)
@@ -94,14 +91,14 @@ void WS2812FX::setUpMatrix() {
9491
DEBUG_PRINT(F("Reading LED gap from "));
9592
DEBUG_PRINTLN(fileName);
9693
// read the array into global JSON buffer
97-
if (readObjectFromFile(fileName, nullptr, &doc)) {
94+
if (readObjectFromFile(fileName, nullptr, pDoc)) {
9895
// the array is similar to ledmap, except it has only 3 values:
9996
// -1 ... missing pixel (do not increase pixel count)
10097
// 0 ... inactive pixel (it does count, but should be mapped out (-1))
10198
// 1 ... active pixel (it will count and will be mapped)
102-
JsonArray map = doc.as<JsonArray>();
99+
JsonArray map = pDoc->as<JsonArray>();
103100
gapSize = map.size();
104-
if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map
101+
if (!map.isNull() && gapSize >= matrixSize) { // not an empty map
105102
gapTable = new int8_t[gapSize];
106103
if (gapTable) for (size_t i = 0; i < gapSize; i++) {
107104
gapTable[i] = constrain(map[i], -1, 1);

0 commit comments

Comments
 (0)