From 831b0f04b29991e4278ddd7c7248d794e316df4c Mon Sep 17 00:00:00 2001 From: Lierop Date: Tue, 5 Apr 2022 14:00:17 +0200 Subject: [PATCH 1/4] thunderstorm added to header file --- platformio.ini | 4 ++-- wled00/FX.h | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index dbbe06d88c..f002df6497 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ ; default_envs = travis_esp8266, travis_esp32 # Release binaries -default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3 +; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3 # Build everything ; default_envs = esp32dev, esp8285_4CH_MagicHome, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, travis_esp8266, travis_esp32, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips @@ -23,7 +23,7 @@ default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s ; default_envs = esp8266_2m ; default_envs = esp01_1m_full ; default_envs = esp07 -; default_envs = d1_mini +default_envs = d1_mini ; default_envs = heltec_wifi_kit_8 ; default_envs = h803wf ; default_envs = d1_mini_debug diff --git a/wled00/FX.h b/wled00/FX.h index aeefee35eb..6e3b37dceb 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -119,7 +119,7 @@ #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED ) -#define MODE_COUNT 118 +#define MODE_COUNT 119 #define FX_MODE_STATIC 0 #define FX_MODE_BLINK 1 @@ -239,6 +239,7 @@ #define FX_MODE_BLENDS 115 #define FX_MODE_TV_SIMULATOR 116 #define FX_MODE_DYNAMIC_SMOOTH 117 +#define FX_MODE_THUNDER_STORM 118 class WS2812FX { @@ -609,6 +610,7 @@ class WS2812FX { _mode[FX_MODE_BLENDS] = &WS2812FX::mode_blends; _mode[FX_MODE_TV_SIMULATOR] = &WS2812FX::mode_tv_simulator; _mode[FX_MODE_DYNAMIC_SMOOTH] = &WS2812FX::mode_dynamic_smooth; + _mode[FX_MODE_THUNDER_STORM] = &WS2812FX::mode_thunder_storm; _brightness = DEFAULT_BRIGHTNESS; currentPalette = CRGBPalette16(CRGB::Black); @@ -833,7 +835,8 @@ class WS2812FX { mode_candy_cane(void), mode_blends(void), mode_tv_simulator(void), - mode_dynamic_smooth(void); + mode_dynamic_smooth(void), + mode_thunder_storm(void); private: uint32_t crgb_to_col(CRGB fastled); @@ -936,7 +939,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","Candy Cane","Blends","TV Simulator","Dynamic Smooth" +"Flow","Chunchun","Dancing Shadows","Washing Machine","Candy Cane","Blends","TV Simulator","Dynamic Smooth","Thunder Storm" ])====="; From eeadfbde102f6d04c75aa5a363a189eab3f017bb Mon Sep 17 00:00:00 2001 From: Lierop Date: Tue, 5 Apr 2022 22:09:15 +0200 Subject: [PATCH 2/4] thunder storm function initiated --- wled00/FX.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ wled00/FX.h | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index fa6cb35513..e7a4f462d7 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4225,5 +4225,45 @@ uint16_t WS2812FX::mode_aurora(void) { setPixelColor(i, mixedRgb[0], mixedRgb[1], mixedRgb[2]); } + return FRAMETIME; +} + +/* + * Description comming.... + */ +uint16_t WS2812FX::mode_thunder_storm(void) { + + uint32_t color1 = WHITE; + uint32_t color2 = BLACK; + + // + uint16_t tiplength = 100 + random8(155); //0-255 + tiplength = (tiplength * (SEGLEN -1)) >> 8; + flare->vel = sqrt(-2.0 * gravity * peakHeight); + flare->col = 255; //brightness + // + + bool theatre = false; + uint8_t width = (theatre ? 3 : 1) + (SEGMENT.intensity >> 4); // window + uint32_t cycleTime = 50 + (255 - SEGMENT.speed); + uint32_t it = now / cycleTime; + bool usePalette = color1 == SEGCOLOR(0); + + for(uint16_t i = 0; i < SEGLEN; i++) { + uint32_t col = color2; + if (usePalette) color1 = color_from_palette(i, true, PALETTE_SOLID_WRAP, 0); + if (theatre) { + if ((i % width) == SEGENV.aux0) col = color1; + } else { + int8_t pos = (i % (width<<1)); + if ((pos < SEGENV.aux0-width) || ((pos >= SEGENV.aux0) && (pos < SEGENV.aux0+width))) col = color1; + } + setPixelColor(i,col); + } + + if (it != SEGENV.step) { + SEGENV.aux0 = (SEGENV.aux0 +1) % (theatre ? width : (width<<1)); + SEGENV.step = it; + } return FRAMETIME; } \ No newline at end of file diff --git a/wled00/FX.h b/wled00/FX.h index 6e3b37dceb..d425ac45a3 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -610,7 +610,7 @@ class WS2812FX { _mode[FX_MODE_BLENDS] = &WS2812FX::mode_blends; _mode[FX_MODE_TV_SIMULATOR] = &WS2812FX::mode_tv_simulator; _mode[FX_MODE_DYNAMIC_SMOOTH] = &WS2812FX::mode_dynamic_smooth; - _mode[FX_MODE_THUNDER_STORM] = &WS2812FX::mode_thunder_storm; + _mode[FX_MODE_THUNDER_STORM] = &WS2812FX::mode_thunder_storm; _brightness = DEFAULT_BRIGHTNESS; currentPalette = CRGBPalette16(CRGB::Black); From 59cdc61c7000378683321d70b8bedb3f203bef26 Mon Sep 17 00:00:00 2001 From: Laityned Date: Wed, 6 Apr 2022 00:26:34 +0200 Subject: [PATCH 3/4] First setup flare --- wled00/FX.cpp | 68 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index e7a4f462d7..c6b28e70ef 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4236,34 +4236,62 @@ uint16_t WS2812FX::mode_thunder_storm(void) { uint32_t color1 = WHITE; uint32_t color2 = BLACK; - // + // calculate location of the lighnting ending uint16_t tiplength = 100 + random8(155); //0-255 - tiplength = (tiplength * (SEGLEN -1)) >> 8; - flare->vel = sqrt(-2.0 * gravity * peakHeight); - flare->col = 255; //brightness - // + tiplength = (tiplength * (SEGLEN -1)) >> 8; + + //flare->vel = sqrt(-2.0 * gravity * peakHeight); + //flare->col = 255; //brightness - bool theatre = false; - uint8_t width = (theatre ? 3 : 1) + (SEGMENT.intensity >> 4); // window uint32_t cycleTime = 50 + (255 - SEGMENT.speed); uint32_t it = now / cycleTime; + + bool usePalette = color1 == SEGCOLOR(0); - for(uint16_t i = 0; i < SEGLEN; i++) { - uint32_t col = color2; - if (usePalette) color1 = color_from_palette(i, true, PALETTE_SOLID_WRAP, 0); - if (theatre) { - if ((i % width) == SEGENV.aux0) col = color1; - } else { - int8_t pos = (i % (width<<1)); - if ((pos < SEGENV.aux0-width) || ((pos >= SEGENV.aux0) && (pos < SEGENV.aux0+width))) col = color1; - } - setPixelColor(i,col); + + if(SEGENV.step < 1) { + SEGENV.aux0 = 0; + SEGENV.aux1 = tiplength; + SEGENV.step++; } + + if (SEGENV.step < 2) { + // draw initial ligtning + for(uint16_t i = 0; i < SEGLEN; i++) { + uint32_t col = color2; - if (it != SEGENV.step) { - SEGENV.aux0 = (SEGENV.aux0 +1) % (theatre ? width : (width<<1)); - SEGENV.step = it; + if (i < SEGENV.aux0) col = color1; + setPixelColor(i,col); + } + + // make ligthning longer + SEGENV.aux0++; + + + if ( SEGENV.aux0 > SEGENV.aux1) { + SEGENV.aux0 = 0; + SEGENV.aux1 = random16(15,30); + SEGENV.step++; + } + } + else if (SEGENV.step < 3) { + // black background + fill(BLACK); + + SEGENV.aux0++; + if ( SEGENV.aux0 > SEGENV.aux1) { + SEGENV.step++; + } } + else if (SEGENV.step < 4) { + fill(RED); + SEGENV.step = 8 + random(10); + } + else { + SEGENV.step--; + if(SEGENV.step < 4) SEGENV.step = 0; + } + return FRAMETIME; } \ No newline at end of file From e9fa5557c7a034b54a57939911ac92cfeaba2b75 Mon Sep 17 00:00:00 2001 From: Bigbengel Date: Tue, 12 Apr 2022 20:32:03 +0200 Subject: [PATCH 4/4] My first commit --- platformio.ini | 6 +- wled00/FX.cpp | 157 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 117 insertions(+), 46 deletions(-) diff --git a/platformio.ini b/platformio.ini index f002df6497..97b64e1709 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,11 +23,11 @@ ; default_envs = esp8266_2m ; default_envs = esp01_1m_full ; default_envs = esp07 -default_envs = d1_mini +; default_envs = d1_mini ; default_envs = heltec_wifi_kit_8 ; default_envs = h803wf ; default_envs = d1_mini_debug -; default_envs = d1_mini_ota +default_envs = d1_mini_ota ; default_envs = esp32dev ; default_envs = esp8285_4CH_MagicHome ; default_envs = esp8285_H801 @@ -405,7 +405,7 @@ lib_deps = ${esp8266.lib_deps} board = d1_mini upload_protocol = espota # exchange for your WLED IP -upload_port = "10.10.1.27" +upload_port = "192.168.178.32" platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_4m1m} diff --git a/wled00/FX.cpp b/wled00/FX.cpp index c6b28e70ef..129c12afa5 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -4232,66 +4232,137 @@ uint16_t WS2812FX::mode_aurora(void) { * Description comming.... */ uint16_t WS2812FX::mode_thunder_storm(void) { - - uint32_t color1 = WHITE; - uint32_t color2 = BLACK; - - // calculate location of the lighnting ending - uint16_t tiplength = 100 + random8(155); //0-255 - tiplength = (tiplength * (SEGLEN -1)) >> 8; - - //flare->vel = sqrt(-2.0 * gravity * peakHeight); - //flare->col = 255; //brightness + uint16_t maxData = FAIR_DATA_PER_SEG; //ESP8266: 256 ESP32: 640 + uint8_t segs = getActiveSegmentsNum(); + if (segs <= (MAX_NUM_SEGMENTS /2)) maxData *= 2; //ESP8266: 512 if <= 8 segs ESP32: 1280 if <= 16 segs + if (segs <= (MAX_NUM_SEGMENTS /4)) maxData *= 2; //ESP8266: 1024 if <= 4 segs ESP32: 2560 if <= 8 segs + int maxSparks = maxData / sizeof(spark); //ESP8266: max. 21/42/85 sparks/seg, ESP32: max. 53/106/213 sparks/seg - uint32_t cycleTime = 50 + (255 - SEGMENT.speed); - uint32_t it = now / cycleTime; + uint16_t numSparks = min(2 + (SEGLEN >> 1), maxSparks); + uint16_t dataSize = sizeof(spark) * numSparks; + if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed + uint32_t color1 = GREEN; + uint32_t color2 = RED; - bool usePalette = color1 == SEGCOLOR(0); + fill(BLACK); + bool actuallyReverse = SEGMENT.getOption(SEG_OPTION_REVERSED); + //have bolt start in either direction based on intensity + SEGMENT.setOption(SEG_OPTION_REVERSED, SEGENV.step); + + // calculate location of the bolt ending, bolt speed and duration of the running of the bolt + Spark* bolt = reinterpret_cast(SEGENV.data); + float boltspeed = 0.0004 + (SEGMENT.speed/8000.0); // m/s/s + boltspeed *= SEGLEN; + bolt->vel = boltspeed; - if(SEGENV.step < 1) { - SEGENV.aux0 = 0; - SEGENV.aux1 = tiplength; - SEGENV.step++; - } - if (SEGENV.step < 2) { - // draw initial ligtning - for(uint16_t i = 0; i < SEGLEN; i++) { - uint32_t col = color2; + if (SEGENV.aux0 < 2) { //Bolt + if (SEGENV.aux0 == 0) { //init bolt + uint16_t boltlength = 100 + random8(155); //0-255 + boltlength = (boltlength * (SEGLEN -1)) >> 8; + SEGENV.aux1 = boltlength; + bolt->pos = 0; + bolt->col = 255; //brightness - if (i < SEGENV.aux0) col = color1; - setPixelColor(i,col); + SEGENV.aux0 = 1; } - // make ligthning longer - SEGENV.aux0++; + // start + if (bolt->pos < SEGENV.aux1) { + // bolt + setPixelColor(int(bolt->pos),(bolt->col * color_from_palette(bolt->pos, true, PALETTE_SOLID_WRAP, 0)) >> 8); //color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum) + for (int i = bolt->pos -1; i > 0; i--) + { + setPixelColor(i,bolt->col >> 4,bolt->col >> 4,bolt->col >> 4); + } + + bolt->pos += bolt->vel; + bolt->pos = constrain(bolt->pos, 0, SEGLEN-1); + } else if (bolt->pos >= SEGENV.aux1) { + SEGENV.aux0 = 2; + } + } - if ( SEGENV.aux0 > SEGENV.aux1) { - SEGENV.aux0 = 0; - SEGENV.aux1 = random16(15,30); - SEGENV.step++; + else if (SEGENV.aux0 == 2) { + for (int i = SEGENV.aux1; i > 0; i--) { + setPixelColor(i,bolt->col,bolt->col,bolt->col); + } + bolt->col -= (1 + (SEGMENT.speed/8.0)); + + if (bolt->col < 50) { + SEGENV.aux0 = 3; } } - else if (SEGENV.step < 3) { - // black background - fill(BLACK); - - SEGENV.aux0++; - if ( SEGENV.aux0 > SEGENV.aux1) { - SEGENV.step++; + + else if (SEGENV.aux0 == 3) { + for (int i = SEGENV.aux1; i > 0; i--) { + setPixelColor(i,bolt->col,bolt->col,bolt->col); + } + bolt->col += (1 + (SEGMENT.speed/8.0)); + + if (bolt->col > 220) { + SEGENV.aux0 = 4; + } + } + + else if (SEGENV.aux0 == 4) { + for (int i = SEGENV.aux1; i > 0; i--) { + setPixelColor(i,bolt->col,bolt->col,bolt->col); + } + bolt->col -= (1 + (SEGMENT.speed/8.0)); + + if (bolt->col < 35) { + SEGENV.aux0 = 5; } } - else if (SEGENV.step < 4) { - fill(RED); - SEGENV.step = 8 + random(10); + + else if (SEGENV.aux0 == 5) { + fill(BLACK); + SEGENV.aux0 = 10 + random8(30); } else { - SEGENV.step--; - if(SEGENV.step < 4) SEGENV.step = 0; + SEGENV.aux0--; + if (SEGENV.aux0 < 7) { + SEGENV.aux0 = 0; //back to begin + SEGENV.step = actuallyReverse ^ (SEGMENT.intensity > random8()); + } + } + + return FRAMETIME; +} + + + +/* +// Blinking part ################################# +uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_palette) { + uint32_t cycleTime = (255 - SEGMENT.speed)*20; + uint32_t onTime = FRAMETIME; + if (!strobe) onTime += ((cycleTime * SEGMENT.intensity) >> 8); + cycleTime += FRAMETIME*2; + uint32_t it = now / cycleTime; + uint32_t rem = now % cycleTime; + + bool on = false; + if (it != SEGENV.step //new iteration, force on state for one frame, even if set time is too brief + || rem <= onTime) { + on = true; } + SEGENV.step = it; //save previous iteration + + uint32_t color = on ? color1 : color2; + if (color == color1 && do_palette) + { + for(uint16_t i = 0; i < SEGLEN; i++) { + setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); + } + } else fill(color); + return FRAMETIME; -} \ No newline at end of file + */ + + \ No newline at end of file