leds(rgb): also adjusted if new ledmap + grow not shrink (unless...)
FX.h: add ledsrgbSize and allocLeds() FX_fcn.cpp: - copy constructor: allocLeds() - move constructor: no change - copy assignment: reuse! + allocLeds() - move asignment: no change - resetIfRequired: no free - setUpLeds/resetSegments: allocLeds() unless...: copy constructor aften called. That is the bad boy causing re-allocs at every effect change!
This commit is contained in:
14
wled00/FX.h
14
wled00/FX.h
@@ -384,6 +384,7 @@ typedef struct Segment {
|
|||||||
uint16_t aux1; // custom var
|
uint16_t aux1; // custom var
|
||||||
byte* data; // effect data pointer
|
byte* data; // effect data pointer
|
||||||
CRGB* ledsrgb; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?)
|
CRGB* ledsrgb; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?)
|
||||||
|
uint16_t ledsrgbSize; //WLEDMM
|
||||||
static CRGB *_globalLeds; // global leds[] array
|
static CRGB *_globalLeds; // global leds[] array
|
||||||
static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)
|
static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)
|
||||||
void *jMap = nullptr; //WLEDMM jMap
|
void *jMap = nullptr; //WLEDMM jMap
|
||||||
@@ -469,6 +470,7 @@ typedef struct Segment {
|
|||||||
aux1(0),
|
aux1(0),
|
||||||
data(nullptr),
|
data(nullptr),
|
||||||
ledsrgb(nullptr),
|
ledsrgb(nullptr),
|
||||||
|
ledsrgbSize(0), //WLEDMM
|
||||||
_capabilities(0),
|
_capabilities(0),
|
||||||
_dataLen(0),
|
_dataLen(0),
|
||||||
_t(nullptr)
|
_t(nullptr)
|
||||||
@@ -486,11 +488,11 @@ typedef struct Segment {
|
|||||||
|
|
||||||
~Segment() {
|
~Segment() {
|
||||||
//#ifdef WLED_DEBUG
|
//#ifdef WLED_DEBUG
|
||||||
//Serial.print(F("Destroying segment:"));
|
Serial.print(F("Destroying segment:"));
|
||||||
//if (name) Serial.printf(" %s (%p)", name, name);
|
if (name) Serial.printf(" %s (%p)", name, name);
|
||||||
//if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
|
if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
|
||||||
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
if (ledsrgb) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
||||||
//Serial.println();
|
Serial.println();
|
||||||
//#endif
|
//#endif
|
||||||
if (!Segment::_globalLeds && ledsrgb) free(ledsrgb);
|
if (!Segment::_globalLeds && ledsrgb) free(ledsrgb);
|
||||||
if (name) delete[] name;
|
if (name) delete[] name;
|
||||||
@@ -521,6 +523,8 @@ typedef struct Segment {
|
|||||||
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
|
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
|
||||||
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
|
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
|
||||||
|
|
||||||
|
void allocLeds(); //WLEDMM
|
||||||
|
|
||||||
void set(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
|
void set(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
|
||||||
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
||||||
void setCCT(uint16_t k);
|
void setCCT(uint16_t k);
|
||||||
|
|||||||
@@ -83,40 +83,55 @@ uint16_t Segment::maxHeight = 1;
|
|||||||
|
|
||||||
// copy constructor
|
// copy constructor
|
||||||
Segment::Segment(const Segment &orig) {
|
Segment::Segment(const Segment &orig) {
|
||||||
//DEBUG_PRINTLN(F("-- Copy segment constructor --"));
|
USER_PRINTLN(F("-- Copy segment constructor --"));
|
||||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
memcpy((void*)this, (void*)&orig, sizeof(Segment)); //WLEDMM copy to this
|
||||||
name = nullptr;
|
name = nullptr;
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_t = nullptr;
|
_t = nullptr;
|
||||||
if (ledsrgb && !Segment::_globalLeds) ledsrgb = nullptr; //WLEDMM ledsrgb not freed as still used by orig!
|
if (ledsrgb && !Segment::_globalLeds) ledsrgb = nullptr; //WLEDMM constructor so there was nothing. ledsrgb not freed as still used by orig!
|
||||||
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
|
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
|
||||||
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
|
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
|
||||||
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
|
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
|
||||||
if (orig.ledsrgb && !Segment::_globalLeds) { ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length()); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
if (orig.ledsrgb && !Segment::_globalLeds) { allocLeds(); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
||||||
jMap = nullptr; //WLEDMM jMap
|
jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WLEDMM: recreate ledsrgb if more space needed (will not free ledsrgb!)
|
||||||
|
void Segment::allocLeds() {
|
||||||
|
if (!ledsrgb || sizeof(CRGB)*length() > ledsrgbSize) {
|
||||||
|
USER_PRINTF("allocLeds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
|
||||||
|
ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length());
|
||||||
|
ledsrgbSize = ledsrgb?sizeof(CRGB)*length():0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
USER_PRINTF("reuse Leds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// move constructor
|
// move constructor
|
||||||
Segment::Segment(Segment &&orig) noexcept {
|
Segment::Segment(Segment &&orig) noexcept {
|
||||||
//DEBUG_PRINTLN(F("-- Move segment constructor --"));
|
USER_PRINTLN(F("-- Move segment constructor --"));
|
||||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||||
orig.name = nullptr;
|
orig.name = nullptr;
|
||||||
orig.data = nullptr;
|
orig.data = nullptr;
|
||||||
orig._dataLen = 0;
|
orig._dataLen = 0;
|
||||||
orig._t = nullptr;
|
orig._t = nullptr;
|
||||||
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here
|
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here (constructor so there where no leds)
|
||||||
orig.jMap = nullptr; //WLEDMM jMap
|
orig.jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy assignment
|
// copy assignment
|
||||||
Segment& Segment::operator= (const Segment &orig) {
|
Segment& Segment::operator= (const Segment &orig) {
|
||||||
//DEBUG_PRINTLN(F("-- Copying segment --"));
|
USER_PRINTLN(F("-- Copying segment --"));
|
||||||
if (this != &orig) {
|
if (this != &orig) {
|
||||||
// clean destination
|
// clean destination
|
||||||
if (name) delete[] name;
|
if (name) delete[] name;
|
||||||
if (_t) delete _t;
|
if (_t) delete _t;
|
||||||
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: nullify below!
|
// WLEDMM reuse leds instead of removing themn
|
||||||
|
// if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: nullify below!
|
||||||
|
CRGB* oldLeds = ledsrgb;
|
||||||
|
uint16_t oldLedsSize = ledsrgbSize;
|
||||||
deallocateData();
|
deallocateData();
|
||||||
// copy source
|
// copy source
|
||||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||||
@@ -125,12 +140,12 @@ Segment& Segment::operator= (const Segment &orig) {
|
|||||||
data = nullptr;
|
data = nullptr;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_t = nullptr;
|
_t = nullptr;
|
||||||
if (!Segment::_globalLeds) ledsrgb = nullptr;
|
if (!Segment::_globalLeds) {ledsrgb = oldLeds; ledsrgbSize = oldLedsSize;};// WLEDMM reuse leds instead of ledsrgb = nullptr;
|
||||||
// copy source data
|
// copy source data
|
||||||
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
|
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
|
||||||
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
|
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
|
||||||
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
|
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
|
||||||
if (orig.ledsrgb && !Segment::_globalLeds) { ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length()); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
if (orig.ledsrgb && !Segment::_globalLeds) { allocLeds(); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
||||||
jMap = nullptr; //WLEDMM jMap
|
jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -138,12 +153,12 @@ Segment& Segment::operator= (const Segment &orig) {
|
|||||||
|
|
||||||
// move assignment
|
// move assignment
|
||||||
Segment& Segment::operator= (Segment &&orig) noexcept {
|
Segment& Segment::operator= (Segment &&orig) noexcept {
|
||||||
//DEBUG_PRINTLN(F("-- Moving segment --"));
|
USER_PRINTLN(F("-- Moving segment --"));
|
||||||
if (this != &orig) {
|
if (this != &orig) {
|
||||||
if (name) delete[] name; // free old name
|
if (name) delete[] name; // free old name
|
||||||
deallocateData(); // free old runtime data
|
deallocateData(); // free old runtime data
|
||||||
if (_t) delete _t;
|
if (_t) delete _t;
|
||||||
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: no need to nullify ledsrgb as it gets new value in memcpy
|
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: not needed anymore as we will use leds from copy. no need to nullify ledsrgb as it gets new value in memcpy
|
||||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||||
orig.name = nullptr;
|
orig.name = nullptr;
|
||||||
orig.data = nullptr;
|
orig.data = nullptr;
|
||||||
@@ -190,7 +205,8 @@ void Segment::deallocateData() {
|
|||||||
*/
|
*/
|
||||||
void Segment::resetIfRequired() {
|
void Segment::resetIfRequired() {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
if (ledsrgb && !Segment::_globalLeds) { free(ledsrgb); ledsrgb = nullptr; }
|
//WLEDMM no need to free leds as we will reuse them
|
||||||
|
// if (ledsrgb && !Segment::_globalLeds) { free(ledsrgb); ledsrgb = nullptr; }
|
||||||
if (transitional && _t) { transitional = false; delete _t; _t = nullptr; }
|
if (transitional && _t) { transitional = false; delete _t; _t = nullptr; }
|
||||||
deallocateData();
|
deallocateData();
|
||||||
next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
|
next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
|
||||||
@@ -212,7 +228,7 @@ void Segment::setUpLeds() {
|
|||||||
// ledsrgb = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
|
// ledsrgb = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
|
||||||
//else
|
//else
|
||||||
//#endif
|
//#endif
|
||||||
ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length());
|
allocLeds(); //WLEDMM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1851,6 +1867,7 @@ void WS2812FX::restartRuntime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
|
void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
|
||||||
|
USER_PRINTF("resetSegments %d %dx%d\n", boundsOnly, Segment::maxWidth, Segment::maxHeight);
|
||||||
if (!boundsOnly) {
|
if (!boundsOnly) {
|
||||||
_segments.clear(); // destructs all Segment as part of clearing
|
_segments.clear(); // destructs all Segment as part of clearing
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
@@ -1862,6 +1879,7 @@ void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
|
|||||||
_mainSegment = 0;
|
_mainSegment = 0;
|
||||||
} else { //WLEDMM boundsonly
|
} else { //WLEDMM boundsonly
|
||||||
for (segment &seg : _segments) {
|
for (segment &seg : _segments) {
|
||||||
|
bool recreateLeds = false;
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
seg.start = 0;
|
seg.start = 0;
|
||||||
seg.stop = Segment::maxWidth;
|
seg.stop = Segment::maxWidth;
|
||||||
@@ -1871,9 +1889,9 @@ void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
|
|||||||
seg.start = 0;
|
seg.start = 0;
|
||||||
seg.stop = _length;
|
seg.stop = _length;
|
||||||
#endif
|
#endif
|
||||||
|
seg.allocLeds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WS2812FX::makeAutoSegments(bool forceReset) {
|
void WS2812FX::makeAutoSegments(bool forceReset) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2305240
|
#define VERSION 2305241
|
||||||
|
|
||||||
//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
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ void getSettingsJS(AsyncWebServerRequest* request, byte subPage, char* dest) //W
|
|||||||
char rf[4] = "RF"; rf[2] = 48+s; rf[3] = 0; //off refresh
|
char rf[4] = "RF"; rf[2] = 48+s; rf[3] = 0; //off refresh
|
||||||
char aw[4] = "AW"; aw[2] = 48+s; aw[3] = 0; //auto white mode
|
char aw[4] = "AW"; aw[2] = 48+s; aw[3] = 0; //auto white mode
|
||||||
char wo[4] = "WO"; wo[2] = 48+s; wo[3] = 0; //swap channels
|
char wo[4] = "WO"; wo[2] = 48+s; wo[3] = 0; //swap channels
|
||||||
char sp[4] = "SP"; sp[2] = 48+s; sp[3] = 0; //bus clock speed
|
// char sp[4] = "SP"; sp[2] = 48+s; sp[3] = 0; //bus clock speed WLEDMM to do bus
|
||||||
oappend(SET_F("addLEDs(1);"));
|
oappend(SET_F("addLEDs(1);"));
|
||||||
uint8_t pins[5];
|
uint8_t pins[5];
|
||||||
uint8_t nPins = bus->getPins(pins);
|
uint8_t nPins = bus->getPins(pins);
|
||||||
|
|||||||
Reference in New Issue
Block a user