kopia lustrzana https://github.com/Aircoookie/WLED
Improved binary size
rodzic
c9c294a1d5
commit
c4c2494dd1
|
@ -309,6 +309,15 @@ void handleSettingsSet(byte subPage)
|
||||||
if (subPage == 2) strip.init(useRGBW,ledCount,skipFirstLed);
|
if (subPage == 2) strip.init(useRGBW,ledCount,skipFirstLed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//helper to get int value at a position in string
|
||||||
|
int getNumVal(String* req, uint16_t pos)
|
||||||
|
{
|
||||||
|
return req->substring(pos + 3).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//HTTP API request parser
|
||||||
bool handleSet(String req)
|
bool handleSet(String req)
|
||||||
{
|
{
|
||||||
if (!(req.indexOf("win") >= 0)) return false;
|
if (!(req.indexOf("win") >= 0)) return false;
|
||||||
|
@ -338,17 +347,17 @@ bool handleSet(String req)
|
||||||
//set brigthness
|
//set brigthness
|
||||||
pos = req.indexOf("&A=");
|
pos = req.indexOf("&A=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
bri = req.substring(pos + 3).toInt();
|
bri = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set hue
|
//set hue
|
||||||
pos = req.indexOf("HU=");
|
pos = req.indexOf("HU=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
uint16_t temphue = req.substring(pos + 3).toInt();
|
uint16_t temphue = getNumVal(&req, pos);
|
||||||
byte tempsat = 255;
|
byte tempsat = 255;
|
||||||
pos = req.indexOf("SA=");
|
pos = req.indexOf("SA=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
tempsat = req.substring(pos + 3).toInt();
|
tempsat = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
|
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
|
||||||
}
|
}
|
||||||
|
@ -356,43 +365,43 @@ bool handleSet(String req)
|
||||||
//set red value
|
//set red value
|
||||||
pos = req.indexOf("&R=");
|
pos = req.indexOf("&R=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
col[0] = req.substring(pos + 3).toInt();
|
col[0] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set green value
|
//set green value
|
||||||
pos = req.indexOf("&G=");
|
pos = req.indexOf("&G=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
col[1] = req.substring(pos + 3).toInt();
|
col[1] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set blue value
|
//set blue value
|
||||||
pos = req.indexOf("&B=");
|
pos = req.indexOf("&B=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
col[2] = req.substring(pos + 3).toInt();
|
col[2] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set white value
|
//set white value
|
||||||
pos = req.indexOf("&W=");
|
pos = req.indexOf("&W=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
white = req.substring(pos + 3).toInt();
|
white = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set 2nd red value
|
//set 2nd red value
|
||||||
pos = req.indexOf("R2=");
|
pos = req.indexOf("R2=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
colSec[0] = req.substring(pos + 3).toInt();
|
colSec[0] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set 2nd green value
|
//set 2nd green value
|
||||||
pos = req.indexOf("G2=");
|
pos = req.indexOf("G2=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
colSec[1] = req.substring(pos + 3).toInt();
|
colSec[1] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set 2nd blue value
|
//set 2nd blue value
|
||||||
pos = req.indexOf("B2=");
|
pos = req.indexOf("B2=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
colSec[2] = req.substring(pos + 3).toInt();
|
colSec[2] = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set 2nd white value
|
//set 2nd white value
|
||||||
pos = req.indexOf("W2=");
|
pos = req.indexOf("W2=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
whiteSec = req.substring(pos + 3).toInt();
|
whiteSec = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set color from HEX or 32bit DEC
|
//set color from HEX or 32bit DEC
|
||||||
|
@ -432,7 +441,7 @@ bool handleSet(String req)
|
||||||
//set to random hue SR=0->1st SR=1->2nd
|
//set to random hue SR=0->1st SR=1->2nd
|
||||||
pos = req.indexOf("SR");
|
pos = req.indexOf("SR");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
_setRandomColor(req.substring(pos + 3).toInt());
|
_setRandomColor(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
//set 2nd to 1st
|
//set 2nd to 1st
|
||||||
pos = req.indexOf("SP");
|
pos = req.indexOf("SP");
|
||||||
|
@ -460,40 +469,28 @@ bool handleSet(String req)
|
||||||
//set current effect index
|
//set current effect index
|
||||||
pos = req.indexOf("FX=");
|
pos = req.indexOf("FX=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
if (effectCurrent != req.substring(pos + 3).toInt())
|
effectCurrent = getNumVal(&req, pos);
|
||||||
{
|
|
||||||
effectCurrent = req.substring(pos + 3).toInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//set effect speed
|
//set effect speed
|
||||||
pos = req.indexOf("SX=");
|
pos = req.indexOf("SX=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
if (effectSpeed != req.substring(pos + 3).toInt())
|
effectSpeed = getNumVal(&req, pos);
|
||||||
{
|
|
||||||
effectSpeed = req.substring(pos + 3).toInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//set effect intensity
|
//set effect intensity
|
||||||
pos = req.indexOf("IX=");
|
pos = req.indexOf("IX=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
if (effectIntensity != req.substring(pos + 3).toInt())
|
|
||||||
{
|
|
||||||
effectIntensity = req.substring(pos + 3).toInt();
|
effectIntensity = req.substring(pos + 3).toInt();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//set effect palette (only for FastLED effects)
|
//set effect palette (only for FastLED effects)
|
||||||
pos = req.indexOf("FP=");
|
pos = req.indexOf("FP=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
if (effectPalette != req.substring(pos + 3).toInt())
|
|
||||||
{
|
|
||||||
effectPalette = req.substring(pos + 3).toInt();
|
effectPalette = req.substring(pos + 3).toInt();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//set hue polling light: 0 -off
|
//set hue polling light: 0 -off
|
||||||
pos = req.indexOf("HP=");
|
pos = req.indexOf("HP=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
int id = req.substring(pos + 3).toInt();
|
int id = getNumVal(&req, pos);
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
{
|
{
|
||||||
if (id < 100) huePollLightId = id;
|
if (id < 100) huePollLightId = id;
|
||||||
|
@ -506,21 +503,21 @@ bool handleSet(String req)
|
||||||
//set default control mode (0 - RGB, 1 - HSB)
|
//set default control mode (0 - RGB, 1 - HSB)
|
||||||
pos = req.indexOf("MD=");
|
pos = req.indexOf("MD=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
useHSB = req.substring(pos + 3).toInt();
|
useHSB = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//set advanced overlay
|
//set advanced overlay
|
||||||
pos = req.indexOf("OL=");
|
pos = req.indexOf("OL=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
overlayCurrent = req.substring(pos + 3).toInt();
|
overlayCurrent = getNumVal(&req, pos);
|
||||||
strip.unlockAll();
|
strip.unlockAll();
|
||||||
}
|
}
|
||||||
//(un)lock pixel (ranges)
|
//(un)lock pixel (ranges)
|
||||||
pos = req.indexOf("&L=");
|
pos = req.indexOf("&L=");
|
||||||
if (pos > 0){
|
if (pos > 0){
|
||||||
int index = req.substring(pos + 3).toInt();
|
int index = getNumVal(&req, pos);
|
||||||
pos = req.indexOf("L2=");
|
pos = req.indexOf("L2=");
|
||||||
if (pos > 0){
|
if (pos > 0){
|
||||||
int index2 = req.substring(pos + 3).toInt();
|
int index2 = getNumVal(&req, pos);
|
||||||
if (req.indexOf("UL") > 0)
|
if (req.indexOf("UL") > 0)
|
||||||
{
|
{
|
||||||
strip.unlockRange(index, index2);
|
strip.unlockRange(index, index2);
|
||||||
|
@ -543,7 +540,7 @@ bool handleSet(String req)
|
||||||
//apply macro
|
//apply macro
|
||||||
pos = req.indexOf("&M=");
|
pos = req.indexOf("&M=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
applyMacro(req.substring(pos + 3).toInt());
|
applyMacro(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
//toggle send UDP direct notifications
|
//toggle send UDP direct notifications
|
||||||
if (req.indexOf("SN=") > 0)
|
if (req.indexOf("SN=") > 0)
|
||||||
|
@ -577,7 +574,7 @@ bool handleSet(String req)
|
||||||
bri = briT;
|
bri = briT;
|
||||||
} else {
|
} else {
|
||||||
nightlightActive = true;
|
nightlightActive = true;
|
||||||
if (!aNlDef) nightlightDelayMins = req.substring(pos + 3).toInt();
|
if (!aNlDef) nightlightDelayMins = getNumVal(&req, pos);
|
||||||
nightlightStartTime = millis();
|
nightlightStartTime = millis();
|
||||||
}
|
}
|
||||||
} else if (aNlDef)
|
} else if (aNlDef)
|
||||||
|
@ -589,7 +586,7 @@ bool handleSet(String req)
|
||||||
//set nightlight target brightness
|
//set nightlight target brightness
|
||||||
pos = req.indexOf("NT=");
|
pos = req.indexOf("NT=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
nightlightTargetBri = req.substring(pos + 3).toInt();
|
nightlightTargetBri = getNumVal(&req, pos);
|
||||||
nightlightActiveOld = false; //re-init
|
nightlightActiveOld = false; //re-init
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,20 +605,20 @@ bool handleSet(String req)
|
||||||
//toggle general purpose output
|
//toggle general purpose output
|
||||||
pos = req.indexOf("AX=");
|
pos = req.indexOf("AX=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
auxTime = req.substring(pos + 3).toInt();
|
auxTime = getNumVal(&req, pos);
|
||||||
auxActive = true;
|
auxActive = true;
|
||||||
if (auxTime == 0) auxActive = false;
|
if (auxTime == 0) auxActive = false;
|
||||||
}
|
}
|
||||||
pos = req.indexOf("TT=");
|
pos = req.indexOf("TT=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
transitionDelay = req.substring(pos + 3).toInt();
|
transitionDelay = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//main toggle on/off
|
//main toggle on/off
|
||||||
pos = req.indexOf("&T=");
|
pos = req.indexOf("&T=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
nightlightActive = false; //always disable nightlight when toggling
|
nightlightActive = false; //always disable nightlight when toggling
|
||||||
switch (req.substring(pos + 3).toInt())
|
switch (getNumVal(&req, pos))
|
||||||
{
|
{
|
||||||
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off
|
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off
|
||||||
case 1: bri = briLast; break; //on
|
case 1: bri = briLast; break; //on
|
||||||
|
@ -634,22 +631,22 @@ bool handleSet(String req)
|
||||||
//set time (unix timestamp)
|
//set time (unix timestamp)
|
||||||
pos = req.indexOf("ST=");
|
pos = req.indexOf("ST=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
setTime(req.substring(pos+3).toInt());
|
setTime(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
//set countdown goal (unix timestamp)
|
//set countdown goal (unix timestamp)
|
||||||
pos = req.indexOf("CT=");
|
pos = req.indexOf("CT=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
countdownTime = req.substring(pos+3).toInt();
|
countdownTime = getNumVal(&req, pos);
|
||||||
if (countdownTime - now() > 0) countdownOverTriggered = false;
|
if (countdownTime - now() > 0) countdownOverTriggered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//set presets
|
//set presets
|
||||||
pos = req.indexOf("P1="); //sets first preset for cycle
|
pos = req.indexOf("P1="); //sets first preset for cycle
|
||||||
if (pos > 0) presetCycleMin = req.substring(pos + 3).toInt();
|
if (pos > 0) presetCycleMin = getNumVal(&req, pos);
|
||||||
|
|
||||||
pos = req.indexOf("P2="); //sets last preset for cycle
|
pos = req.indexOf("P2="); //sets last preset for cycle
|
||||||
if (pos > 0) presetCycleMax = req.substring(pos + 3).toInt();
|
if (pos > 0) presetCycleMax = getNumVal(&req, pos);
|
||||||
|
|
||||||
if (req.indexOf("CY=") > 0) //preset cycle
|
if (req.indexOf("CY=") > 0) //preset cycle
|
||||||
{
|
{
|
||||||
|
@ -662,7 +659,7 @@ bool handleSet(String req)
|
||||||
}
|
}
|
||||||
pos = req.indexOf("PT="); //sets cycle time in ms
|
pos = req.indexOf("PT="); //sets cycle time in ms
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
int v = req.substring(pos + 3).toInt();
|
int v = getNumVal(&req, pos);
|
||||||
if (v > 49) presetCycleTime = v;
|
if (v > 49) presetCycleTime = v;
|
||||||
}
|
}
|
||||||
if (req.indexOf("PA=") > 0) //apply brightness from preset
|
if (req.indexOf("PA=") > 0) //apply brightness from preset
|
||||||
|
@ -683,11 +680,11 @@ bool handleSet(String req)
|
||||||
|
|
||||||
pos = req.indexOf("PS="); //saves current in preset
|
pos = req.indexOf("PS="); //saves current in preset
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
savePreset(req.substring(pos + 3).toInt());
|
savePreset(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
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(getNumVal(&req, pos), presetApplyBri, presetApplyCol, presetApplyFx);
|
||||||
}
|
}
|
||||||
|
|
||||||
//cronixie
|
//cronixie
|
||||||
|
@ -717,11 +714,11 @@ bool handleSet(String req)
|
||||||
|
|
||||||
pos = req.indexOf("U0="); //user var 0
|
pos = req.indexOf("U0="); //user var 0
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
userVar0 = req.substring(pos + 3).toInt();
|
userVar0 = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
pos = req.indexOf("U1="); //user var 1
|
pos = req.indexOf("U1="); //user var 1
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
userVar1 = req.substring(pos + 3).toInt();
|
userVar1 = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
//you can add more if you need
|
//you can add more if you need
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue