Replace sappend and sappends

Use named functions to describe what's being printed.
This commit is contained in:
Will Miles 2024-09-09 20:00:23 -04:00
parent 4ef583c844
commit 71148740d4
3 changed files with 235 additions and 247 deletions

View File

@ -372,8 +372,11 @@ void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
bool getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
bool getBoolVal(JsonVariant elem, bool dflt);
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255);
void sappend(Print& dest, char stype, const char* key, int val);
void sappends(Print& dest, char stype, const char* key, char* val);
size_t printSetCheckbox(Print& dest, const char* key, int val);
size_t printSetValue(Print& dest, const char* key, int val);
size_t printSetValue(Print& dest, const char* key, const char* val);
size_t printSetIndex(Print& dest, const char* key, int index);
size_t printSetMessage(Print& dest, const char* key, const char* val);
void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255);

View File

@ -87,43 +87,28 @@ bool updateVal(const char* req, const char* key, byte* val, byte minv, byte maxv
return true;
}
//append a numeric setting to string buffer
void sappend(Print& dest, char stype, const char* key, int val)
{
const __FlashStringHelper* type_str;
switch(stype)
{
case 'c': //checkbox
type_str = F(".checked=");
break;
case 'v': //numeric
type_str = F(".value=");
break;
case 'i': //selectedIndex
type_str = F(".selectedIndex=");
break;
default:
return; //???
}
dest.printf_P(PSTR("d.Sf.%s%s%d;"), key, type_str, val);
static size_t printSetInt(Print& dest, const char* key, const char* selector, int value) {
return dest.printf_P(PSTR("d.Sf.%s.%s=%d;"), key, selector, value);
}
//append a string setting to buffer
void sappends(Print& dest, char stype, const char* key, char* val)
{
switch(stype)
{
case 's': {//string (we can interpret val as char*)
dest.printf_P(PSTR("d.Sf.%s.value=\"%s\";"),key,val);
break;}
case 'm': //message
dest.printf_P(PSTR("d.getElementsByClassName%s.innerHTML=\"%s\";"), key, val);
break;
}
size_t printSetCheckbox(Print& dest, const char* key, int val) {
return printSetInt(dest, key, PSTR("checked"), val);
}
size_t printSetValue(Print& dest, const char* key, int val) {
return printSetInt(dest, key, PSTR("value"), val);
}
size_t printSetIndex(Print& dest, const char* key, int index) {
return printSetInt(dest, key, PSTR("selectedIndex"), index);
}
size_t printSetValue(Print& dest, const char* key, const char* val) {
return dest.printf_P(PSTR("d.Sf.%s.value=\"%s\";"),key,val);
}
size_t printSetMessage(Print& dest, const char* key, const char* val) {
return dest.printf_P(PSTR("d.getElementsByClassName%s.innerHTML=\"%s\";"), key, val);
}
void prepareHostname(char* hostname)

View File

@ -180,41 +180,41 @@ void getSettingsJS(byte subPage, Print& dest)
(uint32_t) multiWiFi[n].staticSN);
}
sappend(dest,'v',SET_F("D0"),dnsAddress[0]);
sappend(dest,'v',SET_F("D1"),dnsAddress[1]);
sappend(dest,'v',SET_F("D2"),dnsAddress[2]);
sappend(dest,'v',SET_F("D3"),dnsAddress[3]);
printSetValue(dest,PSTR("D0"),dnsAddress[0]);
printSetValue(dest,PSTR("D1"),dnsAddress[1]);
printSetValue(dest,PSTR("D2"),dnsAddress[2]);
printSetValue(dest,PSTR("D3"),dnsAddress[3]);
sappends(dest,'s',SET_F("CM"),cmDNS);
sappend(dest,'i',SET_F("AB"),apBehavior);
sappends(dest,'s',SET_F("AS"),apSSID);
sappend(dest,'c',SET_F("AH"),apHide);
printSetValue(dest,PSTR("CM"),cmDNS);
printSetIndex(dest,PSTR("AB"),apBehavior);
printSetValue(dest,PSTR("AS"),apSSID);
printSetCheckbox(dest,PSTR("AH"),apHide);
l = strlen(apPass);
char fapass[l+1]; //fill password field with ***
fapass[l] = 0;
memset(fapass,'*',l);
sappends(dest,'s',SET_F("AP"),fapass);
printSetValue(dest,PSTR("AP"),fapass);
sappend(dest,'v',SET_F("AC"),apChannel);
printSetValue(dest,PSTR("AC"),apChannel);
#ifdef ARDUINO_ARCH_ESP32
sappend(dest,'v',SET_F("TX"),txPower);
printSetValue(dest,PSTR("TX"),txPower);
#else
dest.print(F("gId('tx').style.display='none';"));
#endif
sappend(dest,'c',SET_F("FG"),force802_3g);
sappend(dest,'c',SET_F("WS"),noWifiSleep);
printSetCheckbox(dest,PSTR("FG"),force802_3g);
printSetCheckbox(dest,PSTR("WS"),noWifiSleep);
#ifndef WLED_DISABLE_ESPNOW
sappend(dest,'c',SET_F("RE"),enableESPNow);
sappends(dest,'s',SET_F("RMAC"),linked_remote);
printSetCheckbox(dest,PSTR("RE"),enableESPNow);
printSetValue(dest,PSTR("RMAC"),linked_remote);
#else
//hide remote settings if not compiled
dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#endif
#ifdef WLED_USE_ETHERNET
sappend(dest,'v',SET_F("ETH"),ethernetType);
printSetValue(dest,PSTR("ETH"),ethernetType);
#else
//hide ethernet setting if not compiled in
dest.print(F("gId('ethd').style.display='none';"));
@ -229,10 +229,10 @@ void getSettingsJS(byte subPage, Print& dest)
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
if (Network.isEthernet()) strcat_P(s ,SET_F(" (Ethernet)"));
#endif
sappends(dest,'m',SET_F("(\"sip\")[0]"),s);
printSetMessage(dest,PSTR("(\"sip\")[0]"),s);
} else
{
sappends(dest,'m',SET_F("(\"sip\")[0]"),(char*)F("Not connected"));
printSetMessage(dest,PSTR("(\"sip\")[0]"),(char*)F("Not connected"));
}
if (WiFi.softAPIP()[0] != 0) //is active
@ -240,19 +240,19 @@ void getSettingsJS(byte subPage, Print& dest)
char s[16];
IPAddress apIP = WiFi.softAPIP();
sprintf(s, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]);
sappends(dest,'m',SET_F("(\"sip\")[1]"),s);
printSetMessage(dest,PSTR("(\"sip\")[1]"),s);
} else
{
sappends(dest,'m',SET_F("(\"sip\")[1]"),(char*)F("Not active"));
printSetMessage(dest,PSTR("(\"sip\")[1]"),(char*)F("Not active"));
}
#ifndef WLED_DISABLE_ESPNOW
if (strlen(last_signal_src) > 0) { //Have seen an ESP-NOW Remote
sappends(dest,'m',SET_F("(\"rlid\")[0]"),last_signal_src);
printSetMessage(dest,PSTR("(\"rlid\")[0]"),last_signal_src);
} else if (!enableESPNow) {
sappends(dest,'m',SET_F("(\"rlid\")[0]"),(char*)F("(Enable ESP-NOW to listen)"));
printSetMessage(dest,PSTR("(\"rlid\")[0]"),(char*)F("(Enable ESP-NOW to listen)"));
} else {
sappends(dest,'m',SET_F("(\"rlid\")[0]"),(char*)F("None"));
printSetMessage(dest,PSTR("(\"rlid\")[0]"),(char*)F("None"));
}
#endif
}
@ -277,14 +277,14 @@ void getSettingsJS(byte subPage, Print& dest)
WLED_MAX_ANALOG_CHANNELS
);
sappend(dest,'c',SET_F("MS"),strip.autoSegments);
sappend(dest,'c',SET_F("CCT"),strip.correctWB);
sappend(dest,'c',SET_F("IC"),cctICused);
sappend(dest,'c',SET_F("CR"),strip.cctFromRgb);
sappend(dest,'v',SET_F("CB"),strip.cctBlending);
sappend(dest,'v',SET_F("FR"),strip.getTargetFps());
sappend(dest,'v',SET_F("AW"),Bus::getGlobalAWMode());
sappend(dest,'c',SET_F("LD"),useGlobalLedBuffer);
printSetCheckbox(dest,PSTR("MS"),strip.autoSegments);
printSetCheckbox(dest,PSTR("CCT"),strip.correctWB);
printSetCheckbox(dest,PSTR("IC"),cctICused);
printSetCheckbox(dest,PSTR("CR"),strip.cctFromRgb);
printSetValue(dest,PSTR("CB"),strip.cctBlending);
printSetValue(dest,PSTR("FR"),strip.getTargetFps());
printSetValue(dest,PSTR("AW"),Bus::getGlobalAWMode());
printSetCheckbox(dest,PSTR("LD"),useGlobalLedBuffer);
unsigned sumMa = 0;
for (int s = 0; s < BusManager::getNumBusses(); s++) {
@ -309,17 +309,17 @@ void getSettingsJS(byte subPage, Print& dest)
int nPins = bus->getPins(pins);
for (int i = 0; i < nPins; i++) {
lp[1] = offset+i;
if (pinManager.isPinOk(pins[i]) || bus->isVirtual()) sappend(dest,'v',lp,pins[i]);
if (pinManager.isPinOk(pins[i]) || bus->isVirtual()) printSetValue(dest,lp,pins[i]);
}
sappend(dest,'v',lc,bus->getLength());
sappend(dest,'v',lt,bus->getType());
sappend(dest,'v',co,bus->getColorOrder() & 0x0F);
sappend(dest,'v',ls,bus->getStart());
sappend(dest,'c',cv,bus->isReversed());
sappend(dest,'v',sl,bus->skippedLeds());
sappend(dest,'c',rf,bus->isOffRefreshRequired());
sappend(dest,'v',aw,bus->getAutoWhiteMode());
sappend(dest,'v',wo,bus->getColorOrder() >> 4);
printSetValue(dest,lc,bus->getLength());
printSetValue(dest,lt,bus->getType());
printSetValue(dest,co,bus->getColorOrder() & 0x0F);
printSetValue(dest,ls,bus->getStart());
printSetCheckbox(dest,cv,bus->isReversed());
printSetValue(dest,sl,bus->skippedLeds());
printSetCheckbox(dest,rf,bus->isOffRefreshRequired());
printSetValue(dest,aw,bus->getAutoWhiteMode());
printSetValue(dest,wo,bus->getColorOrder() >> 4);
unsigned speed = bus->getFrequency();
if (bus->isPWM()) {
switch (speed) {
@ -340,14 +340,14 @@ void getSettingsJS(byte subPage, Print& dest)
case 20000 : speed = 4; break;
}
}
sappend(dest,'v',sp,speed);
sappend(dest,'v',la,bus->getLEDCurrent());
sappend(dest,'v',ma,bus->getMaxCurrent());
printSetValue(dest,sp,speed);
printSetValue(dest,la,bus->getLEDCurrent());
printSetValue(dest,ma,bus->getMaxCurrent());
sumMa += bus->getMaxCurrent();
}
sappend(dest,'v',SET_F("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);
sappend(dest,'c',SET_F("ABL"),BusManager::ablMilliampsMax() || sumMa > 0);
sappend(dest,'c',SET_F("PPL"),!BusManager::ablMilliampsMax() && sumMa > 0);
printSetValue(dest,PSTR("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);
printSetCheckbox(dest,PSTR("ABL"),BusManager::ablMilliampsMax() || sumMa > 0);
printSetCheckbox(dest,PSTR("PPL"),!BusManager::ablMilliampsMax() && sumMa > 0);
dest.printf_P(PSTR("resetCOM(%d);"), WLED_MAX_COLOR_ORDER_MAPPINGS);
const ColorOrderMap& com = BusManager::getColorOrderMap();
@ -357,114 +357,114 @@ void getSettingsJS(byte subPage, Print& dest)
dest.printf_P(PSTR("addCOM(%d,%d,%d);"), entry->start, entry->len, entry->colorOrder);
}
sappend(dest,'v',SET_F("CA"),briS);
printSetValue(dest,PSTR("CA"),briS);
sappend(dest,'c',SET_F("BO"),turnOnAtBoot);
sappend(dest,'v',SET_F("BP"),bootPreset);
printSetCheckbox(dest,PSTR("BO"),turnOnAtBoot);
printSetValue(dest,PSTR("BP"),bootPreset);
sappend(dest,'c',SET_F("GB"),gammaCorrectBri);
sappend(dest,'c',SET_F("GC"),gammaCorrectCol);
dtostrf(gammaCorrectVal,3,1,nS); sappends(dest,'s',SET_F("GV"),nS);
sappend(dest,'c',SET_F("TF"),fadeTransition);
sappend(dest,'c',SET_F("EB"),modeBlending);
sappend(dest,'v',SET_F("TD"),transitionDelayDefault);
sappend(dest,'c',SET_F("PF"),strip.paletteFade);
sappend(dest,'v',SET_F("TP"),randomPaletteChangeTime);
sappend(dest,'c',SET_F("TH"),useHarmonicRandomPalette);
sappend(dest,'v',SET_F("BF"),briMultiplier);
sappend(dest,'v',SET_F("TB"),nightlightTargetBri);
sappend(dest,'v',SET_F("TL"),nightlightDelayMinsDefault);
sappend(dest,'v',SET_F("TW"),nightlightMode);
sappend(dest,'i',SET_F("PB"),strip.paletteBlend);
sappend(dest,'v',SET_F("RL"),rlyPin);
sappend(dest,'c',SET_F("RM"),rlyMde);
sappend(dest,'c',SET_F("RO"),rlyOpenDrain);
printSetCheckbox(dest,PSTR("GB"),gammaCorrectBri);
printSetCheckbox(dest,PSTR("GC"),gammaCorrectCol);
dtostrf(gammaCorrectVal,3,1,nS); printSetValue(dest,PSTR("GV"),nS);
printSetCheckbox(dest,PSTR("TF"),fadeTransition);
printSetCheckbox(dest,PSTR("EB"),modeBlending);
printSetValue(dest,PSTR("TD"),transitionDelayDefault);
printSetCheckbox(dest,PSTR("PF"),strip.paletteFade);
printSetValue(dest,PSTR("TP"),randomPaletteChangeTime);
printSetCheckbox(dest,PSTR("TH"),useHarmonicRandomPalette);
printSetValue(dest,PSTR("BF"),briMultiplier);
printSetValue(dest,PSTR("TB"),nightlightTargetBri);
printSetValue(dest,PSTR("TL"),nightlightDelayMinsDefault);
printSetValue(dest,PSTR("TW"),nightlightMode);
printSetIndex(dest,PSTR("PB"),strip.paletteBlend);
printSetValue(dest,PSTR("RL"),rlyPin);
printSetCheckbox(dest,PSTR("RM"),rlyMde);
printSetCheckbox(dest,PSTR("RO"),rlyOpenDrain);
for (int i = 0; i < WLED_MAX_BUTTONS; i++) {
dest.printf_P(PSTR("addBtn(%d,%d,%d);"), i, btnPin[i], buttonType[i]);
}
sappend(dest,'c',SET_F("IP"),disablePullUp);
sappend(dest,'v',SET_F("TT"),touchThreshold);
printSetCheckbox(dest,PSTR("IP"),disablePullUp);
printSetValue(dest,PSTR("TT"),touchThreshold);
#ifndef WLED_DISABLE_INFRARED
sappend(dest,'v',SET_F("IR"),irPin);
sappend(dest,'v',SET_F("IT"),irEnabled);
printSetValue(dest,PSTR("IR"),irPin);
printSetValue(dest,PSTR("IT"),irEnabled);
#endif
sappend(dest,'c',SET_F("MSO"),!irApplyToAllSelected);
printSetCheckbox(dest,PSTR("MSO"),!irApplyToAllSelected);
}
if (subPage == SUBPAGE_UI)
{
sappends(dest,'s',SET_F("DS"),serverDescription);
sappend(dest,'c',SET_F("SU"),simplifiedUI);
printSetValue(dest,PSTR("DS"),serverDescription);
printSetCheckbox(dest,PSTR("SU"),simplifiedUI);
}
if (subPage == SUBPAGE_SYNC)
{
[[maybe_unused]] char nS[32];
sappend(dest,'v',SET_F("UP"),udpPort);
sappend(dest,'v',SET_F("U2"),udpPort2);
printSetValue(dest,PSTR("UP"),udpPort);
printSetValue(dest,PSTR("U2"),udpPort2);
#ifndef WLED_DISABLE_ESPNOW
if (enableESPNow) sappend(dest,'c',SET_F("EN"),useESPNowSync);
if (enableESPNow) printSetCheckbox(dest,PSTR("EN"),useESPNowSync);
else dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#else
dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#endif
sappend(dest,'v',SET_F("GS"),syncGroups);
sappend(dest,'v',SET_F("GR"),receiveGroups);
printSetValue(dest,PSTR("GS"),syncGroups);
printSetValue(dest,PSTR("GR"),receiveGroups);
sappend(dest,'c',SET_F("RB"),receiveNotificationBrightness);
sappend(dest,'c',SET_F("RC"),receiveNotificationColor);
sappend(dest,'c',SET_F("RX"),receiveNotificationEffects);
sappend(dest,'c',SET_F("RP"),receiveNotificationPalette);
sappend(dest,'c',SET_F("SO"),receiveSegmentOptions);
sappend(dest,'c',SET_F("SG"),receiveSegmentBounds);
sappend(dest,'c',SET_F("SS"),sendNotifications);
sappend(dest,'c',SET_F("SD"),notifyDirect);
sappend(dest,'c',SET_F("SB"),notifyButton);
sappend(dest,'c',SET_F("SH"),notifyHue);
sappend(dest,'v',SET_F("UR"),udpNumRetries);
printSetCheckbox(dest,PSTR("RB"),receiveNotificationBrightness);
printSetCheckbox(dest,PSTR("RC"),receiveNotificationColor);
printSetCheckbox(dest,PSTR("RX"),receiveNotificationEffects);
printSetCheckbox(dest,PSTR("RP"),receiveNotificationPalette);
printSetCheckbox(dest,PSTR("SO"),receiveSegmentOptions);
printSetCheckbox(dest,PSTR("SG"),receiveSegmentBounds);
printSetCheckbox(dest,PSTR("SS"),sendNotifications);
printSetCheckbox(dest,PSTR("SD"),notifyDirect);
printSetCheckbox(dest,PSTR("SB"),notifyButton);
printSetCheckbox(dest,PSTR("SH"),notifyHue);
printSetValue(dest,PSTR("UR"),udpNumRetries);
sappend(dest,'c',SET_F("NL"),nodeListEnabled);
sappend(dest,'c',SET_F("NB"),nodeBroadcastEnabled);
printSetCheckbox(dest,PSTR("NL"),nodeListEnabled);
printSetCheckbox(dest,PSTR("NB"),nodeBroadcastEnabled);
sappend(dest,'c',SET_F("RD"),receiveDirect);
sappend(dest,'c',SET_F("MO"),useMainSegmentOnly);
sappend(dest,'c',SET_F("RLM"),realtimeRespectLedMaps);
sappend(dest,'v',SET_F("EP"),e131Port);
sappend(dest,'c',SET_F("ES"),e131SkipOutOfSequence);
sappend(dest,'c',SET_F("EM"),e131Multicast);
sappend(dest,'v',SET_F("EU"),e131Universe);
sappend(dest,'v',SET_F("DA"),DMXAddress);
sappend(dest,'v',SET_F("XX"),DMXSegmentSpacing);
sappend(dest,'v',SET_F("PY"),e131Priority);
sappend(dest,'v',SET_F("DM"),DMXMode);
sappend(dest,'v',SET_F("ET"),realtimeTimeoutMs);
sappend(dest,'c',SET_F("FB"),arlsForceMaxBri);
sappend(dest,'c',SET_F("RG"),arlsDisableGammaCorrection);
sappend(dest,'v',SET_F("WO"),arlsOffset);
printSetCheckbox(dest,PSTR("RD"),receiveDirect);
printSetCheckbox(dest,PSTR("MO"),useMainSegmentOnly);
printSetCheckbox(dest,PSTR("RLM"),realtimeRespectLedMaps);
printSetValue(dest,PSTR("EP"),e131Port);
printSetCheckbox(dest,PSTR("ES"),e131SkipOutOfSequence);
printSetCheckbox(dest,PSTR("EM"),e131Multicast);
printSetValue(dest,PSTR("EU"),e131Universe);
printSetValue(dest,PSTR("DA"),DMXAddress);
printSetValue(dest,PSTR("XX"),DMXSegmentSpacing);
printSetValue(dest,PSTR("PY"),e131Priority);
printSetValue(dest,PSTR("DM"),DMXMode);
printSetValue(dest,PSTR("ET"),realtimeTimeoutMs);
printSetCheckbox(dest,PSTR("FB"),arlsForceMaxBri);
printSetCheckbox(dest,PSTR("RG"),arlsDisableGammaCorrection);
printSetValue(dest,PSTR("WO"),arlsOffset);
#ifndef WLED_DISABLE_ALEXA
sappend(dest,'c',SET_F("AL"),alexaEnabled);
sappends(dest,'s',SET_F("AI"),alexaInvocationName);
sappend(dest,'c',SET_F("SA"),notifyAlexa);
sappend(dest,'v',SET_F("AP"),alexaNumPresets);
printSetCheckbox(dest,PSTR("AL"),alexaEnabled);
printSetValue(dest,PSTR("AI"),alexaInvocationName);
printSetCheckbox(dest,PSTR("SA"),notifyAlexa);
printSetValue(dest,PSTR("AP"),alexaNumPresets);
#else
dest.print(F("toggle('Alexa');")); // hide Alexa settings
#endif
#ifndef WLED_DISABLE_MQTT
sappend(dest,'c',SET_F("MQ"),mqttEnabled);
sappends(dest,'s',SET_F("MS"),mqttServer);
sappend(dest,'v',SET_F("MQPORT"),mqttPort);
sappends(dest,'s',SET_F("MQUSER"),mqttUser);
printSetCheckbox(dest,PSTR("MQ"),mqttEnabled);
printSetValue(dest,PSTR("MS"),mqttServer);
printSetValue(dest,PSTR("MQPORT"),mqttPort);
printSetValue(dest,PSTR("MQUSER"),mqttUser);
byte l = strlen(mqttPass);
char fpass[l+1]; //fill password field with ***
fpass[l] = 0;
memset(fpass,'*',l);
sappends(dest,'s',SET_F("MQPASS"),fpass);
sappends(dest,'s',SET_F("MQCID"),mqttClientID);
sappends(dest,'s',"MD",mqttDeviceTopic);
sappends(dest,'s',SET_F("MG"),mqttGroupTopic);
sappend(dest,'c',SET_F("BM"),buttonPublishMqtt);
sappend(dest,'c',SET_F("RT"),retainMqttMsg);
printSetValue(dest,PSTR("MQPASS"),fpass);
printSetValue(dest,PSTR("MQCID"),mqttClientID);
printSetValue(dest,PSTR("MD"),mqttDeviceTopic);
printSetValue(dest,PSTR("MG"),mqttGroupTopic);
printSetCheckbox(dest,PSTR("BM"),buttonPublishMqtt);
printSetCheckbox(dest,PSTR("RT"),retainMqttMsg);
dest.printf_P(PSTR("d.Sf.MD.maxlength=%d;d.Sf.MG.maxlength=%d;d.Sf.MS.maxlength=%d;"),
MQTT_MAX_TOPIC_LEN, MQTT_MAX_TOPIC_LEN, MQTT_MAX_SERVER_LEN);
#else
@ -472,16 +472,16 @@ void getSettingsJS(byte subPage, Print& dest)
#endif
#ifndef WLED_DISABLE_HUESYNC
sappend(dest,'v',SET_F("H0"),hueIP[0]);
sappend(dest,'v',SET_F("H1"),hueIP[1]);
sappend(dest,'v',SET_F("H2"),hueIP[2]);
sappend(dest,'v',SET_F("H3"),hueIP[3]);
sappend(dest,'v',SET_F("HL"),huePollLightId);
sappend(dest,'v',SET_F("HI"),huePollIntervalMs);
sappend(dest,'c',SET_F("HP"),huePollingEnabled);
sappend(dest,'c',SET_F("HO"),hueApplyOnOff);
sappend(dest,'c',SET_F("HB"),hueApplyBri);
sappend(dest,'c',SET_F("HC"),hueApplyColor);
printSetValue(dest,PSTR("H0"),hueIP[0]);
printSetValue(dest,PSTR("H1"),hueIP[1]);
printSetValue(dest,PSTR("H2"),hueIP[2]);
printSetValue(dest,PSTR("H3"),hueIP[3]);
printSetValue(dest,PSTR("HL"),huePollLightId);
printSetValue(dest,PSTR("HI"),huePollIntervalMs);
printSetCheckbox(dest,PSTR("HP"),huePollingEnabled);
printSetCheckbox(dest,PSTR("HO"),hueApplyOnOff);
printSetCheckbox(dest,PSTR("HB"),hueApplyBri);
printSetCheckbox(dest,PSTR("HC"),hueApplyColor);
char hueErrorString[25];
switch (hueError)
{
@ -495,11 +495,11 @@ void getSettingsJS(byte subPage, Print& dest)
default: sprintf_P(hueErrorString,PSTR("Bridge Error %i"),hueError);
}
sappends(dest,'m',SET_F("(\"sip\")[0]"),hueErrorString);
printSetMessage(dest,PSTR("(\"sip\")[0]"),hueErrorString);
#else
dest.print(F("toggle('Hue');")); // hide Hue Sync settings
#endif
sappend(dest,'v',SET_F("BD"),serialBaud);
printSetValue(dest,PSTR("BD"),serialBaud);
#ifndef WLED_ENABLE_ADALIGHT
dest.print(SET_F("toggle('Serial);"));
#endif
@ -507,42 +507,42 @@ void getSettingsJS(byte subPage, Print& dest)
if (subPage == SUBPAGE_TIME)
{
sappend(dest,'c',SET_F("NT"),ntpEnabled);
sappends(dest,'s',SET_F("NS"),ntpServerName);
sappend(dest,'c',SET_F("CF"),!useAMPM);
sappend(dest,'i',SET_F("TZ"),currentTimezone);
sappend(dest,'v',SET_F("UO"),utcOffsetSecs);
printSetCheckbox(dest,PSTR("NT"),ntpEnabled);
printSetValue(dest,PSTR("NS"),ntpServerName);
printSetCheckbox(dest,PSTR("CF"),!useAMPM);
printSetIndex(dest,PSTR("TZ"),currentTimezone);
printSetValue(dest,PSTR("UO"),utcOffsetSecs);
char tm[32];
dtostrf(longitude,4,2,tm);
sappends(dest,'s',SET_F("LN"),tm);
printSetValue(dest,PSTR("LN"),tm);
dtostrf(latitude,4,2,tm);
sappends(dest,'s',SET_F("LT"),tm);
printSetValue(dest,PSTR("LT"),tm);
getTimeString(tm);
sappends(dest,'m',SET_F("(\"times\")[0]"),tm);
printSetMessage(dest,PSTR("(\"times\")[0]"),tm);
if ((int)(longitude*10.0f) || (int)(latitude*10.0f)) {
sprintf_P(tm, PSTR("Sunrise: %02d:%02d Sunset: %02d:%02d"), hour(sunrise), minute(sunrise), hour(sunset), minute(sunset));
sappends(dest,'m',SET_F("(\"times\")[1]"),tm);
printSetMessage(dest,PSTR("(\"times\")[1]"),tm);
}
sappend(dest,'c',SET_F("OL"),overlayCurrent);
sappend(dest,'v',SET_F("O1"),overlayMin);
sappend(dest,'v',SET_F("O2"),overlayMax);
sappend(dest,'v',SET_F("OM"),analogClock12pixel);
sappend(dest,'c',SET_F("OS"),analogClockSecondsTrail);
sappend(dest,'c',SET_F("O5"),analogClock5MinuteMarks);
sappend(dest,'c',SET_F("OB"),analogClockSolidBlack);
printSetCheckbox(dest,PSTR("OL"),overlayCurrent);
printSetValue(dest,PSTR("O1"),overlayMin);
printSetValue(dest,PSTR("O2"),overlayMax);
printSetValue(dest,PSTR("OM"),analogClock12pixel);
printSetCheckbox(dest,PSTR("OS"),analogClockSecondsTrail);
printSetCheckbox(dest,PSTR("O5"),analogClock5MinuteMarks);
printSetCheckbox(dest,PSTR("OB"),analogClockSolidBlack);
sappend(dest,'c',SET_F("CE"),countdownMode);
sappend(dest,'v',SET_F("CY"),countdownYear);
sappend(dest,'v',SET_F("CI"),countdownMonth);
sappend(dest,'v',SET_F("CD"),countdownDay);
sappend(dest,'v',SET_F("CH"),countdownHour);
sappend(dest,'v',SET_F("CM"),countdownMin);
sappend(dest,'v',SET_F("CS"),countdownSec);
printSetCheckbox(dest,PSTR("CE"),countdownMode);
printSetValue(dest,PSTR("CY"),countdownYear);
printSetValue(dest,PSTR("CI"),countdownMonth);
printSetValue(dest,PSTR("CD"),countdownDay);
printSetValue(dest,PSTR("CH"),countdownHour);
printSetValue(dest,PSTR("CM"),countdownMin);
printSetValue(dest,PSTR("CS"),countdownSec);
sappend(dest,'v',SET_F("A0"),macroAlexaOn);
sappend(dest,'v',SET_F("A1"),macroAlexaOff);
sappend(dest,'v',SET_F("MC"),macroCountdown);
sappend(dest,'v',SET_F("MN"),macroNl);
printSetValue(dest,PSTR("A0"),macroAlexaOn);
printSetValue(dest,PSTR("A1"),macroAlexaOff);
printSetValue(dest,PSTR("MC"),macroCountdown);
printSetValue(dest,PSTR("MN"),macroNl);
for (unsigned i=0; i<WLED_MAX_BUTTONS; i++) {
dest.printf_P(PSTR("addRow(%d,%d,%d,%d);"), i, macroButton[i], macroLongPress[i], macroDoublePress[i]);
}
@ -552,15 +552,15 @@ void getSettingsJS(byte subPage, Print& dest)
for (int i = 0; i<10; i++)
{
k[1] = 48+i; //ascii 0,1,2,3
if (i<8) { k[0] = 'H'; sappend(dest,'v',k,timerHours[i]); }
k[0] = 'N'; sappend(dest,'v',k,timerMinutes[i]);
k[0] = 'T'; sappend(dest,'v',k,timerMacro[i]);
k[0] = 'W'; sappend(dest,'v',k,timerWeekday[i]);
if (i<8) { k[0] = 'H'; printSetValue(dest,k,timerHours[i]); }
k[0] = 'N'; printSetValue(dest,k,timerMinutes[i]);
k[0] = 'T'; printSetValue(dest,k,timerMacro[i]);
k[0] = 'W'; printSetValue(dest,k,timerWeekday[i]);
if (i<8) {
k[0] = 'M'; sappend(dest,'v',k,(timerMonth[i] >> 4) & 0x0F);
k[0] = 'P'; sappend(dest,'v',k,timerMonth[i] & 0x0F);
k[0] = 'D'; sappend(dest,'v',k,timerDay[i]);
k[0] = 'E'; sappend(dest,'v',k,timerDayEnd[i]);
k[0] = 'M'; printSetValue(dest,k,(timerMonth[i] >> 4) & 0x0F);
k[0] = 'P'; printSetValue(dest,k,timerMonth[i] & 0x0F);
k[0] = 'D'; printSetValue(dest,k,timerDay[i]);
k[0] = 'E'; printSetValue(dest,k,timerDayEnd[i]);
}
}
}
@ -571,41 +571,41 @@ void getSettingsJS(byte subPage, Print& dest)
char fpass[l+1]; //fill PIN field with 0000
fpass[l] = 0;
memset(fpass,'0',l);
sappends(dest,'s',SET_F("PIN"),fpass);
sappend(dest,'c',SET_F("NO"),otaLock);
sappend(dest,'c',SET_F("OW"),wifiLock);
sappend(dest,'c',SET_F("AO"),aOtaEnabled);
printSetValue(dest,PSTR("PIN"),fpass);
printSetCheckbox(dest,PSTR("NO"),otaLock);
printSetCheckbox(dest,PSTR("OW"),wifiLock);
printSetCheckbox(dest,PSTR("AO"),aOtaEnabled);
char tmp_buf[128];
snprintf_P(tmp_buf,sizeof(tmp_buf),PSTR("WLED %s (build %d)"),versionString,VERSION);
sappends(dest,'m',SET_F("(\"sip\")[0]"),tmp_buf);
printSetMessage(dest,PSTR("(\"sip\")[0]"),tmp_buf);
dest.printf_P(PSTR("sd=\"%s\";"), serverDescription);
}
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
if (subPage == SUBPAGE_DMX)
{
sappend(dest,'v',SET_F("PU"),e131ProxyUniverse);
printSetValue(dest,PSTR("PU"),e131ProxyUniverse);
sappend(dest,'v',SET_F("CN"),DMXChannels);
sappend(dest,'v',SET_F("CG"),DMXGap);
sappend(dest,'v',SET_F("CS"),DMXStart);
sappend(dest,'v',SET_F("SL"),DMXStartLED);
printSetValue(dest,PSTR("CN"),DMXChannels);
printSetValue(dest,PSTR("CG"),DMXGap);
printSetValue(dest,PSTR("CS"),DMXStart);
printSetValue(dest,PSTR("SL"),DMXStartLED);
sappend(dest,'i',SET_F("CH1"),DMXFixtureMap[0]);
sappend(dest,'i',SET_F("CH2"),DMXFixtureMap[1]);
sappend(dest,'i',SET_F("CH3"),DMXFixtureMap[2]);
sappend(dest,'i',SET_F("CH4"),DMXFixtureMap[3]);
sappend(dest,'i',SET_F("CH5"),DMXFixtureMap[4]);
sappend(dest,'i',SET_F("CH6"),DMXFixtureMap[5]);
sappend(dest,'i',SET_F("CH7"),DMXFixtureMap[6]);
sappend(dest,'i',SET_F("CH8"),DMXFixtureMap[7]);
sappend(dest,'i',SET_F("CH9"),DMXFixtureMap[8]);
sappend(dest,'i',SET_F("CH10"),DMXFixtureMap[9]);
sappend(dest,'i',SET_F("CH11"),DMXFixtureMap[10]);
sappend(dest,'i',SET_F("CH12"),DMXFixtureMap[11]);
sappend(dest,'i',SET_F("CH13"),DMXFixtureMap[12]);
sappend(dest,'i',SET_F("CH14"),DMXFixtureMap[13]);
sappend(dest,'i',SET_F("CH15"),DMXFixtureMap[14]);
printSetIndex(dest,PSTR("CH1"),DMXFixtureMap[0]);
printSetIndex(dest,PSTR("CH2"),DMXFixtureMap[1]);
printSetIndex(dest,PSTR("CH3"),DMXFixtureMap[2]);
printSetIndex(dest,PSTR("CH4"),DMXFixtureMap[3]);
printSetIndex(dest,PSTR("CH5"),DMXFixtureMap[4]);
printSetIndex(dest,PSTR("CH6"),DMXFixtureMap[5]);
printSetIndex(dest,PSTR("CH7"),DMXFixtureMap[6]);
printSetIndex(dest,PSTR("CH8"),DMXFixtureMap[7]);
printSetIndex(dest,PSTR("CH9"),DMXFixtureMap[8]);
printSetIndex(dest,PSTR("CH10"),DMXFixtureMap[9]);
printSetIndex(dest,PSTR("CH11"),DMXFixtureMap[10]);
printSetIndex(dest,PSTR("CH12"),DMXFixtureMap[11]);
printSetIndex(dest,PSTR("CH13"),DMXFixtureMap[12]);
printSetIndex(dest,PSTR("CH14"),DMXFixtureMap[13]);
printSetIndex(dest,PSTR("CH15"),DMXFixtureMap[14]);
}
#endif
@ -613,11 +613,11 @@ void getSettingsJS(byte subPage, Print& dest)
{
appendGPIOinfo(dest);
dest.printf_P(PSTR("numM=%d;"), usermods.getModCount());
sappend(dest,'v',SET_F("SDA"),i2c_sda);
sappend(dest,'v',SET_F("SCL"),i2c_scl);
sappend(dest,'v',SET_F("MOSI"),spi_mosi);
sappend(dest,'v',SET_F("MISO"),spi_miso);
sappend(dest,'v',SET_F("SCLK"),spi_sclk);
printSetValue(dest,PSTR("SDA"),i2c_sda);
printSetValue(dest,PSTR("SCL"),i2c_scl);
printSetValue(dest,PSTR("MOSI"),spi_mosi);
printSetValue(dest,PSTR("MISO"),spi_miso);
printSetValue(dest,PSTR("SCLK"),spi_sclk);
dest.printf_P(PSTR("addInfo('SDA','%d');"
"addInfo('SCL','%d');"
"addInfo('MOSI','%d');"
@ -641,21 +641,21 @@ void getSettingsJS(byte subPage, Print& dest)
#endif
VERSION);
sappends(dest,'m',SET_F("(\"sip\")[0]"),tmp_buf);
printSetMessage(dest,PSTR("(\"sip\")[0]"),tmp_buf);
}
if (subPage == SUBPAGE_2D) // 2D matrices
{
sappend(dest,'v',SET_F("SOMP"),strip.isMatrix);
printSetValue(dest,PSTR("SOMP"),strip.isMatrix);
#ifndef WLED_DISABLE_2D
dest.print(F("maxPanels=")); dest.print(WLED_MAX_PANELS); dest.print(F(";"));
dest.print(F("resetPanels();"));
if (strip.isMatrix) {
if(strip.panels>0){
sappend(dest,'v',SET_F("PW"),strip.panel[0].width); //Set generator Width and Height to first panel size for convenience
sappend(dest,'v',SET_F("PH"),strip.panel[0].height);
printSetValue(dest,PSTR("PW"),strip.panel[0].width); //Set generator Width and Height to first panel size for convenience
printSetValue(dest,PSTR("PH"),strip.panel[0].height);
}
sappend(dest,'v',SET_F("MPC"),strip.panels);
printSetValue(dest,PSTR("MPC"),strip.panels);
// panels
for (unsigned i=0; i<strip.panels; i++) {
char n[5];
@ -667,14 +667,14 @@ void getSettingsJS(byte subPage, Print& dest)
pO[7] = '\0';
unsigned l = strlen(pO);
// create P0B, P1B, ..., P63B, etc for other PxxX
pO[l] = 'B'; sappend(dest,'v',pO,strip.panel[i].bottomStart);
pO[l] = 'R'; sappend(dest,'v',pO,strip.panel[i].rightStart);
pO[l] = 'V'; sappend(dest,'v',pO,strip.panel[i].vertical);
pO[l] = 'S'; sappend(dest,'c',pO,strip.panel[i].serpentine);
pO[l] = 'X'; sappend(dest,'v',pO,strip.panel[i].xOffset);
pO[l] = 'Y'; sappend(dest,'v',pO,strip.panel[i].yOffset);
pO[l] = 'W'; sappend(dest,'v',pO,strip.panel[i].width);
pO[l] = 'H'; sappend(dest,'v',pO,strip.panel[i].height);
pO[l] = 'B'; printSetValue(dest,pO,strip.panel[i].bottomStart);
pO[l] = 'R'; printSetValue(dest,pO,strip.panel[i].rightStart);
pO[l] = 'V'; printSetValue(dest,pO,strip.panel[i].vertical);
pO[l] = 'S'; printSetCheckbox(dest,pO,strip.panel[i].serpentine);
pO[l] = 'X'; printSetValue(dest,pO,strip.panel[i].xOffset);
pO[l] = 'Y'; printSetValue(dest,pO,strip.panel[i].yOffset);
pO[l] = 'W'; printSetValue(dest,pO,strip.panel[i].width);
pO[l] = 'H'; printSetValue(dest,pO,strip.panel[i].height);
}
}
#else