From f3b399b31f0defc21228554d397231c61aab8c84 Mon Sep 17 00:00:00 2001 From: Def3nder <33399267+Def3nder@users.noreply.github.com> Date: Tue, 28 Jan 2020 13:48:59 +0100 Subject: [PATCH] Fix Police All, Sinelon and Lighthouse (Comet) effects (#634) --- wled00/FX.cpp | 51 +++++++++++++++++++++++++++++++++------------ wled00/NpbWrapper.h | 4 ++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 5c24efdb4..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; } diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index c5d556f26..9f3915568 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -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