From b224a67ea7b88265845d5341ae5ed8bb1ecf37b9 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 22 May 2019 00:23:09 +0200 Subject: [PATCH] Refactored WS2812FX variable names --- wled00/NpbWrapper.h | 16 +- wled00/WS2812FX.cpp | 782 +++++++++++++++++++-------------------- wled00/WS2812FX.h | 50 ++- wled00/WS2812FX_fcn.cpp | 75 ++-- wled00/wled00.ino | 31 +- wled00/wled01_eeprom.ino | 12 +- wled00/wled02_xml.ino | 6 +- wled00/wled03_set.ino | 7 +- wled00/wled05_init.ino | 1 - wled00/wled07_notify.ino | 4 +- wled00/wled08_led.ino | 17 +- wled00/wled19_json.ino | 10 +- 12 files changed, 502 insertions(+), 509 deletions(-) diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 0ca8344f..1a271844 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -3,8 +3,15 @@ #define NpbWrapper_h //PIN CONFIGURATION -#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) +#define LEDPIN 5 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) //#define USE_APA102 // Uncomment for using APA102 LEDs. +#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) +#define IR_PIN 4 //infrared pin (-1 to disable) +#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,... +#define AUXPIN -1 //debug auxiliary output pin (-1 to disable) + +#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on + #ifdef USE_APA102 #define CLKPIN 0 #define DATAPIN 2 @@ -13,13 +20,6 @@ #endif #endif -#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) -#define IR_PIN 4 //infrared pin (-1 to disable) -#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,... -#define AUXPIN -1 //debug auxiliary output pin (-1 to disable) - -#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on - //automatically uses the right driver method for each platform #ifdef ARDUINO_ARCH_ESP32 diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index c6eef0e4..3281f873 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -34,7 +34,7 @@ * No blinking. Just plain old static light. */ uint16_t WS2812FX::mode_static(void) { - fill(SEGMENT.colors[0]); + fill(SEGCOLOR(0)); return (SEGMENT.getOption(7)) ? 20 : 500; //update faster if in transition } @@ -45,7 +45,7 @@ uint16_t WS2812FX::mode_static(void) { * if(strobe == true) then create a strobe effect */ uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_palette) { - uint32_t color = ((SEGMENT_RUNTIME.counter_mode_call & 1) == 0) ? color1 : color2; + uint32_t color = ((SEGENV.call & 1) == 0) ? color1 : color2; if (color == color1 && do_palette) { for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { @@ -55,7 +55,7 @@ uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_ fill(color); } - if((SEGMENT_RUNTIME.counter_mode_call & 1) == 0) { + if((SEGENV.call & 1) == 0) { return strobe ? 20 : (100 + ((1986 * (uint32_t)(255 - SEGMENT.speed)) / 255))*(float)(SEGMENT.intensity/128.0); } else { return strobe ? 50 + ((1986 * (uint32_t)(255 - SEGMENT.speed)) / 255) : (100 + ((1986 * (uint32_t)(255 - SEGMENT.speed)) / 255))*(float)(2.0-(SEGMENT.intensity/128.0)); @@ -67,7 +67,7 @@ uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_ * Normal blinking. 50% on/off time. */ uint16_t WS2812FX::mode_blink(void) { - return blink(SEGMENT.colors[0], SEGMENT.colors[1], false, true); + return blink(SEGCOLOR(0), SEGCOLOR(1), false, true); } @@ -75,7 +75,7 @@ uint16_t WS2812FX::mode_blink(void) { * Classic Blink effect. Cycling through the rainbow. */ uint16_t WS2812FX::mode_blink_rainbow(void) { - return blink(color_wheel(SEGMENT_RUNTIME.counter_mode_call & 0xFF), SEGMENT.colors[1], false, false); + return blink(color_wheel(SEGENV.call & 0xFF), SEGCOLOR(1), false, false); } @@ -83,7 +83,7 @@ uint16_t WS2812FX::mode_blink_rainbow(void) { * Classic Strobe effect. */ uint16_t WS2812FX::mode_strobe(void) { - return blink(SEGMENT.colors[0], SEGMENT.colors[1], true, true); + return blink(SEGCOLOR(0), SEGCOLOR(1), true, true); } @@ -91,7 +91,7 @@ uint16_t WS2812FX::mode_strobe(void) { * Classic Strobe effect. Cycling through the rainbow. */ uint16_t WS2812FX::mode_strobe_rainbow(void) { - return blink(color_wheel(SEGMENT_RUNTIME.counter_mode_call & 0xFF), SEGMENT.colors[1], true, false); + return blink(color_wheel(SEGENV.call & 0xFF), SEGCOLOR(1), true, false); } @@ -101,12 +101,12 @@ uint16_t WS2812FX::mode_strobe_rainbow(void) { * if (bool rev == true) then LEDs are turned off in reverse order */ uint16_t WS2812FX::color_wipe(uint32_t color1, uint32_t color2, bool rev, bool dopalette) { - if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) { - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step; + if(SEGENV.step < SEGLEN) { + uint32_t led_offset = SEGENV.step; uint16_t i = SEGMENT.start + led_offset; setPixelColor(i, dopalette ? color_from_palette(i, true, PALETTE_SOLID_WRAP, 0) : color1); } else { - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step - SEGMENT_LENGTH; + uint32_t led_offset = SEGENV.step - SEGLEN; if(rev) { setPixelColor(SEGMENT.stop -1 - led_offset, color2); } else { @@ -114,7 +114,7 @@ uint16_t WS2812FX::color_wipe(uint32_t color1, uint32_t color2, bool rev, bool d } } - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH * 2); + SEGENV.step = (SEGENV.step + 1) % (SEGLEN * 2); return SPEED_FORMULA_L; } @@ -123,14 +123,14 @@ uint16_t WS2812FX::color_wipe(uint32_t color1, uint32_t color2, bool rev, bool d * Lights all LEDs one after another. */ uint16_t WS2812FX::mode_color_wipe(void) { - return color_wipe(SEGMENT.colors[0], SEGMENT.colors[1], false, true); + return color_wipe(SEGCOLOR(0), SEGCOLOR(1), false, true); } /* * Lights all LEDs one after another. Turns off opposite */ uint16_t WS2812FX::mode_color_sweep(void) { - return color_wipe(SEGMENT.colors[0], SEGMENT.colors[1], true, true); + return color_wipe(SEGCOLOR(0), SEGCOLOR(1), true, true); } @@ -139,10 +139,10 @@ uint16_t WS2812FX::mode_color_sweep(void) { * Then starts over with another color. */ uint16_t WS2812FX::mode_color_wipe_random(void) { - if(SEGMENT_RUNTIME.counter_mode_step % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); + if(SEGENV.step % SEGLEN == 0) { // aux0 will store our random color wheel index + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); } - uint32_t color = color_wheel(SEGMENT_RUNTIME.aux_param); + uint32_t color = color_wheel(SEGENV.aux0); return color_wipe(color, color, false, false); } @@ -151,10 +151,10 @@ uint16_t WS2812FX::mode_color_wipe_random(void) { * Random color introduced alternating from start and end of strip. */ uint16_t WS2812FX::mode_color_sweep_random(void) { - if(SEGMENT_RUNTIME.counter_mode_step % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); + if(SEGENV.step % SEGLEN == 0) { // aux0 will store our random color wheel index + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); } - uint32_t color = color_wheel(SEGMENT_RUNTIME.aux_param); + uint32_t color = color_wheel(SEGENV.aux0); return color_wipe(color, color, true, false); } @@ -164,8 +164,8 @@ uint16_t WS2812FX::mode_color_sweep_random(void) { * to the next random color. */ uint16_t WS2812FX::mode_random_color(void) { - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); // aux_param will store our random color wheel index - uint32_t color = color_wheel(SEGMENT_RUNTIME.aux_param); + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); // aux0 will store our random color wheel index + uint32_t color = color_wheel(SEGENV.aux0); for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color); @@ -179,12 +179,12 @@ uint16_t WS2812FX::mode_random_color(void) { * to new random colors. */ uint16_t WS2812FX::mode_dynamic(void) { - if(SEGMENT.intensity > 127 || SEGMENT_RUNTIME.counter_mode_call == 0) { + if(SEGMENT.intensity > 127 || SEGENV.call == 0) { for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color_wheel(random8())); } } - setPixelColor(SEGMENT.start + random16(SEGMENT_LENGTH), color_wheel(random8())); + setPixelColor(SEGMENT.start + random16(SEGLEN), color_wheel(random8())); return 50 + (15 * (uint32_t)(255 - SEGMENT.speed)); } @@ -194,7 +194,7 @@ uint16_t WS2812FX::mode_dynamic(void) { * Use mode "fade" if you like to have something similar with a different speed. */ uint16_t WS2812FX::mode_breath(void) { - int lum = SEGMENT_RUNTIME.counter_mode_step; + int lum = SEGENV.step; if(lum > 255) lum = 511 - lum; // lum = 15 -> 255 -> 15 uint16_t delay; @@ -209,7 +209,7 @@ uint16_t WS2812FX::mode_breath(void) { if (SEGMENT.palette == 0) { - uint32_t color = SEGMENT.colors[0]; + uint32_t color = SEGCOLOR(0); uint8_t w = ((color >> 24 & 0xFF) * lum) >> 8; uint8_t r = ((color >> 16 & 0xFF) * lum) >> 8; uint8_t g = ((color >> 8 & 0xFF) * lum) >> 8; @@ -224,8 +224,8 @@ uint16_t WS2812FX::mode_breath(void) { } } - SEGMENT_RUNTIME.counter_mode_step += 2; - if(SEGMENT_RUNTIME.counter_mode_step > (512-15)) SEGMENT_RUNTIME.counter_mode_step = 15; + SEGENV.step += 2; + if(SEGENV.step > (512-15)) SEGENV.step = 15; return delay * (((256 - SEGMENT.speed)/64) +1); } @@ -234,15 +234,15 @@ uint16_t WS2812FX::mode_breath(void) { * Fades the LEDs between two colors */ uint16_t WS2812FX::mode_fade(void) { - int lum = SEGMENT_RUNTIME.counter_mode_step; + int lum = SEGENV.step; if(lum > 255) lum = 511 - lum; // lum = 0 -> 255 -> 0 for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { - setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGMENT.colors[1], lum)); + setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), lum)); } - SEGMENT_RUNTIME.counter_mode_step += 4; - if(SEGMENT_RUNTIME.counter_mode_step > 511) SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step += 4; + if(SEGENV.step > 511) SEGENV.step = 0; return 5 + ((15 * (uint32_t)(255 - SEGMENT.speed)) / 255); } @@ -252,24 +252,24 @@ uint16_t WS2812FX::mode_fade(void) { */ uint16_t WS2812FX::scan(bool dual) { - if(SEGMENT_RUNTIME.counter_mode_step > (SEGMENT_LENGTH * 2) - 3) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if(SEGENV.step > (SEGLEN * 2) - 3) { + SEGENV.step = 0; } - fill(SEGMENT.colors[1]); + fill(SEGCOLOR(1)); - int led_offset = SEGMENT_RUNTIME.counter_mode_step - (SEGMENT_LENGTH - 1); + int led_offset = SEGENV.step - (SEGLEN - 1); led_offset = abs(led_offset); uint16_t i = SEGMENT.start + led_offset; setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); if (dual) { - uint16_t i2 = SEGMENT.start + SEGMENT_LENGTH - led_offset - 1; + uint16_t i2 = SEGMENT.start + SEGLEN - led_offset - 1; setPixelColor(i2, color_from_palette(i2, true, PALETTE_SOLID_WRAP, 0)); } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; return SPEED_FORMULA_L; } @@ -295,10 +295,10 @@ uint16_t WS2812FX::mode_dual_scan(void) { * Cycles all LEDs at once through a rainbow. */ uint16_t WS2812FX::mode_rainbow(void) { - uint32_t color = color_wheel(SEGMENT_RUNTIME.counter_mode_step); + uint32_t color = color_wheel(SEGENV.step); fill(color); - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; + SEGENV.step = (SEGENV.step + 1) & 0xFF; return 1 + (((uint32_t)(255 - SEGMENT.speed)) / 5); } @@ -307,12 +307,12 @@ uint16_t WS2812FX::mode_rainbow(void) { * Cycles a rainbow over the entire string of LEDs. */ uint16_t WS2812FX::mode_rainbow_cycle(void) { - for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - uint32_t color = color_wheel(((i * 256 / ((uint16_t)(SEGMENT_LENGTH*(float)(SEGMENT.intensity/128.0))+1)) + SEGMENT_RUNTIME.counter_mode_step) & 0xFF); + for(uint16_t i=0; i < SEGLEN; i++) { + uint32_t color = color_wheel(((i * 256 / ((uint16_t)(SEGLEN*(float)(SEGMENT.intensity/128.0))+1)) + SEGENV.step) & 0xFF); setPixelColor(SEGMENT.start + i, color); } - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; + SEGENV.step = (SEGENV.step + 1) & 0xFF; return 1 + (((uint32_t)(255 - SEGMENT.speed)) / 5); } @@ -321,9 +321,9 @@ uint16_t WS2812FX::mode_rainbow_cycle(void) { * theater chase function */ uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool dopalette) { - SEGMENT_RUNTIME.counter_mode_call = SEGMENT_RUNTIME.counter_mode_call % 3; - for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - if((i % 3) == SEGMENT_RUNTIME.counter_mode_call) { + SEGENV.call = SEGENV.call % 3; + for(uint16_t i=0; i < SEGLEN; i++) { + if((i % 3) == SEGENV.call) { if (dopalette) { setPixelColor(SEGMENT.start + i, color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0)); @@ -343,7 +343,7 @@ uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2, bool dopalett * Inspired by the Adafruit examples. */ uint16_t WS2812FX::mode_theater_chase(void) { - return theater_chase(SEGMENT.colors[0], SEGMENT.colors[1], true); + return theater_chase(SEGCOLOR(0), SEGCOLOR(1), true); } @@ -352,8 +352,8 @@ uint16_t WS2812FX::mode_theater_chase(void) { * Inspired by the Adafruit examples. */ uint16_t WS2812FX::mode_theater_chase_rainbow(void) { - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; - return theater_chase(color_wheel(SEGMENT_RUNTIME.counter_mode_step), SEGMENT.colors[1], false); + SEGENV.step = (SEGENV.step + 1) & 0xFF; + return theater_chase(color_wheel(SEGENV.step), SEGCOLOR(1), false); } @@ -363,9 +363,9 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) { uint16_t WS2812FX::running_base(bool saw) { uint8_t x_scale = SEGMENT.intensity >> 2; - for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { + for(uint16_t i=0; i < SEGLEN; i++) { uint8_t s = 0; - uint8_t a = i*x_scale - (SEGMENT_RUNTIME.counter_mode_step >> 4); + uint8_t a = i*x_scale - (SEGENV.step >> 4); if (saw) { if (a < 16) { @@ -375,9 +375,9 @@ uint16_t WS2812FX::running_base(bool saw) { } } s = sin8(a); - setPixelColor(SEGMENT.start + i, color_blend(color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0), SEGMENT.colors[1], s)); + setPixelColor(SEGMENT.start + i, color_blend(color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), s)); } - SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed; + SEGENV.step += SEGMENT.speed; return 20; } @@ -403,15 +403,15 @@ uint16_t WS2812FX::mode_saw(void) { * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ */ uint16_t WS2812FX::mode_twinkle(void) { - if(SEGMENT_RUNTIME.counter_mode_step == 0) { - fill(SEGMENT.colors[1]); - SEGMENT_RUNTIME.counter_mode_step = map(SEGMENT.intensity, 0, 255, 1, SEGMENT_LENGTH); // make sure, at least one LED is on + if(SEGENV.step == 0) { + fill(SEGCOLOR(1)); + SEGENV.step = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure, at least one LED is on } - uint16_t i = SEGMENT.start + random16(SEGMENT_LENGTH); + uint16_t i = SEGMENT.start + random16(SEGLEN); setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); - SEGMENT_RUNTIME.counter_mode_step--; + SEGENV.step--; return 20 + (5 * (uint16_t)(255 - SEGMENT.speed)); } @@ -420,33 +420,33 @@ uint16_t WS2812FX::mode_twinkle(void) { * Dissolve function */ uint16_t WS2812FX::dissolve(uint32_t color) { - bool wa = (SEGMENT.colors[1] != 0 && _brightness < 255); //workaround, can't compare getPixel to color if not full brightness + bool wa = (SEGCOLOR(1) != 0 && _brightness < 255); //workaround, can't compare getPixel to color if not full brightness - for (uint16_t j = 0; j <= SEGMENT_LENGTH / 15; j++) + for (uint16_t j = 0; j <= SEGLEN / 15; j++) { if (random8() <= SEGMENT.intensity) { for (uint8_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times { - uint16_t i = SEGMENT.start + random16(SEGMENT_LENGTH); - if (SEGMENT_RUNTIME.aux_param) { //dissolve to primary/palette - if (getPixelColor(i) == SEGMENT.colors[1] || wa) { - if (color == SEGMENT.colors[0]) + uint16_t i = SEGMENT.start + random16(SEGLEN); + if (SEGENV.aux0) { //dissolve to primary/palette + if (getPixelColor(i) == SEGCOLOR(1) || wa) { + if (color == SEGCOLOR(0)) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); } else { setPixelColor(i, color); } break; //only spawn 1 new pixel per frame per 50 LEDs } } else { //dissolve to secondary - if (getPixelColor(i) != SEGMENT.colors[1]) { setPixelColor(i, SEGMENT.colors[1]); break; } + if (getPixelColor(i) != SEGCOLOR(1)) { setPixelColor(i, SEGCOLOR(1)); break; } } } } } - if (SEGMENT_RUNTIME.counter_mode_call > (255 - SEGMENT.speed) + 15) + if (SEGENV.call > (255 - SEGMENT.speed) + 15) { - SEGMENT_RUNTIME.aux_param = !SEGMENT_RUNTIME.aux_param; - SEGMENT_RUNTIME.counter_mode_call = 0; + SEGENV.aux0 = !SEGENV.aux0; + SEGENV.call = 0; } return 20; @@ -457,7 +457,7 @@ uint16_t WS2812FX::dissolve(uint32_t color) { * Blink several LEDs on and then off */ uint16_t WS2812FX::mode_dissolve(void) { - return dissolve(SEGMENT.colors[0]); + return dissolve(SEGCOLOR(0)); } @@ -477,8 +477,8 @@ uint16_t WS2812FX::mode_sparkle(void) { for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1)); } - SEGMENT_RUNTIME.aux_param = random16(SEGMENT_LENGTH); // aux_param stores the random led index - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]); + SEGENV.aux0 = random16(SEGLEN); // aux0 stores the random led index + setPixelColor(SEGMENT.start + SEGENV.aux0, SEGCOLOR(0)); return 10 + (uint16_t)(255 - SEGMENT.speed); } @@ -488,18 +488,18 @@ uint16_t WS2812FX::mode_sparkle(void) { * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ */ uint16_t WS2812FX::mode_flash_sparkle(void) { - if(SEGMENT_RUNTIME.counter_mode_call == 0) { + if(SEGENV.call == 0) { for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); } } - uint16_t i = SEGMENT.start + SEGMENT_RUNTIME.aux_param; + uint16_t i = SEGMENT.start + SEGENV.aux0; setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); if(random8(5) == 0) { - SEGMENT_RUNTIME.aux_param = random16(SEGMENT_LENGTH); // aux_param stores the random led index - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[1]); + SEGENV.aux0 = random16(SEGLEN); // aux0 stores the random led index + setPixelColor(SEGMENT.start + SEGENV.aux0, SEGCOLOR(1)); return 20; } return 20 + (uint16_t)(255-SEGMENT.speed); @@ -516,8 +516,8 @@ uint16_t WS2812FX::mode_hyper_sparkle(void) { } if(random8(5) < 2) { - for(uint16_t i=0; i < max(1, SEGMENT_LENGTH/3); i++) { - setPixelColor(SEGMENT.start + random16(SEGMENT_LENGTH), SEGMENT.colors[1]); + for(uint16_t i=0; i < max(1, SEGLEN/3); i++) { + setPixelColor(SEGMENT.start + random16(SEGLEN), SEGCOLOR(1)); } return 20; } @@ -535,17 +535,17 @@ uint16_t WS2812FX::mode_multi_strobe(void) { uint16_t delay = 50 + 20*(uint16_t)(255-SEGMENT.speed); uint16_t count = 2 * ((SEGMENT.speed / 10) + 1); - if(SEGMENT_RUNTIME.counter_mode_step < count) { - if((SEGMENT_RUNTIME.counter_mode_step & 1) == 0) { + if(SEGENV.step < count) { + if((SEGENV.step & 1) == 0) { for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { - setPixelColor(i, SEGMENT.colors[0]); + setPixelColor(i, SEGCOLOR(0)); } delay = 20; } else { delay = 50; } } - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (count + 1); + SEGENV.step = (SEGENV.step + 1) % (count + 1); return delay; } @@ -553,55 +553,55 @@ uint16_t WS2812FX::mode_multi_strobe(void) { * Android loading circle */ uint16_t WS2812FX::mode_android(void) { - if (SEGMENT_RUNTIME.counter_mode_call == 0) + if (SEGENV.call == 0) { - SEGMENT_RUNTIME.aux_param = 0; - SEGMENT_RUNTIME.counter_mode_step = SEGMENT.start; + SEGENV.aux0 = 0; + SEGENV.step = SEGMENT.start; } for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 1)); } - if (SEGMENT_RUNTIME.aux_param2 > ((float)SEGMENT.intensity/255.0)*(float)SEGMENT_LENGTH) + if (SEGENV.aux1 > ((float)SEGMENT.intensity/255.0)*(float)SEGLEN) { - SEGMENT_RUNTIME.aux_param = 1; + SEGENV.aux0 = 1; } else { - if (SEGMENT_RUNTIME.aux_param2 < 2) SEGMENT_RUNTIME.aux_param = 0; + if (SEGENV.aux1 < 2) SEGENV.aux0 = 0; } - uint16_t a = SEGMENT_RUNTIME.counter_mode_step; + uint16_t a = SEGENV.step; - if (SEGMENT_RUNTIME.aux_param == 0) + if (SEGENV.aux0 == 0) { - if (SEGMENT_RUNTIME.counter_mode_call %3 == 1) {a++;} - else {SEGMENT_RUNTIME.aux_param2++;} + if (SEGENV.call %3 == 1) {a++;} + else {SEGENV.aux1++;} } else { a++; - if (SEGMENT_RUNTIME.counter_mode_call %3 != 1) SEGMENT_RUNTIME.aux_param2--; + if (SEGENV.call %3 != 1) SEGENV.aux1--; } if (a >= SEGMENT.stop) a = SEGMENT.start; - if (a + SEGMENT_RUNTIME.aux_param2 < SEGMENT.stop) + if (a + SEGENV.aux1 < SEGMENT.stop) { - for(int i = a; i < a+SEGMENT_RUNTIME.aux_param2; i++) { - setPixelColor(i, SEGMENT.colors[0]); + for(int i = a; i < a+SEGENV.aux1; i++) { + setPixelColor(i, SEGCOLOR(0)); } } else { for(int i = a; i < SEGMENT.stop; i++) { - setPixelColor(i, SEGMENT.colors[0]); + setPixelColor(i, SEGCOLOR(0)); } - for(int i = SEGMENT.start; i < SEGMENT_RUNTIME.aux_param2 - (SEGMENT.stop -a); i++) { - setPixelColor(i, SEGMENT.colors[0]); + for(int i = SEGMENT.start; i < SEGENV.aux1 - (SEGMENT.stop -a); i++) { + setPixelColor(i, SEGCOLOR(0)); } } - SEGMENT_RUNTIME.counter_mode_step = a; + SEGENV.step = a; - return 3 + ((8 * (uint32_t)(255 - SEGMENT.speed)) / SEGMENT_LENGTH); + return 3 + ((8 * (uint32_t)(255 - SEGMENT.speed)) / SEGLEN); } /* @@ -610,9 +610,9 @@ uint16_t WS2812FX::mode_android(void) { * color2 and color3 = colors of two adjacent leds */ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool dopalette) { - uint16_t a = SEGMENT_RUNTIME.counter_mode_step; - uint16_t b = (a + 1) % SEGMENT_LENGTH; - uint16_t c = (b + 1) % SEGMENT_LENGTH; + uint16_t a = SEGENV.step; + uint16_t b = (a + 1) % SEGLEN; + uint16_t c = (b + 1) % SEGLEN; if (dopalette) color1 = color_from_palette(SEGMENT.start + a, true, PALETTE_SOLID_WRAP, 1); @@ -620,7 +620,7 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool setPixelColor(SEGMENT.start + b, color2); setPixelColor(SEGMENT.start + c, color3); - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; + SEGENV.step = (SEGENV.step + 1) % SEGLEN; return SPEED_FORMULA_L; } @@ -629,7 +629,7 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3, bool * Bicolor chase, more primary color. */ uint16_t WS2812FX::mode_chase_color(void) { - return chase(SEGMENT.colors[1], SEGMENT.colors[0], SEGMENT.colors[0], true); + return chase(SEGCOLOR(1), SEGCOLOR(0), SEGCOLOR(0), true); } @@ -637,10 +637,10 @@ uint16_t WS2812FX::mode_chase_color(void) { * Primary running followed by random color. */ uint16_t WS2812FX::mode_chase_random(void) { - if(SEGMENT_RUNTIME.counter_mode_step == 0) { - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); + if(SEGENV.step == 0) { + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); } - return chase(color_wheel(SEGMENT_RUNTIME.aux_param), SEGMENT.colors[0], SEGMENT.colors[0], false); + return chase(color_wheel(SEGENV.aux0), SEGCOLOR(0), SEGCOLOR(0), false); } @@ -648,12 +648,12 @@ uint16_t WS2812FX::mode_chase_random(void) { * Primary running on rainbow. */ uint16_t WS2812FX::mode_chase_rainbow_white(void) { - uint16_t n = SEGMENT_RUNTIME.counter_mode_step; - uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; - uint32_t color2 = color_wheel(((n * 256 / SEGMENT_LENGTH) + (SEGMENT_RUNTIME.counter_mode_call & 0xFF)) & 0xFF); - uint32_t color3 = color_wheel(((m * 256 / SEGMENT_LENGTH) + (SEGMENT_RUNTIME.counter_mode_call & 0xFF)) & 0xFF); + uint16_t n = SEGENV.step; + uint16_t m = (SEGENV.step + 1) % SEGLEN; + uint32_t color2 = color_wheel(((n * 256 / SEGLEN) + (SEGENV.call & 0xFF)) & 0xFF); + uint32_t color3 = color_wheel(((m * 256 / SEGLEN) + (SEGENV.call & 0xFF)) & 0xFF); - return chase(SEGMENT.colors[0], color2, color3, false); + return chase(SEGCOLOR(0), color2, color3, false); } @@ -673,29 +673,29 @@ uint16_t WS2812FX::mode_colorful(void) { int i = SEGMENT.start; for (i; i < SEGMENT.stop ; i+=4) { - setPixelColor(i, cols[SEGMENT_RUNTIME.counter_mode_step]); - setPixelColor(i+1, cols[SEGMENT_RUNTIME.counter_mode_step+1]); - setPixelColor(i+2, cols[SEGMENT_RUNTIME.counter_mode_step+2]); - setPixelColor(i+3, cols[SEGMENT_RUNTIME.counter_mode_step+3]); + setPixelColor(i, cols[SEGENV.step]); + setPixelColor(i+1, cols[SEGENV.step+1]); + setPixelColor(i+2, cols[SEGENV.step+2]); + setPixelColor(i+3, cols[SEGENV.step+3]); } i+=4; if(i < SEGMENT.stop) { - setPixelColor(i, cols[SEGMENT_RUNTIME.counter_mode_step]); + setPixelColor(i, cols[SEGENV.step]); if(i+1 < SEGMENT.stop) { - setPixelColor(i+1, cols[SEGMENT_RUNTIME.counter_mode_step+1]); + setPixelColor(i+1, cols[SEGENV.step+1]); if(i+2 < SEGMENT.stop) { - setPixelColor(i+2, cols[SEGMENT_RUNTIME.counter_mode_step+2]); + setPixelColor(i+2, cols[SEGENV.step+2]); } } } - if (SEGMENT.speed > 0) SEGMENT_RUNTIME.counter_mode_step++; //static if lowest speed - if (SEGMENT_RUNTIME.counter_mode_step >3) SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGMENT.speed > 0) SEGENV.step++; //static if lowest speed + if (SEGENV.step >3) SEGENV.step = 0; return 50 + (15 * (uint32_t)(255 - SEGMENT.speed)); } @@ -709,7 +709,7 @@ uint16_t WS2812FX::mode_traffic_light(void) { uint32_t mdelay = 500; for (int i = SEGMENT.start; i < SEGMENT.stop-2 ; i+=3) { - switch (SEGMENT_RUNTIME.counter_mode_step) + switch (SEGENV.step) { case 0: setPixelColor(i, 0x00FF0000); mdelay = 150 + (100 * (uint32_t)(255 - SEGMENT.speed));break; case 1: setPixelColor(i, 0x00FF0000); mdelay = 150 + (20 * (uint32_t)(255 - SEGMENT.speed)); setPixelColor(i+1, 0x00EECC00); break; @@ -718,8 +718,8 @@ uint16_t WS2812FX::mode_traffic_light(void) { } } - SEGMENT_RUNTIME.counter_mode_step++; - if (SEGMENT_RUNTIME.counter_mode_step >3) SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step++; + if (SEGENV.step >3) SEGENV.step = 0; return mdelay; } @@ -728,11 +728,11 @@ uint16_t WS2812FX::mode_traffic_light(void) { * Primary, secondary running on rainbow. */ uint16_t WS2812FX::mode_chase_rainbow(void) { - uint8_t color_sep = 256 / SEGMENT_LENGTH; - uint8_t color_index = SEGMENT_RUNTIME.counter_mode_call & 0xFF; - uint32_t color = color_wheel(((SEGMENT_RUNTIME.counter_mode_step * color_sep) + color_index) & 0xFF); + uint8_t color_sep = 256 / SEGLEN; + uint8_t color_index = SEGENV.call & 0xFF; + uint32_t color = color_wheel(((SEGENV.step * color_sep) + color_index) & 0xFF); - return chase(color, SEGMENT.colors[0], SEGMENT.colors[1], 0); + return chase(color, SEGCOLOR(0), SEGCOLOR(1), 0); } @@ -741,25 +741,25 @@ uint16_t WS2812FX::mode_chase_rainbow(void) { */ #define FLASH_COUNT 4 uint16_t WS2812FX::mode_chase_flash(void) { - uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((FLASH_COUNT * 2) + 1); + uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1); for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); } - uint16_t delay = 10 + ((30 * (uint16_t)(255 - SEGMENT.speed)) / SEGMENT_LENGTH); + uint16_t delay = 10 + ((30 * (uint16_t)(255 - SEGMENT.speed)) / SEGLEN); if(flash_step < (FLASH_COUNT * 2)) { if(flash_step % 2 == 0) { - uint16_t n = SEGMENT_RUNTIME.counter_mode_step; - uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; - setPixelColor(SEGMENT.start + n, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + m, SEGMENT.colors[1]); + uint16_t n = SEGENV.step; + uint16_t m = (SEGENV.step + 1) % SEGLEN; + setPixelColor(SEGMENT.start + n, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + m, SEGCOLOR(1)); delay = 20; } else { delay = 30; } } else { - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; + SEGENV.step = (SEGENV.step + 1) % SEGLEN; } return delay; } @@ -769,30 +769,30 @@ uint16_t WS2812FX::mode_chase_flash(void) { * Prim flashes running, followed by random color. */ uint16_t WS2812FX::mode_chase_flash_random(void) { - uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((FLASH_COUNT * 2) + 1); + uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1); - for(uint16_t i=0; i < SEGMENT_RUNTIME.counter_mode_step; i++) { - setPixelColor(SEGMENT.start + i, color_wheel(SEGMENT_RUNTIME.aux_param)); + for(uint16_t i=0; i < SEGENV.step; i++) { + setPixelColor(SEGMENT.start + i, color_wheel(SEGENV.aux0)); } - uint16_t delay = 1 + ((10 * (uint16_t)(255 - SEGMENT.speed)) / SEGMENT_LENGTH); + uint16_t delay = 1 + ((10 * (uint16_t)(255 - SEGMENT.speed)) / SEGLEN); if(flash_step < (FLASH_COUNT * 2)) { - uint16_t n = SEGMENT_RUNTIME.counter_mode_step; - uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; + uint16_t n = SEGENV.step; + uint16_t m = (SEGENV.step + 1) % SEGLEN; if(flash_step % 2 == 0) { - setPixelColor(SEGMENT.start + n, SEGMENT.colors[0]); - setPixelColor(SEGMENT.start + m, SEGMENT.colors[0]); + setPixelColor(SEGMENT.start + n, SEGCOLOR(0)); + setPixelColor(SEGMENT.start + m, SEGCOLOR(0)); delay = 20; } else { - setPixelColor(SEGMENT.start + n, color_wheel(SEGMENT_RUNTIME.aux_param)); - setPixelColor(SEGMENT.start + m, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + n, color_wheel(SEGENV.aux0)); + setPixelColor(SEGMENT.start + m, SEGCOLOR(1)); delay = 30; } } else { - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; + SEGENV.step = (SEGENV.step + 1) % SEGLEN; - if(SEGMENT_RUNTIME.counter_mode_step == 0) { - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); + if(SEGENV.step == 0) { + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); } } return delay; @@ -803,9 +803,9 @@ uint16_t WS2812FX::mode_chase_flash_random(void) { * Alternating pixels running function. */ uint16_t WS2812FX::running(uint32_t color1, uint32_t color2) { - for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - if((i + SEGMENT_RUNTIME.counter_mode_step) % 4 < 2) { - if (color1 == SEGMENT.colors[0]) + for(uint16_t i=0; i < SEGLEN; i++) { + if((i + SEGENV.step) % 4 < 2) { + if (color1 == SEGCOLOR(0)) { setPixelColor(SEGMENT.stop -i, color_from_palette(SEGMENT.stop -i -1, true, PALETTE_SOLID_WRAP, 0)); } else @@ -817,7 +817,7 @@ uint16_t WS2812FX::running(uint32_t color1, uint32_t color2) { } } - if (SEGMENT.speed != 0) SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0x3; + if (SEGMENT.speed != 0) SEGENV.step = (SEGENV.step + 1) & 0x3; return 35 + ((350 * (uint32_t)(255 - SEGMENT.speed)) / 255); } @@ -825,7 +825,7 @@ uint16_t WS2812FX::running(uint32_t color1, uint32_t color2) { * Alternating color/sec pixels running. */ uint16_t WS2812FX::mode_running_color(void) { - return running(SEGMENT.colors[0], SEGMENT.colors[1]); + return running(SEGCOLOR(0), SEGCOLOR(1)); } @@ -857,19 +857,19 @@ uint16_t WS2812FX::mode_halloween(void) { * Random colored pixels running. */ uint16_t WS2812FX::mode_running_random(void) { - for(uint16_t i=SEGMENT_LENGTH-1; i > 0; i--) { + for(uint16_t i=SEGLEN-1; i > 0; i--) { setPixelColor(SEGMENT.start + i, getPixelColor(SEGMENT.start + i - 1)); } - if(SEGMENT_RUNTIME.counter_mode_step == 0) { - SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); - setPixelColor(SEGMENT.start, color_wheel(SEGMENT_RUNTIME.aux_param)); + if(SEGENV.step == 0) { + SEGENV.aux0 = get_random_wheel_index(SEGENV.aux0); + setPixelColor(SEGMENT.start, color_wheel(SEGENV.aux0)); } - SEGMENT_RUNTIME.counter_mode_step++; - if (SEGMENT_RUNTIME.counter_mode_step > ((255-SEGMENT.intensity) >> 4)) + SEGENV.step++; + if (SEGENV.step > ((255-SEGMENT.intensity) >> 4)) { - SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step = 0; } return SPEED_FORMULA_L; } @@ -882,14 +882,14 @@ uint16_t WS2812FX::mode_larson_scanner(void) { fade_out(SEGMENT.intensity); uint16_t index = 0; - if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) { - index = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step; + if(SEGENV.step < SEGLEN) { + index = SEGMENT.start + SEGENV.step; } else { - index = SEGMENT.start + ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) - 2; + index = SEGMENT.start + ((SEGLEN * 2) - SEGENV.step) - 2; } setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % ((SEGMENT_LENGTH * 2) - 2); + SEGENV.step = (SEGENV.step + 1) % ((SEGLEN * 2) - 2); return SPEED_FORMULA_L; } @@ -900,10 +900,10 @@ uint16_t WS2812FX::mode_larson_scanner(void) { uint16_t WS2812FX::mode_comet(void) { fade_out(SEGMENT.intensity); - uint16_t index = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step; + uint16_t index = SEGMENT.start + SEGENV.step; setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; + SEGENV.step = (SEGENV.step + 1) % SEGLEN; return SPEED_FORMULA_L; } @@ -913,25 +913,25 @@ uint16_t WS2812FX::mode_comet(void) { */ uint16_t WS2812FX::mode_fireworks() { fade_out(0); - if (SEGMENT_RUNTIME.counter_mode_call == 0) { - SEGMENT_RUNTIME.aux_param = UINT16_MAX; - SEGMENT_RUNTIME.aux_param2 = UINT16_MAX; + if (SEGENV.call == 0) { + SEGENV.aux0 = UINT16_MAX; + SEGENV.aux1 = UINT16_MAX; } - bool valid1 = (SEGMENT_RUNTIME.aux_param < SEGMENT.stop && SEGMENT_RUNTIME.aux_param >= SEGMENT.start); - bool valid2 = (SEGMENT_RUNTIME.aux_param2 < SEGMENT.stop && SEGMENT_RUNTIME.aux_param2 >= SEGMENT.start); + bool valid1 = (SEGENV.aux0 < SEGMENT.stop && SEGENV.aux0 >= SEGMENT.start); + bool valid2 = (SEGENV.aux1 < SEGMENT.stop && SEGENV.aux1 >= SEGMENT.start); uint32_t sv1 = 0, sv2 = 0; - if (valid1) sv1 = getPixelColor(SEGMENT_RUNTIME.aux_param); - if (valid2) sv2 = getPixelColor(SEGMENT_RUNTIME.aux_param2); + if (valid1) sv1 = getPixelColor(SEGENV.aux0); + if (valid2) sv2 = getPixelColor(SEGENV.aux1); blur(255-SEGMENT.speed); - if (valid1) setPixelColor(SEGMENT_RUNTIME.aux_param , sv1); - if (valid2) setPixelColor(SEGMENT_RUNTIME.aux_param2, sv2); + if (valid1) setPixelColor(SEGENV.aux0 , sv1); + if (valid2) setPixelColor(SEGENV.aux1, sv2); - for(uint16_t i=0; i> 1)) == 0) { - uint16_t index = SEGMENT.start + random(SEGMENT_LENGTH); + uint16_t index = SEGMENT.start + random(SEGLEN); setPixelColor(index, color_from_palette(random8(), false, false, 0)); - SEGMENT_RUNTIME.aux_param2 = SEGMENT_RUNTIME.aux_param; - SEGMENT_RUNTIME.aux_param = index; + SEGENV.aux1 = SEGENV.aux0; + SEGENV.aux0 = index; } } return 22; @@ -941,21 +941,21 @@ uint16_t WS2812FX::mode_fireworks() { //Twinkling LEDs running. Inspired by https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Rain.h uint16_t WS2812FX::mode_rain() { - SEGMENT_RUNTIME.counter_mode_step += 22; - if (SEGMENT_RUNTIME.counter_mode_step > SPEED_FORMULA_L) { - SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step += 22; + if (SEGENV.step > SPEED_FORMULA_L) { + SEGENV.step = 0; //shift all leds right uint32_t ctemp = getPixelColor(SEGMENT.stop -1); for(uint16_t i=SEGMENT.stop -1; i>SEGMENT.start; i--) { setPixelColor(i, getPixelColor(i-1)); } setPixelColor(SEGMENT.start, ctemp); - SEGMENT_RUNTIME.aux_param++; - SEGMENT_RUNTIME.aux_param2++; - if (SEGMENT_RUNTIME.aux_param == 0) SEGMENT_RUNTIME.aux_param = UINT16_MAX; - if (SEGMENT_RUNTIME.aux_param2 == 0) SEGMENT_RUNTIME.aux_param = UINT16_MAX; - if (SEGMENT_RUNTIME.aux_param == SEGMENT.stop) SEGMENT_RUNTIME.aux_param = SEGMENT.start; - if (SEGMENT_RUNTIME.aux_param2 == SEGMENT.stop) SEGMENT_RUNTIME.aux_param2 = SEGMENT.start; + SEGENV.aux0++; + SEGENV.aux1++; + if (SEGENV.aux0 == 0) SEGENV.aux0 = UINT16_MAX; + if (SEGENV.aux1 == 0) SEGENV.aux0 = UINT16_MAX; + if (SEGENV.aux0 == SEGMENT.stop) SEGENV.aux0 = SEGMENT.start; + if (SEGENV.aux1 == SEGMENT.stop) SEGENV.aux1 = SEGMENT.start; } return mode_fireworks(); } @@ -965,10 +965,10 @@ uint16_t WS2812FX::mode_rain() * Fire flicker function */ uint16_t WS2812FX::mode_fire_flicker(void) { - byte w = (SEGMENT.colors[0] >> 24) & 0xFF; - byte r = (SEGMENT.colors[0] >> 16) & 0xFF; - byte g = (SEGMENT.colors[0] >> 8) & 0xFF; - byte b = (SEGMENT.colors[0] & 0xFF); + byte w = (SEGCOLOR(0) >> 24) & 0xFF; + byte r = (SEGCOLOR(0) >> 16) & 0xFF; + byte g = (SEGCOLOR(0) >> 8) & 0xFF; + byte b = (SEGCOLOR(0) & 0xFF); byte lum = (SEGMENT.palette == 0) ? max(w, max(r, max(g, b))) : 255; lum /= (((256-SEGMENT.intensity)/16)+1); for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { @@ -987,14 +987,14 @@ uint16_t WS2812FX::mode_fire_flicker(void) { * Gradient run base function */ uint16_t WS2812FX::gradient_base(bool loading) { - if (SEGMENT_RUNTIME.counter_mode_call == 0) SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.call == 0) SEGENV.step = 0; float per,val; //0.0 = sec 1.0 = pri float brd = SEGMENT.intensity; if (!loading) brd = SEGMENT.intensity/2; if (brd <1.0) brd = 1.0; - int pp = SEGMENT_RUNTIME.counter_mode_step; - int p1 = pp-SEGMENT_LENGTH; - int p2 = pp+SEGMENT_LENGTH; + int pp = SEGENV.step; + int p1 = pp-SEGLEN; + int p2 = pp+SEGLEN; for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { @@ -1006,12 +1006,12 @@ uint16_t WS2812FX::gradient_base(bool loading) { } per = val/brd; if (per >1.0) per = 1.0; - setPixelColor(SEGMENT.start + i, color_blend(SEGMENT.colors[0], color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 1), per*255)); + setPixelColor(SEGMENT.start + i, color_blend(SEGCOLOR(0), color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 1), per*255)); } - SEGMENT_RUNTIME.counter_mode_step++; - if (SEGMENT_RUNTIME.counter_mode_step >= SEGMENT.stop) SEGMENT_RUNTIME.counter_mode_step = SEGMENT.start; - if (SEGMENT.speed == 0) SEGMENT_RUNTIME.counter_mode_step = SEGMENT.start + (SEGMENT_LENGTH >> 1); + SEGENV.step++; + if (SEGENV.step >= SEGMENT.stop) SEGENV.step = SEGMENT.start; + if (SEGMENT.speed == 0) SEGENV.step = SEGMENT.start + (SEGLEN >> 1); return SPEED_FORMULA_L; } @@ -1037,34 +1037,34 @@ uint16_t WS2812FX::mode_loading(void) { * finishing in the middle. Then turns them in reverse order off. Repeat. */ uint16_t WS2812FX::mode_dual_color_wipe_in_out(void) { - int end = SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step - 1; - bool odd = (SEGMENT_LENGTH % 2) == 1; - int mid = odd ? ((SEGMENT_LENGTH / 2) + 1) : (SEGMENT_LENGTH / 2); - if (SEGMENT_RUNTIME.counter_mode_step < mid) { - byte pindex = map(SEGMENT_RUNTIME.counter_mode_step, 0, mid -1, 0, 255); + int end = SEGLEN - SEGENV.step - 1; + bool odd = (SEGLEN % 2) == 1; + int mid = odd ? ((SEGLEN / 2) + 1) : (SEGLEN / 2); + if (SEGENV.step < mid) { + byte pindex = map(SEGENV.step, 0, mid -1, 0, 255); uint32_t col = color_from_palette(pindex, false, false, 0); - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, col); + setPixelColor(SEGMENT.start + SEGENV.step, col); setPixelColor(SEGMENT.start + end, col); } else { if (odd) { // If odd, we need to 'double count' the center LED (once to turn it on, // once to turn it off). So trail one behind after the middle LED. - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step - 1, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + end + 1, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + SEGENV.step - 1, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + end + 1, SEGCOLOR(1)); } else { - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + end, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + SEGENV.step, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + end, SEGCOLOR(1)); } } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step > SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step > SEGLEN) { + SEGENV.step = 0; } } else { - if (SEGMENT_RUNTIME.counter_mode_step >= SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step >= SEGLEN) { + SEGENV.step = 0; } } return SPEED_FORMULA_L; @@ -1076,42 +1076,42 @@ uint16_t WS2812FX::mode_dual_color_wipe_in_out(void) { * finishing in the middle. Then turns them in that order off. Repeat. */ uint16_t WS2812FX::mode_dual_color_wipe_in_in(void) { - bool odd = (SEGMENT_LENGTH % 2) == 1; - int mid = SEGMENT_LENGTH / 2; + bool odd = (SEGLEN % 2) == 1; + int mid = SEGLEN / 2; byte pindex = 0; uint32_t col = 0; - if (SEGMENT_RUNTIME.counter_mode_step <= mid) + if (SEGENV.step <= mid) { - pindex = map(SEGMENT_RUNTIME.counter_mode_step, 0, mid, 0, 255); + pindex = map(SEGENV.step, 0, mid, 0, 255); col = color_from_palette(pindex, false, false, 0); } if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step <= mid) { - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, col); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step - 1, col); + if (SEGENV.step <= mid) { + setPixelColor(SEGMENT.start + SEGENV.step, col); + setPixelColor(SEGMENT.start + SEGLEN - SEGENV.step - 1, col); } else { - int i = SEGMENT_RUNTIME.counter_mode_step - mid; - setPixelColor(SEGMENT.start + i - 1, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - i, SEGMENT.colors[1]); + int i = SEGENV.step - mid; + setPixelColor(SEGMENT.start + i - 1, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + SEGLEN - i, SEGCOLOR(1)); } } else { - if (SEGMENT_RUNTIME.counter_mode_step < mid) { - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, col); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step - 1, col); + if (SEGENV.step < mid) { + setPixelColor(SEGMENT.start + SEGENV.step, col); + setPixelColor(SEGMENT.start + SEGLEN - SEGENV.step - 1, col); } else { - int i = SEGMENT_RUNTIME.counter_mode_step - mid; - setPixelColor(SEGMENT.start + i, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - i - 1, SEGMENT.colors[1]); + int i = SEGENV.step - mid; + setPixelColor(SEGMENT.start + i, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + SEGLEN - i - 1, SEGCOLOR(1)); } } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step > SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step > SEGLEN) { + SEGENV.step = 0; } } else { - if (SEGMENT_RUNTIME.counter_mode_step >= SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step >= SEGLEN) { + SEGENV.step = 0; } } return SPEED_FORMULA_L; @@ -1123,41 +1123,41 @@ uint16_t WS2812FX::mode_dual_color_wipe_in_in(void) { * finishing at the edges. Then turns them off in that order. Repeat. */ uint16_t WS2812FX::mode_dual_color_wipe_out_out(void) { - int end = SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step - 1; - bool odd = (SEGMENT_LENGTH % 2) == 1; - int mid = SEGMENT_LENGTH / 2; + int end = SEGLEN - SEGENV.step - 1; + bool odd = (SEGLEN % 2) == 1; + int mid = SEGLEN / 2; byte pindex = 0; uint32_t col = 0; - if (SEGMENT_RUNTIME.counter_mode_step <= mid) + if (SEGENV.step <= mid) { - pindex = map(SEGMENT_RUNTIME.counter_mode_step, 0, mid, 255, 0); + pindex = map(SEGENV.step, 0, mid, 255, 0); col = color_from_palette(pindex, false, false, 0); } if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step <= mid) { - setPixelColor(SEGMENT.start + mid + SEGMENT_RUNTIME.counter_mode_step, col); - setPixelColor(SEGMENT.start + mid - SEGMENT_RUNTIME.counter_mode_step, col); + if (SEGENV.step <= mid) { + setPixelColor(SEGMENT.start + mid + SEGENV.step, col); + setPixelColor(SEGMENT.start + mid - SEGENV.step, col); } else { - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step - 1, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + end + 1, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + SEGENV.step - 1, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + end + 1, SEGCOLOR(1)); } } else { - if (SEGMENT_RUNTIME.counter_mode_step < mid) { - setPixelColor(SEGMENT.start + mid - SEGMENT_RUNTIME.counter_mode_step - 1, col); - setPixelColor(SEGMENT.start + mid + SEGMENT_RUNTIME.counter_mode_step, col); + if (SEGENV.step < mid) { + setPixelColor(SEGMENT.start + mid - SEGENV.step - 1, col); + setPixelColor(SEGMENT.start + mid + SEGENV.step, col); } else { - setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + end, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + SEGENV.step, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + end, SEGCOLOR(1)); } } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step > SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step > SEGLEN) { + SEGENV.step = 0; } } else { - if (SEGMENT_RUNTIME.counter_mode_step >= SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step >= SEGLEN) { + SEGENV.step = 0; } } return SPEED_FORMULA_L; @@ -1169,42 +1169,42 @@ uint16_t WS2812FX::mode_dual_color_wipe_out_out(void) { * finishing at the edges. Then turns them off in reverse order. Repeat. */ uint16_t WS2812FX::mode_dual_color_wipe_out_in(void) { - bool odd = (SEGMENT_LENGTH % 2) == 1; - int mid = SEGMENT_LENGTH / 2; + bool odd = (SEGLEN % 2) == 1; + int mid = SEGLEN / 2; byte pindex = 0; uint32_t col = 0; - if (SEGMENT_RUNTIME.counter_mode_step <= mid) + if (SEGENV.step <= mid) { - pindex = map(SEGMENT_RUNTIME.counter_mode_step, 0, mid, 255, 0); + pindex = map(SEGENV.step, 0, mid, 255, 0); col = color_from_palette(pindex, false, false, 0); } if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step <= mid) { - setPixelColor(SEGMENT.start + mid + SEGMENT_RUNTIME.counter_mode_step, col); - setPixelColor(SEGMENT.start + mid - SEGMENT_RUNTIME.counter_mode_step, col); + if (SEGENV.step <= mid) { + setPixelColor(SEGMENT.start + mid + SEGENV.step, col); + setPixelColor(SEGMENT.start + mid - SEGENV.step, col); } else { - int i = SEGMENT_RUNTIME.counter_mode_step - mid; - setPixelColor(SEGMENT.start + i - 1, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - i, SEGMENT.colors[1]); + int i = SEGENV.step - mid; + setPixelColor(SEGMENT.start + i - 1, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + SEGLEN - i, SEGCOLOR(1)); } } else { - if (SEGMENT_RUNTIME.counter_mode_step < mid) { - setPixelColor(SEGMENT.start + mid - SEGMENT_RUNTIME.counter_mode_step - 1, col); - setPixelColor(SEGMENT.start + mid + SEGMENT_RUNTIME.counter_mode_step, col); + if (SEGENV.step < mid) { + setPixelColor(SEGMENT.start + mid - SEGENV.step - 1, col); + setPixelColor(SEGMENT.start + mid + SEGENV.step, col); } else { - int i = SEGMENT_RUNTIME.counter_mode_step - mid; - setPixelColor(SEGMENT.start + i, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + SEGMENT_LENGTH - i - 1, SEGMENT.colors[1]); + int i = SEGENV.step - mid; + setPixelColor(SEGMENT.start + i, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + SEGLEN - i - 1, SEGCOLOR(1)); } } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; if (odd) { - if (SEGMENT_RUNTIME.counter_mode_step > SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step > SEGLEN) { + SEGENV.step = 0; } } else { - if (SEGMENT_RUNTIME.counter_mode_step >= SEGMENT_LENGTH) { - SEGMENT_RUNTIME.counter_mode_step = 0; + if (SEGENV.step >= SEGLEN) { + SEGENV.step = 0; } } return SPEED_FORMULA_L; @@ -1215,8 +1215,8 @@ uint16_t WS2812FX::mode_dual_color_wipe_out_in(void) { * Tricolor chase function */ uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2) { - uint16_t index = SEGMENT_RUNTIME.counter_mode_step % 6; - for(uint16_t i=0; i < SEGMENT_LENGTH; i++, index++) { + uint16_t index = SEGENV.step % 6; + for(uint16_t i=0; i < SEGLEN; i++, index++) { if(index > 5) index = 0; uint32_t color = color1; @@ -1226,7 +1226,7 @@ uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2) { setPixelColor(SEGMENT.stop - i -1, color); } - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; return 35 + ((350 * (uint32_t)(255 - SEGMENT.speed)) / 255); } @@ -1243,7 +1243,7 @@ uint16_t WS2812FX::mode_circus_combustus(void) { * Tricolor chase mode */ uint16_t WS2812FX::mode_tricolor_chase(void) { - return tricolor_chase(SEGMENT.colors[2], SEGMENT.colors[0]); + return tricolor_chase(SEGCOLOR(2), SEGCOLOR(0)); } @@ -1251,36 +1251,36 @@ uint16_t WS2812FX::mode_tricolor_chase(void) { * ICU mode */ uint16_t WS2812FX::mode_icu(void) { - uint16_t dest = SEGMENT_RUNTIME.counter_mode_step & 0xFFFF; + uint16_t dest = SEGENV.step & 0xFFFF; - fill(SEGMENT.colors[1]); + fill(SEGCOLOR(1)); - byte pindex = map(dest, 0, SEGMENT_LENGTH/2, 0, 255); + byte pindex = map(dest, 0, SEGLEN/2, 0, 255); uint32_t col = color_from_palette(pindex, false, false, 0); setPixelColor(SEGMENT.start + dest, col); - setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, col); + setPixelColor(SEGMENT.start + dest + SEGLEN/2, col); - if(SEGMENT_RUNTIME.aux_param == dest) { // pause between eye movements + if(SEGENV.aux0 == dest) { // pause between eye movements if(random8(6) == 0) { // blink once in a while - setPixelColor(SEGMENT.start + dest, SEGMENT.colors[1]); - setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[1]); + setPixelColor(SEGMENT.start + dest, SEGCOLOR(1)); + setPixelColor(SEGMENT.start + dest + SEGLEN/2, SEGCOLOR(1)); return 200; } - SEGMENT_RUNTIME.aux_param = random16(SEGMENT_LENGTH/2); + SEGENV.aux0 = random16(SEGLEN/2); return 1000 + random16(2000); } - if(SEGMENT_RUNTIME.aux_param > SEGMENT_RUNTIME.counter_mode_step) { - SEGMENT_RUNTIME.counter_mode_step++; + if(SEGENV.aux0 > SEGENV.step) { + SEGENV.step++; dest++; - } else if (SEGMENT_RUNTIME.aux_param < SEGMENT_RUNTIME.counter_mode_step) { - SEGMENT_RUNTIME.counter_mode_step--; + } else if (SEGENV.aux0 < SEGENV.step) { + SEGENV.step--; dest--; } setPixelColor(SEGMENT.start + dest, col); - setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, col); + setPixelColor(SEGMENT.start + dest + SEGLEN/2, col); return SPEED_FORMULA_L; } @@ -1291,19 +1291,19 @@ uint16_t WS2812FX::mode_icu(void) { */ uint16_t WS2812FX::mode_tricolor_wipe(void) { - if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) { - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step; - setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]); - } else if (SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH*2) { - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step - SEGMENT_LENGTH; - setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[1]); + if(SEGENV.step < SEGLEN) { + uint32_t led_offset = SEGENV.step; + setPixelColor(SEGMENT.start + led_offset, SEGCOLOR(0)); + } else if (SEGENV.step < SEGLEN*2) { + uint32_t led_offset = SEGENV.step - SEGLEN; + setPixelColor(SEGMENT.start + led_offset, SEGCOLOR(1)); } else { - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step - SEGMENT_LENGTH*2; + uint32_t led_offset = SEGENV.step - SEGLEN*2; setPixelColor(SEGMENT.start + led_offset, color_from_palette(SEGMENT.start + led_offset, true, PALETTE_SOLID_WRAP, 2)); } - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH * 3); + SEGENV.step = (SEGENV.step + 1) % (SEGLEN * 3); return SPEED_FORMULA_L; } @@ -1318,21 +1318,21 @@ uint16_t WS2812FX::mode_tricolor_fade(void) uint32_t color1 = 0, color2 = 0; byte stage = 0; - if(SEGMENT_RUNTIME.counter_mode_step < 256) { - color1 = SEGMENT.colors[0]; - color2 = SEGMENT.colors[1]; + if(SEGENV.step < 256) { + color1 = SEGCOLOR(0); + color2 = SEGCOLOR(1); stage = 0; - } else if(SEGMENT_RUNTIME.counter_mode_step < 512) { - color1 = SEGMENT.colors[1]; - color2 = SEGMENT.colors[2]; + } else if(SEGENV.step < 512) { + color1 = SEGCOLOR(1); + color2 = SEGCOLOR(2); stage = 1; } else { - color1 = SEGMENT.colors[2]; - color2 = SEGMENT.colors[0]; + color1 = SEGCOLOR(2); + color2 = SEGCOLOR(0); stage = 2; } - byte stp = SEGMENT_RUNTIME.counter_mode_step % 256; + byte stp = SEGENV.step % 256; uint32_t color = 0; for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) { if (stage == 2) { @@ -1345,8 +1345,8 @@ uint16_t WS2812FX::mode_tricolor_fade(void) setPixelColor(i, color); } - SEGMENT_RUNTIME.counter_mode_step += 4; - if(SEGMENT_RUNTIME.counter_mode_step >= 768) SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step += 4; + if(SEGENV.step >= 768) SEGENV.step = 0; return 5 + ((uint32_t)(255 - SEGMENT.speed) / 10); } @@ -1363,18 +1363,18 @@ uint16_t WS2812FX::mode_multi_comet(void) static uint16_t comets[] = {UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX}; for(uint8_t i=0; i < 8; i++) { - if(comets[i] < SEGMENT_LENGTH) { + if(comets[i] < SEGLEN) { uint16_t index = SEGMENT.start + comets[i]; - if (SEGMENT.colors[2] != 0) + if (SEGCOLOR(2) != 0) { - setPixelColor(index, i % 2 ? color_from_palette(index, true, PALETTE_SOLID_WRAP, 0) : SEGMENT.colors[2]); + setPixelColor(index, i % 2 ? color_from_palette(index, true, PALETTE_SOLID_WRAP, 0) : SEGCOLOR(2)); } else { setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); } comets[i]++; } else { - if(!random(SEGMENT_LENGTH)) { + if(!random(SEGLEN)) { comets[i] = 0; } } @@ -1388,29 +1388,29 @@ uint16_t WS2812FX::mode_multi_comet(void) * Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/DualLarson.h */ uint16_t WS2812FX::mode_dual_larson_scanner(void){ - if (SEGMENT_RUNTIME.aux_param) + if (SEGENV.aux0) { - SEGMENT_RUNTIME.counter_mode_step--; + SEGENV.step--; } else { - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.step++; } fade_out(SEGMENT.intensity); - uint16_t index = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step; + uint16_t index = SEGMENT.start + SEGENV.step; setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); - index = SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step -1; - if (SEGMENT.colors[2] != 0) + index = SEGMENT.stop - SEGENV.step -1; + if (SEGCOLOR(2) != 0) { - setPixelColor(index, SEGMENT.colors[2]); + setPixelColor(index, SEGCOLOR(2)); } else { setPixelColor(index, color_from_palette(index, true, PALETTE_SOLID_WRAP, 0)); } - if(SEGMENT_RUNTIME.counter_mode_step >= SEGMENT_LENGTH -1 || SEGMENT_RUNTIME.counter_mode_step <= 0) - SEGMENT_RUNTIME.aux_param = !SEGMENT_RUNTIME.aux_param; + if(SEGENV.step >= SEGLEN -1 || SEGENV.step <= 0) + SEGENV.aux0 = !SEGENV.aux0; return SPEED_FORMULA_L; } @@ -1426,7 +1426,7 @@ uint16_t WS2812FX::mode_random_chase(void) setPixelColor(i, getPixelColor(i-1)); } uint32_t color = getPixelColor(SEGMENT.start); - if (SEGMENT_LENGTH > 1) color = getPixelColor(SEGMENT.start + 1); + if (SEGLEN > 1) color = getPixelColor(SEGMENT.start + 1); uint8_t r = random8(6) != 0 ? (color >> 16 & 0xFF) : random8(); uint8_t g = random8(6) != 0 ? (color >> 8 & 0xFF) : random8(); uint8_t b = random8(6) != 0 ? (color & 0xFF) : random8(); @@ -1446,9 +1446,9 @@ typedef struct Oscillator { uint16_t WS2812FX::mode_oscillate(void) { static oscillator oscillators[2] = { - {SEGMENT_LENGTH/4, SEGMENT_LENGTH/8, 1, 1}, - {SEGMENT_LENGTH/4*2, SEGMENT_LENGTH/8, -1, 1} - //{SEGMENT_LENGTH/4*3, SEGMENT_LENGTH/8, 1, 2} + {SEGLEN/4, SEGLEN/8, 1, 1}, + {SEGLEN/4*2, SEGLEN/8, -1, 1} + //{SEGLEN/4*3, SEGLEN/8, 1, 2} }; for(int8_t i=0; i < sizeof(oscillators)/sizeof(oscillators[0]); i++) { @@ -1458,14 +1458,14 @@ uint16_t WS2812FX::mode_oscillate(void) oscillators[i].dir = 1; oscillators[i].speed = random8(1, 3); } - if((oscillators[i].dir == 1) && (oscillators[i].pos >= (SEGMENT_LENGTH - 1))) { - oscillators[i].pos = SEGMENT_LENGTH - 1; + if((oscillators[i].dir == 1) && (oscillators[i].pos >= (SEGLEN - 1))) { + oscillators[i].pos = SEGLEN - 1; oscillators[i].dir = -1; oscillators[i].speed = random8(1, 3); } } - for(int16_t i=0; i < SEGMENT_LENGTH; i++) { + for(int16_t i=0; i < SEGLEN; i++) { uint32_t color = BLACK; for(int8_t j=0; j < sizeof(oscillators)/sizeof(oscillators[0]); j++) { if(i >= oscillators[j].pos - oscillators[j].size && i <= oscillators[j].pos + oscillators[j].size) { @@ -1480,20 +1480,20 @@ uint16_t WS2812FX::mode_oscillate(void) uint16_t WS2812FX::mode_lightning(void) { - uint16_t ledstart = SEGMENT.start + random8(SEGMENT_LENGTH); // Determine starting location of flash + uint16_t ledstart = SEGMENT.start + random8(SEGLEN); // Determine starting location of flash uint16_t ledlen = random8(SEGMENT.stop -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) uint8_t bri = 255/random8(1, 3); - if (SEGMENT_RUNTIME.counter_mode_step == 0) + if (SEGENV.step == 0) { - SEGMENT_RUNTIME.aux_param = random8(3, 3 + SEGMENT.intensity/20); //number of flashes + SEGENV.aux0 = random8(3, 3 + SEGMENT.intensity/20); //number of flashes bri = 52; - SEGMENT_RUNTIME.aux_param2 = 1; + SEGENV.aux1 = 1; } - fill(SEGMENT.colors[1]); + fill(SEGCOLOR(1)); - if (SEGMENT_RUNTIME.aux_param2) { + if (SEGENV.aux1) { for (int i = ledstart; i < ledstart + ledlen; i++) { if (SEGMENT.palette == 0) @@ -1503,17 +1503,17 @@ uint16_t WS2812FX::mode_lightning(void) setPixelColor(i,color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, bri)); } } - SEGMENT_RUNTIME.aux_param2 = 0; - SEGMENT_RUNTIME.counter_mode_step++; + SEGENV.aux1 = 0; + SEGENV.step++; return random8(4, 10); // each flash only lasts 4-10 milliseconds } - SEGMENT_RUNTIME.aux_param2 = 1; - if (SEGMENT_RUNTIME.counter_mode_step == 1) return (200); // longer delay until next flash after the leader + SEGENV.aux1 = 1; + if (SEGENV.step == 1) return (200); // longer delay until next flash after the leader - if (SEGMENT_RUNTIME.counter_mode_step <= SEGMENT_RUNTIME.aux_param) return (50 + random8(100)); // shorter delay between strokes + if (SEGENV.step <= SEGENV.aux0) return (50 + random8(100)); // shorter delay between strokes - SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step = 0; return (random8(255 - SEGMENT.speed) * 100); // delay between strikes } @@ -1524,8 +1524,8 @@ uint16_t WS2812FX::mode_lightning(void) uint16_t WS2812FX::mode_pride_2015(void) { uint16_t duration = 10 + SEGMENT.speed; - uint16_t sPseudotime = SEGMENT_RUNTIME.counter_mode_step; - uint16_t sHue16 = SEGMENT_RUNTIME.aux_param; + uint16_t sPseudotime = SEGENV.step; + uint16_t sHue16 = SEGENV.aux0; uint8_t sat8 = beatsin88( 87, 220, 250); uint8_t brightdepth = beatsin88( 341, 96, 224); @@ -1557,8 +1557,8 @@ uint16_t WS2812FX::mode_pride_2015(void) nblend( fastled_col, newcolor, 64); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } - SEGMENT_RUNTIME.counter_mode_step = sPseudotime; - SEGMENT_RUNTIME.aux_param = sHue16; + SEGENV.step = sPseudotime; + SEGENV.aux0 = sHue16; return 20; } @@ -1569,7 +1569,7 @@ uint16_t WS2812FX::mode_juggle(void){ CRGB fastled_col; byte dothue = 0; for ( byte i = 0; i < 8; i++) { - uint16_t index = SEGMENT.start + beatsin16(i + 7, 0, SEGMENT_LENGTH -1); + uint16_t index = SEGMENT.start + beatsin16(i + 7, 0, SEGLEN -1); fastled_col = fastled_from_col(getPixelColor(index)); fastled_col |= (SEGMENT.palette==0)?CHSV(dothue, 220, 255):ColorFromPalette(currentPalette, dothue, 255); setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue); @@ -1584,14 +1584,14 @@ uint16_t WS2812FX::mode_palette(void) bool noWrap = (paletteBlend == 2 || (paletteBlend == 0 && SEGMENT.speed == 0)); for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { - uint8_t colorIndex = map(i,SEGMENT.start,SEGMENT.stop -1,0,255) - (SEGMENT_RUNTIME.counter_mode_step >> 6 & 0xFF); + uint8_t colorIndex = map(i,SEGMENT.start,SEGMENT.stop -1,0,255) - (SEGENV.step >> 6 & 0xFF); if (noWrap) colorIndex = map(colorIndex, 0, 255, 0, 240); //cut off blend at palette "end" setPixelColor(i, color_from_palette(colorIndex, false, true, 255)); } - SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed; - if (SEGMENT.speed == 0) SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step += SEGMENT.speed; + if (SEGMENT.speed == 0) SEGENV.step = 0; return 20; } @@ -1634,7 +1634,7 @@ uint16_t WS2812FX::mode_fire_2012(void) { // Step 1. Cool down every cell a little for( int i = SEGMENT.start; i < SEGMENT.stop; i++) { - _locked[i] = qsub8(_locked[i], random8(0, ((COOLING * 10) / SEGMENT_LENGTH) + 2)); + _locked[i] = qsub8(_locked[i], random8(0, ((COOLING * 10) / SEGLEN) + 2)); } // Step 2. Heat from each cell drifts 'up' and diffuses a little @@ -1663,8 +1663,8 @@ uint16_t WS2812FX::mode_fire_2012(void) uint16_t WS2812FX::mode_colorwaves(void) { uint16_t duration = 10 + SEGMENT.speed; - uint16_t sPseudotime = SEGMENT_RUNTIME.counter_mode_step; - uint16_t sHue16 = SEGMENT_RUNTIME.aux_param; + uint16_t sPseudotime = SEGENV.step; + uint16_t sHue16 = SEGENV.aux0; uint8_t brightdepth = beatsin88( 341, 96, 224); uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256)); @@ -1701,8 +1701,8 @@ uint16_t WS2812FX::mode_colorwaves(void) nblend(fastled_col, newcolor, 128); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } - SEGMENT_RUNTIME.counter_mode_step = sPseudotime; - SEGMENT_RUNTIME.aux_param = sHue16; + SEGENV.step = sPseudotime; + SEGENV.aux0 = sHue16; return 20; } @@ -1713,25 +1713,25 @@ uint16_t WS2812FX::mode_bpm(void) CRGB fastled_col; uint8_t beat = beatsin8(SEGMENT.speed, 64, 255); for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { - fastled_col = ColorFromPalette(currentPalette, SEGMENT_RUNTIME.counter_mode_step + (i * 2), beat - SEGMENT_RUNTIME.counter_mode_step + (i * 10)); + fastled_col = ColorFromPalette(currentPalette, SEGENV.step + (i * 2), beat - SEGENV.step + (i * 10)); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } - SEGMENT_RUNTIME.counter_mode_step++; - if (SEGMENT_RUNTIME.counter_mode_step >= 255) SEGMENT_RUNTIME.counter_mode_step = 0; + SEGENV.step++; + if (SEGENV.step >= 255) SEGENV.step = 0; return 20; } uint16_t WS2812FX::mode_fillnoise8(void) { - if (SEGMENT_RUNTIME.counter_mode_call == 0) SEGMENT_RUNTIME.counter_mode_step = random16(12345); + if (SEGENV.call == 0) SEGENV.step = random16(12345); CRGB fastled_col; for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { - uint8_t index = inoise8(i * SEGMENT_LENGTH, SEGMENT_RUNTIME.counter_mode_step + i * SEGMENT_LENGTH) % 255; + uint8_t index = inoise8(i * SEGLEN, SEGENV.step + i * SEGLEN) % 255; fastled_col = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } - SEGMENT_RUNTIME.counter_mode_step += beatsin8(SEGMENT.speed, 1, 6); //10,1,4 + SEGENV.step += beatsin8(SEGMENT.speed, 1, 6); //10,1,4 return 20; } @@ -1740,17 +1740,17 @@ uint16_t WS2812FX::mode_noise16_1(void) { uint16_t scale = 320; // the "zoom factor" for the noise CRGB fastled_col; - SEGMENT_RUNTIME.counter_mode_step += (1 + SEGMENT.speed/16); + SEGENV.step += (1 + SEGMENT.speed/16); for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { uint16_t shift_x = beatsin8(11); // the x position of the noise field swings @ 17 bpm - uint16_t shift_y = SEGMENT_RUNTIME.counter_mode_step/42; // the y position becomes slowly incremented + uint16_t shift_y = SEGENV.step/42; // the y position becomes slowly incremented uint16_t real_x = (i + shift_x) * scale; // the x position of the noise field swings @ 17 bpm uint16_t real_y = (i + shift_y) * scale; // the y position becomes slowly incremented - uint32_t real_z = SEGMENT_RUNTIME.counter_mode_step; // the z position becomes quickly incremented + uint32_t real_z = SEGENV.step; // the z position becomes quickly incremented uint8_t noise = inoise16(real_x, real_y, real_z) >> 8; // get the noise data and scale it down @@ -1768,12 +1768,12 @@ uint16_t WS2812FX::mode_noise16_2(void) { uint16_t scale = 1000; // the "zoom factor" for the noise CRGB fastled_col; - SEGMENT_RUNTIME.counter_mode_step += (1 + SEGMENT.speed); + SEGENV.step += (1 + SEGMENT.speed); for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { - uint16_t shift_x = SEGMENT_RUNTIME.counter_mode_step >> 6; // x as a function of time - uint16_t shift_y = SEGMENT_RUNTIME.counter_mode_step/42; + uint16_t shift_x = SEGENV.step >> 6; // x as a function of time + uint16_t shift_y = SEGENV.step/42; uint32_t real_x = (i + shift_x) * scale; // calculate the coordinates within the noise field @@ -1793,7 +1793,7 @@ uint16_t WS2812FX::mode_noise16_3(void) { uint16_t scale = 800; // the "zoom factor" for the noise CRGB fastled_col; - SEGMENT_RUNTIME.counter_mode_step += (1 + SEGMENT.speed); + SEGENV.step += (1 + SEGMENT.speed); for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { @@ -1802,7 +1802,7 @@ uint16_t WS2812FX::mode_noise16_3(void) uint32_t real_x = (i + shift_x) * scale; // calculate the coordinates within the noise field uint32_t real_y = (i + shift_y) * scale; // based on the precalculated positions - uint32_t real_z = SEGMENT_RUNTIME.counter_mode_step*8; + uint32_t real_z = SEGENV.step*8; uint8_t noise = inoise16(real_x, real_y, real_z) >> 8; // get the noise data and scale it down @@ -1820,9 +1820,9 @@ uint16_t WS2812FX::mode_noise16_3(void) uint16_t WS2812FX::mode_noise16_4(void) { CRGB fastled_col; - SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed; + SEGENV.step += SEGMENT.speed; for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { - int16_t index = inoise16(uint32_t(i - SEGMENT.start) << 12, SEGMENT_RUNTIME.counter_mode_step/8); + int16_t index = inoise16(uint32_t(i - SEGMENT.start) << 12, SEGENV.step/8); fastled_col = ColorFromPalette(currentPalette, index); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); } @@ -1859,12 +1859,12 @@ uint16_t WS2812FX::mode_colortwinkle() } } - for (uint16_t j = 0; j <= SEGMENT_LENGTH / 50; j++) + for (uint16_t j = 0; j <= SEGLEN / 50; j++) { if ( random8() <= SEGMENT.intensity ) { for (uint8_t times = 0; times < 5; times++) //attempt to spawn a new pixel 5 times { - int i = SEGMENT.start + random16(SEGMENT_LENGTH); + int i = SEGMENT.start + random16(SEGLEN); if(getPixelColor(i) == 0) { fastled_col = ColorFromPalette(currentPalette, random8(), 64, NOBLEND); _locked[i] = true; @@ -1901,8 +1901,8 @@ uint16_t WS2812FX::mode_lake() { // send a meteor from begining to to the end of the strip with a trail that randomly decays. // adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain uint16_t WS2812FX::mode_meteor() { - byte meteorSize= 1+ SEGMENT_LENGTH / 10; - uint16_t in = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step; + byte meteorSize= 1+ SEGLEN / 10; + uint16_t in = SEGMENT.start + SEGENV.step; // fade all leds to colors[1] in LEDs one step for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { @@ -1925,7 +1925,7 @@ uint16_t WS2812FX::mode_meteor() { setPixelColor(index, color_from_palette(_locked[index], false, true, 255)); } - SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH); + SEGENV.step = (SEGENV.step + 1) % (SEGLEN); return SPEED_FORMULA_L; } @@ -1934,8 +1934,8 @@ uint16_t WS2812FX::mode_meteor() { // send a meteor from begining to to the end of the strip with a trail that randomly decays. // adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain uint16_t WS2812FX::mode_meteor_smooth() { - byte meteorSize= 1+ SEGMENT_LENGTH / 10; - uint16_t in = map((SEGMENT_RUNTIME.counter_mode_step >> 6 & 0xFF), 0, 255, SEGMENT.start, SEGMENT.stop -1); + byte meteorSize= 1+ SEGLEN / 10; + uint16_t in = map((SEGENV.step >> 6 & 0xFF), 0, 255, SEGMENT.start, SEGMENT.stop -1); // fade all leds to colors[1] in LEDs one step for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) { @@ -1959,7 +1959,7 @@ uint16_t WS2812FX::mode_meteor_smooth() { _locked[index] = 240; } - SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed +1; + SEGENV.step += SEGMENT.speed +1; return 20; } @@ -1969,19 +1969,19 @@ uint16_t WS2812FX::mode_railway() { uint16_t dur = 40 + (255 - SEGMENT.speed) * 10; uint16_t rampdur = (dur * SEGMENT.intensity) >> 8; - if (SEGMENT_RUNTIME.counter_mode_step > dur) + if (SEGENV.step > dur) { //reverse direction - SEGMENT_RUNTIME.counter_mode_step = 0; - SEGMENT_RUNTIME.aux_param = !SEGMENT_RUNTIME.aux_param; + SEGENV.step = 0; + SEGENV.aux0 = !SEGENV.aux0; } uint8_t pos = 255; if (rampdur != 0) { - uint16_t p0 = (SEGMENT_RUNTIME.counter_mode_step * 255) / rampdur; + uint16_t p0 = (SEGENV.step * 255) / rampdur; if (p0 < 255) pos = p0; } - if (SEGMENT_RUNTIME.aux_param) pos = 255 - pos; + if (SEGENV.aux0) pos = 255 - pos; for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i += 2) { setPixelColor(i, color_from_palette(255 - pos, false, false, 255)); @@ -1990,7 +1990,7 @@ uint16_t WS2812FX::mode_railway() setPixelColor(i + 1, color_from_palette(pos, false, false, 255)); } } - SEGMENT_RUNTIME.counter_mode_step += 20; + SEGENV.step += 20; return 20; } @@ -2000,10 +2000,10 @@ uint16_t WS2812FX::mode_railway() //drop rate from intensity uint16_t WS2812FX::mode_ripple() { - uint16_t maxripples = SEGMENT_LENGTH / 4; + uint16_t maxripples = SEGLEN / 4; if (maxripples == 0) return mode_static(); - fill(SEGMENT.colors[1]); + fill(SEGCOLOR(1)); //draw wave for (uint16_t rippleI = 0; rippleI < maxripples; rippleI++) @@ -2041,7 +2041,7 @@ uint16_t WS2812FX::mode_ripple() if (random16(IBN + 10000) <= SEGMENT.intensity) { _locked[storeI] = 1; - uint16_t origin = SEGMENT.start + random16(SEGMENT_LENGTH); + uint16_t origin = SEGMENT.start + random16(SEGLEN); _locked[storeI+1] = origin >> 8; _locked[storeI+2] = origin & 0xFF; _locked[storeI+3] = random8(); diff --git a/wled00/WS2812FX.h b/wled00/WS2812FX.h index d7ff5b46..15d9e626 100644 --- a/wled00/WS2812FX.h +++ b/wled00/WS2812FX.h @@ -42,12 +42,13 @@ /* each segment uses 37 bytes of SRAM memory, so if you're application fails because of insufficient memory, decreasing MAX_NUM_SEGMENTS may help */ -#define MAX_NUM_SEGMENTS 1 -#define NUM_COLORS 3 /* number of colors per segment */ +#define MAX_NUM_SEGMENTS 8 +#define NUM_COLORS 3 /* number of colors per segment */ #define SEGMENT _segments[_segment_index] -#define SEGMENT_RUNTIME _segment_runtimes[_segment_index] -#define SEGMENT_LENGTH (SEGMENT.stop - SEGMENT.start) -#define SPEED_FORMULA_L 5 + (50*(255 - SEGMENT.speed))/SEGMENT_LENGTH +#define SEGCOLOR(x) gamma32(_segments[_segment_index].colors[x]) +#define SEGENV _segment_runtimes[_segment_index] +#define SEGLEN SEGMENT.length() +#define SPEED_FORMULA_L 5 + (50*(255 - SEGMENT.speed))/SEGLEN #define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes)) // some common colors @@ -176,11 +177,6 @@ class WS2812FX { uint8_t mode; uint8_t options; //bit pattern: msb first: transitional tbd tbd tbd tbd paused reverse selected uint32_t colors[NUM_COLORS]; - //member functions - uint32_t color(uint8_t n) - { - return colors[n]; - } void setOption(uint8_t n, bool val) { if (val) { @@ -194,16 +190,20 @@ class WS2812FX { { return ((options >> n) & 0x01); } + inline uint16_t length() + { + return stop - start; + } } segment; // segment runtime parameters typedef struct Segment_runtime { // 16 bytes unsigned long next_time; - uint32_t counter_mode_step; - uint32_t counter_mode_call; - uint16_t aux_param; - uint16_t aux_param2; - void reset(){next_time = 0; counter_mode_step = 0; counter_mode_call = 0; aux_param = 0; aux_param2 = 0;}; + uint32_t step; + uint32_t call; + uint16_t aux0; + uint16_t aux1; + void reset(){next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;}; } segment_runtime; WS2812FX() { @@ -296,11 +296,6 @@ class WS2812FX { _segments[0].speed = DEFAULT_SPEED; currentPalette = CRGBPalette16(CRGB::Black); targetPalette = CloudColors_p; - _reverseMode = false; - _skipFirstMode = false; - colorOrder = 0; - paletteFade = 0; - paletteBlend = 0; ablMilliampsMax = 850; currentMilliamps = 0; _locked = nullptr; @@ -310,7 +305,7 @@ class WS2812FX { } void - init(bool supportWhite, uint16_t countPixels, bool skipFirst), + init(bool supportWhite, uint16_t countPixels, bool skipFirs), service(void), blur(uint8_t), fade_out(uint8_t r), @@ -323,7 +318,6 @@ class WS2812FX { setColor(uint32_t c), setSecondaryColor(uint32_t c), setBrightness(uint8_t b), - setReverseMode(bool b), driverModeCronixie(bool b), setCronixieDigits(byte* d), setCronixieBacklight(bool b), @@ -343,12 +337,15 @@ class WS2812FX { show(void); bool + reverseMode = true, + gammaCorrectBri = false, + gammaCorrectCol = true, setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p); uint8_t - paletteFade, - paletteBlend, - colorOrder, + paletteFade = 0, + paletteBlend = 0, + colorOrder = 0, getBrightness(void), getMode(void), getSpeed(void), @@ -356,12 +353,14 @@ class WS2812FX { getModeCount(void), getPaletteCount(void), getMaxSegments(void), + gamma8(uint8_t), get_random_wheel_index(uint8_t); uint32_t color_wheel(uint8_t), color_from_palette(uint16_t, bool, bool, uint8_t, uint8_t pbri = 255), color_blend(uint32_t,uint32_t,uint8_t), + gamma32(uint32_t), getPixelColor(uint16_t), getColor(void); @@ -491,7 +490,6 @@ class WS2812FX { bool _modeUsesLock, _rgbwMode, - _reverseMode, _cronixieMode, _cronixieBacklightEnabled, _skipFirstMode, diff --git a/wled00/WS2812FX_fcn.cpp b/wled00/WS2812FX_fcn.cpp index dce048f9..34b76469 100644 --- a/wled00/WS2812FX_fcn.cpp +++ b/wled00/WS2812FX_fcn.cpp @@ -61,13 +61,13 @@ void WS2812FX::service() { for(uint8_t i=0; i < _num_segments; i++) { _segment_index = i; - if(now > SEGMENT_RUNTIME.next_time || _triggered) + if(now > SEGENV.next_time || _triggered) { doShow = true; handle_palette(); uint16_t delay = (this->*_mode[SEGMENT.mode])(); - SEGMENT_RUNTIME.next_time = now + max(delay, MIN_SHOW_DELAY); - SEGMENT_RUNTIME.counter_mode_call++; + SEGENV.next_time = now + max(delay, MIN_SHOW_DELAY); + SEGENV.call++; } } if(doShow) { @@ -97,7 +97,7 @@ void WS2812FX::setPixelColor(uint16_t n, uint32_t c) { void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) { if (_locked[i] && !_modeUsesLock) return; - if (_reverseMode) i = _length -1 -i; + if (reverseMode) i = _length -1 -i; if (IS_REVERSE) i = SEGMENT.stop -1 -i - SEGMENT.start; //reverse just individual segment byte tmpg = g; switch (colorOrder) //0 = Grb, default @@ -153,11 +153,6 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) } } -void WS2812FX::setReverseMode(bool b) -{ - _reverseMode = b; -} - void WS2812FX::driverModeCronixie(bool b) { _cronixieMode = b; @@ -316,8 +311,8 @@ void WS2812FX::setSecondaryColor(uint32_t c) { void WS2812FX::setBrightness(uint8_t b) { if (_brightness == b) return; - _brightness = b; - if (SEGMENT_RUNTIME.next_time > millis() + 20) show(); //apply brightness change immeadiately if no refresh soon + _brightness = gammaCorrectBri ? gamma8(b) : b; + if (SEGENV.next_time > millis() + 20) show(); //apply brightness change immediately if no refresh soon } uint8_t WS2812FX::getMode(void) { @@ -346,7 +341,7 @@ uint32_t WS2812FX::getColor(void) { uint32_t WS2812FX::getPixelColor(uint16_t i) { - if (_reverseMode) i = _length- 1 -i; + if (reverseMode) i = _length- 1 -i; if (IS_REVERSE) i = SEGMENT.stop -1 -i - SEGMENT.start; //reverse just individual segment if (_skipFirstMode) i += LED_SKIP_AMOUNT; if (_cronixieMode) @@ -386,7 +381,7 @@ WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) { } WS2812FX::Segment_runtime WS2812FX::getSegmentRuntime(void) { - return SEGMENT_RUNTIME; + return SEGENV; } WS2812FX::Segment* WS2812FX::getSegments(void) { @@ -477,7 +472,7 @@ void WS2812FX::setTransitionMode(bool t) SEGMENT.setOption(7,t); if (!t) return; unsigned long waitMax = millis() + 20; //refresh after 20 ms if transition enabled - if (SEGMENT.mode == FX_MODE_STATIC && SEGMENT_RUNTIME.next_time > waitMax) SEGMENT_RUNTIME.next_time = waitMax; + if (SEGMENT.mode == FX_MODE_STATIC && SEGENV.next_time > waitMax) SEGENV.next_time = waitMax; } /* @@ -521,7 +516,7 @@ void WS2812FX::fade_out(uint8_t rate) { rate = (255-rate) >> 1; float mappedRate = float(rate) +1.1; - uint32_t color = SEGMENT.colors[1]; // target color + uint32_t color = SEGCOLOR(1); // target color int w2 = (color >> 24) & 0xff; int r2 = (color >> 16) & 0xff; int g2 = (color >> 8) & 0xff; @@ -663,11 +658,11 @@ void WS2812FX::handle_palette(void) _lastPaletteChange = millis(); } break;} case 2: {//primary color only - CRGB prim = fastled_from_col(SEGMENT.colors[0]); + CRGB prim = fastled_from_col(SEGCOLOR(0)); targetPalette = CRGBPalette16(prim); break;} case 3: {//based on primary //considering performance implications - CRGB prim = fastled_from_col(SEGMENT.colors[0]); + CRGB prim = fastled_from_col(SEGCOLOR(0)); CHSV prim_hsv = rgb2hsv_approximate(prim); targetPalette = CRGBPalette16( CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v), //color itself @@ -676,12 +671,12 @@ void WS2812FX::handle_palette(void) CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v)); //color itself break;} case 4: {//primary + secondary - CRGB prim = fastled_from_col(SEGMENT.colors[0]); - CRGB sec = fastled_from_col(SEGMENT.colors[1]); + CRGB prim = fastled_from_col(SEGCOLOR(0)); + CRGB sec = fastled_from_col(SEGCOLOR(1)); targetPalette = CRGBPalette16(sec,prim); break;} case 5: {//based on primary + secondary - CRGB prim = fastled_from_col(SEGMENT.colors[0]); - CRGB sec = fastled_from_col(SEGMENT.colors[1]); + CRGB prim = fastled_from_col(SEGCOLOR(0)); + CRGB sec = fastled_from_col(SEGCOLOR(1)); targetPalette = CRGBPalette16(sec,prim,CRGB::White); break;} case 6: //Party colors targetPalette = PartyColors_p; break; @@ -720,3 +715,41 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8 fastled_col = ColorFromPalette( currentPalette, paletteIndex, pbri, (paletteBlend == 3)? NOBLEND:LINEARBLEND); return fastled_col.r*65536 + fastled_col.g*256 + fastled_col.b; } + +//gamma 2.4 lookup table used for color correction +const byte gammaT[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, + 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, + 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, + 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, + 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, + 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, + 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, + 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, + 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, + 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, + 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; + +uint8_t WS2812FX::gamma8(uint8_t b) +{ + return gammaT[b]; +} + +uint32_t WS2812FX::gamma32(uint32_t color) +{ + if (!gammaCorrectCol) return color; + uint8_t w = (color >> 24) & 0xFF; + uint8_t r = (color >> 16) & 0xFF; + uint8_t g = (color >> 8) & 0xFF; + uint8_t b = color & 0xFF; + w = gammaT[w]; + r = gammaT[r]; + g = gammaT[g]; + b = gammaT[b]; + return ((w << 24) | (r << 16) | (g << 8) | (b)); +} diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 97559810..1b90af15 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -30,7 +30,7 @@ //#define WLED_ENABLE_FS_EDITOR //enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock //to toggle usb serial debug (un)comment the following line -#define WLED_DEBUG +//#define WLED_DEBUG //library inclusions @@ -98,7 +98,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1905091 +#define VERSION 1905222 char versionString[] = "0.8.4"; @@ -144,17 +144,17 @@ byte effectSpeedDefault = 75; byte effectIntensityDefault = 128; //intensity is supported on some effects as an additional parameter (e.g. for blink you can change the duty cycle) byte effectPaletteDefault = 0; //palette is supported on the FastLED effects, otherwise it has no effect -bool useGammaCorrectionBri = false; //gamma correct brightness (not recommended) -bool useGammaCorrectionRGB = true; //gamma correct colors (strongly recommended) +//bool strip.gammaCorrectBri = false; //gamma correct brightness (not recommended) --> edit in WS2812FX.h +//bool strip.gammaCorrectCol = true; //gamma correct colors (strongly recommended) byte nightlightTargetBri = 0; //brightness after nightlight is over byte nightlightDelayMins = 60; bool nightlightFade = true; //if enabled, light will gradually dim towards the target bri. Otherwise, it will instantly set after delay over bool fadeTransition = true; //enable crossfading color transition bool enableSecTransition = true; //also enable transition for secondary color -uint16_t transitionDelay = 750; //default crossfade duration in ms +uint16_t transitionDelay = 750; //default crossfade duration in ms -bool reverseMode = false; //flip entire LED strip (reverses all effect directions) +//bool strip.reverseMode = false; //flip entire LED strip (reverses all effect directions) --> edit in WS2812FX.h bool skipFirstLed = false; //ignore first LED in strip (useful if you need the LED as signal repeater) byte briMultiplier = 100; //% of brightness to set (to limit power, if you set it to 50 and set bri to 255, actual brightness will be 127) @@ -450,25 +450,6 @@ WS2812FX strip = WS2812FX(); #include "SPIFFSEditor.h" #endif -//gamma 2.4 lookup table used for color correction -const byte gamma8[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, - 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, - 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, - 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, - 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, - 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, - 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, - 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, - 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, - 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, - 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, - 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, - 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, - 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; - //function prototypes void serveMessage(AsyncWebServerRequest*,uint16_t,String,String,byte); diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 19e9cc0d..9aa3a339 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -96,7 +96,7 @@ void saveSettingsToEEPROM() EEPROM.write(250, receiveNotificationBrightness); EEPROM.write(251, fadeTransition); - EEPROM.write(252, reverseMode); + EEPROM.write(252, strip.reverseMode); EEPROM.write(253, transitionDelayDefault & 0xFF); EEPROM.write(254, (transitionDelayDefault >> 8) & 0xFF); EEPROM.write(255, briMultiplier); @@ -117,8 +117,8 @@ void saveSettingsToEEPROM() EEPROM.write(327, ntpEnabled); EEPROM.write(328, currentTimezone); EEPROM.write(329, useAMPM); - EEPROM.write(330, useGammaCorrectionBri); - EEPROM.write(331, useGammaCorrectionRGB); + EEPROM.write(330, strip.gammaCorrectBri); + EEPROM.write(331, strip.gammaCorrectCol); EEPROM.write(332, overlayDefault); EEPROM.write(333, alexaEnabled); @@ -321,7 +321,7 @@ void loadSettingsFromEEPROM(bool first) } receiveNotificationBrightness = EEPROM.read(250); fadeTransition = EEPROM.read(251); - reverseMode = EEPROM.read(252); + strip.reverseMode = EEPROM.read(252); transitionDelayDefault = EEPROM.read(253) + ((EEPROM.read(254) << 8) & 0xFF00); transitionDelay = transitionDelayDefault; briMultiplier = EEPROM.read(255); @@ -339,8 +339,8 @@ void loadSettingsFromEEPROM(bool first) ntpEnabled = EEPROM.read(327); currentTimezone = EEPROM.read(328); useAMPM = EEPROM.read(329); - useGammaCorrectionBri = EEPROM.read(330); - useGammaCorrectionRGB = EEPROM.read(331); + strip.gammaCorrectBri = EEPROM.read(330); + strip.gammaCorrectCol = EEPROM.read(331); overlayDefault = EEPROM.read(332); if (lastEEPROMversion < 8 && overlayDefault > 0) overlayDefault--; //overlay mode 1 (solid) was removed diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index d8754c80..a828c0ba 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -253,8 +253,8 @@ void getSettingsJS(byte subPage, char* dest) oappend(";"); sappend('v',"SX",effectSpeedDefault); sappend('v',"IX",effectIntensityDefault); - sappend('c',"GB",useGammaCorrectionBri); - sappend('c',"GC",useGammaCorrectionRGB); + sappend('c',"GB",strip.gammaCorrectBri); + sappend('c',"GC",strip.gammaCorrectCol); sappend('c',"TF",fadeTransition); sappend('v',"TD",transitionDelay); sappend('c',"PF",strip.paletteFade); @@ -264,7 +264,7 @@ void getSettingsJS(byte subPage, char* dest) sappend('v',"TL",nightlightDelayMinsDefault); sappend('c',"TW",nightlightFade); sappend('i',"PB",strip.paletteBlend); - sappend('c',"RV",reverseMode); + sappend('c',"RV",strip.reverseMode); sappend('c',"SL",skipFirstLed); } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index a9706da6..6ad4ddea 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -98,8 +98,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) turnOnAtBoot = request->hasArg("BO"); t = request->arg("BP").toInt(); if (t <= 25) bootPreset = t; - useGammaCorrectionBri = request->hasArg("GB"); - useGammaCorrectionRGB = request->hasArg("GC"); + strip.gammaCorrectBri = request->hasArg("GB"); + strip.gammaCorrectCol = request->hasArg("GC"); fadeTransition = request->hasArg("TF"); t = request->arg("TD").toInt(); @@ -115,8 +115,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) t = request->arg("PB").toInt(); if (t >= 0 && t < 4) strip.paletteBlend = t; - reverseMode = request->hasArg("RV"); - strip.setReverseMode(reverseMode); + strip.reverseMode = request->hasArg("RV"); skipFirstLed = request->hasArg("SL"); t = request->arg("BF").toInt(); if (t > 0) briMultiplier = t; diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index e4871399..f78ab818 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -143,7 +143,6 @@ void wledInit() void beginStrip() { // Initialize NeoPixel Strip and button - strip.setReverseMode(reverseMode); strip.setColor(0); strip.setBrightness(255); diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index d54c80d0..60b69c5f 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -258,9 +258,9 @@ void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) uint16_t pix = i + arlsOffset; if (pix < ledCount) { - if (!arlsDisableGammaCorrection && useGammaCorrectionRGB) + if (!arlsDisableGammaCorrection && strip.gammaCorrectCol) { - strip.setPixelColor(pix, gamma8[r], gamma8[g], gamma8[b], gamma8[w]); + strip.setPixelColor(pix, strip.gamma8(r), strip.gamma8(g), strip.gamma8(b), strip.gamma8(w)); } else { strip.setPixelColor(pix, r, g, b, w); } diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index 2395c5db..c839e1fe 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -21,12 +21,7 @@ void setAllLeds() { double d = briT*briMultiplier; int val = d/100; if (val > 255) val = 255; - if (useGammaCorrectionBri) - { - strip.setBrightness(gamma8[val]); - } else { - strip.setBrightness(val); - } + strip.setBrightness(val); } if (!enableSecTransition) { @@ -40,14 +35,8 @@ void setAllLeds() { colorRGBtoRGBW(colT); colorRGBtoRGBW(colSecT); } - if (useGammaCorrectionRGB) - { - strip.setColor(gamma8[colT[0]], gamma8[colT[1]], gamma8[colT[2]], gamma8[colT[3]]); - strip.setSecondaryColor(gamma8[colSecT[0]], gamma8[colSecT[1]], gamma8[colSecT[2]], gamma8[colSecT[3]]); - } else { - strip.setColor(colT[0], colT[1], colT[2], colT[3]); - strip.setSecondaryColor(colSecT[0], colSecT[1], colSecT[2], colSecT[3]); - } + strip.setColor(colT[0], colT[1], colT[2], colT[3]); + strip.setSecondaryColor(colSecT[0], colSecT[1], colSecT[2], colSecT[3]); } diff --git a/wled00/wled19_json.ino b/wled00/wled19_json.ino index 6ea34933..0f07238c 100644 --- a/wled00/wled19_json.ino +++ b/wled00/wled19_json.ino @@ -125,13 +125,7 @@ void serializeSegment(JsonObject& root) JsonArray& colarr = root.createNestedArray("col"); - //temporary - JsonArray& c0 = colarr.createNestedArray(); - c0.add(col[0]); c0.add(col[1]); c0.add(col[2]); if (useRGBW) c0.add(col[3]); - JsonArray& c1 = colarr.createNestedArray(); - c1.add(colSec[0]); c1.add(colSec[1]); c1.add(colSec[2]); if (useRGBW) c1.add(colSec[3]); - //set i back to 0 once temporary is removed! - for (uint8_t i = 2; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) { JsonArray& colX = colarr.createNestedArray(); colX.add((seg.colors[i] >> 16) & 0xFF); @@ -211,7 +205,7 @@ void serializeInfo(JsonObject& root) root["brand"] = "WLED"; root["product"] = "DIY light"; - root["btype"] = "src"; + root["btype"] = "dev"; root["mac"] = escapedMac; }