Started adding Custom Chase FX functions, still crashing if CP>1

Removed name function from FX library because it is unused in WLED
This commit is contained in:
cschwinne 2017-11-29 23:56:02 +01:00
parent 0c087cc9c9
commit e20cab74de
4 changed files with 153 additions and 77 deletions

View File

@ -164,14 +164,6 @@ uint32_t WS2812FX::getColor(void) {
return _color;
}
const char* WS2812FX::getModeName(uint8_t m) {
if(m < MODE_COUNT) {
return _name[m];
} else {
return "";
}
}
/* #####################################################
#
# Color and Blinken Functions
@ -1559,6 +1551,41 @@ void WS2812FX::mode_circus_combustus(void) {
_mode_delay = 100 + ((100 * (uint32_t)(SPEED_MAX - _speed)) / _led_count);
}
void WS2812FX::mode_cc_core()
{
for(uint16_t i=_cc_i1; i <= _cc_i2; i++)
{
if(i % (_cc_num1 + _cc_num2) == _counter_cc_step)
{
for (uint16_t j=i; j < _cc_num1 +i; j++)
{
if (j > _cc_i2) j = (j % _cc_i2) + _cc_i1;
if (_cc_fs) setPixelColor(j, _color);
if (_cc_fe) setPixelColor(_cc_i2 - (j-_cc_i1), _color);
}
}
}
show();
_counter_cc_step = (_counter_cc_step + _cc_step) % (_cc_num1 + _cc_num2);
}
void WS2812FX::mode_cc_standard()
{
for(uint16_t i=0; i < _led_count; i++)
{
setPixelColor(i, (_cc_i1 <= i && i <= _cc_i2) ? _color_sec : _color);
}
mode_cc_core();
_mode_delay = 20 + ((50 * (uint32_t)(SPEED_MAX - _speed)) / _led_count);
}
void WS2812FX::mode_cc_rainbow(){}
void WS2812FX::mode_cc_cycle(){}
void WS2812FX::mode_cc_blink(){}
void WS2812FX::mode_cc_random(){}
//WLED specific methods
@ -1704,9 +1731,67 @@ void WS2812FX::setFastUpdateMode(bool y)
if (_mode_index == 0) _mode_delay = 20;
}
void WS2812FX::setCustomChase(uint8_t i1, uint8_t i2, uint8_t sp, uint8_t np, uint8_t ns, uint8_t stp, uint8_t stpps, bool fs, bool fe)
void WS2812FX::setCCIndex1(uint8_t i1)
{
//NI
if (i1 < _led_count-1) _cc_i1 = i1;
if (_cc_i2 <= i1) _cc_i2 = i1+1;
_counter_cc_step = 0;
}
void WS2812FX::setCCIndex2(uint8_t i2)
{
if (i2 < _led_count && i2 > _cc_i1) _cc_i2 = i2;
_counter_cc_step = 0;
}
void WS2812FX::setCCStart(uint8_t is)
{
_cc_is = (is < _cc_i1 || is > _cc_i2) ? _cc_i1 : is;
_counter_cc_step = 0;
}
void WS2812FX::setCCNum1(uint8_t np)
{
_cc_num1 = np;
_counter_cc_step = 0;
}
void WS2812FX::setCCNum2(uint8_t ns)
{
_cc_num2 = ns;
_counter_cc_step = 0;
}
void WS2812FX::setCCStep(uint8_t stp)
{
_cc_step = stp;
_counter_cc_step = 0;
}
void WS2812FX::setCCFS(bool fs)
{
_cc_fs = fs;
_cc_fe = (fs) ? _cc_fe : true;
_counter_cc_step = 0;
}
void WS2812FX::setCCFE(bool fe)
{
_cc_fe = fe;
_cc_fs = (fe) ? _cc_fs : true;
_counter_cc_step = 0;
}
void WS2812FX::setCustomChase(uint8_t i1, uint8_t i2, uint8_t is, uint8_t np, uint8_t ns, uint8_t stp, bool fs, bool fe)
{
setCCIndex1(i1);
setCCIndex2(i2);
setCCStart(is);
_cc_num1 = np;
_cc_num2 = ns;
_cc_step = stp;
setCCFS(fs);
setCCFE(fe);
}
//Added for quick NeoPixelBus compatibility with Adafruit syntax

View File

@ -41,7 +41,7 @@
#define DEFAULT_BRIGHTNESS 50
#define DEFAULT_MODE 0
#define DEFAULT_SPEED 150
#define DEFAULT_COLOR 0xFF0000
#define DEFAULT_COLOR 0xFFAA00
#define SPEED_MIN 0
#define SPEED_MAX 255
@ -49,7 +49,7 @@
#define BRIGHTNESS_MIN 0
#define BRIGHTNESS_MAX 255
#define MODE_COUNT 53
#define MODE_COUNT 58
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
@ -104,6 +104,11 @@
#define FX_MODE_DUAL_COLOR_WIPE_OUT_OUT 50
#define FX_MODE_DUAL_COLOR_WIPE_OUT_IN 51
#define FX_MODE_CIRCUS_COMBUSTUS 52
#define FX_MODE_CUSTOM_CHASE 53
#define FX_MODE_CC_ON_RAINBOW 54
#define FX_MODE_CC_ON_RAINBOW_CYCLE 55
#define FX_MODE_CC_BLINK 56
#define FX_MODE_CC_RANDOM 57
#ifdef RGBW
class WS2812FX : public NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266Uart800KbpsMethod> {
@ -171,60 +176,11 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
_mode[FX_MODE_DUAL_COLOR_WIPE_OUT_OUT] = &WS2812FX::mode_dual_color_wipe_out_out;
_mode[FX_MODE_DUAL_COLOR_WIPE_OUT_IN] = &WS2812FX::mode_dual_color_wipe_out_in;
_mode[FX_MODE_CIRCUS_COMBUSTUS] = &WS2812FX::mode_circus_combustus;
_name[FX_MODE_STATIC] = "Static";
_name[FX_MODE_BLINK] = "Blink";
_name[FX_MODE_BREATH] = "Breath";
_name[FX_MODE_COLOR_WIPE] = "Color Wipe";
_name[FX_MODE_COLOR_WIPE_RANDOM] = "Color Wipe R";
_name[FX_MODE_RANDOM_COLOR] = "R Color";
_name[FX_MODE_SINGLE_DYNAMIC] = "Dynamic";
_name[FX_MODE_MULTI_DYNAMIC] = "M Dynamic";
_name[FX_MODE_RAINBOW] = "Rainbow";
_name[FX_MODE_RAINBOW_CYCLE] = "Cycle";
_name[FX_MODE_SCAN] = "Scan";
_name[FX_MODE_DUAL_SCAN] = "2x Scan";
_name[FX_MODE_FADE] = "Fade";
_name[FX_MODE_THEATER_CHASE] = "T Chase";
_name[FX_MODE_THEATER_CHASE_RAINBOW] = "T Chase Rainbow";
_name[FX_MODE_RUNNING_LIGHTS] = "Running";
_name[FX_MODE_TWINKLE] = "Twinkle";
_name[FX_MODE_TWINKLE_RANDOM] = "Twinkle R";
_name[FX_MODE_TWINKLE_FADE] = "Twinkle F";
_name[FX_MODE_TWINKLE_FADE_RANDOM] = "Twinkle F R";
_name[FX_MODE_SPARKLE] = "Sparkle";
_name[FX_MODE_FLASH_SPARKLE] = "Flash Sparkle";
_name[FX_MODE_HYPER_SPARKLE] = "Hyper Sparkle";
_name[FX_MODE_STROBE] = "Strobe";
_name[FX_MODE_STROBE_RAINBOW] = "Strobe Rainbow";
_name[FX_MODE_MULTI_STROBE] = "Multi Strobe";
_name[FX_MODE_BLINK_RAINBOW] = "Blink Rainbow";
_name[FX_MODE_CHASE_WHITE] = "Chase White";
_name[FX_MODE_CHASE_COLOR] = "Chase Color";
_name[FX_MODE_CHASE_RANDOM] = "Chase R";
_name[FX_MODE_CHASE_RAINBOW] = "Chase Rainbow";
_name[FX_MODE_CHASE_FLASH] = "Chase Flash";
_name[FX_MODE_CHASE_FLASH_RANDOM] = "Chase Flash R";
_name[FX_MODE_CHASE_RAINBOW_WHITE] = "Chase Rainbow White";
_name[FX_MODE_CHASE_BLACKOUT] = "Chase Black";
_name[FX_MODE_CHASE_BLACKOUT_RAINBOW]= "Chase Black Rainbow";
_name[FX_MODE_COLOR_SWEEP_RANDOM] = "Color Sweep Random";
_name[FX_MODE_RUNNING_COLOR] = "Running Color";
_name[FX_MODE_RUNNING_RED_BLUE] = "Running Red Blue";
_name[FX_MODE_RUNNING_RANDOM] = "Running R";
_name[FX_MODE_LARSON_SCANNER] = "Scanner";
_name[FX_MODE_COMET] = "Comet";
_name[FX_MODE_FIREWORKS] = "Fireworks";
_name[FX_MODE_FIREWORKS_RANDOM] = "Fireworks R";
_name[FX_MODE_MERRY_CHRISTMAS] = "Christmas";
_name[FX_MODE_FIRE_FLICKER] = "Flicker";
_name[FX_MODE_FIRE_FLICKER_SOFT] = "Flicker (soft)";
_name[FX_MODE_FADE_DOWN] = "Fade (Internal)";
_name[FX_MODE_DUAL_COLOR_WIPE_IN_OUT] = "Wipe In Out";
_name[FX_MODE_DUAL_COLOR_WIPE_IN_IN] = "Wipe In In";
_name[FX_MODE_DUAL_COLOR_WIPE_OUT_OUT] = "Wipe Out Out";
_name[FX_MODE_DUAL_COLOR_WIPE_OUT_IN] = "Wipe Out In";
_name[FX_MODE_CIRCUS_COMBUSTUS] = "Circus";
_mode[FX_MODE_CUSTOM_CHASE] = &WS2812FX::mode_cc_standard;
_mode[FX_MODE_CC_ON_RAINBOW] = &WS2812FX::mode_cc_rainbow;
_mode[FX_MODE_CC_ON_RAINBOW_CYCLE] = &WS2812FX::mode_cc_cycle;
_mode[FX_MODE_CC_BLINK] = &WS2812FX::mode_cc_blink;
_mode[FX_MODE_CC_RANDOM] = &WS2812FX::mode_cc_random;
_mode_index = DEFAULT_MODE;
_speed = DEFAULT_SPEED;
@ -237,8 +193,17 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
_mode_color = DEFAULT_COLOR;
_color_sec = 0;
_mode_color_sec = 0;
_cc_fs = true;
_cc_fe = false;
_cc_is = 0;
_cc_i1 = 0;
_cc_i2 = n-1;
_cc_num1 = 5;
_cc_num2 = 5;
_cc_step = 1;
_counter_mode_call = 0;
_counter_mode_step = 0;
_counter_cc_step = 0;
_fastStandard = false;
_locked = new boolean[n];
}
@ -249,7 +214,15 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
start(void),
stop(void),
setMode(uint8_t m),
setCustomChase(uint8_t i1, uint8_t i2, uint8_t sp, uint8_t np, uint8_t ns, uint8_t stp, uint8_t stpps, bool fs, bool fe),
setCustomChase(uint8_t i1, uint8_t i2, uint8_t is, uint8_t np, uint8_t ns, uint8_t stp, bool fs, bool fe),
setCCIndex1(uint8_t i1),
setCCIndex2(uint8_t i2),
setCCStart(uint8_t is),
setCCNum1(uint8_t np),
setCCNum2(uint8_t ns),
setCCStep(uint8_t stp),
setCCFS(bool fs),
setCCFE(bool fe),
setSpeed(uint8_t s),
increaseSpeed(uint8_t s),
decreaseSpeed(uint8_t s),
@ -290,9 +263,6 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
uint32_t
getColor(void);
const char*
getModeName(uint8_t m);
private:
void
@ -358,11 +328,19 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
mode_dual_color_wipe_in_in(void),
mode_dual_color_wipe_out_out(void),
mode_dual_color_wipe_out_in(void),
mode_circus_combustus(void);
mode_circus_combustus(void),
mode_cc_core(void),
mode_cc_standard(void),
mode_cc_rainbow(void),
mode_cc_cycle(void),
mode_cc_blink(void),
mode_cc_random(void);
boolean
_triggered,
_fastStandard,
_cc_fs,
_cc_fe,
_running;
boolean*
@ -374,6 +352,12 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
get_random_wheel_index(uint8_t),
_mode_index,
_speed,
_cc_i1,
_cc_i2,
_cc_is,
_cc_num1,
_cc_num2,
_cc_step,
_brightness;
uint16_t
@ -386,6 +370,7 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
_color_sec,
_counter_mode_call,
_counter_mode_step,
_counter_cc_step,
_mode_color,
_mode_color_sec,
_mode_delay;
@ -393,9 +378,6 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
unsigned long
_mode_last_call_time;
const char*
_name[MODE_COUNT];
mode_ptr
_mode[MODE_COUNT];
};

View File

@ -20,7 +20,7 @@
#include "CallbackFunction.h"
//version in format yymmddb (b = daily build)
#define VERSION 1711282
#define VERSION 1711292
//If you have an RGBW strip, uncomment first line in WS2812FX.h!

View File

@ -335,9 +335,9 @@ boolean handleSet(String req)
}
}
//(un)lock pixel (ranges)
pos = req.indexOf("L=");
pos = req.indexOf("&L=");
if (pos > 0){
int index = req.substring(pos + 2).toInt();
int index = req.substring(pos + 3).toInt();
pos = req.indexOf("L2=");
if (pos > 0){
int index2 = req.substring(pos + 3).toInt();
@ -413,6 +413,15 @@ boolean handleSet(String req)
}
}
}
pos = req.indexOf("C0="); if (pos > 0) { strip.setCCStart(req.substring(pos + 3).toInt()); }
pos = req.indexOf("C1="); if (pos > 0) { strip.setCCIndex1(req.substring(pos + 3).toInt()); }
pos = req.indexOf("C2="); if (pos > 0) { strip.setCCIndex2(req.substring(pos + 3).toInt()); }
pos = req.indexOf("CP="); if (pos > 0) { strip.setCCNum1(req.substring(pos + 3).toInt()); }
pos = req.indexOf("CS="); if (pos > 0) { strip.setCCNum2(req.substring(pos + 3).toInt()); }
pos = req.indexOf("CM="); if (pos > 0) { strip.setCCStep(req.substring(pos + 3).toInt()); }
pos = req.indexOf("CF="); if (pos > 0) { strip.setCCFS(req.substring(pos + 3).toInt()); }
pos = req.indexOf("CE="); if (pos > 0) { strip.setCCFE(req.substring(pos + 3).toInt()); }
//internal call, does not send XML response
pos = req.indexOf("IN");
if (pos < 1)