From b5437532636d42ab728c69f738f2ef1d6041856a Mon Sep 17 00:00:00 2001 From: cschwinne Date: Thu, 30 Nov 2017 23:35:22 +0100 Subject: [PATCH] Added all Custom Chase functions Added applyPreset() function Allocated EEPROM slots for secondary colors and CC parameters --- wled00/WS2812FX.cpp | 68 +++++++++++++++++++++++++++++++--------- wled00/wled00.ino | 18 ++++++++--- wled00/wled01_eeprom.ino | 64 +++++++++++++++++++++++++++++++------ wled00/wled03_set.ino | 28 ++++++++++++----- 4 files changed, 142 insertions(+), 36 deletions(-) diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index 4139df604..02bdd79fb 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -1553,20 +1553,19 @@ void WS2812FX::mode_circus_combustus(void) { void WS2812FX::mode_cc_core() { - for(uint16_t i=_cc_i1; i <= _cc_i2; i++) + for (int k = _cc_i1; k <= _cc_i2; k = k + _cc_num1 + _cc_num2) { - if(i % (_cc_num1 + _cc_num2) == _counter_cc_step) + for (int i = 0; i < _cc_num1; i++) { - 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); - } + int num = 0; + num = ((k + i + _counter_cc_step) % _cc_i2) +_cc_i1; + if (_cc_fs) setPixelColor(num, _color); + if (_cc_fe) setPixelColor(_cc_i2 - num, _color); } } show(); - _counter_cc_step = (_counter_cc_step + _cc_step) % (_cc_num1 + _cc_num2); + _counter_cc_step = (_counter_cc_step + _cc_step) % (_cc_i2 - _cc_i1); + _mode_delay = 10 + ((250 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX); } void WS2812FX::mode_cc_standard() @@ -1576,16 +1575,54 @@ void WS2812FX::mode_cc_standard() 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_rainbow() +{ + uint32_t color = color_wheel(_counter_mode_step); + for(uint16_t i=0; i < _led_count; i++) { + if (!_locked[i]) + setPixelColor(i, color); + } + mode_cc_core(); + _counter_mode_step = (_counter_mode_step + 1) % 256; +} -void WS2812FX::mode_cc_cycle(){} +void WS2812FX::mode_cc_cycle() +{ + for(uint16_t i=0; i < _led_count; i++) { + if (!_locked[i]) + setPixelColor(i, color_wheel(((i * 256 / _led_count) + _counter_mode_step) % 256)); + } + mode_cc_core(); + _counter_mode_step = (_counter_mode_step + 1) % 256; +} -void WS2812FX::mode_cc_blink(){} +void WS2812FX::mode_cc_blink() +{ + for(uint16_t i=0; i < _led_count; i++) + { + setPixelColor(i, (_cc_i1 <= i && i <= _cc_i2) ? _color_sec : _color); + } + if (_counter_mode_step) + { + mode_cc_core(); + _counter_mode_step = 0; + } else { + show(); + _counter_mode_step = 1; + _mode_delay = 10 + ((250 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX); + } +} -void WS2812FX::mode_cc_random(){} +void WS2812FX::mode_cc_random() +{ + for(uint16_t i=0; i < _led_count; i++) { + if (!_locked[i]) + setPixelColor(i, color_wheel(random(256))); + } + mode_cc_core(); +} //WLED specific methods @@ -1740,7 +1777,8 @@ void WS2812FX::setCCIndex1(uint8_t i1) void WS2812FX::setCCIndex2(uint8_t i2) { - if (i2 < _led_count && i2 > _cc_i1) _cc_i2 = i2; + if (i2 > _cc_i1) _cc_i2 = i2; + if (_cc_i2 >= _led_count) _cc_i2 = _led_count-1; _counter_cc_step = 0; } diff --git a/wled00/wled00.ino b/wled00/wled00.ino index f6c27a7ce..ff9059fdc 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -20,8 +20,7 @@ #include "CallbackFunction.h" //version in format yymmddb (b = daily build) -#define VERSION 1711292 - +#define VERSION 1711302 //If you have an RGBW strip, uncomment first line in WS2812FX.h! @@ -49,9 +48,10 @@ #endif //eeprom Version code, enables default settings instead of 0 init on update -#define EEPVER 1 +#define EEPVER 2 //0 -> old version, default -//1 -> 0.4p 1711271 and up +//1 -> 0.4p 1711272 and up +//2 -> 0.4p 1711302 and up /* * @title WLED project sketch @@ -93,8 +93,10 @@ IPAddress staticsubnet(255, 255, 255, 0); boolean useHSB = false, useHSBDefault = false; boolean turnOnAtBoot = true; byte col_s[]{255, 159, 0}; +byte col_sec_s[]{0, 0, 0}; boolean useRGBW = false; byte white_s = 0; +byte white_sec_s = 0; byte bri_s = 127; uint8_t bri_nl = 0, bri_nls; boolean fadeTransition = true; @@ -115,6 +117,14 @@ uint8_t effectSpeedDefault = 75; boolean ntpEnabled = false; IPAddress ntpServerIP; const char* ntpServerName = "time.nist.gov"; +//custom chase +uint8_t cc_numPrimary = 2; +uint8_t cc_numSecondary = 4; +uint8_t cc_index1 = 0; +uint8_t cc_index2 = ledcount -1; +bool cc_fromStart = true, cc_fromEnd = false; +uint8_t cc_step = 1; +uint8_t cc_start = 0; //alexa boolean alexaEnabled = true; diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 5065554b1..a2fd4d554 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -109,6 +109,17 @@ void saveSettingsToEEPROM() EEPROM.write(375, apWaitTimeSecs); EEPROM.write(376, recoveryAPDisabled); EEPROM.write(377, EEPVER); //eeprom was updated to latest + EEPROM.write(378, col_sec_s[0]); + EEPROM.write(379, col_sec_s[1]); + EEPROM.write(380, col_sec_s[2]); + EEPROM.write(381, white_sec_s); + EEPROM.write(382, cc_index1); + EEPROM.write(383, cc_index2); + EEPROM.write(384, cc_numPrimary); + EEPROM.write(385, cc_numSecondary); + EEPROM.write(386, cc_fromStart); + EEPROM.write(387, cc_fromEnd); + EEPROM.write(388, cc_step); EEPROM.commit(); } @@ -230,7 +241,21 @@ void loadSettingsFromEEPROM() apWaitTimeSecs = EEPROM.read(375); recoveryAPDisabled = EEPROM.read(376); } - //377-380 reserved for second color default + //377 = lastEEPROMversion + if (lastEEPROMversion > 1) { + col_sec_s[0] = EEPROM.read(378); + col_sec_s[1] = EEPROM.read(379); + col_sec_s[2] = EEPROM.read(380); + white_sec_s = EEPROM.read(381); + cc_index1 = EEPROM.read(382); + cc_index2 = EEPROM.read(383); + cc_numPrimary = EEPROM.read(384); + cc_numSecondary = EEPROM.read(385); + cc_fromStart = EEPROM.read(386); + cc_fromEnd = EEPROM.read(387); + cc_step = EEPROM.read(388); + } + //favorite setting memory (25 slots/ each 20byte) //400 - 899 reserved @@ -239,25 +264,46 @@ void loadSettingsFromEEPROM() } //PRESET PROTOCOL 20 bytes -//0: multipurpose byte, bit 0: brightness is valid, 1: col valid, 2: ecol valid, 5: cc valid, 6: ccFromStart, 7: ccFromEnd -//1:a 2:r 3:g 4:b 5:w 6:er 7:eg 8:eb 9:ew 10:fx 11:sx | custom chase 12:numP 13:numS 14:pStart 15-20:undefinded +//0: (0:invalid 1: just bri 2: just col 3: just fx 4: bri/col 5: bri/fx 6: col/fx 7: all 8:i_like_pancakes >8:invalid) +//1:a 2:r 3:g 4:b 5:w 6:er 7:eg 8:eb 9:ew 10:fx 11:sx | custom chase 12:numP 13:numS 14:(0:fs 1:fe 2:both) 15:step 16-19:Zeros -void loadPreset(uint8_t index, uint8_t data[]) +void applyPreset(uint8_t index) { if (index > 24) return; - uint8_t temp[20]; - for (int i = 0; i < 20; i++) + uint16_t i = 400 + index*20; + uint8_t m = EEPROM.read(i); + if (m == 7 || m == 1 || m == 4 || m == 5) bri = EEPROM.read(i+1); + if (m == 7 || m == 2 || m == 4 || m == 6) { - data[i] = EEPROM.read(400 + index*20 + i); + col[0] = EEPROM.read(i+2); + col[1] = EEPROM.read(i+3); + col[2] = EEPROM.read(i+4); + white = EEPROM.read(i+5); + col_sec[0] = EEPROM.read(i+6); + col_sec[1] = EEPROM.read(i+7); + col_sec[2] = EEPROM.read(i+8); + white_sec = EEPROM.read(i+9); + } + if (m == 3 || (m > 4 && m < 8)) + { + effectCurrent = EEPROM.read(i+10); + effectSpeed = EEPROM.read(i+11); + cc_numPrimary = EEPROM.read(i+12); + cc_numSecondary = EEPROM.read(i+13); + cc_fromEnd = EEPROM.read(i+14); + cc_fromStart = (EEPROM.read(i+14)<2); + cc_step = EEPROM.read(i+15); + strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd); } } -void savePreset(uint8_t index, uint8_t data[]) +void savePreset(uint8_t index, uint8_t m) { if (index > 24) return; for (int i = 0; i < 20; i++) { - EEPROM.write(400 + index*20 + i, data[i]); + EEPROM.write(400 + index*20 + i, 0); //CHANGE!!! } + EEPROM.commit(); } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 08d0736a9..5bc8a014c 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -413,14 +413,26 @@ 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()); } + //set custom chase data + bool _cc_updated = false; + pos = req.indexOf("C0="); if (pos > 0) {cc_start = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("C1="); if (pos > 0) {cc_index1 = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("C2="); if (pos > 0) {cc_index2 = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("CP="); if (pos > 0) {cc_numPrimary = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("CS="); if (pos > 0) {cc_numSecondary = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("CM="); if (pos > 0) {cc_step = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("CF="); if (pos > 0) {cc_fromStart = (req.substring(pos + 3).toInt()); _cc_updated = true;} + pos = req.indexOf("CE="); if (pos > 0) {cc_fromEnd = (req.substring(pos + 3).toInt()); _cc_updated = true;} + if (_cc_updated) strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd); + //set presets + pos = req.indexOf("PS="); //saves current in preset + if (pos > 0) { + savePreset(req.substring(pos + 3).toInt(), 0); //CHANGE!!! + } + pos = req.indexOf("PL="); //applies preset + if (pos > 0) { + applyPreset(req.substring(pos + 3).toInt()); + } //internal call, does not send XML response pos = req.indexOf("IN");