mirror of
https://github.com/wled/WLED.git
synced 2025-07-10 12:26:31 +00:00
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
This commit is contained in:
parent
66da57f375
commit
69f9a484ca
@ -4565,38 +4565,41 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma
|
|||||||
|
|
||||||
const uint16_t cols = SEGMENT.virtualWidth();
|
const uint16_t cols = SEGMENT.virtualWidth();
|
||||||
const uint16_t rows = SEGMENT.virtualHeight();
|
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
|
// if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
|
||||||
CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
|
// CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
|
||||||
|
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
||||||
// initialize on first call
|
// initialize on first call
|
||||||
if (SEGENV.call == 0) {
|
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
|
float t = (float)(millis())/128; // timebase
|
||||||
// outer stars
|
// outer stars
|
||||||
for (size_t i = 0; i < 8; i++) {
|
for (size_t i = 0; i < 8; i++) {
|
||||||
x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * 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);
|
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
|
// inner stars
|
||||||
for (size_t i = 0; i < 4; i++) {
|
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);
|
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);
|
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
|
// 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
|
// blur everything a bit
|
||||||
SEGMENT.blur2d(leds, 16);
|
SEGMENT.blur2d(strip.leds, 16);
|
||||||
|
|
||||||
SEGMENT.setPixels(leds);
|
SEGMENT.setPixels(strip.leds);
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
} // mode_2DBlackHole()
|
} // 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.;;";
|
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);
|
um_data = simulateSound(SEGMENT.soundSim);
|
||||||
}
|
}
|
||||||
uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
|
uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
|
||||||
|
#ifdef ESP32
|
||||||
float FFT_MajorPeak = *(float*) um_data->u_data[4];
|
float FFT_MajorPeak = *(float*) um_data->u_data[4];
|
||||||
|
#endif
|
||||||
uint8_t *maxVol = (uint8_t*)um_data->u_data[6];
|
uint8_t *maxVol = (uint8_t*)um_data->u_data[6];
|
||||||
uint8_t *binNum = (uint8_t*)um_data->u_data[7];
|
uint8_t *binNum = (uint8_t*)um_data->u_data[7];
|
||||||
|
|
||||||
|
@ -610,8 +610,7 @@ class WS2812FX { // 96 bytes
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
// FastLED array, so we can refer to leds[i] instead of getPixel() and setPixel()
|
// 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).
|
CRGB *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() :
|
WS2812FX() :
|
||||||
gammaCorrectBri(false),
|
gammaCorrectBri(false),
|
||||||
|
@ -116,8 +116,6 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col)
|
|||||||
uint16_t index = y * matrixWidth + x;
|
uint16_t index = y * matrixWidth + x;
|
||||||
if (index >= _length) return;
|
if (index >= _length) return;
|
||||||
if (index < customMappingSize) index = customMappingTable[index];
|
if (index < customMappingSize) index = customMappingTable[index];
|
||||||
if (useLedsArray)
|
|
||||||
leds[index] = col;
|
|
||||||
busses.setPixelColor(index, col);
|
busses.setPixelColor(index, col);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -128,9 +126,6 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
|
|||||||
uint16_t index = (y * matrixWidth + x);
|
uint16_t index = (y * matrixWidth + x);
|
||||||
if (index >= _length) return 0;
|
if (index >= _length) return 0;
|
||||||
if (index < customMappingSize) index = customMappingTable[index];
|
if (index < customMappingSize) index = customMappingTable[index];
|
||||||
if (useLedsArray)
|
|
||||||
return leds[index];
|
|
||||||
else
|
|
||||||
return busses.getPixelColor(index);
|
return busses.getPixelColor(index);
|
||||||
#else
|
#else
|
||||||
return 0;
|
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);
|
uint16_t xX = (x+g), yY = (y+j);
|
||||||
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
|
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);
|
strip.setPixelColorXY(start + xX, startY + yY, col);
|
||||||
|
|
||||||
if (getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel
|
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
|
x *= groupLength(); // expand to physical pixels
|
||||||
y *= groupLength(); // expand to physical pixels
|
y *= groupLength(); // expand to physical pixels
|
||||||
if (x >= width() || y >= height()) return 0;
|
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
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -464,6 +464,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
|
|||||||
}
|
}
|
||||||
indexSet += offset; // offset/phase
|
indexSet += offset; // offset/phase
|
||||||
if (indexSet >= stop) indexSet -= len; // wrap
|
if (indexSet >= stop) indexSet -= len; // wrap
|
||||||
|
if (strip.useLedsArray)
|
||||||
|
strip.leds[indexSet] = col;
|
||||||
strip.setPixelColor(indexSet, col);
|
strip.setPixelColor(indexSet, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +529,12 @@ uint32_t Segment::getPixelColor(uint16_t i)
|
|||||||
/* offset/phase */
|
/* offset/phase */
|
||||||
i += offset;
|
i += offset;
|
||||||
if (i >= stop) i -= length();
|
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) {
|
uint8_t Segment::differs(Segment& b) {
|
||||||
@ -832,7 +839,7 @@ void WS2812FX::service() {
|
|||||||
// leds = nullptr;
|
// leds = nullptr;
|
||||||
// }
|
// }
|
||||||
if (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 >= seg.stop) indexMir -= len; // wrap
|
||||||
if (indexMir < customMappingSize) indexMir = customMappingTable[indexMir];
|
if (indexMir < customMappingSize) indexMir = customMappingTable[indexMir];
|
||||||
|
|
||||||
if (useLedsArray)
|
|
||||||
leds[indexMir] = col;
|
|
||||||
busses.setPixelColor(indexMir, col);
|
busses.setPixelColor(indexMir, col);
|
||||||
}
|
}
|
||||||
indexSet += seg.offset; // offset/phase
|
indexSet += seg.offset; // offset/phase
|
||||||
if (indexSet >= seg.stop) indexSet -= len; // wrap
|
if (indexSet >= seg.stop) indexSet -= len; // wrap
|
||||||
if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet];
|
if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet];
|
||||||
|
|
||||||
if (useLedsArray)
|
|
||||||
leds[indexSet] = col;
|
|
||||||
busses.setPixelColor(indexSet, col);
|
busses.setPixelColor(indexSet, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i < customMappingSize) i = customMappingTable[i];
|
if (i < customMappingSize) i = customMappingTable[i];
|
||||||
if (useLedsArray)
|
|
||||||
leds[i] = col;
|
|
||||||
busses.setPixelColor(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
|
//if (isMatrix) return getPixelColorXY(i%matrixWidth, i/matrixWidth); // compatibility w/ non-effect fn
|
||||||
//#endif
|
//#endif
|
||||||
if (i < customMappingSize) i = customMappingTable[i];
|
if (i < customMappingSize) i = customMappingTable[i];
|
||||||
if (useLedsArray)
|
|
||||||
return leds[i];
|
|
||||||
else
|
|
||||||
return busses.getPixelColor(i);
|
return busses.getPixelColor(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user