From 1e3834dc3d06aba42b52ebb5188abe361cfc1ffc Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sun, 27 Sep 2020 14:42:14 +0200 Subject: [PATCH] Move tristate_square8 to FX_fcn.cpp --- wled00/FX.cpp | 38 ++++++-------------------------------- wled00/FX.h | 5 ++++- wled00/FX_fcn.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 611451fd..b3888488 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3713,45 +3713,19 @@ uint16_t WS2812FX::mode_dancing_shadows(void) return FRAMETIME; } -/* - * Generates a tristate square wave w/ attac & decay - * @param x input value 0-255 - * @param pulsewidth 0-127 - * @param attdec attac & decay, max. pulsewidth / 2 - * @returns signed waveform value - */ -int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) { - int8_t a; - if (x > 127) { - a = -127; - x -= 127; - } - else - a = 127; - - if (x < attdec) { //inc to max - return (int16_t) x * a / attdec; - } - else if (x < pulsewidth - attdec) { //max - return a; - } - else if (x < pulsewidth) { //dec to 0 - return (int16_t) (pulsewidth - x) * a / attdec; - } - return 0; -} - /* Imitates a washing machine, rotating same waves forward, then pause, then backward. By Stefan Seegel */ uint16_t WS2812FX::mode_washing_machine(void) { - int8_t speed= tristate_square8((uint16_t) (SEGMENT.speed + 100) * now / 20000, 90, 15) / 15; - - SEGENV.step += speed; + float speed = tristate_square8(now >> 7, 90, 15); + float quot = 32.0f - ((float)SEGMENT.speed / 16.0f); + speed /= quot; + + SEGENV.step += (speed * 128.0f); for (int i=0; i> 7)); setPixelColor(i, color_from_palette(col, false, PALETTE_SOLID_WRAP, 3)); } diff --git a/wled00/FX.h b/wled00/FX.h index 3e8c70c4..e3c170f7 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -487,6 +487,9 @@ class WS2812FX { gamma8(uint8_t), get_random_wheel_index(uint8_t); + int8_t + tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec); + uint16_t ablMilliampsMax, currentMilliamps, @@ -715,7 +718,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([ "Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst", "Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow", "Heartbeat","Pacifica","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise", -"Flow","Chunchun","Dancing Shadows", "Washing machine" +"Flow","Chunchun","Dancing Shadows","Washing Machine" ])====="; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 20bed951..56fdb98a 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -699,6 +699,32 @@ uint16_t WS2812FX::triwave16(uint16_t in) return 0xFFFF - (in - 0x8000)*2; } +/* + * Generates a tristate square wave w/ attac & decay + * @param x input value 0-255 + * @param pulsewidth 0-127 + * @param attdec attac & decay, max. pulsewidth / 2 + * @returns signed waveform value + */ +int8_t WS2812FX::tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) { + int8_t a = 127; + if (x > 127) { + a = -127; + x -= 127; + } + + if (x < attdec) { //inc to max + return (int16_t) x * a / attdec; + } + else if (x < pulsewidth - attdec) { //max + return a; + } + else if (x < pulsewidth) { //dec to 0 + return (int16_t) (pulsewidth - x) * a / attdec; + } + return 0; +} + /* * Put a value 0 to 255 in to get a color value. * The colours are a transition r -> g -> b -> back to r @@ -844,7 +870,7 @@ void WS2812FX::handle_palette(void) load_gradient_palette(paletteIndex -13); } - if (singleSegmentMode && paletteFade) //only blend if just one segment uses FastLED mode + if (singleSegmentMode && paletteFade && SEGENV.call > 0) //only blend if just one segment uses FastLED mode { nblendPaletteTowardPalette(currentPalette, targetPalette, 48); } else