mirror of
https://github.com/wled/WLED.git
synced 2025-07-09 20:06:33 +00:00
Bugfixes.
- removed IS_ macors - replaced .options with getOptions() - Fire2012 matrix fix
This commit is contained in:
parent
d6883d0c1c
commit
adb7726974
@ -1851,23 +1851,31 @@ uint16_t WS2812FX::mode_fire_2012()
|
||||
{
|
||||
uint32_t it = now >> 5; //div 32
|
||||
uint16_t nFlames = SEGMENT.virtualHeight();
|
||||
uint16_t q = SEGLEN>>2; // a quarter of segment
|
||||
uint16_t q = nFlames>>2; // a quarter of segment height
|
||||
|
||||
if (!SEGENV.allocateData(SEGLEN*nFlames)) return mode_static(); //allocation failed
|
||||
|
||||
byte* heat = SEGENV.data;
|
||||
|
||||
for (uint16_t f = 0; f < nFlames; f++) {
|
||||
if (it != SEGENV.step) {
|
||||
uint8_t ignition = max(3,SEGLEN/10); // ignition area: 10% of segment length or minimum 3 pixels
|
||||
if (SEGENV.call == 0) {
|
||||
DEBUG_PRINTLN(nFlames);
|
||||
DEBUG_PRINTLN(SEGLEN);
|
||||
DEBUG_PRINTLN(nFlames*SEGLEN);
|
||||
DEBUG_PRINTLN(q);
|
||||
}
|
||||
|
||||
if (it != SEGENV.step) {
|
||||
SEGENV.step = it;
|
||||
uint8_t ignition = max(3,SEGLEN/10); // ignition area: 10% of segment length or minimum 3 pixels
|
||||
|
||||
for (uint16_t f = 0; f < nFlames; f++) {
|
||||
// Step 1. Cool down every cell a little
|
||||
for (uint16_t i = 0; i < SEGLEN; i++) {
|
||||
uint8_t cool = (((20 + SEGMENT.speed /3) * 10) / SEGLEN);
|
||||
// 2D enhancement: cool sides of the flame a bit more
|
||||
if (nFlames>1) {
|
||||
if (i < q) cool += (uint16_t)((cool * (q-i))/SEGLEN); // cool sides a bit more
|
||||
if (i > 3*q) cool += (uint16_t)((cool * (SEGLEN-i))/SEGLEN); // cool sides a bit more
|
||||
if (nFlames>5) {
|
||||
if (f < q) qadd8(cool, (uint16_t)((cool * (q-f))/nFlames)); // cool segment sides a bit more
|
||||
if (f > 3*q) qadd8(cool, (uint16_t)((cool * (nFlames-f))/nFlames)); // cool segment sides a bit more
|
||||
}
|
||||
uint8_t temp = qsub8(heat[i+SEGLEN*f], random8(0, cool + 2));
|
||||
heat[i+SEGLEN*f] = (temp==0 && i<ignition) ? 16 : temp; // prevent ignition area from becoming black
|
||||
@ -1883,14 +1891,13 @@ uint16_t WS2812FX::mode_fire_2012()
|
||||
uint8_t y = random8(ignition);
|
||||
if (y < SEGLEN) heat[y+SEGLEN*f] = qadd8(heat[y+SEGLEN*f], random8(160,255));
|
||||
}
|
||||
SEGENV.step = it;
|
||||
}
|
||||
|
||||
// Step 4. Map from heat cells to LED colors
|
||||
for (uint16_t j = 0; j < SEGLEN; j++) {
|
||||
CRGB color = ColorFromPalette(currentPalette, MIN(heat[j],240), 255, LINEARBLEND);
|
||||
if (nFlames==1) setPixelColor(j, color);
|
||||
else setPixelColorXY(j, f, color);
|
||||
// Step 4. Map from heat cells to LED colors
|
||||
for (uint16_t j = 0; j < SEGLEN; j++) {
|
||||
CRGB color = ColorFromPalette(currentPalette, MIN(heat[j+SEGLEN*f],240), 255, LINEARBLEND);
|
||||
if (isMatrix) setPixelColorXY(j, f, color);
|
||||
else setPixelColor(j, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
return FRAMETIME;
|
||||
@ -3730,7 +3737,7 @@ uint16_t WS2812FX::mode_flow(void)
|
||||
{
|
||||
uint8_t colorIndex = (i * 255 / zoneLen) - counter;
|
||||
uint16_t led = (z & 0x01) ? i : (zoneLen -1) -i;
|
||||
if (IS_REVERSE) led = (zoneLen -1) -led;
|
||||
if (SEGMENT.getOption(SEG_OPTION_REVERSED)) led = (zoneLen -1) -led;
|
||||
setPixelColor(pos + led, color_from_palette(colorIndex, false, true, 255));
|
||||
}
|
||||
}
|
||||
@ -4300,7 +4307,7 @@ uint16_t WS2812FX::mode_2DBlackHole_B() { // By: Stepko https://edito
|
||||
setPixelColorXY(x, y, col_to_crgb(getPixelColorXY(x,y)) + CHSV(i*32, 255, 255));
|
||||
}
|
||||
setPixelColorXY(w/2, h/2, WHITE);
|
||||
blur2d(16);
|
||||
//blur2d(16);
|
||||
return FRAMETIME;
|
||||
} // mode_2DBlackHole()
|
||||
|
||||
|
28
wled00/FX.h
28
wled00/FX.h
@ -111,22 +111,14 @@
|
||||
// bit 1: reverse segment
|
||||
// bit 0: segment is selected
|
||||
#define NO_OPTIONS (uint8_t)0x00
|
||||
#define TRANSITIONAL (uint8_t)0x80
|
||||
#define TRANSPOSED (uint8_t)0x40 // rotated 90deg & reversed
|
||||
#define REVERSE_Y_2D (uint8_t)0x20
|
||||
#define MIRROR_Y_2D (uint8_t)0x10
|
||||
#define MIRROR (uint8_t)0x08
|
||||
#define SEGMENT_ON (uint8_t)0x04
|
||||
#define REVERSE (uint8_t)0x02
|
||||
#define SELECTED (uint8_t)0x01
|
||||
#define IS_TRANSITIONAL ((SEGMENT.options & TRANSITIONAL) == TRANSITIONAL)
|
||||
#define IS_MIRROR ((SEGMENT.options & MIRROR ) == MIRROR )
|
||||
#define IS_SEGMENT_ON ((SEGMENT.options & SEGMENT_ON ) == SEGMENT_ON )
|
||||
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
|
||||
#define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED )
|
||||
#define IS_REVERSE_Y_2D ((SEGMENT.options & REVERSE_Y_2D) == REVERSE_Y_2D)
|
||||
#define IS_MIRROR_Y_2D ((SEGMENT.options & MIRROR_Y_2D ) == MIRROR_Y_2D )
|
||||
#define IS_TRANSPOSED ((SEGMENT.options & TRANSPOSED ) == TRANSPOSED )
|
||||
#define TRANSPOSED (uint8_t)0x400 // rotated 90deg & reversed
|
||||
#define REVERSE_Y_2D (uint8_t)0x200
|
||||
#define MIRROR_Y_2D (uint8_t)0x100
|
||||
#define TRANSITIONAL (uint8_t)0x080
|
||||
#define MIRROR (uint8_t)0x008
|
||||
#define SEGMENT_ON (uint8_t)0x004
|
||||
#define REVERSE (uint8_t)0x002
|
||||
#define SELECTED (uint8_t)0x001
|
||||
|
||||
#define MODE_COUNT 120
|
||||
|
||||
@ -284,8 +276,8 @@ class WS2812FX {
|
||||
inline bool getOption(uint8_t n) { return ((options >> n) & 0x01); }
|
||||
inline bool isSelected() { return getOption(0); }
|
||||
inline bool isActive() { return stop > start; }
|
||||
inline uint16_t width() { return options & TRANSPOSED ? stopY - startY : stop - start; }
|
||||
inline uint16_t height() { return options & TRANSPOSED ? stop - start : stopY - startY; }
|
||||
inline uint16_t width() { return getOption(SEG_OPTION_TRANSPOSED) ? stopY - startY : stop - start; }
|
||||
inline uint16_t height() { return getOption(SEG_OPTION_TRANSPOSED) ? stop - start : stopY - startY; }
|
||||
inline uint16_t length() { return width(); }
|
||||
inline uint16_t groupLength() { return grouping + spacing; }
|
||||
inline uint8_t getLightCapabilities() { return _capabilities; }
|
||||
|
@ -131,9 +131,9 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(uint16_t x, uint16_t y, byte r, byte g,
|
||||
}
|
||||
uint32_t col = RGBW32(r, g, b, w);
|
||||
|
||||
uint16_t width = _segments[segIdx].virtualWidth(); // segment width in logical pixels (includes mirror)
|
||||
uint16_t height = _segments[segIdx].virtualHeight(); // segment height in logical pixels (includes mirror)
|
||||
if (_segments[segIdx].options & TRANSPOSED ) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||
uint16_t width = _segments[segIdx].virtualWidth(); // segment width in logical pixels (includes grouping, spacing, mirror & transposed)
|
||||
uint16_t height = _segments[segIdx].virtualHeight(); // segment height in logical pixels (includes grouping, spacing, mirror & transposed)
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||
|
||||
x *= _segments[segIdx].groupLength();
|
||||
y *= _segments[segIdx].groupLength();
|
||||
@ -144,19 +144,19 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(uint16_t x, uint16_t y, byte r, byte g,
|
||||
uint16_t index, xX = (x+g), yY = (y+j);
|
||||
if (xX >= width || yY >= height) continue; // we have reached one dimension's end
|
||||
|
||||
if (_segments[segIdx].options & REVERSE ) xX = width - xX - 1;
|
||||
if (_segments[segIdx].options & REVERSE_Y_2D) yY = height - yY - 1;
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_REVERSED) ) xX = width - xX - 1;
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_REVERSED_Y)) yY = height - yY - 1;
|
||||
|
||||
index = XY(xX, yY, segIdx);
|
||||
if (index < customMappingSize) index = customMappingTable[index];
|
||||
busses.setPixelColor(index, col);
|
||||
|
||||
if (_segments[segIdx].options & MIRROR) { //set the corresponding horizontally mirrored pixel
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel
|
||||
index = XY(_segments[segIdx].width() - xX - 1, yY, segIdx);
|
||||
if (index < customMappingSize) index = customMappingTable[index];
|
||||
busses.setPixelColor(index, col);
|
||||
}
|
||||
if (_segments[segIdx].options & MIRROR_Y_2D) { //set the corresponding vertically mirrored pixel
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_MIRROR_Y)) { //set the corresponding vertically mirrored pixel
|
||||
index = XY(xX, _segments[segIdx].height() - yY - 1, segIdx);
|
||||
if (index < customMappingSize) index = customMappingTable[index];
|
||||
busses.setPixelColor(index, col);
|
||||
@ -171,14 +171,14 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y)
|
||||
uint8_t segIdx = _segment_index;
|
||||
uint16_t width = _segments[segIdx].virtualWidth(); // segment width in logical pixels
|
||||
uint16_t height = _segments[segIdx].virtualHeight(); // segment height in logical pixels
|
||||
if (_segments[segIdx].options & TRANSPOSED ) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||
|
||||
x *= _segments[segIdx].groupLength();
|
||||
y *= _segments[segIdx].groupLength();
|
||||
if (x >= width || y >= height) return 0;
|
||||
|
||||
if (_segments[segIdx].options & REVERSE ) x = width - x - 1;
|
||||
if (_segments[segIdx].options & REVERSE_Y_2D) y = height - y - 1;
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_REVERSED) ) x = width - x - 1;
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_REVERSED_Y)) y = height - y - 1;
|
||||
|
||||
uint16_t index = XY(x, y, segIdx);
|
||||
if (index < customMappingSize) index = customMappingTable[index];
|
||||
|
@ -152,7 +152,7 @@ void WS2812FX::service() {
|
||||
SEGLEN = SEGMENT.virtualLength();
|
||||
_bri_t = SEGMENT.opacity; _colors_t[0] = SEGMENT.colors[0]; _colors_t[1] = SEGMENT.colors[1]; _colors_t[2] = SEGMENT.colors[2];
|
||||
uint8_t _cct_t = SEGMENT.cct;
|
||||
if (!IS_SEGMENT_ON) _bri_t = 0;
|
||||
if (!SEGMENT.getOption(SEG_OPTION_ON)) _bri_t = 0;
|
||||
for (uint8_t t = 0; t < MAX_NUM_TRANSITIONS; t++) {
|
||||
if ((transitions[t].segment & 0x3F) != i) continue;
|
||||
uint8_t slot = transitions[t].segment >> 6;
|
||||
@ -208,8 +208,8 @@ void IRAM_ATTR WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte
|
||||
|
||||
// get physical pixel address (taking into account start, grouping, spacing [and offset])
|
||||
i = i * _segments[segIdx].groupLength();
|
||||
if (_segments[segIdx].options & REVERSE) { // is segment reversed?
|
||||
if (_segments[segIdx].options & MIRROR) { // is segment mirrored?
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_REVERSED)) { // is segment reversed?
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_MIRROR)) { // is segment mirrored?
|
||||
i = (len - 1) / 2 - i; //only need to index half the pixels
|
||||
} else {
|
||||
i = (len - 1) - i;
|
||||
@ -219,10 +219,10 @@ void IRAM_ATTR WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte
|
||||
|
||||
// set all the pixels in the group
|
||||
for (uint16_t j = 0; j < _segments[segIdx].grouping; j++) {
|
||||
uint16_t indexSet = i + ((_segments[segIdx].options & REVERSE) ? -j : j);
|
||||
uint16_t indexSet = i + ((_segments[segIdx].getOption(SEG_OPTION_REVERSED)) ? -j : j);
|
||||
if (indexSet >= _segments[segIdx].start && indexSet < _segments[segIdx].stop) {
|
||||
|
||||
if (_segments[segIdx].options & MIRROR) { //set the corresponding mirrored pixel
|
||||
if (_segments[segIdx].getOption(SEG_OPTION_MIRROR)) { //set the corresponding mirrored pixel
|
||||
uint16_t indexMir = _segments[segIdx].stop - indexSet + _segments[segIdx].start - 1;
|
||||
indexMir += _segments[segIdx].offset; // offset/phase
|
||||
if (indexMir >= _segments[segIdx].stop) indexMir -= len; // wrap
|
||||
@ -502,9 +502,9 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
|
||||
|
||||
// get physical pixel
|
||||
i = i * SEGMENT.groupLength();;
|
||||
if (IS_REVERSE) {
|
||||
if (IS_MIRROR) i = (SEGMENT.length() - 1) / 2 - i; //only need to index half the pixels
|
||||
else i = (SEGMENT.length() - 1) - i;
|
||||
if (SEGMENT.getOption(SEG_OPTION_REVERSED)) {
|
||||
if (SEGMENT.getOption(SEG_OPTION_MIRROR)) i = (SEGMENT.length() - 1) / 2 - i; //only need to index half the pixels
|
||||
else i = (SEGMENT.length() - 1) - i;
|
||||
}
|
||||
i += SEGMENT.start;
|
||||
|
||||
|
@ -225,7 +225,7 @@
|
||||
#define SEG_OPTION_TRANSITIONAL 7
|
||||
#define SEG_OPTION_REVERSED_Y 8
|
||||
#define SEG_OPTION_MIRROR_Y 9
|
||||
#define SEG_OPTION_TRANSPOSE 10
|
||||
#define SEG_OPTION_TRANSPOSED 10
|
||||
|
||||
//Segment differs return byte
|
||||
#define SEG_DIFFERS_BRI 0x01
|
||||
|
@ -153,7 +153,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
// 2D options
|
||||
seg.setOption(SEG_OPTION_REVERSED_Y, elem[F("rY")] | seg.getOption(SEG_OPTION_REVERSED_Y));
|
||||
seg.setOption(SEG_OPTION_MIRROR_Y , elem[F("mY")] | seg.getOption(SEG_OPTION_MIRROR_Y ));
|
||||
seg.setOption(SEG_OPTION_TRANSPOSE , elem[F("tp")] | seg.getOption(SEG_OPTION_TRANSPOSE ));
|
||||
seg.setOption(SEG_OPTION_TRANSPOSED, elem[F("tp")] | seg.getOption(SEG_OPTION_TRANSPOSED));
|
||||
|
||||
byte fx = seg.mode;
|
||||
if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value)
|
||||
@ -442,7 +442,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
|
||||
if (strip.isMatrix) {
|
||||
root[F("rY")] = seg.getOption(SEG_OPTION_REVERSED_Y);
|
||||
root[F("mY")] = seg.getOption(SEG_OPTION_MIRROR_Y);
|
||||
root[F("tp")] = seg.getOption(SEG_OPTION_TRANSPOSE);
|
||||
root[F("tp")] = seg.getOption(SEG_OPTION_TRANSPOSED);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user