diff --git a/wled00/FX.cpp b/wled00/FX.cpp index c3b8ed092..96880f4d8 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1025,15 +1025,22 @@ uint16_t WS2812FX::larson_scanner(bool dual) { /* - * Firing comets from one end. + * Firing comets from one end. "Lighthouse" */ uint16_t WS2812FX::mode_comet(void) { - uint16_t counter = now * (SEGMENT.speed >>3) +1; + uint16_t counter = now * ((SEGMENT.speed >>2) +1); uint16_t index = counter * SEGLEN >> 16; + if (SEGENV.call == 0) SEGENV.aux0 = index; fade_out(SEGMENT.intensity); setPixelColor( index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); + if (index > SEGENV.aux0) { + for (uint16_t i = SEGENV.aux0; i < index ; i++) { + setPixelColor( i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); + } + } + SEGENV.aux0 = index++; return FRAMETIME; } @@ -1172,19 +1179,26 @@ uint16_t WS2812FX::mode_loading(void) { //American Police Light with all LEDs Red and Blue uint16_t WS2812FX::police_base(uint32_t color1, uint32_t color2) { - uint16_t counter = now * ((SEGMENT.speed >> 3) +1); + uint16_t counter = now * ((SEGMENT.speed >> 2) +1); uint16_t idexR = (counter * SEGLEN) >> 16; if (idexR >= SEGLEN) idexR = 0; uint16_t topindex = SEGLEN >> 1; uint16_t idexB = idexR + topindex; - + if (SEGENV.call == 0) SEGENV.aux0 = idexR; + if (idexR > topindex) idexB -= SEGLEN; if (idexB >= SEGLEN) idexB = 0; //otherwise overflow on odd number of LEDs - setPixelColor(idexR, color1); - setPixelColor(idexB, color2); - + uint8_t gap = (SEGENV.aux0 < idexR)? idexR - SEGENV.aux0:SEGLEN - SEGENV.aux0 + idexR; + for (uint8_t i = 0; i < gap ; i++) { + if ((idexR - i) < 0) idexR = SEGLEN-1 + i; + if ((idexB - i) < 0) idexB = SEGLEN-1 + i; + setPixelColor(idexR-i, color1); + setPixelColor(idexB-i, color2); + } + SEGENV.aux0 = idexR; + return FRAMETIME; } @@ -2486,22 +2500,33 @@ uint16_t WS2812FX::mode_bouncing_balls(void) { */ uint16_t WS2812FX::sinelon_base(bool dual, bool rainbow=false) { fade_out(SEGMENT.intensity); - int pos = beatsin16(SEGMENT.speed/10,0,SEGLEN-1); - + uint16_t pos = beatsin16(SEGMENT.speed/10,0,SEGLEN-1); + if (SEGENV.call == 0) SEGENV.aux0 = pos; uint32_t color1 = color_from_palette(pos, true, false, 0); + uint32_t color2 = SEGCOLOR(2); if (rainbow) { color1 = color_wheel((pos & 0x07) * 32); } setPixelColor(pos, color1); - if (dual) { - uint32_t color2 = SEGCOLOR(2); - if (!color2) color2 = color_from_palette(pos, true, false, 0); if (rainbow) color2 = color1; //rainbow - setPixelColor(SEGLEN-1-pos, color2); } + if (SEGENV.aux0 != pos) { + if (SEGENV.aux0 < pos) { + for (uint16_t i = SEGENV.aux0; i < pos ; i++) { + setPixelColor(i, color1); + if (dual) setPixelColor(SEGLEN-1-i, color2); + } + } else { + for (uint16_t i = SEGENV.aux0; i > pos ; i--) { + setPixelColor(i, color1); + if (dual) setPixelColor(SEGLEN-1-i, color2); + } + } + SEGENV.aux0 = pos; + } return FRAMETIME; } @@ -2985,23 +3010,26 @@ uint16_t WS2812FX::mode_plasma(void) { uint16_t WS2812FX::mode_percent(void) { uint8_t percent = max(0, min(100, SEGMENT.intensity)); - - float active_float = SEGLEN * percent / 100.0; - uint16_t active_leds = active_float; - uint16_t active_part = (active_float - active_leds) * 255; - CRGB color; - - for (uint16_t i = 0; i < SEGLEN; i++) { - if (i < active_leds) { + uint16_t active_leds = SEGLEN * percent / 100.0; + + if (SEGENV.call == 0) SEGENV.step = 0; + uint8_t size = (1 + ((SEGMENT.speed * SEGLEN) >> 11)) & 0xFF ; + + for (uint16_t i = 0; i < SEGLEN; i++) { + if (i < SEGENV.step) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); } - else if (i == active_leds) { - setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, active_part)); - } else { setPixelColor(i, SEGCOLOR(1)); } - } + } + if(active_leds > SEGENV.step) { + SEGENV.step += size; + if (SEGENV.step > active_leds) SEGENV.step = active_leds; + } else if (active_leds < SEGENV.step) { + SEGENV.step -= size; + if (SEGENV.step < active_leds) SEGENV.step = active_leds; + } - return FRAMETIME; + return FRAMETIME; } \ No newline at end of file diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 22625c29a..7c87a2920 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -469,7 +469,19 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, if (seg.stop) setRange(seg.start, seg.stop -1, 0); //turn old segment range off if (i2 <= i1) //disable segment { - seg.stop = 0; return; + seg.stop = 0; + if (n == mainSegment) //if main segment is deleted, set first active as main segment + { + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) + { + if (_segments[i].isActive()) { + mainSegment = i; + return; + } + } + mainSegment = 0; //should not happen (always at least one active segment) + } + return; } if (i1 < _length) seg.start = i1; seg.stop = i2; @@ -482,6 +494,7 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, } void WS2812FX::resetSegments() { + mainSegment = 0; memset(_segments, 0, sizeof(_segments)); //memset(_segment_runtimes, 0, sizeof(_segment_runtimes)); _segment_index = 0; diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 6cfe3e181..9f3915568 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -9,7 +9,7 @@ //#define USE_LPD8806 // Uncomment for using LPD8806 //#define WLED_USE_ANALOG_LEDS //Uncomment for using "dumb" PWM controlled LEDs (see pins below, default R: gpio5, G: 12, B: 15, W: 13) //#define WLED_USE_H801 //H801 controller. Please uncomment #define WLED_USE_ANALOG_LEDS as well -//#define WLED_USE_5CH //5 Channel H801 for cold and warm white +//#define WLED_USE_5CH_LEDS //5 Channel H801 for cold and warm white #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) #define IR_PIN 4 //infrared pin (-1 to disable) MagicHome: 4, H801 Wifi: 0 @@ -34,7 +34,7 @@ #define RPIN 15 //R pin for analog LED strip #define GPIN 13 //G pin for analog LED strip #define BPIN 12 //B pin for analog LED strip - #define WPIN 14 //W pin for analog LED strip (W1: 14, W2: 04) + #define WPIN 14 //W pin for analog LED strip #define W2PIN 04 //W2 pin for analog LED strip #undef BTNPIN #undef IR_PIN @@ -44,7 +44,7 @@ #define RPIN 5 //R pin for analog LED strip #define GPIN 12 //G pin for analog LED strip #define BPIN 15 //B pin for analog LED strip - #define WPIN 13 //W pin for analog LED strip (W1: 14, W2: 04) + #define WPIN 13 //W pin for analog LED strip #endif #undef RLYPIN #define RLYPIN -1 //disable as pin 12 is used by analog LEDs diff --git a/wled00/html_settings.h b/wled00/html_settings.h index d6cf7490d..44f9842b8 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -189,7 +189,7 @@ const char PAGE_settings_sync[] PROGMEM = R"=====(