diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index 8a263561..6465d0fb 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -110,6 +110,14 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) if (_locked[i] && !modeUsesLock(SEGMENT.mode)) return; if (_reverseMode) i = _length - 1 -i; if (IS_REVERSE) i = SEGMENT.stop - (i - SEGMENT.start); //reverse just individual segment + byte tmpg = g; + switch (colorOrder) //0 = Grb, default + { + case 0: break; //0 = Grb, default + case 1: g = r; r = tmpg; break; //1 = Rgb, common for WS2811 + case 2: g = b; b = tmpg; break; //2 = Brg + case 3: g = b; b = r; r = tmpg; //3 = Rbg + } if (!_cronixieMode) { if (_skipFirstMode) {i++;if(i==1)bus->SetPixelColor(i, RgbwColor(0,0,0,0));} @@ -185,7 +193,8 @@ void WS2812FX::trigger() { void WS2812FX::setMode(uint8_t m) { RESET_RUNTIME; bool ua = modeUsesLock(_segments[0].mode) && !modeUsesLock(m); - _segments[0].mode = constrain(m, 0, MODE_COUNT - 1); + if (m > MODE_COUNT - 1) m = MODE_COUNT - 1; + _segments[0].mode = m; if (ua) unlockAll(); setBrightness(_brightness); } @@ -204,6 +213,16 @@ void WS2812FX::setPalette(uint8_t p) { _segments[0].palette = p; } +bool WS2812FX::setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p) { + bool changed = false; + m = constrain(m, 0, MODE_COUNT - 1); + if (m != _segments[0].mode) { setMode(m); changed = true; } + if (s != _segments[0].speed) { setSpeed(s); changed = true; } + if (i != _segments[0].intensity) { setIntensity(i); changed = true; } + if (p != _segments[0].palette) { setPalette(p); changed = true; } + return changed; +} + void WS2812FX::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { setColor(((uint32_t)w << 24) |((uint32_t)r << 16) | ((uint32_t)g << 8) | b); } diff --git a/wled00/WS2812FX.h b/wled00/WS2812FX.h index fd76fafa..0a2cd2bc 100644 --- a/wled00/WS2812FX.h +++ b/wled00/WS2812FX.h @@ -278,6 +278,7 @@ class WS2812FX { _segments[0].speed = DEFAULT_SPEED; _reverseMode = false; _skipFirstMode = false; + colorOrder = 0; paletteFade = 0; paletteBlend = 0; _locked = NULL; @@ -323,9 +324,13 @@ class WS2812FX { setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0), show(void); + bool + setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p); + uint8_t paletteFade, paletteBlend, + colorOrder, getBrightness(void), getMode(void), getSpeed(void), diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 649fbcce..1e986d48 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -74,7 +74,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1811221 +#define VERSION 1811241 char versionString[] = "0.8.2-dev"; diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 56a0bc13..3edcf2e0 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -18,6 +18,7 @@ //8 -> 0.8.0-a and up //9 -> 0.8.0 + /* * Erase all configuration data */ @@ -30,6 +31,7 @@ void clearEEPROM() EEPROM.commit(); } + void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len) { for (int i = 0; i < len; ++i) @@ -39,6 +41,7 @@ void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len) } } + void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len) { for (int i = 0; i < len; ++i) @@ -49,6 +52,7 @@ void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len) str[len] = 0; //make sure every string is properly terminated. str must be at least len +1 big. } + /* * Write configuration to flash */ @@ -251,6 +255,7 @@ void saveSettingsToEEPROM() commit(); } + /* * Read all configuration from flash */ @@ -498,13 +503,10 @@ void loadSettingsFromEEPROM(bool first) useHSB = useHSBDefault; - strip.setMode(effectCurrent); - strip.setSpeed(effectSpeed); - strip.setIntensity(effectIntensity); - strip.setPalette(effectPalette); overlayCurrent = overlayDefault; } + //PRESET PROTOCOL 20 bytes //0: preset purpose byte 0:invalid 1:valid preset 1.0 //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:both 2:fe) 15:step 16:ix 17: fp 18-19:Zeros @@ -533,15 +535,10 @@ bool applyPreset(byte index, bool loadBri = true, bool loadCol = true, bool load } if (loadFX) { - byte lastfx = effectCurrent; effectCurrent = EEPROM.read(i+10); effectSpeed = EEPROM.read(i+11); effectIntensity = EEPROM.read(i+16); effectPalette = EEPROM.read(i+17); - if (lastfx != effectCurrent) strip.setMode(effectCurrent); - strip.setSpeed(effectSpeed); - strip.setIntensity(effectIntensity); - strip.setPalette(effectPalette); } return true; } @@ -569,6 +566,7 @@ void savePreset(byte index) commit(); } + String loadMacro(byte index) { index-=1; @@ -582,6 +580,7 @@ String loadMacro(byte index) return m; } + void applyMacro(byte index) { index-=1; @@ -600,6 +599,7 @@ void applyMacro(byte index) handleSet(mc); } + void saveMacro(byte index, String mc, bool sing=true) //only commit on single save, not in settings { index-=1; @@ -612,9 +612,11 @@ void saveMacro(byte index, String mc, bool sing=true) //only commit on single sa if (sing) commit(); } + void commit() { DEBUG_PRINT("s"); + //this is to support IR on ESP32, needs work /*#ifdef ARDUINO_ARCH_ESP32 portMUX_TYPE mMux = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&mMux); diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 0c24fa20..48c54508 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -311,7 +311,6 @@ void handleSettingsSet(byte subPage) bool handleSet(String req) { - bool effectUpdated = false; if (!(req.indexOf("win") >= 0)) return false; int pos = 0; @@ -464,8 +463,6 @@ bool handleSet(String req) if (effectCurrent != req.substring(pos + 3).toInt()) { effectCurrent = req.substring(pos + 3).toInt(); - strip.setMode(effectCurrent); - effectUpdated = true; } } //set effect speed @@ -474,8 +471,6 @@ bool handleSet(String req) if (effectSpeed != req.substring(pos + 3).toInt()) { effectSpeed = req.substring(pos + 3).toInt(); - strip.setSpeed(effectSpeed); - effectUpdated = true; } } //set effect intensity @@ -484,8 +479,6 @@ bool handleSet(String req) if (effectIntensity != req.substring(pos + 3).toInt()) { effectIntensity = req.substring(pos + 3).toInt(); - strip.setIntensity(effectIntensity); - effectUpdated = true; } } //set effect palette (only for FastLED effects) @@ -494,8 +487,6 @@ bool handleSet(String req) if (effectPalette != req.substring(pos + 3).toInt()) { effectPalette = req.substring(pos + 3).toInt(); - strip.setPalette(effectPalette); - effectUpdated = true; } } @@ -697,7 +688,6 @@ bool handleSet(String req) pos = req.indexOf("PL="); //applies entire preset if (pos > 0) { applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx); - if (presetApplyFx) effectUpdated = true; } //cronixie @@ -738,19 +728,9 @@ bool handleSet(String req) //internal call, does not send XML response pos = req.indexOf("IN"); if (pos < 1) XML_response(true, (req.indexOf("IT") > 0)); //include theme if firstload - //do not send UDP notifications this time - pos = req.indexOf("NN"); - if (pos > 0) - { - colorUpdated(5); - return true; - } - if (effectUpdated) - { - colorUpdated(6); - } else - { - colorUpdated(1); - } + + pos = req.indexOf("NN"); //do not send UDP notifications this time + colorUpdated((pos > 0) ? 5:1); + return true; } diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index d6b2f732..cdf02c81 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -125,6 +125,7 @@ void wledInit() Serial.println("Ada"); } + void initStrip() { // Initialize NeoPixel Strip and button @@ -142,6 +143,7 @@ void initStrip() if(digitalRead(BTNPIN) == LOW) buttonEnabled = false; } + void initAP(){ bool set = apSSID[0]; if (!set) strcpy(apSSID,"WLED-AP"); @@ -149,6 +151,7 @@ void initAP(){ if (!set) apSSID[0] = 0; } + void initCon() { WiFi.disconnect(); //close old connections diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index 4e1e01f8..958f8a59 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -5,6 +5,7 @@ #define WLEDPACKETSIZE 24 #define UDP_IN_MAXSIZE 1472 + void notify(byte callMode, bool followUp=false) { if (!udpConnected) return; @@ -53,6 +54,7 @@ void notify(byte callMode, bool followUp=false) notificationTwoRequired = (followUp)? false:notifyTwice; } + void arlsLock(uint32_t timeoutMs) { if (!realtimeActive){ @@ -60,13 +62,14 @@ void arlsLock(uint32_t timeoutMs) { strip.setPixelColor(i,0,0,0,0); } - strip.setMode(0); + strip.unlockAll(); } realtimeActive = true; realtimeTimeout = millis() + timeoutMs; if (arlsForceMaxBri) strip.setBrightness(255); } + void initE131(){ if (WiFi.status() == WL_CONNECTED && e131Enabled) { @@ -77,6 +80,7 @@ void initE131(){ } } + void handleE131(){ //E1.31 protocol support if(e131Enabled) { @@ -98,6 +102,7 @@ void handleE131(){ } } + void handleNotifications() { //send second notification if enabled @@ -110,10 +115,10 @@ void handleNotifications() //unlock strip when realtime UDP times out if (realtimeActive && millis() > realtimeTimeout) { - strip.unlockAll(); + //strip.unlockAll(); strip.setBrightness(bri); realtimeActive = false; - strip.setMode(effectCurrent); + //strip.setMode(effectCurrent); realtimeIP[0] = 0; } @@ -176,26 +181,10 @@ void handleNotifications() //apply effects from notification if (receiveNotificationEffects) { - if (udpIn[8] != effectCurrent) - { - effectCurrent = udpIn[8]; - strip.setMode(effectCurrent); - } - if (udpIn[9] != effectSpeed) - { - effectSpeed = udpIn[9]; - strip.setSpeed(effectSpeed); - } - if (udpIn[11] > 2 && udpIn[16] != effectIntensity) - { - effectIntensity = udpIn[16]; - strip.setIntensity(effectIntensity); - } - if (udpIn[11] > 4 && udpIn[19] != effectPalette) - { - effectPalette = udpIn[19]; - strip.setPalette(effectPalette); - } + effectCurrent = udpIn[8]; + effectSpeed = udpIn[9]; + if (udpIn[11] > 2) effectIntensity = udpIn[16]; + if (udpIn[11] > 4) effectPalette = udpIn[19]; } if (udpIn[11] > 3) @@ -261,6 +250,7 @@ void handleNotifications() } } + void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) { uint16_t pix = i + arlsOffset; diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index d7ebfb49..ffda2762 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -14,6 +14,7 @@ void toggleOnOff() } } + void setAllLeds() { if (!realtimeActive || !arlsForceMaxBri) { @@ -50,6 +51,7 @@ void setAllLeds() { } } + void setLedsStandard() { for (byte i = 0; i<3; i++) @@ -68,6 +70,7 @@ void setLedsStandard() setAllLeds(); } + bool colorChanged() { for (int i = 0; i < 3; i++) @@ -80,17 +83,19 @@ bool colorChanged() return false; } + void colorUpdated(int callMode) { - //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (NN)6: fx changed 7: hue 8: preset cycle 9: blynk + //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification) + // 6: fx changed 7: hue 8: preset cycle 9: blynk + bool fxChanged = strip.setEffectConfig(effectCurrent, effectSpeed, effectIntensity, effectPalette); if (!colorChanged()) { if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5) { notify(4); return; } - if (callMode == 2) notify(2); - else if (callMode == 6) notify(6); + else if (fxChanged) notify(6); return; //no change } if (callMode != 5 && nightlightActive && nightlightFade) @@ -150,6 +155,7 @@ void colorUpdated(int callMode) updateInterfaces(callMode); } + void updateInterfaces(uint8_t callMode) { if (callMode != 9 && callMode != 5) updateBlynk(); @@ -157,6 +163,7 @@ void updateInterfaces(uint8_t callMode) lastInterfaceUpdate = millis(); } + void handleTransitions() { //handle still pending interface update @@ -197,6 +204,7 @@ void handleTransitions() } } + void handleNightlight() { if (nightlightActive) diff --git a/wled00/wled16_blynk.ino b/wled00/wled16_blynk.ino index da964180..df070d09 100644 --- a/wled00/wled16_blynk.ino +++ b/wled00/wled16_blynk.ino @@ -66,22 +66,19 @@ BLYNK_WRITE(V3) BLYNK_WRITE(V4) { effectCurrent = param.asInt()-1;//fx - strip.setMode(effectCurrent); - colorUpdated(6); + colorUpdated(9); } BLYNK_WRITE(V5) { effectSpeed = param.asInt();//sx - strip.setSpeed(effectSpeed); - colorUpdated(6); + colorUpdated(9); } BLYNK_WRITE(V6) { effectIntensity = param.asInt();//ix - strip.setIntensity(effectIntensity); - colorUpdated(6); + colorUpdated(9); } BLYNK_WRITE(V7)