Added relative API calls

pull/133/head
cschwinne 2019-02-22 22:53:33 +01:00
rodzic f86cdd8cde
commit f0e525d2e2
6 zmienionych plików z 118 dodań i 161 usunięć

Wyświetl plik

@ -335,6 +335,8 @@ class WS2812FX {
getMode(void), getMode(void),
getSpeed(void), getSpeed(void),
getNumSegments(void), getNumSegments(void),
getModeCount(void),
getPaletteCount(void),
get_random_wheel_index(uint8_t); get_random_wheel_index(uint8_t);
uint32_t uint32_t

Wyświetl plik

@ -259,6 +259,16 @@ void WS2812FX::setMode(uint8_t m) {
setBrightness(_brightness); setBrightness(_brightness);
} }
uint8_t WS2812FX::getModeCount()
{
return MODE_COUNT;
}
uint8_t WS2812FX::getPaletteCount()
{
return 13 + gGradientPaletteCount;
}
//TODO transitions //TODO transitions
void WS2812FX::setSpeed(uint8_t s) { void WS2812FX::setSpeed(uint8_t s) {

Wyświetl plik

@ -87,7 +87,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1902211 #define VERSION 1902222
char versionString[] = "0.8.4-dev"; char versionString[] = "0.8.4-dev";

Wyświetl plik

@ -256,7 +256,7 @@ void saveSettingsToEEPROM()
writeStringToEEPROM(2333, mqttDeviceTopic, 32); writeStringToEEPROM(2333, mqttDeviceTopic, 32);
writeStringToEEPROM(2366, mqttGroupTopic, 32); writeStringToEEPROM(2366, mqttGroupTopic, 32);
commit(); EEPROM.commit();
} }
@ -570,7 +570,7 @@ void savePreset(byte index)
EEPROM.write(i+16, effectIntensity); EEPROM.write(i+16, effectIntensity);
EEPROM.write(i+17, effectPalette); EEPROM.write(i+17, effectPalette);
commit(); EEPROM.commit();
} }
@ -616,23 +616,5 @@ void saveMacro(byte index, String mc, bool sing=true) //only commit on single sa
{ {
EEPROM.write(i, mc.charAt(i-s)); EEPROM.write(i, mc.charAt(i-s));
} }
if (sing) commit(); if (sing) EEPROM.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);
#endif*/
EEPROM.commit();
/*#ifdef ARDUINO_ARCH_ESP32
portEXIT_CRITICAL(&mMux);
#endif*/
DEBUG_PRINT(".");
} }

Wyświetl plik

@ -307,10 +307,41 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
} }
//helper to get int value at a position in string //helper to get int value at a position in string
int getNumVal(String* req, uint16_t pos) int getNumVal(String* req, uint16_t pos)
{ {
return req->substring(pos + 3).toInt(); return req->substring(pos+3).toInt();
}
//helper to get int value at a position in string
bool updateVal(String* req, const char* key, byte* val, byte minv=0, byte maxv=255)
{
int pos = req->indexOf(key);
if (pos < 1) return false;
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;
} }
@ -341,11 +372,18 @@ bool handleSet(AsyncWebServerRequest *request, String req)
//if you save a macro in one request, other commands in that request are ignored due to unwanted behavior otherwise //if you save a macro in one request, other commands in that request are ignored due to unwanted behavior otherwise
} }
//set brigthness //set brightness
pos = req.indexOf("&A="); updateVal(&req, "&A=", &bri);
if (pos > 0) {
bri = getNumVal(&req, pos); //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]);
//set hue //set hue
pos = req.indexOf("HU="); pos = req.indexOf("HU=");
@ -359,48 +397,6 @@ bool handleSet(AsyncWebServerRequest *request, String req)
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col); colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
} }
//set red value
pos = req.indexOf("&R=");
if (pos > 0) {
col[0] = getNumVal(&req, pos);
}
//set green value
pos = req.indexOf("&G=");
if (pos > 0) {
col[1] = getNumVal(&req, pos);
}
//set blue value
pos = req.indexOf("&B=");
if (pos > 0) {
col[2] = getNumVal(&req, pos);
}
//set white value
pos = req.indexOf("&W=");
if (pos > 0) {
col[3] = getNumVal(&req, pos);
}
//set 2nd red value
pos = req.indexOf("R2=");
if (pos > 0) {
colSec[0] = getNumVal(&req, pos);
}
//set 2nd green value
pos = req.indexOf("G2=");
if (pos > 0) {
colSec[1] = getNumVal(&req, pos);
}
//set 2nd blue value
pos = req.indexOf("B2=");
if (pos > 0) {
colSec[2] = getNumVal(&req, pos);
}
//set 2nd white value
pos = req.indexOf("W2=");
if (pos > 0) {
colSec[3] = getNumVal(&req, pos);
}
//set color from HEX or 32bit DEC //set color from HEX or 32bit DEC
pos = req.indexOf("CL="); pos = req.indexOf("CL=");
if (pos > 0) { if (pos > 0) {
@ -440,6 +436,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
if (pos > 0) { if (pos > 0) {
_setRandomColor(getNumVal(&req, pos)); _setRandomColor(getNumVal(&req, pos));
} }
//set 2nd to 1st //set 2nd to 1st
pos = req.indexOf("SP"); pos = req.indexOf("SP");
if (pos > 0) { if (pos > 0) {
@ -448,6 +445,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
colSec[2] = col[2]; colSec[2] = col[2];
colSec[3] = col[3]; colSec[3] = col[3];
} }
//swap 2nd & 1st //swap 2nd & 1st
pos = req.indexOf("SC"); pos = req.indexOf("SC");
if (pos > 0) { if (pos > 0) {
@ -460,27 +458,11 @@ bool handleSet(AsyncWebServerRequest *request, String req)
} }
} }
//set current effect index //set effect parameters
pos = req.indexOf("FX="); if (updateVal(&req, "FX=", &effectCurrent, 0, strip.getModeCount()-1)) presetCyclingEnabled = false;
if (pos > 0) { updateVal(&req, "SX=", &effectSpeed);
effectCurrent = getNumVal(&req, pos); updateVal(&req, "IX=", &effectIntensity);
presetCyclingEnabled = false; updateVal(&req, "FP=", &effectPalette, 0, strip.getPaletteCount()-1);
}
//set effect speed
pos = req.indexOf("SX=");
if (pos > 0) {
effectSpeed = getNumVal(&req, pos);
}
//set effect intensity
pos = req.indexOf("IX=");
if (pos > 0) {
effectIntensity = req.substring(pos + 3).toInt();
}
//set effect palette (only for FastLED effects)
pos = req.indexOf("FP=");
if (pos > 0) {
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=");
@ -500,33 +482,31 @@ bool handleSet(AsyncWebServerRequest *request, String req)
if (pos > 0) { if (pos > 0) {
useHSB = getNumVal(&req, pos); 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 = getNumVal(&req, pos); 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 = getNumVal(&req, pos); uint16_t index = getNumVal(&req, pos);
pos = req.indexOf("L2="); pos = req.indexOf("L2=");
bool unlock = req.indexOf("UL") > 0;
if (pos > 0){ if (pos > 0){
int index2 = getNumVal(&req, pos); uint16_t index2 = getNumVal(&req, pos);
if (req.indexOf("UL") > 0) if (unlock) {
{
strip.unlockRange(index, index2); strip.unlockRange(index, index2);
} else } else {
{
strip.lockRange(index, index2); strip.lockRange(index, index2);
} }
} else } else {
{ if (unlock) {
if (req.indexOf("UL") > 0)
{
strip.unlock(index); strip.unlock(index);
} else } else {
{
strip.lock(index); strip.lock(index);
} }
} }
@ -537,25 +517,14 @@ bool handleSet(AsyncWebServerRequest *request, String req)
if (pos > 0) { if (pos > 0) {
applyMacro(getNumVal(&req, pos)); applyMacro(getNumVal(&req, pos));
} }
//toggle send UDP direct notifications //toggle send UDP direct notifications
if (req.indexOf("SN=") > 0) pos = req.indexOf("SN=");
{ if (pos > 0) notifyDirect = (req.charAt(pos+3) != '0');
notifyDirect = true;
if (req.indexOf("SN=0") > 0)
{
notifyDirect = false;
}
}
//toggle receive UDP direct notifications //toggle receive UDP direct notifications
if (req.indexOf("RN=") > 0) pos = req.indexOf("RN=");
{ if (pos > 0) receiveNotifications = (req.charAt(pos+3) != '0');
receiveNotifications = true;
if (req.indexOf("RN=0") > 0)
{
receiveNotifications = false;
}
}
//toggle nightlight mode //toggle nightlight mode
bool aNlDef = false; bool aNlDef = false;
@ -563,7 +532,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
pos = req.indexOf("NL="); pos = req.indexOf("NL=");
if (pos > 0) if (pos > 0)
{ {
if (req.indexOf("NL=0") > 0) if (req.charAt(pos+3) == '0')
{ {
nightlightActive = false; nightlightActive = false;
bri = briT; bri = briT;
@ -586,14 +555,10 @@ bool handleSet(AsyncWebServerRequest *request, String req)
} }
//toggle nightlight fade //toggle nightlight fade
if (req.indexOf("NF=") > 0) pos = req.indexOf("NF=");
if (pos > 0)
{ {
if (req.indexOf("NF=0") > 0) nightlightFade = (req.charAt(pos+3) != '0');
{
nightlightFade = false;
} else {
nightlightFade = true;
}
nightlightActiveOld = false; //re-init nightlightActiveOld = false; //re-init
} }
@ -604,11 +569,10 @@ bool handleSet(AsyncWebServerRequest *request, String req)
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 = getNumVal(&req, pos);
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) {
@ -642,43 +606,35 @@ bool handleSet(AsyncWebServerRequest *request, String req)
pos = req.indexOf("P2="); //sets last preset for cycle pos = req.indexOf("P2="); //sets last preset for cycle
if (pos > 0) presetCycleMax = getNumVal(&req, pos); if (pos > 0) presetCycleMax = getNumVal(&req, pos);
if (req.indexOf("CY=") > 0) //preset cycle //preset cycle
pos = req.indexOf("CY=");
if (pos > 0)
{ {
presetCyclingEnabled = true; presetCyclingEnabled = req.charAt(pos+3 != '0');
if (req.indexOf("CY=0") > 0)
{
presetCyclingEnabled = false;
}
presetCycCurr = presetCycleMin; presetCycCurr = presetCycleMin;
} }
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 = getNumVal(&req, pos); int v = getNumVal(&req, pos);
if (v > 49) presetCycleTime = v; if (v > 49) presetCycleTime = v;
} }
if (req.indexOf("PA=") > 0) //apply brightness from preset
{ pos = req.indexOf("PA="); //apply brightness from preset
presetApplyBri = true; if (pos > 0) presetApplyBri = req.charAt(pos+3 != '0');
if (req.indexOf("PA=0") > 0) presetApplyBri = false;
} pos = req.indexOf("PC="); //apply color from preset
if (req.indexOf("PC=") > 0) //apply color from preset if (pos > 0) presetApplyCol = req.charAt(pos+3 != '0');
{
presetApplyCol = true; pos = req.indexOf("PX="); //apply effects from preset
if (req.indexOf("PC=0") > 0) presetApplyCol = false; if (pos > 0) presetApplyFx = req.charAt(pos+3 != '0');
}
if (req.indexOf("PX=") > 0) //apply effects from preset
{
presetApplyFx = true;
if (req.indexOf("PX=0") > 0) presetApplyFx = false;
}
pos = req.indexOf("PS="); //saves current in preset pos = req.indexOf("PS="); //saves current in preset
if (pos > 0) { if (pos > 0) savePreset(getNumVal(&req, pos));
savePreset(getNumVal(&req, pos));
} //apply preset
pos = req.indexOf("PL="); //applies entire preset if (updateVal(&req, "PL=", &presetCycCurr, presetCycleMin, presetCycleMax)) {
if (pos > 0) {
applyPreset(getNumVal(&req, pos), presetApplyBri, presetApplyCol, presetApplyFx); applyPreset(getNumVal(&req, pos), presetApplyBri, presetApplyCol, presetApplyFx);
} }
@ -688,6 +644,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str()); strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str());
setCronixie(); setCronixie();
} }
pos = req.indexOf("NM="); //mode, 1 countdown pos = req.indexOf("NM="); //mode, 1 countdown
if (pos > 0) { if (pos > 0) {
countdownMode = true; countdownMode = true;
@ -696,6 +653,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
countdownMode = false; countdownMode = false;
} }
} }
if (req.indexOf("NB=") > 0) //sets backlight if (req.indexOf("NB=") > 0) //sets backlight
{ {
cronixieBacklight = true; cronixieBacklight = true;
@ -711,6 +669,7 @@ bool handleSet(AsyncWebServerRequest *request, String req)
if (pos > 0) { if (pos > 0) {
userVar0 = getNumVal(&req, pos); 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 = getNumVal(&req, pos); userVar1 = getNumVal(&req, pos);
@ -719,9 +678,9 @@ bool handleSet(AsyncWebServerRequest *request, 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(request, (req.indexOf("IT") > 0)); //include theme if firstload if (pos < 1) XML_response(request, (req.indexOf("&IT") > 0)); //include theme if firstload
pos = req.indexOf("NN"); //do not send UDP notifications this time pos = req.indexOf("&NN"); //do not send UDP notifications this time
colorUpdated((pos > 0) ? 5:1); colorUpdated((pos > 0) ? 5:1);
return true; return true;

Wyświetl plik

@ -238,6 +238,10 @@ void getJsonInfo()
oappend(serverDescription); oappend(serverDescription);
oappend("\",\r\n\"udpport\":"); oappend("\",\r\n\"udpport\":");
oappendi(udpPort); oappendi(udpPort);
oappend(",\r\n\"modecount\":");
oappendi(strip.getModeCount());
oappend(",\r\n\"palettecount\":");
oappendi(strip.getPaletteCount());
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\""); oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\"");
oappend((char*)ESP.getSdkVersion()); oappend((char*)ESP.getSdkVersion());