Refactor callMode (#702)

This commit is contained in:
Def3nder 2020-02-22 16:17:32 +01:00 committed by GitHub
parent c1a8fde9a0
commit 1a4061fdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 114 additions and 106 deletions

View File

@ -39,7 +39,7 @@ void userLoop() {
//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 10: alexa
colorUpdated(6);
colorUpdated(NOTIFIER_CALL_MODE_FX_CHANGED);
lastTime = millis();
}
}

View File

@ -47,7 +47,7 @@ void userLoop()
if (millis() + strip.timebase > (cycleTime - 25)) { //wipe complete
effectCurrent = FX_MODE_STATIC;
timeStaticStart = millis();
colorUpdated(3);
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
wipeState = 2;
}
} else if (wipeState == 2) { //static
@ -59,7 +59,7 @@ void userLoop()
#ifdef STAIRCASE_WIPE_OFF
effectCurrent = FX_MODE_COLOR_WIPE;
strip.timebase = 360 + (255 - effectSpeed)*75 - millis(); //make sure wipe starts fully lit
colorUpdated(3);
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
wipeState = 4;
#else
turnOff();
@ -93,7 +93,7 @@ void startWipe()
bool doReverse = (userVar0 == 2);
seg.setOption(1, doReverse);
colorUpdated(3);
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
}
void turnOff()
@ -104,7 +104,7 @@ void turnOff()
transitionDelayTemp = 4000; //fade out slowly
#endif
bri = 0;
colorUpdated(3);
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
wipeState = 0;
userVar0 = 0;
previousUserVar0 = 0;

View File

@ -7,6 +7,19 @@
#define AP_BEHAVIOR_ALWAYS 2 //Always open
#define AP_BEHAVIOR_BUTTON_ONLY 3 //Only when button pressed for 6 sec
//Notifier callMode
#define NOTIFIER_CALL_MODE_INIT 0 // no updates on init, can be used to disable updates
#define NOTIFIER_CALL_MODE_DIRECT_CHANGE 1
#define NOTIFIER_CALL_MODE_BUTTON 2
#define NOTIFIER_CALL_MODE_NOTIFICATION 3
#define NOTIFIER_CALL_MODE_NIGHTLIGHT 4
#define NOTIFIER_CALL_MODE_NO_NOTIFY 5
#define NOTIFIER_CALL_MODE_FX_CHANGED 6
#define NOTIFIER_CALL_MODE_HUE 7
#define NOTIFIER_CALL_MODE_PRESET_CYCLE 8
#define NOTIFIER_CALL_MODE_BLYNK 9
#define NOTIFIER_CALL_MODE_ALEXA 10
//RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
#define RGBW_MODE_AUTO_BRIGHTER 1 //New algorithm. Adds as much white as the darkest RGBW channel

View File

@ -301,7 +301,7 @@ unsigned long buttonWaitTime = 0;
bool notifyDirectDefault = notifyDirect;
bool receiveNotifications = true;
unsigned long notificationSentTime = 0;
byte notificationSentCallMode = 0;
byte notificationSentCallMode = NOTIFIER_CALL_MODE_INIT;
bool notificationTwoRequired = false;
//effects
@ -369,7 +369,7 @@ unsigned long realtimeTimeout = 0;
//mqtt
long lastMqttReconnectAttempt = 0;
long lastInterfaceUpdate = 0;
byte interfaceUpdateCallMode = 0;
byte interfaceUpdateCallMode = NOTIFIER_CALL_MODE_INIT;
char mqttStatusTopic[40] = ""; //this must be global because of async handlers
#if AUXPIN >= 0

View File

@ -651,7 +651,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req)
if (pos < 1) XML_response(request);
pos = req.indexOf("&NN"); //do not send UDP notifications this time
colorUpdated((pos > 0) ? 5:1);
colorUpdated((pos > 0) ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
return true;
}

View File

@ -99,7 +99,7 @@ void beginStrip()
#endif
if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true);
colorUpdated(0);
colorUpdated(NOTIFIER_CALL_MODE_INIT);
//init relay pin
#if RLYPIN >= 0

View File

@ -11,15 +11,15 @@ void notify(byte callMode, bool followUp=false)
if (!udpConnected) return;
switch (callMode)
{
case 0: return;
case 1: if (!notifyDirect) return; break;
case 2: if (!notifyButton) return; break;
case 4: if (!notifyDirect) return; break;
case 6: if (!notifyDirect) return; break; //fx change
case 7: if (!notifyHue) return; break;
case 8: if (!notifyDirect) return; break;
case 9: if (!notifyDirect) return; break;
case 10: if (!notifyAlexa) return; break;
case NOTIFIER_CALL_MODE_INIT: return;
case NOTIFIER_CALL_MODE_DIRECT_CHANGE: if (!notifyDirect) return; break;
case NOTIFIER_CALL_MODE_BUTTON: if (!notifyButton) return; break;
case NOTIFIER_CALL_MODE_NIGHTLIGHT: if (!notifyDirect) return; break;
case NOTIFIER_CALL_MODE_FX_CHANGED: if (!notifyDirect) return; break; //fx change
case NOTIFIER_CALL_MODE_HUE: if (!notifyHue) return; break;
case NOTIFIER_CALL_MODE_PRESET_CYCLE: if (!notifyDirect) return; break;
case NOTIFIER_CALL_MODE_BLYNK: if (!notifyDirect) return; break;
case NOTIFIER_CALL_MODE_ALEXA: if (!notifyAlexa) return; break;
default: return;
}
byte udpOut[WLEDPACKETSIZE];
@ -158,7 +158,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP){
colSec[3] = p->property_values[DMXAddress+12];
}
transitionDelayTemp = 0; // act fast
colorUpdated(3); // don't send UDP
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION); // don't send UDP
return; // don't activate realtime live mode
break;
@ -329,7 +329,7 @@ void handleNotifications()
if (nightlightActive) nightlightDelayMins = udpIn[7];
if (receiveNotificationBrightness || !someSel) bri = udpIn[2];
colorUpdated(3);
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
} else if (udpIn[0] > 0 && udpIn[0] < 5 && receiveDirect) //1 warls //2 drgb //3 drgbw
{

View File

@ -79,6 +79,7 @@ bool colorChanged()
{
if (col[i] != colIT[i]) return true;
if (colSec[i] != colSecIT[i]) return true;
if (col[i] != colNlT[i]) return true;
}
if (bri != briIT) return true;
return false;
@ -89,18 +90,24 @@ void colorUpdated(int callMode)
{
//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 10: alexa
if (callMode != 0 && callMode != 1 && callMode != 5) strip.applyToAllSelected = true; //if not from JSON api, which directly sets segments
if (callMode != NOTIFIER_CALL_MODE_INIT &&
callMode != NOTIFIER_CALL_MODE_DIRECT_CHANGE &&
callMode != NOTIFIER_CALL_MODE_NO_NOTIFY) strip.applyToAllSelected = true; //if not from JSON api, which directly sets segments
bool fxChanged = strip.setEffectConfig(effectCurrent, effectSpeed, effectIntensity, effectPalette);
if (!colorChanged())
{
if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5)
if (nightlightActive && !nightlightActiveOld &&
callMode != NOTIFIER_CALL_MODE_NOTIFICATION &&
callMode != NOTIFIER_CALL_MODE_NO_NOTIFY)
{
notify(4); interfaceUpdateCallMode = 4; return;
notify(NOTIFIER_CALL_MODE_NIGHTLIGHT);
interfaceUpdateCallMode = NOTIFIER_CALL_MODE_NIGHTLIGHT;
return;
}
else if (fxChanged) {
notify(6);
if (callMode != 8) interfaceUpdateCallMode = 6;
notify(NOTIFIER_CALL_MODE_FX_CHANGED);
if (callMode != NOTIFIER_CALL_MODE_PRESET_CYCLE) interfaceUpdateCallMode = NOTIFIER_CALL_MODE_FX_CHANGED;
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
if (isPreset) {isPreset = false;}
else {currentPreset = -1;}
@ -110,7 +117,7 @@ void colorUpdated(int callMode)
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
if (isPreset) {isPreset = false;}
else {currentPreset = -1;}
if (callMode != 5 && nightlightActive && nightlightFade)
if (callMode != NOTIFIER_CALL_MODE_NO_NOTIFY && nightlightActive && nightlightFade)
{
briNlT = bri;
nightlightDelayMs -= (millis() - nightlightStartTime);
@ -124,7 +131,7 @@ void colorUpdated(int callMode)
if (briT == 0)
{
setLedsStandard(true); //do not color transition if starting from off
if (callMode != 3) resetTimebase(); //effect start from beginning
if (callMode != NOTIFIER_CALL_MODE_NOTIFICATION) resetTimebase(); //effect start from beginning
}
briIT = bri;
@ -135,7 +142,7 @@ void colorUpdated(int callMode)
if (fadeTransition)
{
//set correct delay if not using notification delay
if (callMode != 3 && !jsonTransitionOnce) transitionDelayTemp = transitionDelay;
if (callMode != NOTIFIER_CALL_MODE_NOTIFICATION && !jsonTransitionOnce) transitionDelayTemp = transitionDelay;
jsonTransitionOnce = false;
if (transitionDelayTemp == 0) {setLedsStandard(); strip.trigger(); return;}
@ -158,7 +165,7 @@ void colorUpdated(int callMode)
strip.trigger();
}
if (callMode == 8) return;
if (callMode == NOTIFIER_CALL_MODE_PRESET_CYCLE) return;
//set flag to update blynk and mqtt
interfaceUpdateCallMode = callMode;
}
@ -167,12 +174,13 @@ void colorUpdated(int callMode)
void updateInterfaces(uint8_t callMode)
{
#ifndef WLED_DISABLE_ALEXA
if (espalexaDevice != nullptr && callMode != 10) {
if (espalexaDevice != nullptr && callMode != NOTIFIER_CALL_MODE_ALEXA) {
espalexaDevice->setValue(bri);
espalexaDevice->setColor(col[0], col[1], col[2]);
}
#endif
if (callMode != 9 && callMode != 5) updateBlynk();
if (callMode != NOTIFIER_CALL_MODE_BLYNK &&
callMode != NOTIFIER_CALL_MODE_NO_NOTIFY) updateBlynk();
doPublishMqtt = true;
lastInterfaceUpdate = millis();
}
@ -233,7 +241,7 @@ void handleNightlight()
{
for (byte i=0; i<4; i++) col[i] = colNlT[i]+ ((colSec[i] - colNlT[i])*nper); // fading from actual color to secondary color
}
colorUpdated(5);
colorUpdated(NOTIFIER_CALL_MODE_NO_NOTIFY);
}
if (nper >= 1)
{
@ -241,7 +249,7 @@ void handleNightlight()
if (!nightlightFade)
{
bri = nightlightTargetBri;
colorUpdated(5);
colorUpdated(NOTIFIER_CALL_MODE_NO_NOTIFY);
}
updateBlynk();
if (bri == 0) briLast = briNlT;
@ -257,7 +265,7 @@ void handleNightlight()
applyPreset(presetCycCurr,presetApplyBri,presetApplyCol,presetApplyFx);
presetCycCurr++; if (presetCycCurr > presetCycleMax) presetCycCurr = presetCycleMin;
if (presetCycCurr > 25) presetCycCurr = 1;
colorUpdated(8);
colorUpdated(NOTIFIER_CALL_MODE_PRESET_CYCLE);
presetCycledTime = millis();
}
}

View File

@ -7,7 +7,7 @@ void shortPressAction()
if (!macroButton)
{
toggleOnOff();
colorUpdated(2);
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
} else {
applyMacro(macroButton);
}

View File

@ -41,7 +41,7 @@ void onAlexaChange(EspalexaDevice* dev)
if (bri == 0)
{
bri = briLast;
colorUpdated(10);
colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
}
} else applyMacro(macroAlexaOn);
} else if (m == EspalexaDeviceProperty::off)
@ -52,13 +52,13 @@ void onAlexaChange(EspalexaDevice* dev)
{
briLast = bri;
bri = 0;
colorUpdated(10);
colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
}
} else applyMacro(macroAlexaOff);
} else if (m == EspalexaDeviceProperty::bri)
{
bri = espalexaDevice->getValue();
colorUpdated(10);
colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
} else //color
{
uint32_t color = espalexaDevice->getRGB();
@ -67,7 +67,7 @@ void onAlexaChange(EspalexaDevice* dev)
col[1] = ((color >> 8) & 0xFF);
col[2] = (color & 0xFF);
if (useRGBW && col[3] == 0) colorRGBtoRGBW(col); // do not touch white value if EspalexaDevice.cpp did set the white channel
colorUpdated(10);
colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
}
}

View File

@ -6,7 +6,7 @@ void handleHue()
{
if (hueReceived)
{
colorUpdated(7); hueReceived = false;
colorUpdated(NOTIFIER_CALL_MODE_HUE); hueReceived = false;
if (hueStoreAllowed && hueNewKey)
{
saveSettingsToEEPROM(); //save api key

View File

@ -41,45 +41,45 @@ void updateBlynk()
BLYNK_WRITE(V0)
{
bri = param.asInt();//bri
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V1)
{
blHue = param.asInt();//hue
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V2)
{
blSat = param.asInt();//sat
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V3)
{
bool on = (param.asInt()>0);
if (!on != !bri) {toggleOnOff(); colorUpdated(9);}
if (!on != !bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BLYNK);}
}
BLYNK_WRITE(V4)
{
effectCurrent = param.asInt()-1;//fx
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V5)
{
effectSpeed = param.asInt();//sx
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V6)
{
effectIntensity = param.asInt();//ix
colorUpdated(9);
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
}
BLYNK_WRITE(V7)

View File

@ -12,7 +12,7 @@ void parseMQTTBriPayload(char* payload)
uint8_t in = strtoul(payload, NULL, 10);
if (in == 0 && bri > 0) briLast = bri;
bri = in;
colorUpdated(1);
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
}
}
@ -60,7 +60,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
if (strstr(topic, "/col"))
{
colorFromDecOrHexString(col, (char*)payload);
colorUpdated(1);
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
} else if (strstr(topic, "/api"))
{
String apireq = "win&";

View File

@ -154,7 +154,7 @@ bool deserializeState(JsonObject root)
}
}
colorUpdated(noNotification ? 5:1);
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
ps = root["psave"] | -1;
if (ps >= 0) savePreset(ps);

View File

@ -29,7 +29,7 @@ bool decodeIRCustom(uint32_t code)
default: return false;
}
if (code != IRCUSTOM_MACRO1) colorUpdated(2); //don't update color again if we apply macro, it already does it
if (code != IRCUSTOM_MACRO1) colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //don't update color again if we apply macro, it already does it
return true;
}
@ -51,25 +51,25 @@ void decodeIR(uint32_t code)
irTimesRepeated++;
if (lastValidCode == IR24_BRIGHTER || lastValidCode == IR40_BPLUS )
{
relativeChange(&bri, 10); colorUpdated(2);
relativeChange(&bri, 10); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
else if (lastValidCode == IR24_DARKER || lastValidCode == IR40_BMINUS )
{
relativeChange(&bri, -10, 5); colorUpdated(2);
relativeChange(&bri, -10, 5); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
if (lastValidCode == IR40_WPLUS)
{
relativeChangeWhite(10); colorUpdated(2);
relativeChangeWhite(10); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
else if (lastValidCode == IR40_WMINUS)
{
relativeChangeWhite(-10, 5); colorUpdated(2);
relativeChangeWhite(-10, 5); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
else if ((lastValidCode == IR24_ON || lastValidCode == IR40_ON) && irTimesRepeated > 7 )
{
nightlightActive = true;
nightlightStartTime = millis();
colorUpdated(2);
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
return;
}
@ -90,6 +90,7 @@ void decodeIR(uint32_t code)
// sets bright plain white
default: return;
}
colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //for notifier, IR is considered a button input
}
//code <= 0xF70000 also invalid
}
@ -125,7 +126,6 @@ void decodeIR24(uint32_t code)
default: return;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
void decodeIR24OLD(uint32_t code)
@ -158,7 +158,6 @@ void decodeIR24OLD(uint32_t code)
default: return;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
@ -194,7 +193,6 @@ void decodeIR24CT(uint32_t code)
default: return;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
@ -253,7 +251,6 @@ void decodeIR40(uint32_t code)
case IR40_FLASH : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
void decodeIR44(uint32_t code)
@ -317,7 +314,6 @@ void decodeIR44(uint32_t code)
case IR44_FADE7 : bri = 255; break;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
void decodeIR21(uint32_t code)
@ -347,12 +343,10 @@ void decodeIR21(uint32_t code)
default: return;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}
void decodeIR6(uint32_t code)
{
switch (code) {
case IR6_POWER: toggleOnOff(); break;
case IR6_CHANNEL_UP: relativeChange(&bri, 10); break;
@ -360,11 +354,8 @@ void decodeIR6(uint32_t code)
case IR6_VOLUME_UP: /* next effect */ relativeChange(&effectCurrent, 1); break;
case IR6_VOLUME_DOWN:
/* next palette */
relativeChange(&effectPalette, 1);
switch(lastIR6ColourIdx)
{
switch(lastIR6ColourIdx) {
case 0: colorFromUint32(COLOR_RED); break;
case 1: colorFromUint32(COLOR_REDDISH); break;
case 2:colorFromUint32(COLOR_ORANGE); break;
@ -379,17 +370,13 @@ void decodeIR6(uint32_t code)
case 11:colorFromUint32(COLOR_PINK); break;
case 12:colorFromUint32(COLOR_WHITE); break;
default:break;
}
lastIR6ColourIdx++;
if(lastIR6ColourIdx > 12) lastIR6ColourIdx = 0;
break;
case IR6_MUTE: effectCurrent = 0; effectPalette = 0; colorFromUint32(COLOR_WHITE); bri=255; break;
}
lastValidCode = code;
colorUpdated(2); //for notifier, IR is considered a button input
}