From 66da57f375138809b116d309743b47a065642b89 Mon Sep 17 00:00:00 2001 From: ewowi Date: Sun, 31 Jul 2022 12:38:10 +0200 Subject: [PATCH] POC to use leds array in strip.set/getPixelColor --- wled00/FX.h | 7 ++++++- wled00/FX_2Dfcn.cpp | 7 ++++++- wled00/FX_fcn.cpp | 22 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 7f66f074..8ec7b44d 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -609,6 +609,10 @@ class WS2812FX { // 96 bytes public: + // FastLED array, so we can refer to leds[i] instead of getPixel() and setPixel() + uint32_t *leds = nullptr ; //See FX_fcn.cpp for init (wip). + //Type is uint32_t as with CRGB assigning CRGB to uint32_t in gPC not implemented (yet) in pixeltypes.h, + WS2812FX() : gammaCorrectBri(false), gammaCorrectCol(true), @@ -716,7 +720,8 @@ class WS2812FX { // 96 bytes hasRGBWBus(void), hasCCTBus(void), // return true if the strip is being sent pixel updates - isUpdating(void); + isUpdating(void), + useLedsArray = true; inline bool isServicing(void) { return _isServicing; } inline bool hasWhiteChannel(void) {return _hasWhiteChannel;} diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 63530080..681c661e 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -116,6 +116,8 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col) uint16_t index = y * matrixWidth + x; if (index >= _length) return; if (index < customMappingSize) index = customMappingTable[index]; + if (useLedsArray) + leds[index] = col; busses.setPixelColor(index, col); #endif } @@ -126,7 +128,10 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) { uint16_t index = (y * matrixWidth + x); if (index >= _length) return 0; if (index < customMappingSize) index = customMappingTable[index]; - return busses.getPixelColor(index); + if (useLedsArray) + return leds[index]; + else + return busses.getPixelColor(index); #else return 0; #endif diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index a4cb9c48..34328f74 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -825,6 +825,17 @@ void WS2812FX::service() { if (nowUp - _lastShow < MIN_SHOW_DELAY) return; bool doShow = false; + //initialize leds array. Move to better place then service??? TBD: realloc if nr of leds change + if (useLedsArray) { + // if (leds != nullptr && sizeof(leds) / sizeof(uint32_t) != _length) { + // free(leds); + // leds = nullptr; + // } + if (leds == nullptr) { + leds = (uint32_t*) malloc(sizeof(uint32_t) * _length); + } + } + _isServicing = true; _segment_index = 0; for (segment &seg : _segments) { @@ -918,17 +929,23 @@ void WS2812FX::setPixelColor(int i, uint32_t col) if (indexMir >= seg.stop) indexMir -= len; // wrap if (indexMir < customMappingSize) indexMir = customMappingTable[indexMir]; + if (useLedsArray) + leds[indexMir] = col; busses.setPixelColor(indexMir, col); } indexSet += seg.offset; // offset/phase if (indexSet >= seg.stop) indexSet -= len; // wrap if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; + if (useLedsArray) + leds[indexSet] = col; busses.setPixelColor(indexSet, col); } } } else { if (i < customMappingSize) i = customMappingTable[i]; + if (useLedsArray) + leds[i] = col; busses.setPixelColor(i, col); } } @@ -940,7 +957,10 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) //if (isMatrix) return getPixelColorXY(i%matrixWidth, i/matrixWidth); // compatibility w/ non-effect fn //#endif if (i < customMappingSize) i = customMappingTable[i]; - return busses.getPixelColor(i); + if (useLedsArray) + return leds[i]; + else + return busses.getPixelColor(i); }