segment.leds refactor (wip)
rename leds to ledsrgb
This commit is contained in:
@@ -383,7 +383,7 @@ typedef struct Segment {
|
|||||||
uint16_t aux0; // custom var
|
uint16_t aux0; // custom var
|
||||||
uint16_t aux1; // custom var
|
uint16_t aux1; // custom var
|
||||||
byte* data; // effect data pointer
|
byte* data; // effect data pointer
|
||||||
CRGB* leds; // local leds[] array (may be a pointer to global)
|
CRGB* ledsrgb; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?)
|
||||||
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
|
||||||
@@ -468,7 +468,7 @@ typedef struct Segment {
|
|||||||
aux0(0),
|
aux0(0),
|
||||||
aux1(0),
|
aux1(0),
|
||||||
data(nullptr),
|
data(nullptr),
|
||||||
leds(nullptr),
|
ledsrgb(nullptr),
|
||||||
_capabilities(0),
|
_capabilities(0),
|
||||||
_dataLen(0),
|
_dataLen(0),
|
||||||
_t(nullptr)
|
_t(nullptr)
|
||||||
@@ -492,7 +492,7 @@ typedef struct Segment {
|
|||||||
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
||||||
//Serial.println();
|
//Serial.println();
|
||||||
//#endif
|
//#endif
|
||||||
if (!Segment::_globalLeds && leds) free(leds);
|
if (!Segment::_globalLeds && ledsrgb) free(ledsrgb);
|
||||||
if (name) delete[] name;
|
if (name) delete[] name;
|
||||||
if (_t) delete _t;
|
if (_t) delete _t;
|
||||||
deallocateData();
|
deallocateData();
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
|
|||||||
if (Segment::maxHeight==1) return; // not a matrix set-up
|
if (Segment::maxHeight==1) return; // not a matrix set-up
|
||||||
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
|
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
|
||||||
|
|
||||||
if (leds) leds[XY(x,y)] = col;
|
if (ledsrgb) ledsrgb[XY(x,y)] = col;
|
||||||
|
|
||||||
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
||||||
if (!_bri_t && !transitional) return;
|
if (!_bri_t && !transitional) return;
|
||||||
@@ -289,7 +289,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
|
|||||||
// returns RGBW values of pixel
|
// returns RGBW values of pixel
|
||||||
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
|
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
|
||||||
int i = XY(x,y);
|
int i = XY(x,y);
|
||||||
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
|
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
|
||||||
if (reverse ) x = virtualWidth() - x - 1;
|
if (reverse ) x = virtualWidth() - x - 1;
|
||||||
if (reverse_y) y = virtualHeight() - y - 1;
|
if (reverse_y) y = virtualHeight() - y - 1;
|
||||||
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ Segment::Segment(const Segment &orig) {
|
|||||||
data = nullptr;
|
data = nullptr;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_t = nullptr;
|
_t = nullptr;
|
||||||
if (leds && !Segment::_globalLeds) leds = nullptr;
|
if (ledsrgb && !Segment::_globalLeds) ledsrgb = nullptr; //WLEDMM 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.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); }
|
if (orig.ledsrgb && !Segment::_globalLeds) { ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length()); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
||||||
jMap = nullptr; //WLEDMM jMap
|
jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ Segment::Segment(Segment &&orig) noexcept {
|
|||||||
orig.data = nullptr;
|
orig.data = nullptr;
|
||||||
orig._dataLen = 0;
|
orig._dataLen = 0;
|
||||||
orig._t = nullptr;
|
orig._t = nullptr;
|
||||||
orig.leds = nullptr;
|
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here
|
||||||
orig.jMap = nullptr; //WLEDMM jMap
|
orig.jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Segment& Segment::operator= (const Segment &orig) {
|
|||||||
// clean destination
|
// clean destination
|
||||||
if (name) delete[] name;
|
if (name) delete[] name;
|
||||||
if (_t) delete _t;
|
if (_t) delete _t;
|
||||||
if (leds && !Segment::_globalLeds) free(leds);
|
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: nullify below!
|
||||||
deallocateData();
|
deallocateData();
|
||||||
// copy source
|
// copy source
|
||||||
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
memcpy((void*)this, (void*)&orig, sizeof(Segment));
|
||||||
@@ -125,12 +125,12 @@ Segment& Segment::operator= (const Segment &orig) {
|
|||||||
data = nullptr;
|
data = nullptr;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_t = nullptr;
|
_t = nullptr;
|
||||||
if (!Segment::_globalLeds) leds = nullptr;
|
if (!Segment::_globalLeds) 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.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); }
|
if (orig.ledsrgb && !Segment::_globalLeds) { ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length()); if (ledsrgb) memcpy(ledsrgb, orig.ledsrgb, sizeof(CRGB)*length()); }
|
||||||
jMap = nullptr; //WLEDMM jMap
|
jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -143,13 +143,13 @@ Segment& Segment::operator= (Segment &&orig) noexcept {
|
|||||||
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 (leds && !Segment::_globalLeds) free(leds);
|
if (ledsrgb && !Segment::_globalLeds) free(ledsrgb); //WLEDMM: 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;
|
||||||
orig._dataLen = 0;
|
orig._dataLen = 0;
|
||||||
orig._t = nullptr;
|
orig._t = nullptr;
|
||||||
orig.leds = nullptr;
|
orig.ledsrgb = nullptr; //WLEDMM: do not free as moved to here
|
||||||
orig.jMap = nullptr; //WLEDMM jMap
|
orig.jMap = nullptr; //WLEDMM jMap
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -190,7 +190,7 @@ void Segment::deallocateData() {
|
|||||||
*/
|
*/
|
||||||
void Segment::resetIfRequired() {
|
void Segment::resetIfRequired() {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
if (leds && !Segment::_globalLeds) { free(leds); leds = nullptr; }
|
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;
|
||||||
@@ -202,17 +202,17 @@ void Segment::setUpLeds() {
|
|||||||
// deallocation happens in resetIfRequired() as it is called when segment changes or in destructor
|
// deallocation happens in resetIfRequired() as it is called when segment changes or in destructor
|
||||||
if (Segment::_globalLeds)
|
if (Segment::_globalLeds)
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
leds = &Segment::_globalLeds[start + startY*Segment::maxWidth];
|
ledsrgb = &Segment::_globalLeds[start + startY*Segment::maxWidth];
|
||||||
#else
|
#else
|
||||||
leds = &Segment::_globalLeds[start];
|
leds = &Segment::_globalLeds[start];
|
||||||
#endif
|
#endif
|
||||||
else if (!leds) {
|
else if (!ledsrgb) {
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound())
|
if (psramFound())
|
||||||
leds = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // WLEDMM: stupid - PSRAM is too slow for this !!!
|
ledsrgb = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // WLEDMM: stupid - PSRAM is too slow for this !!!
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
leds = (CRGB*)malloc(sizeof(CRGB)*length());
|
ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,7 +891,7 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (leds) leds[i] = col;
|
if (ledsrgb) ledsrgb[i] = col;
|
||||||
|
|
||||||
uint16_t len = length();
|
uint16_t len = length();
|
||||||
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
||||||
@@ -1017,7 +1017,7 @@ uint32_t Segment::getPixelColor(int i)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
|
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
|
||||||
|
|
||||||
if (reverse) i = virtualLength() - i - 1;
|
if (reverse) i = virtualLength() - i - 1;
|
||||||
i *= groupLength();
|
i *= groupLength();
|
||||||
|
|||||||
Reference in New Issue
Block a user