From e20cab74de1e71c642e5937fb97cde90d41bb818 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 29 Nov 2017 23:56:02 +0100 Subject: [PATCH] Started adding Custom Chase FX functions, still crashing if CP>1 Removed name function from FX library because it is unused in WLED --- wled00/WS2812FX.cpp | 105 ++++++++++++++++++++++++++++++++++++---- wled00/WS2812FX.h | 110 ++++++++++++++++++------------------------ wled00/wled00.ino | 2 +- wled00/wled03_set.ino | 13 ++++- 4 files changed, 153 insertions(+), 77 deletions(-) diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index 9d8bc5e7..4139df60 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -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 diff --git a/wled00/WS2812FX.h b/wled00/WS2812FX.h index b75b168f..8d66894e 100644 --- a/wled00/WS2812FX.h +++ b/wled00/WS2812FX.h @@ -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 { @@ -171,60 +176,11 @@ class WS2812FX : public NeoPixelBrightnessBus 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)