2020-04-10 12:30:08 +02:00
|
|
|
#include "wled.h"
|
|
|
|
|
2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* Receives client input
|
|
|
|
*/
|
|
|
|
|
2020-04-10 12:30:08 +02:00
|
|
|
void _setRandomColor(bool _sec,bool fromButton)
|
2017-12-11 23:59:12 +01:00
|
|
|
{
|
|
|
|
lastRandomIndex = strip.get_random_wheel_index(lastRandomIndex);
|
|
|
|
if (_sec){
|
2018-03-15 13:03:50 +01:00
|
|
|
colorHStoRGB(lastRandomIndex*256,255,colSec);
|
2017-12-11 23:59:12 +01:00
|
|
|
} else {
|
2018-03-15 13:03:50 +01:00
|
|
|
colorHStoRGB(lastRandomIndex*256,255,col);
|
2017-12-11 23:59:12 +01:00
|
|
|
}
|
2018-03-15 13:03:50 +01:00
|
|
|
if (fromButton) colorUpdated(2);
|
2017-12-11 23:59:12 +01:00
|
|
|
}
|
|
|
|
|
2018-09-17 11:15:08 +02:00
|
|
|
|
2019-12-11 00:59:15 +01:00
|
|
|
bool isAsterisksOnly(const char* str, byte maxLen)
|
|
|
|
{
|
|
|
|
for (byte i = 0; i < maxLen; i++) {
|
|
|
|
if (str[i] == 0) break;
|
|
|
|
if (str[i] != '*') return false;
|
|
|
|
}
|
2020-09-10 11:01:05 +02:00
|
|
|
//at this point the password contains asterisks only
|
|
|
|
return (str[0] != 0); //false on empty string
|
2019-12-11 00:59:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-17 11:15:08 +02:00
|
|
|
//called upon POST settings form submit
|
2019-02-16 00:21:22 +01:00
|
|
|
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2020-02-23 22:24:51 +01:00
|
|
|
|
|
|
|
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 7: DMX
|
|
|
|
if (subPage <1 || subPage >7) return;
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-02-20 22:29:48 +01:00
|
|
|
//WIFI SETTINGS
|
|
|
|
if (subPage == 1)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
strlcpy(clientSSID,request->arg(F("CS")).c_str(), 33);
|
2019-12-11 00:59:15 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
if (!isAsterisksOnly(request->arg(F("CP")).c_str(), 65)) strlcpy(clientPass, request->arg(F("CP")).c_str(), 65);
|
2018-09-17 11:15:08 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
strlcpy(cmDNS, request->arg(F("CM")).c_str(), 33);
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
apBehavior = request->arg(F("AB")).toInt();
|
|
|
|
strlcpy(apSSID, request->arg(F("AS")).c_str(), 33);
|
|
|
|
apHide = request->hasArg(F("AH"));
|
|
|
|
int passlen = request->arg(F("AP")).length();
|
|
|
|
if (passlen == 0 || (passlen > 7 && !isAsterisksOnly(request->arg(F("AP")).c_str(), 65))) strlcpy(apPass, request->arg(F("AP")).c_str(), 65);
|
|
|
|
int t = request->arg(F("AC")).toInt(); if (t > 0 && t < 14) apChannel = t;
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
noWifiSleep = request->hasArg(F("WS"));
|
2020-02-20 17:08:56 +01:00
|
|
|
|
2021-01-15 10:37:45 +01:00
|
|
|
#ifdef WLED_USE_ETHERNET
|
|
|
|
ethernetType = request->arg(F("ETH")).toInt();
|
|
|
|
#endif
|
|
|
|
|
2018-09-17 11:15:08 +02:00
|
|
|
char k[3]; k[2] = 0;
|
2018-07-21 23:21:07 +02:00
|
|
|
for (int i = 0; i<4; i++)
|
2018-01-27 23:28:20 +01:00
|
|
|
{
|
2018-09-17 11:15:08 +02:00
|
|
|
k[1] = i+48;//ascii 0,1,2,3
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-07-21 23:21:07 +02:00
|
|
|
k[0] = 'I'; //static IP
|
2019-02-16 00:21:22 +01:00
|
|
|
staticIP[i] = request->arg(k).toInt();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-07-21 23:21:07 +02:00
|
|
|
k[0] = 'G'; //gateway
|
2019-02-16 00:21:22 +01:00
|
|
|
staticGateway[i] = request->arg(k).toInt();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-07-21 23:21:07 +02:00
|
|
|
k[0] = 'S'; //subnet
|
2019-02-16 00:21:22 +01:00
|
|
|
staticSubnet[i] = request->arg(k).toInt();
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
|
|
|
|
//LED SETTINGS
|
|
|
|
if (subPage == 2)
|
2016-12-11 20:11:14 +01:00
|
|
|
{
|
2021-01-21 01:21:16 +01:00
|
|
|
int t = 0;
|
|
|
|
|
2021-01-17 00:20:31 +01:00
|
|
|
if (rlyPin>=0 && pinManager.isPinAllocated(rlyPin)) pinManager.deallocatePin(rlyPin);
|
|
|
|
#ifndef WLED_DISABLE_INFRARED
|
|
|
|
if (irPin>=0 && pinManager.isPinAllocated(irPin)) pinManager.deallocatePin(irPin);
|
|
|
|
#endif
|
|
|
|
if (btnPin>=0 && pinManager.isPinAllocated(btnPin)) pinManager.deallocatePin(btnPin);
|
|
|
|
|
2021-03-29 23:12:19 +02:00
|
|
|
strip.isRgbw = false;
|
2021-02-24 20:23:32 +01:00
|
|
|
|
2021-04-07 21:04:54 +02:00
|
|
|
// uint8_t skip = request->hasArg(F("SL")) ? LED_SKIP_AMOUNT : 0;
|
|
|
|
uint8_t colorOrder, type, skip;
|
2021-01-26 00:19:41 +01:00
|
|
|
uint16_t length, start;
|
2021-02-24 20:23:32 +01:00
|
|
|
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
2021-01-21 01:21:16 +01:00
|
|
|
|
2021-01-30 20:51:36 +01:00
|
|
|
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
|
|
|
|
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
|
|
|
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
|
|
|
|
char co[4] = "CO"; co[2] = 48+s; co[3] = 0; //strip color order
|
|
|
|
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type
|
|
|
|
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
|
|
|
|
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
|
2021-04-07 21:04:54 +02:00
|
|
|
char sl[4] = "SL"; sl[2] = 48+s; sl[3] = 0; //skip 1st LED
|
|
|
|
// char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override
|
2021-01-30 20:51:36 +01:00
|
|
|
if (!request->hasArg(lp)) {
|
2021-04-01 12:53:01 +02:00
|
|
|
DEBUG_PRINTLN(F("No data.")); break;
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
2021-02-24 14:49:39 +01:00
|
|
|
for (uint8_t i = 0; i < 5; i++) {
|
|
|
|
lp[1] = 48+i;
|
|
|
|
if (!request->hasArg(lp)) break;
|
|
|
|
pins[i] = (request->arg(lp).length() > 0) ? request->arg(lp).toInt() : 255;
|
2021-01-30 20:51:36 +01:00
|
|
|
}
|
|
|
|
type = request->arg(lt).toInt();
|
2021-04-07 21:04:54 +02:00
|
|
|
// if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary)
|
|
|
|
// strip.isRgbw = strip.isRgbw || request->hasArg(ew);
|
|
|
|
strip.isRgbw = strip.isRgbw || Bus::isRgbw(type);
|
|
|
|
skip = request->hasArg(sl) ? LED_SKIP_AMOUNT : 0;
|
2021-02-24 22:11:27 +01:00
|
|
|
|
2021-02-25 09:54:10 +01:00
|
|
|
colorOrder = request->arg(co).toInt();
|
|
|
|
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : t;
|
2021-01-30 20:51:36 +01:00
|
|
|
if (request->hasArg(lc) && request->arg(lc).toInt() > 0) {
|
2021-02-25 09:54:10 +01:00
|
|
|
t += length = request->arg(lc).toInt();
|
2021-01-30 20:51:36 +01:00
|
|
|
} else {
|
|
|
|
break; // no parameter
|
|
|
|
}
|
|
|
|
|
2021-03-03 22:04:24 +01:00
|
|
|
// actual finalization is done in WLED::loop() (removing old busses and adding new)
|
2021-01-30 20:51:36 +01:00
|
|
|
if (busConfigs[s] != nullptr) delete busConfigs[s];
|
2021-03-29 23:12:19 +02:00
|
|
|
busConfigs[s] = new BusConfig(type, pins, start, length, colorOrder, request->hasArg(cv), skip);
|
2021-03-23 07:05:40 +01:00
|
|
|
doInitBusses = true;
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 21:33:44 +01:00
|
|
|
ledCount = request->arg(F("LC")).toInt();
|
2021-01-17 00:20:31 +01:00
|
|
|
|
|
|
|
// upate other pins
|
|
|
|
#ifndef WLED_DISABLE_INFRARED
|
|
|
|
int hw_ir_pin = request->arg(F("IR")).toInt();
|
2021-02-24 20:23:32 +01:00
|
|
|
if (pinManager.allocatePin(hw_ir_pin,false)) {
|
2021-01-17 00:20:31 +01:00
|
|
|
irPin = hw_ir_pin;
|
|
|
|
} else {
|
|
|
|
irPin = -1;
|
|
|
|
}
|
2018-09-17 11:15:08 +02:00
|
|
|
#endif
|
2021-01-17 00:20:31 +01:00
|
|
|
|
|
|
|
int hw_rly_pin = request->arg(F("RL")).toInt();
|
|
|
|
if (pinManager.allocatePin(hw_rly_pin,true)) {
|
|
|
|
rlyPin = hw_rly_pin;
|
|
|
|
} else {
|
|
|
|
rlyPin = -1;
|
|
|
|
}
|
|
|
|
rlyMde = (bool)request->hasArg(F("RM"));
|
|
|
|
|
|
|
|
int hw_btn_pin = request->arg(F("BT")).toInt();
|
|
|
|
if (pinManager.allocatePin(hw_btn_pin,false)) {
|
|
|
|
btnPin = hw_btn_pin;
|
|
|
|
pinMode(btnPin, INPUT_PULLUP);
|
|
|
|
} else {
|
|
|
|
btnPin = -1;
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
strip.ablMilliampsMax = request->arg(F("MA")).toInt();
|
|
|
|
strip.milliampsPerLed = request->arg(F("LA")).toInt();
|
2019-11-12 19:33:34 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
strip.rgbwMode = request->arg(F("AW")).toInt();
|
2018-11-09 17:00:36 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
briS = request->arg(F("CA")).toInt();
|
2019-12-04 02:01:47 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
saveCurrPresetCycConf = request->hasArg(F("PC"));
|
|
|
|
turnOnAtBoot = request->hasArg(F("BO"));
|
|
|
|
t = request->arg(F("BP")).toInt();
|
2021-01-13 11:24:27 +01:00
|
|
|
if (t <= 250) bootPreset = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
strip.gammaCorrectBri = request->hasArg(F("GB"));
|
|
|
|
strip.gammaCorrectCol = request->hasArg(F("GC"));
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
fadeTransition = request->hasArg(F("TF"));
|
|
|
|
t = request->arg(F("TD")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 0) transitionDelay = t;
|
2018-09-28 23:53:51 +02:00
|
|
|
transitionDelayDefault = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
strip.paletteFade = request->hasArg(F("PF"));
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
nightlightTargetBri = request->arg(F("TB")).toInt();
|
|
|
|
t = request->arg(F("TL")).toInt();
|
2018-11-22 00:09:30 +01:00
|
|
|
if (t > 0) nightlightDelayMinsDefault = t;
|
2019-09-19 21:15:20 +02:00
|
|
|
nightlightDelayMins = nightlightDelayMinsDefault;
|
2020-09-20 01:18:31 +02:00
|
|
|
nightlightMode = request->arg(F("TW")).toInt();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("PB")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t >= 0 && t < 4) strip.paletteBlend = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("BF")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 0) briMultiplier = t;
|
2016-12-11 20:11:14 +01:00
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
|
|
|
|
//UI
|
|
|
|
if (subPage == 3)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
strlcpy(serverDescription, request->arg(F("DS")).c_str(), 33);
|
|
|
|
syncToggleReceive = request->hasArg(F("ST"));
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
|
|
|
|
//SYNC
|
|
|
|
if (subPage == 4)
|
2017-02-24 23:21:48 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
buttonEnabled = request->hasArg(F("BT"));
|
|
|
|
irEnabled = request->arg(F("IR")).toInt();
|
|
|
|
int t = request->arg(F("UP")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 0) udpPort = t;
|
2020-09-27 11:43:28 +02:00
|
|
|
t = request->arg(F("U2")).toInt();
|
|
|
|
if (t > 0) udpPort2 = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
receiveNotificationBrightness = request->hasArg(F("RB"));
|
|
|
|
receiveNotificationColor = request->hasArg(F("RC"));
|
|
|
|
receiveNotificationEffects = request->hasArg(F("RX"));
|
2018-02-20 22:29:48 +01:00
|
|
|
receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
|
2020-09-20 01:18:31 +02:00
|
|
|
notifyDirectDefault = request->hasArg(F("SD"));
|
2018-02-20 22:29:48 +01:00
|
|
|
notifyDirect = notifyDirectDefault;
|
2020-09-20 01:18:31 +02:00
|
|
|
notifyButton = request->hasArg(F("SB"));
|
|
|
|
notifyAlexa = request->hasArg(F("SA"));
|
|
|
|
notifyHue = request->hasArg(F("SH"));
|
|
|
|
notifyMacro = request->hasArg(F("SM"));
|
|
|
|
notifyTwice = request->hasArg(F("S2"));
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
nodeListEnabled = request->hasArg(F("NL"));
|
|
|
|
if (!nodeListEnabled) Nodes.clear();
|
|
|
|
nodeBroadcastEnabled = request->hasArg(F("NB"));
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
receiveDirect = request->hasArg(F("RD"));
|
|
|
|
e131SkipOutOfSequence = request->hasArg(F("ES"));
|
|
|
|
e131Multicast = request->hasArg(F("EM"));
|
|
|
|
t = request->arg(F("EP")).toInt();
|
2020-04-13 00:42:27 +02:00
|
|
|
if (t > 0) e131Port = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("EU")).toInt();
|
2020-04-13 00:42:27 +02:00
|
|
|
if (t >= 0 && t <= 63999) e131Universe = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("DA")).toInt();
|
2020-04-13 00:42:27 +02:00
|
|
|
if (t >= 0 && t <= 510) DMXAddress = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("DM")).toInt();
|
2020-11-27 11:37:39 +01:00
|
|
|
if (t >= DMX_MODE_DISABLED && t <= DMX_MODE_MULTIPLE_RGBW) DMXMode = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("ET")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 99 && t <= 65000) realtimeTimeoutMs = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
arlsForceMaxBri = request->hasArg(F("FB"));
|
|
|
|
arlsDisableGammaCorrection = request->hasArg(F("RG"));
|
|
|
|
t = request->arg(F("WO")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t >= -255 && t <= 255) arlsOffset = t;
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
alexaEnabled = request->hasArg(F("AL"));
|
|
|
|
strlcpy(alexaInvocationName, request->arg(F("AI")).c_str(), 33);
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-12-22 00:44:16 +01:00
|
|
|
strlcpy(blynkHost, request->arg("BH").c_str(), 33);
|
|
|
|
t = request->arg(F("BP")).toInt();
|
|
|
|
if (t > 0) blynkPort = t;
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
if (request->hasArg("BK") && !request->arg("BK").equals(F("Hidden"))) {
|
2020-12-22 00:44:16 +01:00
|
|
|
strlcpy(blynkApiKey, request->arg("BK").c_str(), 36); initBlynk(blynkApiKey, blynkHost, blynkPort);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-10-04 16:50:12 +02:00
|
|
|
|
2019-12-11 00:59:15 +01:00
|
|
|
#ifdef WLED_ENABLE_MQTT
|
2020-09-20 01:18:31 +02:00
|
|
|
mqttEnabled = request->hasArg(F("MQ"));
|
|
|
|
strlcpy(mqttServer, request->arg(F("MS")).c_str(), 33);
|
|
|
|
t = request->arg(F("MQPORT")).toInt();
|
2019-08-18 18:14:17 +02:00
|
|
|
if (t > 0) mqttPort = t;
|
2020-09-20 01:18:31 +02:00
|
|
|
strlcpy(mqttUser, request->arg(F("MQUSER")).c_str(), 41);
|
|
|
|
if (!isAsterisksOnly(request->arg(F("MQPASS")).c_str(), 41)) strlcpy(mqttPass, request->arg(F("MQPASS")).c_str(), 41);
|
|
|
|
strlcpy(mqttClientID, request->arg(F("MQCID")).c_str(), 41);
|
|
|
|
strlcpy(mqttDeviceTopic, request->arg(F("MD")).c_str(), 33);
|
|
|
|
strlcpy(mqttGroupTopic, request->arg(F("MG")).c_str(), 33);
|
2019-12-11 00:59:15 +01:00
|
|
|
#endif
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2019-12-11 00:59:15 +01:00
|
|
|
#ifndef WLED_DISABLE_HUESYNC
|
2018-02-28 00:27:10 +01:00
|
|
|
for (int i=0;i<4;i++){
|
2018-03-14 19:05:51 +01:00
|
|
|
String a = "H"+String(i);
|
2019-02-16 00:21:22 +01:00
|
|
|
hueIP[i] = request->arg(a).toInt();
|
2018-02-28 00:27:10 +01:00
|
|
|
}
|
2018-09-17 11:15:08 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("HL")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 0) huePollLightId = t;
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("HI")).toInt();
|
2018-09-17 11:15:08 +02:00
|
|
|
if (t > 50) huePollIntervalMs = t;
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
hueApplyOnOff = request->hasArg(F("HO"));
|
|
|
|
hueApplyBri = request->hasArg(F("HB"));
|
|
|
|
hueApplyColor = request->hasArg(F("HC"));
|
|
|
|
huePollingEnabled = request->hasArg(F("HP"));
|
2019-02-18 22:34:21 +01:00
|
|
|
hueStoreAllowed = true;
|
|
|
|
reconnectHue();
|
2019-12-11 00:59:15 +01:00
|
|
|
#endif
|
2017-02-24 23:21:48 +01:00
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
|
|
|
|
//TIME
|
|
|
|
if (subPage == 5)
|
2017-02-24 23:21:48 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
ntpEnabled = request->hasArg(F("NT"));
|
|
|
|
strlcpy(ntpServerName, request->arg(F("NS")).c_str(), 33);
|
|
|
|
useAMPM = !request->hasArg(F("CF"));
|
|
|
|
currentTimezone = request->arg(F("TZ")).toInt();
|
|
|
|
utcOffsetSecs = request->arg(F("UO")).toInt();
|
2018-11-09 17:00:36 +01:00
|
|
|
|
|
|
|
//start ntp if not already connected
|
2019-10-18 13:26:39 +02:00
|
|
|
if (ntpEnabled && WLED_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort);
|
2021-03-09 13:24:20 +01:00
|
|
|
|
2021-03-05 23:05:09 +01:00
|
|
|
longitude = request->arg(F("LN")).toFloat();
|
|
|
|
latitude = request->arg(F("LT")).toFloat();
|
2021-03-08 19:52:43 +01:00
|
|
|
// force a sunrise/sunset re-calculation
|
2021-03-09 13:24:20 +01:00
|
|
|
calculateSunriseAndSunset();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
if (request->hasArg(F("OL"))) {
|
|
|
|
overlayDefault = request->arg(F("OL")).toInt();
|
2018-03-14 00:25:54 +01:00
|
|
|
overlayCurrent = overlayDefault;
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
overlayMin = request->arg(F("O1")).toInt();
|
|
|
|
overlayMax = request->arg(F("O2")).toInt();
|
|
|
|
analogClock12pixel = request->arg(F("OM")).toInt();
|
|
|
|
analogClock5MinuteMarks = request->hasArg(F("O5"));
|
|
|
|
analogClockSecondsTrail = request->hasArg(F("OS"));
|
|
|
|
|
|
|
|
strcpy(cronixieDisplay,request->arg(F("CX")).c_str());
|
|
|
|
cronixieBacklight = request->hasArg(F("CB"));
|
|
|
|
countdownMode = request->hasArg(F("CE"));
|
|
|
|
countdownYear = request->arg(F("CY")).toInt();
|
|
|
|
countdownMonth = request->arg(F("CI")).toInt();
|
|
|
|
countdownDay = request->arg(F("CD")).toInt();
|
|
|
|
countdownHour = request->arg(F("CH")).toInt();
|
|
|
|
countdownMin = request->arg(F("CM")).toInt();
|
|
|
|
countdownSec = request->arg(F("CS")).toInt();
|
2020-12-31 20:47:38 +01:00
|
|
|
setCountdown();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
macroAlexaOn = request->arg(F("A0")).toInt();
|
|
|
|
macroAlexaOff = request->arg(F("A1")).toInt();
|
|
|
|
macroButton = request->arg(F("MP")).toInt();
|
|
|
|
macroLongPress = request->arg(F("ML")).toInt();
|
|
|
|
macroCountdown = request->arg(F("MC")).toInt();
|
|
|
|
macroNl = request->arg(F("MN")).toInt();
|
|
|
|
macroDoublePress = request->arg(F("MD")).toInt();
|
2018-09-22 22:49:24 +02:00
|
|
|
|
|
|
|
char k[3]; k[2] = 0;
|
2021-03-07 00:04:46 +01:00
|
|
|
for (int i = 0; i<10; i++)
|
2018-09-22 22:49:24 +02:00
|
|
|
{
|
|
|
|
k[1] = i+48;//ascii 0,1,2,3
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-09-22 22:49:24 +02:00
|
|
|
k[0] = 'H'; //timer hours
|
2019-02-16 00:21:22 +01:00
|
|
|
timerHours[i] = request->arg(k).toInt();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-09-22 22:49:24 +02:00
|
|
|
k[0] = 'N'; //minutes
|
2019-02-16 00:21:22 +01:00
|
|
|
timerMinutes[i] = request->arg(k).toInt();
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-09-22 22:49:24 +02:00
|
|
|
k[0] = 'T'; //macros
|
2019-02-16 00:21:22 +01:00
|
|
|
timerMacro[i] = request->arg(k).toInt();
|
2019-01-31 00:09:44 +01:00
|
|
|
|
|
|
|
k[0] = 'W'; //weekdays
|
2019-02-16 00:21:22 +01:00
|
|
|
timerWeekday[i] = request->arg(k).toInt();
|
2018-09-22 22:49:24 +02:00
|
|
|
}
|
2017-02-24 23:21:48 +01:00
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
|
|
|
|
//SECURITY
|
|
|
|
if (subPage == 6)
|
2016-11-20 01:47:15 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
if (request->hasArg(F("RS"))) //complete factory reset
|
2016-11-20 01:47:15 +01:00
|
|
|
{
|
2020-11-06 22:12:48 +01:00
|
|
|
WLED_FS.format();
|
2020-12-10 16:27:23 +01:00
|
|
|
clearEEPROM();
|
2020-09-20 01:18:31 +02:00
|
|
|
serveMessage(request, 200, F("All Settings erased."), F("Connect to WLED-AP to setup again"),255);
|
2019-02-17 17:11:10 +01:00
|
|
|
doReboot = true;
|
2018-02-20 22:29:48 +01:00
|
|
|
}
|
2018-02-23 01:33:32 +01:00
|
|
|
|
|
|
|
bool pwdCorrect = !otaLock; //always allow access if ota not locked
|
2020-09-20 01:18:31 +02:00
|
|
|
if (request->hasArg(F("OP")))
|
2016-11-20 01:47:15 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
if (otaLock && strcmp(otaPass,request->arg(F("OP")).c_str()) == 0)
|
2018-02-20 22:29:48 +01:00
|
|
|
{
|
2018-02-23 01:33:32 +01:00
|
|
|
pwdCorrect = true;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
if (!otaLock && request->arg(F("OP")).length() > 0)
|
2016-11-20 01:47:15 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
strlcpy(otaPass,request->arg(F("OP")).c_str(), 33);
|
2016-11-20 01:47:15 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-02-23 01:33:32 +01:00
|
|
|
if (pwdCorrect) //allow changes if correct pwd or no ota active
|
2018-02-20 22:29:48 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
otaLock = request->hasArg(F("NO"));
|
|
|
|
wifiLock = request->hasArg(F("OW"));
|
|
|
|
aOtaEnabled = request->hasArg(F("AO"));
|
2018-02-20 22:29:48 +01:00
|
|
|
}
|
2016-11-20 01:47:15 +01:00
|
|
|
}
|
2020-02-23 22:24:51 +01:00
|
|
|
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
|
|
|
|
if (subPage == 7)
|
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
int t = request->arg(F("PU")).toInt();
|
2020-05-11 11:51:11 +02:00
|
|
|
if (t >= 0 && t <= 63999) e131ProxyUniverse = t;
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("CN")).toInt();
|
2020-02-23 22:24:51 +01:00
|
|
|
if (t>0 && t<16) {
|
|
|
|
DMXChannels = t;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("CS")).toInt();
|
2020-02-23 22:24:51 +01:00
|
|
|
if (t>0 && t<513) {
|
|
|
|
DMXStart = t;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("CG")).toInt();
|
2020-02-23 22:24:51 +01:00
|
|
|
if (t>0 && t<513) {
|
|
|
|
DMXGap = t;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
t = request->arg(F("SL")).toInt();
|
2020-04-10 12:30:08 +02:00
|
|
|
if (t>=0 && t < MAX_LEDS) {
|
|
|
|
DMXStartLED = t;
|
|
|
|
}
|
2020-02-23 22:24:51 +01:00
|
|
|
for (int i=0; i<15; i++) {
|
|
|
|
String argname = "CH" + String((i+1));
|
|
|
|
t = request->arg(argname).toInt();
|
|
|
|
DMXFixtureMap[i] = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-01-17 00:20:31 +01:00
|
|
|
|
2021-01-31 00:38:27 +01:00
|
|
|
if (subPage != 2 && (subPage != 6 || !doReboot)) serializeConfig(); //do not save if factory reset or LED settings (which are saved after LED re-init)
|
2019-01-09 22:52:42 +01:00
|
|
|
if (subPage == 4) alexaInit();
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
|
2018-11-25 00:00:02 +01:00
|
|
|
|
2019-02-22 22:53:33 +01:00
|
|
|
|
2018-11-25 00:00:02 +01:00
|
|
|
//helper to get int value at a position in string
|
2019-03-09 21:41:23 +01:00
|
|
|
int getNumVal(const String* req, uint16_t pos)
|
2018-11-25 00:00:02 +01:00
|
|
|
{
|
2019-02-22 22:53:33 +01:00
|
|
|
return req->substring(pos+3).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//helper to get int value at a position in string
|
2020-04-10 12:30:08 +02:00
|
|
|
bool updateVal(const String* req, const char* key, byte* val, byte minv, byte maxv)
|
2019-02-22 22:53:33 +01:00
|
|
|
{
|
|
|
|
int pos = req->indexOf(key);
|
|
|
|
if (pos < 1) return false;
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2019-02-22 22:53:33 +01:00
|
|
|
if (req->charAt(pos+3) == '~') {
|
|
|
|
int out = getNumVal(req, pos+1);
|
|
|
|
if (out == 0)
|
|
|
|
{
|
|
|
|
if (req->charAt(pos+4) == '-')
|
|
|
|
{
|
|
|
|
*val = (*val <= minv)? maxv : *val -1;
|
|
|
|
} else {
|
|
|
|
*val = (*val >= maxv)? minv : *val +1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out += *val;
|
|
|
|
if (out > maxv) out = maxv;
|
|
|
|
if (out < minv) out = minv;
|
|
|
|
*val = out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
*val = getNumVal(req, pos);
|
|
|
|
}
|
|
|
|
return true;
|
2018-11-25 00:00:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//HTTP API request parser
|
2020-10-03 00:29:36 +02:00
|
|
|
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2018-11-09 17:00:36 +01:00
|
|
|
if (!(req.indexOf("win") >= 0)) return false;
|
2018-09-17 11:15:08 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
int pos = 0;
|
2020-09-20 01:18:31 +02:00
|
|
|
DEBUG_PRINT(F("API req: "));
|
2018-11-09 17:00:36 +01:00
|
|
|
DEBUG_PRINTLN(req);
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2021-01-05 21:35:07 +01:00
|
|
|
strip.applyToAllSelected = false;
|
|
|
|
//snapshot to check if request changed values later, temporary.
|
|
|
|
byte prevCol[4] = {col[0], col[1], col[2], col[3]};
|
|
|
|
byte prevColSec[4] = {colSec[0], colSec[1], colSec[2], colSec[3]};
|
|
|
|
byte prevEffect = effectCurrent;
|
|
|
|
byte prevSpeed = effectSpeed;
|
|
|
|
byte prevIntensity = effectIntensity;
|
|
|
|
byte prevPalette = effectPalette;
|
2019-12-02 12:41:35 +01:00
|
|
|
|
2019-12-01 01:42:52 +01:00
|
|
|
//segment select (sets main segment)
|
2019-12-04 02:01:47 +01:00
|
|
|
byte prevMain = strip.getMainSegmentId();
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SM="));
|
2019-12-01 01:42:52 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
strip.mainSegment = getNumVal(&req, pos);
|
|
|
|
}
|
2021-01-05 21:35:07 +01:00
|
|
|
byte selectedSeg = strip.getMainSegmentId();
|
|
|
|
if (selectedSeg != prevMain) setValuesFromMainSeg();
|
2019-12-04 02:01:47 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SS="));
|
2019-12-04 02:01:47 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
byte t = getNumVal(&req, pos);
|
2021-01-05 21:35:07 +01:00
|
|
|
if (t < strip.getMaxSegments()) selectedSeg = t;
|
2019-12-04 02:01:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-05 21:35:07 +01:00
|
|
|
WS2812FX::Segment& mainseg = strip.getSegment(selectedSeg);
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SV=")); //segment selected
|
2020-06-26 23:30:13 +02:00
|
|
|
if (pos > 0) {
|
|
|
|
byte t = getNumVal(&req, pos);
|
|
|
|
if (t == 2) {
|
|
|
|
for (uint8_t i = 0; i < strip.getMaxSegments(); i++)
|
|
|
|
{
|
|
|
|
strip.getSegment(i).setOption(SEG_OPTION_SELECTED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mainseg.setOption(SEG_OPTION_SELECTED, t);
|
|
|
|
}
|
2019-12-01 01:42:52 +01:00
|
|
|
|
2020-01-19 01:07:38 +01:00
|
|
|
uint16_t startI = mainseg.start;
|
|
|
|
uint16_t stopI = mainseg.stop;
|
|
|
|
uint8_t grpI = mainseg.grouping;
|
|
|
|
uint16_t spcI = mainseg.spacing;
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("&S=")); //segment start
|
2019-12-01 01:42:52 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
startI = getNumVal(&req, pos);
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("S2=")); //segment stop
|
2019-12-01 01:42:52 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
stopI = getNumVal(&req, pos);
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("GP=")); //segment grouping
|
2020-01-19 01:07:38 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
grpI = getNumVal(&req, pos);
|
|
|
|
if (grpI == 0) grpI = 1;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SP=")); //segment spacing
|
2020-01-19 01:07:38 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
spcI = getNumVal(&req, pos);
|
|
|
|
}
|
2021-01-05 21:35:07 +01:00
|
|
|
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI);
|
2019-12-01 01:42:52 +01:00
|
|
|
|
2020-02-09 16:11:38 +01:00
|
|
|
//set presets
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("P1=")); //sets first preset for cycle
|
2020-02-09 16:11:38 +01:00
|
|
|
if (pos > 0) presetCycleMin = getNumVal(&req, pos);
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("P2=")); //sets last preset for cycle
|
2020-02-09 16:11:38 +01:00
|
|
|
if (pos > 0) presetCycleMax = getNumVal(&req, pos);
|
|
|
|
|
|
|
|
//preset cycle
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("CY="));
|
2020-02-09 16:11:38 +01:00
|
|
|
if (pos > 0)
|
|
|
|
{
|
2020-09-20 16:40:32 +02:00
|
|
|
char cmd = req.charAt(pos+3);
|
|
|
|
if (cmd == '2') presetCyclingEnabled = !presetCyclingEnabled;
|
|
|
|
else presetCyclingEnabled = (cmd != '0');
|
2020-02-09 16:11:38 +01:00
|
|
|
presetCycCurr = presetCycleMin;
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("PT=")); //sets cycle time in ms
|
2020-02-09 16:11:38 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
int v = getNumVal(&req, pos);
|
2020-05-18 16:36:31 +02:00
|
|
|
if (v > 100) presetCycleTime = v/100;
|
2020-02-09 16:11:38 +01:00
|
|
|
}
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("PS=")); //saves current in preset
|
2020-10-08 00:52:15 +02:00
|
|
|
if (pos > 0) savePreset(getNumVal(&req, pos));
|
2020-02-09 16:11:38 +01:00
|
|
|
|
|
|
|
//apply preset
|
|
|
|
if (updateVal(&req, "PL=", &presetCycCurr, presetCycleMin, presetCycleMax)) {
|
2020-10-08 00:52:15 +02:00
|
|
|
applyPreset(presetCycCurr);
|
2020-02-09 16:11:38 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:53:33 +01:00
|
|
|
//set brightness
|
|
|
|
updateVal(&req, "&A=", &bri);
|
|
|
|
|
|
|
|
//set colors
|
|
|
|
updateVal(&req, "&R=", &col[0]);
|
|
|
|
updateVal(&req, "&G=", &col[1]);
|
|
|
|
updateVal(&req, "&B=", &col[2]);
|
|
|
|
updateVal(&req, "&W=", &col[3]);
|
|
|
|
updateVal(&req, "R2=", &colSec[0]);
|
|
|
|
updateVal(&req, "G2=", &colSec[1]);
|
|
|
|
updateVal(&req, "B2=", &colSec[2]);
|
|
|
|
updateVal(&req, "W2=", &colSec[3]);
|
2018-02-28 00:27:10 +01:00
|
|
|
|
2020-09-27 11:43:28 +02:00
|
|
|
#ifdef WLED_ENABLE_LOXONE
|
2020-09-27 11:37:16 +02:00
|
|
|
//lox parser
|
|
|
|
pos = req.indexOf(F("LX=")); // Lox primary color
|
|
|
|
if (pos > 0) {
|
|
|
|
int lxValue = getNumVal(&req, pos);
|
2020-09-27 11:43:28 +02:00
|
|
|
if (parseLx(lxValue, col)) {
|
2020-09-27 11:37:16 +02:00
|
|
|
bri = 255;
|
|
|
|
nightlightActive = false; //always disable nightlight when toggling
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 11:43:28 +02:00
|
|
|
pos = req.indexOf(F("LY=")); // Lox secondary color
|
2020-09-27 11:37:16 +02:00
|
|
|
if (pos > 0) {
|
|
|
|
int lxValue = getNumVal(&req, pos);
|
2020-09-27 11:43:28 +02:00
|
|
|
if(parseLx(lxValue, colSec)) {
|
2020-09-27 11:37:16 +02:00
|
|
|
bri = 255;
|
|
|
|
nightlightActive = false; //always disable nightlight when toggling
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-27 11:43:28 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set hue
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("HU="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
uint16_t temphue = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
byte tempsat = 255;
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SA="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
tempsat = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
colorHStoRGB(temphue,tempsat,(req.indexOf(F("H2"))>0)? colSec:col);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-27 11:43:28 +02:00
|
|
|
//set white spectrum (kelvin)
|
|
|
|
pos = req.indexOf(F("&K="));
|
|
|
|
if (pos > 0) {
|
|
|
|
colorKtoRGB(getNumVal(&req, pos),(req.indexOf(F("K2"))>0)? colSec:col);
|
|
|
|
}
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set color from HEX or 32bit DEC
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("CL="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2019-02-05 21:53:39 +01:00
|
|
|
colorFromDecOrHexString(col, (char*)req.substring(pos + 3).c_str());
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("C2="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2019-02-05 21:53:39 +01:00
|
|
|
colorFromDecOrHexString(colSec, (char*)req.substring(pos + 3).c_str());
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("C3="));
|
2020-04-23 23:52:33 +02:00
|
|
|
if (pos > 0) {
|
|
|
|
byte t[4];
|
|
|
|
colorFromDecOrHexString(t, (char*)req.substring(pos + 3).c_str());
|
2021-01-05 21:35:07 +01:00
|
|
|
if (selectedSeg != strip.getMainSegmentId()) {
|
|
|
|
strip.applyToAllSelected = true;
|
|
|
|
strip.setColor(2, t[0], t[1], t[2], t[3]);
|
|
|
|
} else {
|
2021-01-09 00:35:48 +01:00
|
|
|
strip.getSegment(selectedSeg).setColor(2,((t[0] << 16) + (t[1] << 8) + t[2] + (t[3] << 24)), selectedSeg);
|
2021-01-05 21:35:07 +01:00
|
|
|
}
|
2020-04-23 23:52:33 +02:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set to random hue SR=0->1st SR=1->2nd
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SR"));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
_setRandomColor(getNumVal(&req, pos));
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//swap 2nd & 1st
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SC"));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2019-02-05 21:53:39 +01:00
|
|
|
byte temp;
|
|
|
|
for (uint8_t i=0; i<4; i++)
|
2018-11-09 17:00:36 +01:00
|
|
|
{
|
2019-02-05 21:53:39 +01:00
|
|
|
temp = col[i];
|
2018-11-09 17:00:36 +01:00
|
|
|
col[i] = colSec[i];
|
2019-02-05 21:53:39 +01:00
|
|
|
colSec[i] = temp;
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2019-02-22 22:53:33 +01:00
|
|
|
//set effect parameters
|
|
|
|
if (updateVal(&req, "FX=", &effectCurrent, 0, strip.getModeCount()-1)) presetCyclingEnabled = false;
|
|
|
|
updateVal(&req, "SX=", &effectSpeed);
|
|
|
|
updateVal(&req, "IX=", &effectIntensity);
|
|
|
|
updateVal(&req, "FP=", &effectPalette, 0, strip.getPaletteCount()-1);
|
2018-11-09 17:00:36 +01:00
|
|
|
|
|
|
|
//set advanced overlay
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("OL="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
overlayCurrent = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-09-04 15:51:38 +02:00
|
|
|
|
2020-11-06 22:12:48 +01:00
|
|
|
//apply macro (deprecated, added for compatibility with pre-0.11 automations)
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("&M="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2020-11-06 22:12:48 +01:00
|
|
|
applyPreset(getNumVal(&req, pos) + 16);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//toggle send UDP direct notifications
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SN="));
|
2019-02-22 22:53:33 +01:00
|
|
|
if (pos > 0) notifyDirect = (req.charAt(pos+3) != '0');
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//toggle receive UDP direct notifications
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("RN="));
|
2019-02-22 22:53:33 +01:00
|
|
|
if (pos > 0) receiveNotifications = (req.charAt(pos+3) != '0');
|
2019-03-09 14:48:13 +01:00
|
|
|
|
|
|
|
//receive live data via UDP/Hyperion
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("RD="));
|
2019-03-09 14:48:13 +01:00
|
|
|
if (pos > 0) receiveDirect = (req.charAt(pos+3) != '0');
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-10-02 12:30:17 +02:00
|
|
|
//main toggle on/off (parse before nightlight, #1214)
|
|
|
|
pos = req.indexOf(F("&T="));
|
|
|
|
if (pos > 0) {
|
|
|
|
nightlightActive = false; //always disable nightlight when toggling
|
|
|
|
switch (getNumVal(&req, pos))
|
|
|
|
{
|
|
|
|
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off, only if it was previously on
|
|
|
|
case 1: if (bri == 0) bri = briLast; break; //on, only if it was previously off
|
|
|
|
default: toggleOnOff(); //toggle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//toggle nightlight mode
|
|
|
|
bool aNlDef = false;
|
2020-09-20 01:18:31 +02:00
|
|
|
if (req.indexOf(F("&ND")) > 0) aNlDef = true;
|
|
|
|
pos = req.indexOf(F("NL="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0)
|
|
|
|
{
|
2019-02-22 22:53:33 +01:00
|
|
|
if (req.charAt(pos+3) == '0')
|
2018-11-09 17:00:36 +01:00
|
|
|
{
|
|
|
|
nightlightActive = false;
|
|
|
|
} else {
|
2018-04-15 15:27:54 +02:00
|
|
|
nightlightActive = true;
|
2018-11-25 00:00:02 +01:00
|
|
|
if (!aNlDef) nightlightDelayMins = getNumVal(&req, pos);
|
2018-04-15 15:27:54 +02:00
|
|
|
nightlightStartTime = millis();
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
|
|
|
} else if (aNlDef)
|
|
|
|
{
|
|
|
|
nightlightActive = true;
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set nightlight target brightness
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("NT="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
nightlightTargetBri = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
nightlightActiveOld = false; //re-init
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//toggle nightlight fade
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("NF="));
|
2019-02-22 22:53:33 +01:00
|
|
|
if (pos > 0)
|
2018-11-09 17:00:36 +01:00
|
|
|
{
|
2020-06-22 12:30:31 +02:00
|
|
|
nightlightMode = getNumVal(&req, pos);
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
nightlightActiveOld = false; //re-init
|
|
|
|
}
|
2020-06-22 12:30:31 +02:00
|
|
|
if (nightlightMode > NL_MODE_SUN) nightlightMode = NL_MODE_SUN;
|
2019-02-25 19:14:13 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("TT="));
|
2019-02-22 22:53:33 +01:00
|
|
|
if (pos > 0) transitionDelay = getNumVal(&req, pos);
|
|
|
|
|
2019-03-01 17:10:42 +01:00
|
|
|
//Segment reverse
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("RV="));
|
2021-01-05 21:35:07 +01:00
|
|
|
if (pos > 0) strip.getSegment(selectedSeg).setOption(SEG_OPTION_REVERSED, req.charAt(pos+3) != '0');
|
2020-04-23 23:52:33 +02:00
|
|
|
|
2020-08-07 00:50:19 +02:00
|
|
|
//Segment reverse
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("MI="));
|
2021-01-05 21:35:07 +01:00
|
|
|
if (pos > 0) strip.getSegment(selectedSeg).setOption(SEG_OPTION_MIRROR, req.charAt(pos+3) != '0');
|
2020-08-07 00:50:19 +02:00
|
|
|
|
2020-04-23 23:52:33 +02:00
|
|
|
//Segment brightness/opacity
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("SB="));
|
2020-04-23 23:52:33 +02:00
|
|
|
if (pos > 0) {
|
|
|
|
byte segbri = getNumVal(&req, pos);
|
2021-01-09 00:35:48 +01:00
|
|
|
strip.getSegment(selectedSeg).setOption(SEG_OPTION_ON, segbri, selectedSeg);
|
2020-04-23 23:52:33 +02:00
|
|
|
if (segbri) {
|
2021-01-09 00:35:48 +01:00
|
|
|
strip.getSegment(selectedSeg).setOpacity(segbri, selectedSeg);
|
2020-04-23 23:52:33 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set time (unix timestamp)
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("ST="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
setTime(getNumVal(&req, pos));
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//set countdown goal (unix timestamp)
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("CT="));
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
countdownTime = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
if (countdownTime - now() > 0) countdownOverTriggered = false;
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("LO="));
|
2020-06-22 12:30:31 +02:00
|
|
|
if (pos > 0) {
|
|
|
|
realtimeOverride = getNumVal(&req, pos);
|
|
|
|
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("RB"));
|
2020-04-30 01:52:36 +02:00
|
|
|
if (pos > 0) doReboot = true;
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//cronixie
|
2019-03-01 17:10:42 +01:00
|
|
|
#ifndef WLED_DISABLE_CRONIXIE
|
2020-01-01 01:04:54 +01:00
|
|
|
//mode, 1 countdown
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("NM="));
|
2020-01-01 01:04:54 +01:00
|
|
|
if (pos > 0) countdownMode = (req.charAt(pos+3) != '0');
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("NX=")); //sets digits to code
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2019-11-13 01:20:14 +01:00
|
|
|
strlcpy(cronixieDisplay, req.substring(pos + 3, pos + 9).c_str(), 6);
|
2018-11-09 17:00:36 +01:00
|
|
|
setCronixie();
|
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("NB="));
|
2019-12-04 02:01:47 +01:00
|
|
|
if (pos > 0) //sets backlight
|
2018-11-09 17:00:36 +01:00
|
|
|
{
|
2020-02-29 18:42:55 +01:00
|
|
|
cronixieBacklight = (req.charAt(pos+3) != '0');
|
2018-11-09 17:00:36 +01:00
|
|
|
overlayRefreshedTime = 0;
|
|
|
|
}
|
2019-03-01 17:10:42 +01:00
|
|
|
#endif
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("U0=")); //user var 0
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
userVar0 = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("U1=")); //user var 1
|
2018-11-09 17:00:36 +01:00
|
|
|
if (pos > 0) {
|
2018-11-25 00:00:02 +01:00
|
|
|
userVar1 = getNumVal(&req, pos);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
|
|
|
//you can add more if you need
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2021-01-05 21:35:07 +01:00
|
|
|
//apply to all selected manually to prevent #1618. Temporary
|
|
|
|
bool col0Changed = false, col1Changed = false;
|
|
|
|
for (uint8_t i = 0; i < 4; i++) {
|
|
|
|
if (col[i] != prevCol[i]) col0Changed = true;
|
|
|
|
if (colSec[i] != prevColSec[i]) col1Changed = true;
|
|
|
|
}
|
|
|
|
for (uint8_t i = 0; i < strip.getMaxSegments(); i++)
|
|
|
|
{
|
|
|
|
WS2812FX::Segment& seg = strip.getSegment(i);
|
|
|
|
if (!seg.isSelected()) continue;
|
2021-03-01 22:44:28 +01:00
|
|
|
if (effectCurrent != prevEffect) {
|
|
|
|
seg.mode = effectCurrent;
|
|
|
|
effectChanged = true;
|
|
|
|
}
|
|
|
|
if (effectSpeed != prevSpeed) {
|
|
|
|
seg.speed = effectSpeed;
|
|
|
|
effectChanged = true;
|
|
|
|
}
|
|
|
|
if (effectIntensity != prevIntensity) {
|
|
|
|
seg.intensity = effectIntensity;
|
|
|
|
effectChanged = true;
|
|
|
|
}
|
|
|
|
if (effectPalette != prevPalette) {
|
|
|
|
seg.palette = effectPalette;
|
|
|
|
effectChanged = true;
|
|
|
|
}
|
2021-01-05 21:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (col0Changed) {
|
|
|
|
if (selectedSeg == strip.getMainSegmentId()) {
|
|
|
|
strip.applyToAllSelected = true;
|
|
|
|
strip.setColor(0, colorFromRgbw(col));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (col1Changed) {
|
|
|
|
if (selectedSeg == strip.getMainSegmentId()) {
|
|
|
|
strip.applyToAllSelected = true;
|
|
|
|
strip.setColor(1, colorFromRgbw(colSec));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//end of temporary fix code
|
|
|
|
|
2020-10-03 00:29:36 +02:00
|
|
|
if (!apply) return true; //when called by JSON API, do not call colorUpdated() here
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
//internal call, does not send XML response
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("IN"));
|
2019-12-04 02:01:47 +01:00
|
|
|
if (pos < 1) XML_response(request);
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2021-01-05 21:35:07 +01:00
|
|
|
strip.applyToAllSelected = false;
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
pos = req.indexOf(F("&NN")); //do not send UDP notifications this time
|
2020-02-22 16:17:32 +01:00
|
|
|
colorUpdated((pos > 0) ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
2019-08-17 12:27:06 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
return true;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|