mirror of
https://github.com/wled/WLED.git
synced 2025-07-24 03:06:36 +00:00
xml: Print optimization
Reduce the total number of calls by using printf_P and skipping atoi().
This commit is contained in:
parent
16f61ea96d
commit
4ef583c844
171
wled00/xml.cpp
171
wled00/xml.cpp
@ -8,63 +8,22 @@
|
||||
//build XML response to HTTP /win API request
|
||||
void XML_response(Print& dest)
|
||||
{
|
||||
dest.print(F("<?xml version=\"1.0\" ?><vs><ac>"));
|
||||
dest.print((nightlightActive && nightlightMode > NL_MODE_SET) ? briT : bri);
|
||||
dest.print(F("</ac>"));
|
||||
|
||||
dest.printf_P(PSTR("<?xml version=\"1.0\" ?><vs><ac>%d</ac>"), (nightlightActive && nightlightMode > NL_MODE_SET) ? briT : bri);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
dest.print("<cl>");
|
||||
dest.print(col[i]);
|
||||
dest.print("</cl>");
|
||||
dest.printf_P(PSTR("<cl>%d</cl>"), col[i]);
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
dest.print("<cs>");
|
||||
dest.print(colSec[i]);
|
||||
dest.print("</cs>");
|
||||
dest.printf_P(PSTR("<cs>%d</cs>"), colSec[i]);
|
||||
}
|
||||
dest.print(F("<ns>"));
|
||||
dest.print(notifyDirect);
|
||||
dest.print(F("</ns><nr>"));
|
||||
dest.print(receiveGroups!=0);
|
||||
dest.print(F("</nr><nl>"));
|
||||
dest.print(nightlightActive);
|
||||
dest.print(F("</nl><nf>"));
|
||||
dest.print(nightlightMode > NL_MODE_SET);
|
||||
dest.print(F("</nf><nd>"));
|
||||
dest.print(nightlightDelayMins);
|
||||
dest.print(F("</nd><nt>"));
|
||||
dest.print(nightlightTargetBri);
|
||||
dest.print(F("</nt><fx>"));
|
||||
dest.print(effectCurrent);
|
||||
dest.print(F("</fx><sx>"));
|
||||
dest.print(effectSpeed);
|
||||
dest.print(F("</sx><ix>"));
|
||||
dest.print(effectIntensity);
|
||||
dest.print(F("</ix><fp>"));
|
||||
dest.print(effectPalette);
|
||||
dest.print(F("</fp><wv>"));
|
||||
if (strip.hasWhiteChannel()) {
|
||||
dest.print(col[3]);
|
||||
} else {
|
||||
dest.print("-1");
|
||||
}
|
||||
dest.print(F("</wv><ws>"));
|
||||
dest.print(colSec[3]);
|
||||
dest.print(F("</ws><ps>"));
|
||||
dest.print(currentPreset);
|
||||
dest.print(F("</ps><cy>"));
|
||||
dest.print(currentPlaylist >= 0);
|
||||
dest.print(F("</cy><ds>"));
|
||||
dest.print(serverDescription);
|
||||
if (realtimeMode)
|
||||
{
|
||||
dest.print(F(" (live)"));
|
||||
}
|
||||
dest.print(F("</ds><ss>"));
|
||||
dest.print(strip.getFirstSelectedSegId());
|
||||
dest.print(F("</ss></vs>"));
|
||||
dest.printf_P(PSTR("<ns>%d</ns><nr>%d</nr><nl>%d</nl><nf>%d</nf><nd>%d</nd><nt>%d</nt><fx>%d</fx><sx>%d</sx><ix>%d</ix><fp>%d</fp><wv>%d</wv><ws>%d</ws><ps>%d</ps><cy>%d</cy><ds>%s%s</ds><ss>%d</ss></vs>"),
|
||||
notifyDirect, receiveGroups!=0, nightlightActive, nightlightMode > NL_MODE_SET, nightlightDelayMins,
|
||||
nightlightTargetBri, effectCurrent, effectSpeed, effectIntensity, effectPalette,
|
||||
strip.hasWhiteChannel() ? col[3] : -1, colSec[3], currentPreset, currentPlaylist >= 0,
|
||||
serverDescription, realtimeMode ? PSTR(" (live)") : "",
|
||||
strip.getFirstSelectedSegId()
|
||||
);
|
||||
}
|
||||
|
||||
static void extractPin(Print& dest, JsonObject &obj, const char *key) {
|
||||
@ -114,17 +73,12 @@ void fillUMPins(Print& dest, JsonObject &mods)
|
||||
}
|
||||
|
||||
void appendGPIOinfo(Print& dest) {
|
||||
char nS[8];
|
||||
|
||||
// add usermod pins as d.um_p array
|
||||
dest.print(F("d.um_p=[-1")); // has to have 1 element
|
||||
if (i2c_sda > -1 && i2c_scl > -1) {
|
||||
dest.print(","); dest.print(itoa(i2c_sda,nS,10));
|
||||
dest.print(","); dest.print(itoa(i2c_scl,nS,10));
|
||||
dest.printf_P(PSTR(",%d,%d"), i2c_sda, i2c_scl);
|
||||
}
|
||||
if (spi_mosi > -1 && spi_sclk > -1) {
|
||||
dest.print(","); dest.print(itoa(spi_mosi,nS,10));
|
||||
dest.print(","); dest.print(itoa(spi_sclk,nS,10));
|
||||
dest.printf_P(PSTR(",%d,%d"), spi_mosi, spi_sclk);
|
||||
}
|
||||
// usermod pin reservations will become unnecessary when settings pages will read cfg.json directly
|
||||
if (requestJSONBufferLock(6)) {
|
||||
@ -147,16 +101,16 @@ void appendGPIOinfo(Print& dest) {
|
||||
dest.print(SET_F("2,")); // DMX hardcoded pin
|
||||
#endif
|
||||
#if defined(WLED_DEBUG) && !defined(WLED_DEBUG_HOST)
|
||||
dest.print(itoa(hardwareTX,nS,10)); dest.print(","); // debug output (TX) pin
|
||||
dest.printf_P(PSTR(",%d"),hardwareTX); // debug output (TX) pin
|
||||
#endif
|
||||
//Note: Using pin 3 (RX) disables Adalight / Serial JSON
|
||||
#ifdef WLED_USE_ETHERNET
|
||||
if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
|
||||
for (unsigned p=0; p<WLED_ETH_RSVD_PINS_COUNT; p++) { dest.print(itoa(esp32_nonconfigurable_ethernet_pins[p].pin,nS,10)); dest.print(","); }
|
||||
if (ethernetBoards[ethernetType].eth_power>=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_power,nS,10)); dest.print(","); }
|
||||
if (ethernetBoards[ethernetType].eth_mdc>=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_mdc,nS,10)); dest.print(","); }
|
||||
if (ethernetBoards[ethernetType].eth_mdio>=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_mdio,nS,10)); dest.print(","); }
|
||||
switch (ethernetBoards[ethernetType].eth_clk_mode) {
|
||||
for (unsigned p=0; p<WLED_ETH_RSVD_PINS_COUNT; p++) { dest.printf(",%d", esp32_nonconfigurable_ethernet_pins[p].pin); }
|
||||
if (ethernetBoards[ethernetType].eth_power>=0) { dest.printf(",%d", ethernetBoards[ethernetType].eth_power); }
|
||||
if (ethernetBoards[ethernetType].eth_mdc>=0) { dest.printf(",%d", ethernetBoards[ethernetType].eth_mdc); }
|
||||
if (ethernetBoards[ethernetType].eth_mdio>=0) { dest.printf(",%d", ethernetBoards[ethernetType].eth_mdio); }
|
||||
switch (ethernetBoards[ethernetType].eth_clk_mode) {
|
||||
case ETH_CLOCK_GPIO0_IN:
|
||||
case ETH_CLOCK_GPIO0_OUT:
|
||||
dest.print(SET_F("0"));
|
||||
@ -211,27 +165,19 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
|
||||
if (subPage == SUBPAGE_WIFI)
|
||||
{
|
||||
char nS[10];
|
||||
size_t l;
|
||||
dest.print(F("resetWiFi("));
|
||||
dest.print(WLED_MAX_WIFI_COUNT);
|
||||
dest.print(F(");"));
|
||||
dest.printf_P(PSTR("resetWiFi(%d);"), WLED_MAX_WIFI_COUNT);
|
||||
for (size_t n = 0; n < multiWiFi.size(); n++) {
|
||||
l = strlen(multiWiFi[n].clientPass);
|
||||
char fpass[l+1]; //fill password field with ***
|
||||
fpass[l] = 0;
|
||||
memset(fpass,'*',l);
|
||||
dest.print(F("addWiFi(\""));
|
||||
dest.print(multiWiFi[n].clientSSID);
|
||||
dest.print(F("\",\""));
|
||||
dest.print(fpass);
|
||||
dest.print(F("\",0x"));
|
||||
dest.print(itoa(multiWiFi[n].staticIP,nS,16));
|
||||
dest.print(F(",0x"));
|
||||
dest.print(itoa(multiWiFi[n].staticGW,nS,16));
|
||||
dest.print(F(",0x"));
|
||||
dest.print(itoa(multiWiFi[n].staticSN,nS,16));
|
||||
dest.print(F(");"));
|
||||
dest.printf_P(PSTR("addWiFi(\"%s\",\",%s\",0x%X,0x%X,0x%X);"),
|
||||
multiWiFi[n].clientSSID,
|
||||
fpass,
|
||||
(uint32_t) multiWiFi[n].staticIP, // explicit cast required as this is a struct
|
||||
(uint32_t) multiWiFi[n].staticGW,
|
||||
(uint32_t) multiWiFi[n].staticSN);
|
||||
}
|
||||
|
||||
sappend(dest,'v',SET_F("D0"),dnsAddress[0]);
|
||||
@ -320,16 +266,16 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
dest.print(SET_F("d.ledTypes=")); dest.print(BusManager::getLEDTypesJSONString().c_str()); dest.print(";");
|
||||
|
||||
// set limits
|
||||
dest.print(F("bLimits("));
|
||||
dest.print(itoa(WLED_MAX_BUSSES,nS,10)); dest.print(",");
|
||||
dest.print(itoa(WLED_MIN_VIRTUAL_BUSSES,nS,10)); dest.print(",");
|
||||
dest.print(itoa(MAX_LEDS_PER_BUS,nS,10)); dest.print(",");
|
||||
dest.print(itoa(MAX_LED_MEMORY,nS,10)); dest.print(",");
|
||||
dest.print(itoa(MAX_LEDS,nS,10)); dest.print(",");
|
||||
dest.print(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10)); dest.print(",");
|
||||
dest.print(itoa(WLED_MAX_DIGITAL_CHANNELS,nS,10)); dest.print(",");
|
||||
dest.print(itoa(WLED_MAX_ANALOG_CHANNELS,nS,10));
|
||||
dest.print(F(");"));
|
||||
dest.printf_P(PSTR("bLimits(%d,%d,%d,%d,%d,%d,%d,%d);"),
|
||||
WLED_MAX_BUSSES,
|
||||
WLED_MIN_VIRTUAL_BUSSES,
|
||||
MAX_LEDS_PER_BUS,
|
||||
MAX_LED_MEMORY,
|
||||
MAX_LEDS,
|
||||
WLED_MAX_COLOR_ORDER_MAPPINGS,
|
||||
WLED_MAX_DIGITAL_CHANNELS,
|
||||
WLED_MAX_ANALOG_CHANNELS
|
||||
);
|
||||
|
||||
sappend(dest,'c',SET_F("MS"),strip.autoSegments);
|
||||
sappend(dest,'c',SET_F("CCT"),strip.correctWB);
|
||||
@ -403,17 +349,12 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
sappend(dest,'c',SET_F("ABL"),BusManager::ablMilliampsMax() || sumMa > 0);
|
||||
sappend(dest,'c',SET_F("PPL"),!BusManager::ablMilliampsMax() && sumMa > 0);
|
||||
|
||||
dest.print(F("resetCOM("));
|
||||
dest.print(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10));
|
||||
dest.print(F(");"));
|
||||
dest.printf_P(PSTR("resetCOM(%d);"), WLED_MAX_COLOR_ORDER_MAPPINGS);
|
||||
const ColorOrderMap& com = BusManager::getColorOrderMap();
|
||||
for (int s = 0; s < com.count(); s++) {
|
||||
const ColorOrderMapEntry* entry = com.get(s);
|
||||
if (entry == nullptr) break;
|
||||
dest.print(F("addCOM("));
|
||||
dest.print(itoa(entry->start,nS,10)); dest.print(",");
|
||||
dest.print(itoa(entry->len,nS,10)); dest.print(",");
|
||||
dest.print(itoa(entry->colorOrder,nS,10)); dest.print(");");
|
||||
dest.printf_P(PSTR("addCOM(%d,%d,%d);"), entry->start, entry->len, entry->colorOrder);
|
||||
}
|
||||
|
||||
sappend(dest,'v',SET_F("CA"),briS);
|
||||
@ -439,11 +380,7 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
sappend(dest,'c',SET_F("RM"),rlyMde);
|
||||
sappend(dest,'c',SET_F("RO"),rlyOpenDrain);
|
||||
for (int i = 0; i < WLED_MAX_BUTTONS; i++) {
|
||||
dest.print(F("addBtn("));
|
||||
dest.print(itoa(i,nS,10)); dest.print(",");
|
||||
dest.print(itoa(btnPin[i],nS,10)); dest.print(",");
|
||||
dest.print(itoa(buttonType[i],nS,10));
|
||||
dest.print(F(");"));
|
||||
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);
|
||||
@ -528,9 +465,8 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
sappends(dest,'s',SET_F("MG"),mqttGroupTopic);
|
||||
sappend(dest,'c',SET_F("BM"),buttonPublishMqtt);
|
||||
sappend(dest,'c',SET_F("RT"),retainMqttMsg);
|
||||
dest.print(F("d.Sf.MD.maxlength=")); dest.print(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); dest.print(F(";"));
|
||||
dest.print(F("d.Sf.MG.maxlength=")); dest.print(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); dest.print(F(";"));
|
||||
dest.print(F("d.Sf.MS.maxlength=")); dest.print(itoa(MQTT_MAX_SERVER_LEN,nS,10)); dest.print(F(";"));
|
||||
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
|
||||
dest.print(F("toggle('MQTT');")); // hide MQTT settings
|
||||
#endif
|
||||
@ -608,12 +544,7 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
sappend(dest,'v',SET_F("MC"),macroCountdown);
|
||||
sappend(dest,'v',SET_F("MN"),macroNl);
|
||||
for (unsigned i=0; i<WLED_MAX_BUTTONS; i++) {
|
||||
dest.print(F("addRow("));
|
||||
dest.print(itoa(i,tm,10)); dest.print(",");
|
||||
dest.print(itoa(macroButton[i],tm,10)); dest.print(",");
|
||||
dest.print(itoa(macroLongPress[i],tm,10)); dest.print(",");
|
||||
dest.print(itoa(macroDoublePress[i],tm,10));
|
||||
dest.print(F(");"));
|
||||
dest.printf_P(PSTR("addRow(%d,%d,%d,%d);"), i, macroButton[i], macroLongPress[i], macroDoublePress[i]);
|
||||
}
|
||||
|
||||
char k[4];
|
||||
@ -647,9 +578,7 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
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);
|
||||
dest.print(F("sd=\""));
|
||||
dest.print(serverDescription);
|
||||
dest.print(F("\";"));
|
||||
dest.printf_P(PSTR("sd=\"%s\";"), serverDescription);
|
||||
}
|
||||
|
||||
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
|
||||
@ -683,19 +612,19 @@ void getSettingsJS(byte subPage, Print& dest)
|
||||
if (subPage == SUBPAGE_UM) //usermods
|
||||
{
|
||||
appendGPIOinfo(dest);
|
||||
dest.print(F("numM="));
|
||||
dest.print(usermods.getModCount());
|
||||
dest.print(";");
|
||||
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);
|
||||
dest.print(F("addInfo('SDA','")); dest.print(HW_PIN_SDA); dest.print(F("');"));
|
||||
dest.print(F("addInfo('SCL','")); dest.print(HW_PIN_SCL); dest.print(F("');"));
|
||||
dest.print(F("addInfo('MOSI','")); dest.print(HW_PIN_DATASPI); dest.print(F("');"));
|
||||
dest.print(F("addInfo('MISO','")); dest.print(HW_PIN_MISOSPI); dest.print(F("');"));
|
||||
dest.print(F("addInfo('SCLK','")); dest.print(HW_PIN_CLOCKSPI); dest.print(F("');"));
|
||||
dest.printf_P(PSTR("addInfo('SDA','%d');"
|
||||
"addInfo('SCL','%d');"
|
||||
"addInfo('MOSI','%d');"
|
||||
"addInfo('MISO','%d');"
|
||||
"addInfo('SCLK','%d');"),
|
||||
HW_PIN_SDA, HW_PIN_SCL, HW_PIN_DATASPI, HW_PIN_MISOSPI, HW_PIN_CLOCKSPI
|
||||
);
|
||||
usermods.appendConfigData(dest);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user