Improved effect updating internals

This commit is contained in:
cschwinne 2018-11-24 11:52:23 +01:00
parent b2db61aa03
commit 6359a8a8a2
9 changed files with 71 additions and 67 deletions

View File

@ -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 (_locked[i] && !modeUsesLock(SEGMENT.mode)) return;
if (_reverseMode) i = _length - 1 -i; if (_reverseMode) i = _length - 1 -i;
if (IS_REVERSE) i = SEGMENT.stop - (i - SEGMENT.start); //reverse just individual segment 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 (!_cronixieMode)
{ {
if (_skipFirstMode) {i++;if(i==1)bus->SetPixelColor(i, RgbwColor(0,0,0,0));} 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) { void WS2812FX::setMode(uint8_t m) {
RESET_RUNTIME; RESET_RUNTIME;
bool ua = modeUsesLock(_segments[0].mode) && !modeUsesLock(m); 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(); if (ua) unlockAll();
setBrightness(_brightness); setBrightness(_brightness);
} }
@ -204,6 +213,16 @@ void WS2812FX::setPalette(uint8_t p) {
_segments[0].palette = 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) { 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); setColor(((uint32_t)w << 24) |((uint32_t)r << 16) | ((uint32_t)g << 8) | b);
} }

View File

@ -278,6 +278,7 @@ class WS2812FX {
_segments[0].speed = DEFAULT_SPEED; _segments[0].speed = DEFAULT_SPEED;
_reverseMode = false; _reverseMode = false;
_skipFirstMode = false; _skipFirstMode = false;
colorOrder = 0;
paletteFade = 0; paletteFade = 0;
paletteBlend = 0; paletteBlend = 0;
_locked = NULL; _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), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
show(void); show(void);
bool
setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p);
uint8_t uint8_t
paletteFade, paletteFade,
paletteBlend, paletteBlend,
colorOrder,
getBrightness(void), getBrightness(void),
getMode(void), getMode(void),
getSpeed(void), getSpeed(void),

View File

@ -74,7 +74,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1811221 #define VERSION 1811241
char versionString[] = "0.8.2-dev"; char versionString[] = "0.8.2-dev";

View File

@ -18,6 +18,7 @@
//8 -> 0.8.0-a and up //8 -> 0.8.0-a and up
//9 -> 0.8.0 //9 -> 0.8.0
/* /*
* Erase all configuration data * Erase all configuration data
*/ */
@ -30,6 +31,7 @@ void clearEEPROM()
EEPROM.commit(); EEPROM.commit();
} }
void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len) void writeStringToEEPROM(uint16_t pos, char* str, uint16_t len)
{ {
for (int i = 0; i < len; ++i) 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) void readStringFromEEPROM(uint16_t pos, char* str, uint16_t len)
{ {
for (int i = 0; i < len; ++i) 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. str[len] = 0; //make sure every string is properly terminated. str must be at least len +1 big.
} }
/* /*
* Write configuration to flash * Write configuration to flash
*/ */
@ -251,6 +255,7 @@ void saveSettingsToEEPROM()
commit(); commit();
} }
/* /*
* Read all configuration from flash * Read all configuration from flash
*/ */
@ -498,13 +503,10 @@ void loadSettingsFromEEPROM(bool first)
useHSB = useHSBDefault; useHSB = useHSBDefault;
strip.setMode(effectCurrent);
strip.setSpeed(effectSpeed);
strip.setIntensity(effectIntensity);
strip.setPalette(effectPalette);
overlayCurrent = overlayDefault; overlayCurrent = overlayDefault;
} }
//PRESET PROTOCOL 20 bytes //PRESET PROTOCOL 20 bytes
//0: preset purpose byte 0:invalid 1:valid preset 1.0 //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 //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) if (loadFX)
{ {
byte lastfx = effectCurrent;
effectCurrent = EEPROM.read(i+10); effectCurrent = EEPROM.read(i+10);
effectSpeed = EEPROM.read(i+11); effectSpeed = EEPROM.read(i+11);
effectIntensity = EEPROM.read(i+16); effectIntensity = EEPROM.read(i+16);
effectPalette = EEPROM.read(i+17); effectPalette = EEPROM.read(i+17);
if (lastfx != effectCurrent) strip.setMode(effectCurrent);
strip.setSpeed(effectSpeed);
strip.setIntensity(effectIntensity);
strip.setPalette(effectPalette);
} }
return true; return true;
} }
@ -569,6 +566,7 @@ void savePreset(byte index)
commit(); commit();
} }
String loadMacro(byte index) String loadMacro(byte index)
{ {
index-=1; index-=1;
@ -582,6 +580,7 @@ String loadMacro(byte index)
return m; return m;
} }
void applyMacro(byte index) void applyMacro(byte index)
{ {
index-=1; index-=1;
@ -600,6 +599,7 @@ void applyMacro(byte index)
handleSet(mc); handleSet(mc);
} }
void saveMacro(byte index, String mc, bool sing=true) //only commit on single save, not in settings void saveMacro(byte index, String mc, bool sing=true) //only commit on single save, not in settings
{ {
index-=1; index-=1;
@ -612,9 +612,11 @@ void saveMacro(byte index, String mc, bool sing=true) //only commit on single sa
if (sing) commit(); if (sing) commit();
} }
void commit() void commit()
{ {
DEBUG_PRINT("s"); DEBUG_PRINT("s");
//this is to support IR on ESP32, needs work
/*#ifdef ARDUINO_ARCH_ESP32 /*#ifdef ARDUINO_ARCH_ESP32
portMUX_TYPE mMux = portMUX_INITIALIZER_UNLOCKED; portMUX_TYPE mMux = portMUX_INITIALIZER_UNLOCKED;
portENTER_CRITICAL(&mMux); portENTER_CRITICAL(&mMux);

View File

@ -311,7 +311,6 @@ void handleSettingsSet(byte subPage)
bool handleSet(String req) bool handleSet(String req)
{ {
bool effectUpdated = false;
if (!(req.indexOf("win") >= 0)) return false; if (!(req.indexOf("win") >= 0)) return false;
int pos = 0; int pos = 0;
@ -464,8 +463,6 @@ bool handleSet(String req)
if (effectCurrent != req.substring(pos + 3).toInt()) if (effectCurrent != req.substring(pos + 3).toInt())
{ {
effectCurrent = req.substring(pos + 3).toInt(); effectCurrent = req.substring(pos + 3).toInt();
strip.setMode(effectCurrent);
effectUpdated = true;
} }
} }
//set effect speed //set effect speed
@ -474,8 +471,6 @@ bool handleSet(String req)
if (effectSpeed != req.substring(pos + 3).toInt()) if (effectSpeed != req.substring(pos + 3).toInt())
{ {
effectSpeed = req.substring(pos + 3).toInt(); effectSpeed = req.substring(pos + 3).toInt();
strip.setSpeed(effectSpeed);
effectUpdated = true;
} }
} }
//set effect intensity //set effect intensity
@ -484,8 +479,6 @@ bool handleSet(String req)
if (effectIntensity != req.substring(pos + 3).toInt()) if (effectIntensity != req.substring(pos + 3).toInt())
{ {
effectIntensity = req.substring(pos + 3).toInt(); effectIntensity = req.substring(pos + 3).toInt();
strip.setIntensity(effectIntensity);
effectUpdated = true;
} }
} }
//set effect palette (only for FastLED effects) //set effect palette (only for FastLED effects)
@ -494,8 +487,6 @@ bool handleSet(String req)
if (effectPalette != req.substring(pos + 3).toInt()) if (effectPalette != req.substring(pos + 3).toInt())
{ {
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 pos = req.indexOf("PL="); //applies entire preset
if (pos > 0) { if (pos > 0) {
applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx); applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx);
if (presetApplyFx) effectUpdated = true;
} }
//cronixie //cronixie
@ -738,19 +728,9 @@ bool handleSet(String req)
//internal call, does not send XML response //internal call, does not send XML response
pos = req.indexOf("IN"); pos = req.indexOf("IN");
if (pos < 1) XML_response(true, (req.indexOf("IT") > 0)); //include theme if firstload 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"); pos = req.indexOf("NN"); //do not send UDP notifications this time
if (pos > 0) colorUpdated((pos > 0) ? 5:1);
{
colorUpdated(5);
return true;
}
if (effectUpdated)
{
colorUpdated(6);
} else
{
colorUpdated(1);
}
return true; return true;
} }

View File

@ -125,6 +125,7 @@ void wledInit()
Serial.println("Ada"); Serial.println("Ada");
} }
void initStrip() void initStrip()
{ {
// Initialize NeoPixel Strip and button // Initialize NeoPixel Strip and button
@ -142,6 +143,7 @@ void initStrip()
if(digitalRead(BTNPIN) == LOW) buttonEnabled = false; if(digitalRead(BTNPIN) == LOW) buttonEnabled = false;
} }
void initAP(){ void initAP(){
bool set = apSSID[0]; bool set = apSSID[0];
if (!set) strcpy(apSSID,"WLED-AP"); if (!set) strcpy(apSSID,"WLED-AP");
@ -149,6 +151,7 @@ void initAP(){
if (!set) apSSID[0] = 0; if (!set) apSSID[0] = 0;
} }
void initCon() void initCon()
{ {
WiFi.disconnect(); //close old connections WiFi.disconnect(); //close old connections

View File

@ -5,6 +5,7 @@
#define WLEDPACKETSIZE 24 #define WLEDPACKETSIZE 24
#define UDP_IN_MAXSIZE 1472 #define UDP_IN_MAXSIZE 1472
void notify(byte callMode, bool followUp=false) void notify(byte callMode, bool followUp=false)
{ {
if (!udpConnected) return; if (!udpConnected) return;
@ -53,6 +54,7 @@ void notify(byte callMode, bool followUp=false)
notificationTwoRequired = (followUp)? false:notifyTwice; notificationTwoRequired = (followUp)? false:notifyTwice;
} }
void arlsLock(uint32_t timeoutMs) void arlsLock(uint32_t timeoutMs)
{ {
if (!realtimeActive){ if (!realtimeActive){
@ -60,13 +62,14 @@ void arlsLock(uint32_t timeoutMs)
{ {
strip.setPixelColor(i,0,0,0,0); strip.setPixelColor(i,0,0,0,0);
} }
strip.setMode(0); strip.unlockAll();
} }
realtimeActive = true; realtimeActive = true;
realtimeTimeout = millis() + timeoutMs; realtimeTimeout = millis() + timeoutMs;
if (arlsForceMaxBri) strip.setBrightness(255); if (arlsForceMaxBri) strip.setBrightness(255);
} }
void initE131(){ void initE131(){
if (WiFi.status() == WL_CONNECTED && e131Enabled) if (WiFi.status() == WL_CONNECTED && e131Enabled)
{ {
@ -77,6 +80,7 @@ void initE131(){
} }
} }
void handleE131(){ void handleE131(){
//E1.31 protocol support //E1.31 protocol support
if(e131Enabled) { if(e131Enabled) {
@ -98,6 +102,7 @@ void handleE131(){
} }
} }
void handleNotifications() void handleNotifications()
{ {
//send second notification if enabled //send second notification if enabled
@ -110,10 +115,10 @@ void handleNotifications()
//unlock strip when realtime UDP times out //unlock strip when realtime UDP times out
if (realtimeActive && millis() > realtimeTimeout) if (realtimeActive && millis() > realtimeTimeout)
{ {
strip.unlockAll(); //strip.unlockAll();
strip.setBrightness(bri); strip.setBrightness(bri);
realtimeActive = false; realtimeActive = false;
strip.setMode(effectCurrent); //strip.setMode(effectCurrent);
realtimeIP[0] = 0; realtimeIP[0] = 0;
} }
@ -175,27 +180,11 @@ void handleNotifications()
//apply effects from notification //apply effects from notification
if (receiveNotificationEffects) if (receiveNotificationEffects)
{
if (udpIn[8] != effectCurrent)
{ {
effectCurrent = udpIn[8]; effectCurrent = udpIn[8];
strip.setMode(effectCurrent);
}
if (udpIn[9] != effectSpeed)
{
effectSpeed = udpIn[9]; effectSpeed = udpIn[9];
strip.setSpeed(effectSpeed); if (udpIn[11] > 2) effectIntensity = udpIn[16];
} if (udpIn[11] > 4) effectPalette = udpIn[19];
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);
}
} }
if (udpIn[11] > 3) if (udpIn[11] > 3)
@ -261,6 +250,7 @@ void handleNotifications()
} }
} }
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w)
{ {
uint16_t pix = i + arlsOffset; uint16_t pix = i + arlsOffset;

View File

@ -14,6 +14,7 @@ void toggleOnOff()
} }
} }
void setAllLeds() { void setAllLeds() {
if (!realtimeActive || !arlsForceMaxBri) if (!realtimeActive || !arlsForceMaxBri)
{ {
@ -50,6 +51,7 @@ void setAllLeds() {
} }
} }
void setLedsStandard() void setLedsStandard()
{ {
for (byte i = 0; i<3; i++) for (byte i = 0; i<3; i++)
@ -68,6 +70,7 @@ void setLedsStandard()
setAllLeds(); setAllLeds();
} }
bool colorChanged() bool colorChanged()
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
@ -80,17 +83,19 @@ bool colorChanged()
return false; return false;
} }
void colorUpdated(int callMode) 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 (!colorChanged())
{ {
if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5) if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5)
{ {
notify(4); return; notify(4); return;
} }
if (callMode == 2) notify(2); else if (fxChanged) notify(6);
else if (callMode == 6) notify(6);
return; //no change return; //no change
} }
if (callMode != 5 && nightlightActive && nightlightFade) if (callMode != 5 && nightlightActive && nightlightFade)
@ -150,6 +155,7 @@ void colorUpdated(int callMode)
updateInterfaces(callMode); updateInterfaces(callMode);
} }
void updateInterfaces(uint8_t callMode) void updateInterfaces(uint8_t callMode)
{ {
if (callMode != 9 && callMode != 5) updateBlynk(); if (callMode != 9 && callMode != 5) updateBlynk();
@ -157,6 +163,7 @@ void updateInterfaces(uint8_t callMode)
lastInterfaceUpdate = millis(); lastInterfaceUpdate = millis();
} }
void handleTransitions() void handleTransitions()
{ {
//handle still pending interface update //handle still pending interface update
@ -197,6 +204,7 @@ void handleTransitions()
} }
} }
void handleNightlight() void handleNightlight()
{ {
if (nightlightActive) if (nightlightActive)

View File

@ -66,22 +66,19 @@ BLYNK_WRITE(V3)
BLYNK_WRITE(V4) BLYNK_WRITE(V4)
{ {
effectCurrent = param.asInt()-1;//fx effectCurrent = param.asInt()-1;//fx
strip.setMode(effectCurrent); colorUpdated(9);
colorUpdated(6);
} }
BLYNK_WRITE(V5) BLYNK_WRITE(V5)
{ {
effectSpeed = param.asInt();//sx effectSpeed = param.asInt();//sx
strip.setSpeed(effectSpeed); colorUpdated(9);
colorUpdated(6);
} }
BLYNK_WRITE(V6) BLYNK_WRITE(V6)
{ {
effectIntensity = param.asInt();//ix effectIntensity = param.asInt();//ix
strip.setIntensity(effectIntensity); colorUpdated(9);
colorUpdated(6);
} }
BLYNK_WRITE(V7) BLYNK_WRITE(V7)