strip.leds array fully fastLed and segment compatible

- leds array from uint32_t to CRGB for fastled compatibility
- reading and writing leds from strip to segment sPC/gPC so it has logical instead of physical indexes so it can be used in effects
- change mode_2DBlackHole as showcase how it can both work with leds or with sPC/gPC
pull/2737/head
ewowi 2022-07-31 14:48:00 +02:00
rodzic 66da57f375
commit 69f9a484ca
4 zmienionych plików z 32 dodań i 29 usunięć

Wyświetl plik

@ -4565,38 +4565,41 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma
const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled
// const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
// if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
// CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
uint16_t x, y;
// initialize on first call
if (SEGENV.call == 0) {
SEGMENT.fill_solid(leds, CRGB::Black);
SEGMENT.fill_solid(strip.leds, CRGB::Black);
}
SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails
SEGMENT.fadeToBlackBy(strip.leds, 16 + (SEGMENT.speed>>3)); // create fading trails
float t = (float)(millis())/128; // timebase
// outer stars
for (size_t i = 0; i < 8; i++) {
x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255);
strip.leds[XY(x,y)] += CHSV(i*32, 255, 255);
// SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255));
}
// inner stars
for (size_t i = 0; i < 4; i++) {
x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255);
strip.leds[XY(x,y)] += CHSV(i*32, 255, 255);
// SEGMENT.setPixelColorXY(x, y, SEGMENT.getPixelColorXY(x, y) + CHSV(i*32, 255, 255));
}
// central white dot
leds[XY(cols/2,rows/2)] = CHSV(0,0,255);
strip.leds[XY(cols/2,rows/2)] = CHSV(0,0,255);
// SEGMENT.setPixelColorXY(cols/2,rows/2, CHSV(0,0,255));
// blur everything a bit
SEGMENT.blur2d(leds, 16);
SEGMENT.blur2d(strip.leds, 16);
SEGMENT.setPixels(leds);
SEGMENT.setPixels(strip.leds);
return FRAMETIME;
} // mode_2DBlackHole()
static const char *_data_FX_MODE_2DBLACKHOLE PROGMEM = "2D Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;";
@ -6006,7 +6009,9 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
#ifdef ESP32
float FFT_MajorPeak = *(float*) um_data->u_data[4];
#endif
uint8_t *maxVol = (uint8_t*)um_data->u_data[6];
uint8_t *binNum = (uint8_t*)um_data->u_data[7];

Wyświetl plik

@ -610,8 +610,7 @@ 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,
CRGB *leds = nullptr ; //See FX_fcn.cpp for init (wip).
WS2812FX() :
gammaCorrectBri(false),

Wyświetl plik

@ -116,8 +116,6 @@ 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
}
@ -128,9 +126,6 @@ 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];
if (useLedsArray)
return leds[index];
else
return busses.getPixelColor(index);
#else
return 0;
@ -180,6 +175,8 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
uint16_t xX = (x+g), yY = (y+j);
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
if (strip.useLedsArray)
strip.leds[start + xX + (startY + yY) * strip.matrixWidth] = col;
strip.setPixelColorXY(start + xX, startY + yY, col);
if (getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel
@ -253,7 +250,11 @@ uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
x *= groupLength(); // expand to physical pixels
y *= groupLength(); // expand to physical pixels
if (x >= width() || y >= height()) return 0;
return strip.getPixelColorXY(start + x, startY + y);
if (strip.useLedsArray) {
CRGB led = strip.leds[start + x + (startY + y) * strip.matrixWidth];
return led.r * 65536 + led.g * 256 + led.b;
}
return strip.getPixelColorXY(start + x, startY + y);
#else
return 0;
#endif

Wyświetl plik

@ -464,6 +464,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
}
indexSet += offset; // offset/phase
if (indexSet >= stop) indexSet -= len; // wrap
if (strip.useLedsArray)
strip.leds[indexSet] = col;
strip.setPixelColor(indexSet, col);
}
}
@ -527,7 +529,12 @@ uint32_t Segment::getPixelColor(uint16_t i)
/* offset/phase */
i += offset;
if (i >= stop) i -= length();
return strip.getPixelColor(i);
if (strip.useLedsArray) {
CRGB led = strip.leds[i];
return led.r * 65536 + led.g * 256 + led.b;
}
else
return strip.getPixelColor(i);
}
uint8_t Segment::differs(Segment& b) {
@ -832,7 +839,7 @@ void WS2812FX::service() {
// leds = nullptr;
// }
if (leds == nullptr) {
leds = (uint32_t*) malloc(sizeof(uint32_t) * _length);
leds = (CRGB*) malloc(sizeof(CRGB) * _length);
}
}
@ -929,23 +936,17 @@ 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);
}
}
@ -957,9 +958,6 @@ 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];
if (useLedsArray)
return leds[i];
else
return busses.getPixelColor(i);
}