Skip to content

Commit

Permalink
Merge branch 'mdev' into 1D2D_Waterfall
Browse files Browse the repository at this point in the history
  • Loading branch information
softhack007 committed Nov 24, 2024
2 parents 540b580 + 5a2096a commit 350e80c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ AR_build_flags = -D USERMOD_AUDIOREACTIVE -D UM_AUDIOREACTIVE_USE_NEW_FFT ;; WLE
AR_lib_deps = https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3

animartrix_build_flags = -D USERMOD_ANIMARTRIX ;; WLEDMM usermod: CC BY-NC 3.0 licensed effects by Stefan Petrick
animartrix_lib_deps = https://github.com/netmindz/animartrix.git#ccb11dd9a4ec4ff6e7bdf617f6651cced4ed9826 ;; Speed fixes
animartrix_lib_deps = https://github.com/netmindz/animartrix.git#657f754783268b648e1d56b3cd31c810379d0c89 ;; Dirty state fix
animartrix_lib_ignore = animartrix ;; to remove the animartrix lib dependancy (saves a few bytes)

DMXin_build_flags = -D WLED_ENABLE_DMX_INPUT ;; WLEDMM DMX physical input - requires ESP-IDF v4.4.x
Expand Down
4 changes: 2 additions & 2 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4763,7 +4763,7 @@ class AuroraWave {
alive = true;
}

CRGB getColorForLED(int ledIndex) {
CRGB getColorForLED(int ledIndex) const {
if(ledIndex < center - width || ledIndex > center + width) return 0; //Position out of range of this wave

CRGB rgb;
Expand Down Expand Up @@ -4818,7 +4818,7 @@ class AuroraWave {
}
};

bool stillAlive() {
bool stillAlive() const {
return alive;
};
};
Expand Down
24 changes: 18 additions & 6 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ typedef struct Segment {
};
size_t _dataLen; // WLEDMM uint16_t is too small
static size_t _usedSegmentData; // WLEDMM uint16_t is too small
void setPixelColorXY_fast(int x, int y,uint32_t c, uint32_t scaled_col, int cols, int rows); // set relative pixel within segment with color - faster, but no error checking!!!
void setPixelColorXY_fast(int x, int y,uint32_t c, uint32_t scaled_col, int cols, int rows) const; // set relative pixel within segment with color - faster, but no error checking!!!

bool _isSimpleSegment = false; // simple = no grouping or spacing - mirror, transpose or reverse allowed
bool _isSuperSimpleSegment = false; // superSimple = no grouping or spacing, no mirror - only transpose or reverse allowed
Expand Down Expand Up @@ -609,7 +609,7 @@ typedef struct Segment {
// transition functions
void startTransition(uint16_t dur); // transition has to start before actual segment values change
void handleTransition(void);
uint16_t progress(void); //transition progression between 0-65535
uint16_t progress(void) const; //transition progression between 0-65535

// WLEDMM method inlined for speed (its called at each setPixelColor)
inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
Expand All @@ -624,7 +624,7 @@ typedef struct Segment {

uint8_t currentMode(uint8_t modeNew);
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal) const;
void setCurrentPalette(void);

// 1D strip
Expand Down Expand Up @@ -724,10 +724,21 @@ typedef struct Segment {

uint32_t scaled_col = (_brightness == 255) ? col : color_fade(col, _brightness); // calculate final color
setPixelColorXY_fast(x, y, col, scaled_col, int(_2dWidth), int(_2dHeight)); // call "fast" function
}
}
}
}
inline uint32_t getPixelColorXY(int x, int y) const {
// minimal sanity checks
if (!_isValid2D) return 0; // not active
if ((unsigned(x) >= _2dWidth) || (unsigned(y) >= _2dHeight)) return 0 ; // check if (x,y) are out-of-range - due to 2's complement, this also catches negative values
if (ledsrgb) {
int i = x + y*_2dWidth; // avoid error checking done by XY() - be optimistic about ranges of x and y
return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
}
else return getPixelColorXY_part2(x, y, int(_2dWidth), int(_2dHeight)); // call "no ledsrgb" function to retrieve pixel from bus driver
}
#else
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
uint32_t __attribute__((pure)) getPixelColorXY(int x, int y) const { return getPixelColorXY_slow(x,y);}
#endif
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColorXY(int(x), int(y), c); }
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
Expand All @@ -738,7 +749,8 @@ typedef struct Segment {
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColorXY(x, y, RGBW32(r,g,b,w), aa); }
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); }
//#endif
uint32_t __attribute__((pure)) getPixelColorXY(int x, int y) const;
uint32_t __attribute__((pure)) getPixelColorXY_part2(int x, int y, int cols, int rows) const;
uint32_t __attribute__((pure)) getPixelColorXY_slow(int x, int y) const;
// 2D support functions
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
inline void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); }
Expand Down
16 changes: 13 additions & 3 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void Segment::startFrame(void) {

// Simplified version of Segment::setPixelColorXY - without error checking. Does not support grouping or spacing
// * expects scaled color (final brightness) as additional input parameter, plus segment virtualWidth() and virtualHeight()
void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) //WLEDMM
void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) const //WLEDMM
{
unsigned i = UINT_MAX;
bool sameColor = false;
Expand Down Expand Up @@ -476,8 +476,18 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
#endif
}

// returns RGBW values of pixel
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const {
// WLEDMM this function is only called by getPixelColorXY, in case we don't have the ledsrgb buffer!
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY_part2(int x, int y, int cols, int rows) const {
if (reverse ) x = cols - x - 1;
if (reverse_y) y = rows - y - 1;
if (transpose) std::swap(x,y); // swap X & Y if segment transposed
const uint_fast16_t groupLength_ = groupLength(); // WLEDMM small optimization
x *= groupLength_; // expand to physical pixels
y *= groupLength_; // expand to physical pixels
return strip.getPixelColorXYRestored(start + x, startY + y);
}

uint32_t IRAM_ATTR_YN Segment::getPixelColorXY_slow(int x, int y) const { // WLEDMM fallback for non-fastpath builds
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
if (ledsrgb) {
int i = XY(x,y);
Expand Down
4 changes: 2 additions & 2 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void Segment::setUpLeds() {
}
}

CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) const {
static unsigned long _lastPaletteChange = millis() - 990000; // perhaps it should be per segment //WLEDMM changed init value to avoid pure orange after startup
static CRGBPalette16 randomPalette = CRGBPalette16(DEFAULT_COLOR);
static CRGBPalette16 prevRandomPalette = CRGBPalette16(CRGB(BLACK));
Expand Down Expand Up @@ -452,7 +452,7 @@ void Segment::startTransition(uint16_t dur) {
}

// transition progression between 0-65535
uint16_t IRAM_ATTR_YN Segment::progress() {
uint16_t IRAM_ATTR_YN Segment::progress() const {
if (!transitional || !_t) return 0xFFFFU;
unsigned long timeNow = millis();
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
Expand Down
12 changes: 6 additions & 6 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
USER_PRINT(F("heap usage: ")); USER_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
}

void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c) {
void __attribute__((hot)) IRAM_ATTR BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid || pix >= _len) return;
// if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT

Expand Down Expand Up @@ -1097,12 +1097,12 @@ void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c
#endif
}

uint32_t BusHub75Matrix::getPixelColor(uint16_t pix) const {
uint32_t IRAM_ATTR BusHub75Matrix::getPixelColor(uint16_t pix) const {
if (!_valid || pix >= _len || !_ledBuffer) return BLACK;
return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours
}

uint32_t __attribute__((hot)) BusHub75Matrix::getPixelColorRestored(uint16_t pix) const {
uint32_t __attribute__((hot)) IRAM_ATTR BusHub75Matrix::getPixelColorRestored(uint16_t pix) const {
if (!_valid || pix >= _len || !_ledBuffer) return BLACK;
return uint32_t(_ledBuffer[pix]) & 0x00FFFFFF;
}
Expand All @@ -1117,7 +1117,7 @@ void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) {
if (display) display->setBrightness(_bri);
}

void __attribute__((hot)) BusHub75Matrix::show(void) {
void __attribute__((hot)) IRAM_ATTR BusHub75Matrix::show(void) {
if (!_valid) return;
MatrixPanel_I2S_DMA* display = BusHub75Matrix::activeDisplay;
if (!display) return;
Expand Down Expand Up @@ -1277,8 +1277,8 @@ void BusManager::removeAll() {
lastend = 0;
}

void BusManager::show() {
for (uint8_t i = 0; i < numBusses; i++) {
void __attribute__((hot)) BusManager::show() {
for (unsigned i = 0; i < numBusses; i++) {
busses[i]->show();
}
}
Expand Down
2 changes: 1 addition & 1 deletion wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Bus {
inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
inline static uint8_t getGlobalAWMode() { return _gAWM; }

inline uint32_t restore_Color_Lossy(uint32_t c, uint8_t restoreBri) const { // shamelessly grabbed from upstream, who grabbed from NPB, who ..
inline static uint32_t restore_Color_Lossy(uint32_t c, uint8_t restoreBri) { // shamelessly grabbed from upstream, who grabbed from NPB, who ..
if (restoreBri < 255) {
uint8_t* chan = (uint8_t*) &c;
for (uint_fast8_t i=0; i<4; i++) {
Expand Down

0 comments on commit 350e80c

Please sign in to comment.