POC to use leds array in strip.set/getPixelColor
This commit is contained in:
parent
a70717f2f7
commit
66da57f375
@ -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;}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user