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 getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
bool getBoolVal(JsonVariant elem, bool dflt); bool getBoolVal(JsonVariant elem, bool dflt);
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255); 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); size_t printSetCheckbox(Print& dest, const char* key, int val);
void sappends(Print& dest, char stype, const char* key, char* 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); void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen); bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255); 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; return true;
} }
static size_t printSetInt(Print& dest, const char* key, const char* selector, int value) {
//append a numeric setting to string buffer return dest.printf_P(PSTR("d.Sf.%s.%s=%d;"), key, selector, value);
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);
} }
size_t printSetCheckbox(Print& dest, const char* key, int val) {
//append a string setting to buffer return printSetInt(dest, key, PSTR("checked"), val);
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 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) void prepareHostname(char* hostname)

View File

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