refactor resetSegments to work properly

add boundsOnly
This commit is contained in:
Ewoud
2023-02-13 15:54:18 +01:00
parent d215633578
commit 0d0f6b5e30
5 changed files with 30 additions and 20 deletions

View File

@@ -731,7 +731,7 @@ class WS2812FX { // 96 bytes
setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 1, uint8_t spacing = 0, uint16_t offset = UINT16_MAX, uint16_t startY=0, uint16_t stopY=1), setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 1, uint8_t spacing = 0, uint16_t offset = UINT16_MAX, uint16_t startY=0, uint16_t stopY=1),
setMainSegmentId(uint8_t n), setMainSegmentId(uint8_t n),
restartRuntime(), restartRuntime(),
resetSegments(), resetSegments(bool boundsOnly = false), //WLEDMM add boundsOnly
makeAutoSegments(bool forceReset = false), makeAutoSegments(bool forceReset = false),
fixInvalidSegments(), fixInvalidSegments(),
setPixelColor(int n, uint32_t c), setPixelColor(int n, uint32_t c),

View File

@@ -68,7 +68,7 @@ void WS2812FX::setUpMatrix(bool reset) {
Segment::maxHeight = 1; Segment::maxHeight = 1;
panels = 0; panels = 0;
panel.clear(); // release memory allocated by panels panel.clear(); // release memory allocated by panels
resetSegments(); resetSegments(true); //WLEDMM bounds only
return; return;
} }
@@ -131,13 +131,7 @@ void WS2812FX::setUpMatrix(bool reset) {
Segment::maxWidth = _length; Segment::maxWidth = _length;
Segment::maxHeight = 1; Segment::maxHeight = 1;
} }
if (reset) //resetSegments(); //WLEDMM: only if reset, and only update width and height, keep the fx in place //WLEDMM: no resetSegments here, only do it in set.cpp/handleSettingsSet
for (segment &seg : _segments) {
seg.start = 0;
seg.stop = Segment::maxWidth;
seg.startY = 0;
seg.stopY = Segment::maxHeight;
}
} }
#else #else
isMatrix = false; // no matter what config says isMatrix = false; // no matter what config says

View File

@@ -1740,15 +1740,30 @@ void WS2812FX::restartRuntime() {
for (segment &seg : _segments) seg.markForReset(); for (segment &seg : _segments) seg.markForReset();
} }
void WS2812FX::resetSegments() { void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
_segments.clear(); // destructs all Segment as part of clearing if (!boundsOnly) {
#ifndef WLED_DISABLE_2D _segments.clear(); // destructs all Segment as part of clearing
segment seg = isMatrix ? Segment(0, Segment::maxWidth, 0, Segment::maxHeight) : Segment(0, _length); #ifndef WLED_DISABLE_2D
#else segment seg = isMatrix ? Segment(0, Segment::maxWidth, 0, Segment::maxHeight) : Segment(0, _length);
segment seg = Segment(0, _length); #else
#endif segment seg = Segment(0, _length);
_segments.push_back(seg); #endif
_mainSegment = 0; _segments.push_back(seg);
_mainSegment = 0;
} else { //WLEDMM boundsonly
for (segment &seg : _segments) {
#ifndef WLED_DISABLE_2D
seg.start = 0;
seg.stop = Segment::maxWidth;
seg.startY = 0;
seg.stopY = Segment::maxHeight;
#else
seg.start = 0;
seg.stop = _length;
#endif
}
}
} }
void WS2812FX::makeAutoSegments(bool forceReset) { void WS2812FX::makeAutoSegments(bool forceReset) {

View File

@@ -714,6 +714,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
Segment::maxHeight = 1; Segment::maxHeight = 1;
} }
strip.setUpMatrix(); // will check limits strip.setUpMatrix(); // will check limits
strip.resetSegments(true); //WLEDMM reset segments, boundsOnly!!
} }
#endif #endif

View File

@@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2302120 #define VERSION 2302130
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@@ -681,7 +681,7 @@ WLED_GLOBAL BusManager busses _INIT(BusManager());
WLED_GLOBAL WS2812FX strip _INIT(WS2812FX()); WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
WLED_GLOBAL BusConfig* busConfigs[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES] _INIT({nullptr}); //temporary, to remember values from network callback until after WLED_GLOBAL BusConfig* busConfigs[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES] _INIT({nullptr}); //temporary, to remember values from network callback until after
WLED_GLOBAL bool doInitBusses _INIT(false); WLED_GLOBAL bool doInitBusses _INIT(false);
WLED_GLOBAL bool loadLedmap _INIT(false); WLED_GLOBAL bool loadLedmap _INIT(false); //WLEDMM use as bool and use loadedLedmap for Nr
WLED_GLOBAL uint8_t loadedLedmap _INIT(0); //WLEDMM default 0 WLED_GLOBAL uint8_t loadedLedmap _INIT(0); //WLEDMM default 0
WLED_GLOBAL uint16_t ledMaps _INIT(0); // bitfield representation of available ledmaps WLED_GLOBAL uint16_t ledMaps _INIT(0); // bitfield representation of available ledmaps