From 109a8f69896caee0fa18786c199d9b67a11878c1 Mon Sep 17 00:00:00 2001 From: TD-er Date: Sat, 11 Jun 2022 11:49:02 +0200 Subject: [PATCH] [Cleanup] Small optimizations to reduce bin size --- platformio_special_envs.ini | 18 +++-- src/_C018.cpp | 4 +- src/_P001_Switch.ino | 8 +-- src/_P009_MCP.ino | 10 +-- src/_P013_HCSR04.ino | 2 +- src/_P019_PCF8574.ino | 10 +-- src/_P073_7DGT.ino | 76 +++++++++++----------- src/_P098_PWM_motor.ino | 2 +- src/_P119_ITG3205_Gyro.ino | 5 +- src/src/ESPEasyCore/ESPEasyGPIO.cpp | 4 +- src/src/ESPEasyCore/ESPEasyGPIO.h | 2 +- src/src/PluginStructs/P120_data_struct.cpp | 5 +- src/src/WebServer/HardwarePage.cpp | 4 +- src/src/WebServer/Markup_Forms.cpp | 38 ++++++++++- src/src/WebServer/Markup_Forms.h | 45 +++++++++---- src/src/WebServer/WebServer.cpp | 4 ++ src/src/WebServer/WebServer.h | 2 + 17 files changed, 155 insertions(+), 84 deletions(-) diff --git a/platformio_special_envs.ini b/platformio_special_envs.ini index 0462399c7..9b109ff72 100644 --- a/platformio_special_envs.ini +++ b/platformio_special_envs.ini @@ -74,34 +74,42 @@ lib_ignore = ${regular_platform.lib_ignore} extra_scripts = ${extra_scripts_esp8266.extra_scripts} -[env:spec_debug_custom_ESP32_4M316k] +[env:spec_debug_custom_ESP32_16M8M] extends = esp32_common build_type = ${debug_pio.build_type} check_tool = ${debug_pio.check_tool} check_flags = ${debug_pio.check_flags} platform = ${esp32_common.platform} build_flags = ${esp32_common.build_flags} ${debug_pio.build_flags} -DPLUGIN_BUILD_CUSTOM -board = esp32dev +board = esp32_16M8M +board_upload.maximum_size = 4194304 extra_scripts = ${esp32_common.extra_scripts} pre:tools/pio/pre_custom_esp32.py [env:spec_debug_max_ESP32_16M8M] -extends = esp32_common +extends = esp32_base build_type = ${debug_pio.build_type} check_tool = ${debug_pio.check_tool} check_flags = ${debug_pio.check_flags} lib_ignore = ${esp32_always.lib_ignore} ESP32_ping board_upload.maximum_size = 4194304 -build_flags = ${esp32_common.build_flags} +build_flags = ${esp32_base.build_flags} ${debug_pio.build_flags} + -DUSE_LITTLEFS -DFEATURE_ARDUINO_OTA -DPLUGIN_BUILD_MAX_ESP32 -DPLUGIN_BUILD_IR_EXTENDED +lib_deps = ${esp32_base.lib_deps} + LittleFS +board_build.filesystem = littlefs + ; TODO: To enable PS-RAM Support needs more build flags than these 2, for now define BOARD_HAS_PSRAM is used to en/disable detecting PS-Ram size on Info page ; -DBOARD_HAS_PSRAM // both flags already enabled for Lolin D32 Pro board by PlatformIO ; -mfix-esp32-psram-cache-issue -board = lolin_d32_pro +;board = lolin_d32_pro +board = esp32_16M8M + diff --git a/src/_C018.cpp b/src/_C018.cpp index 99ffb2739..49b079265 100644 --- a/src/_C018.cpp +++ b/src/_C018.cpp @@ -627,8 +627,8 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String& } { - String options[2] = { F("OTAA"), F("ABP") }; - int values[2] = { C018_USE_OTAA, C018_USE_ABP }; + const __FlashStringHelper * options[2] = { F("OTAA"), F("ABP") }; + const int values[2] = { C018_USE_OTAA, C018_USE_ABP }; addFormSelector_script(F("Activation Method"), F("joinmethod"), 2, options, values, nullptr, joinmethod, F("joinChanged(this)")); // Script to toggle OTAA/ABP fields visibility when changing selection. diff --git a/src/_P001_Switch.ino b/src/_P001_Switch.ino index 8f4f91543..4daae8afa 100644 --- a/src/_P001_Switch.ino +++ b/src/_P001_Switch.ino @@ -408,7 +408,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string) // long timerstats = millis(); // Bug fixed: avoid 10xSEC in case of a non-fully configured device (no GPIO defined yet) - const String monitorEventString = F("GPIO"); + const __FlashStringHelper * monitorEventString = F("GPIO"); if (validGpio(CONFIG_PIN1)) { @@ -531,7 +531,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string) // send task event sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PIN1, output_value); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PIN1, output_value); // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = sendState ? 1 : 0; @@ -625,7 +625,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string) // send task event sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PIN1, output_value); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PIN1, output_value); // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = sendState ? 1 : 0; @@ -654,7 +654,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string) // send task event: DO NOT SEND TASK EVENT //sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PIN1, SAFE_BUTTON_EVENT); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PIN1, SAFE_BUTTON_EVENT); // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = tempUserVar; diff --git a/src/_P009_MCP.ino b/src/_P009_MCP.ino index e931ef8c8..52c1878c0 100644 --- a/src/_P009_MCP.ino +++ b/src/_P009_MCP.ino @@ -289,7 +289,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { const int8_t state = GPIO_MCP_Read(CONFIG_PORT); - const String monitorEventString = F("MCP"); + const __FlashStringHelper * monitorEventString = F("MCP"); /**************************************************************************\ 20181022 - @giig1967g: new doubleclick logic is: @@ -392,7 +392,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string) sendData(event); // send monitor event - if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); } + if (currentStatus.monitor) { sendMonitorEvent(monitorEventString, CONFIG_PORT, output_value); } // Reset forceEvent currentStatus.forceEvent = 0; @@ -459,7 +459,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string) sendData(event); // send monitor event - if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); } + if (currentStatus.monitor) { sendMonitorEvent(monitorEventString, CONFIG_PORT, output_value); } // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = sendState ? 1 : 0; @@ -483,7 +483,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string) // send task event: DO NOT SEND TASK EVENT //sendData(event); // send monitor event - if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, 4); } + if (currentStatus.monitor) { sendMonitorEvent(monitorEventString, CONFIG_PORT, 4); } // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = tempUserVar; @@ -506,7 +506,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string) sendData(event); // send monitor event - if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, -1); } + if (currentStatus.monitor) { sendMonitorEvent(monitorEventString, CONFIG_PORT, -1); } savePortStatus(key, currentStatus); } diff --git a/src/_P013_HCSR04.ino b/src/_P013_HCSR04.ino index dab198098..389560f4d 100644 --- a/src/_P013_HCSR04.ino +++ b/src/_P013_HCSR04.ino @@ -94,7 +94,7 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even } - String strUnit = (measuringUnit == UNIT_CM) ? F("cm") : F("inch"); + const __FlashStringHelper * strUnit = (measuringUnit == UNIT_CM) ? F("cm") : F("inch"); { const __FlashStringHelper *optionsOpMode[2]; diff --git a/src/_P019_PCF8574.ino b/src/_P019_PCF8574.ino index 849eb0eb8..9023f7ece 100644 --- a/src/_P019_PCF8574.ino +++ b/src/_P019_PCF8574.ino @@ -340,7 +340,7 @@ boolean Plugin_019(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { const int8_t state = Plugin_019_Read(CONFIG_PORT); - const String monitorEventString = F("PCF"); + const __FlashStringHelper * monitorEventString = F("PCF"); /**************************************************************************\ 20181022 - @giig1967g: new doubleclick logic is: @@ -449,7 +449,7 @@ boolean Plugin_019(uint8_t function, struct EventStruct *event, String& string) // send task event sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PORT, output_value); // Reset forceEvent currentStatus.forceEvent = 0; @@ -514,7 +514,7 @@ boolean Plugin_019(uint8_t function, struct EventStruct *event, String& string) // send task event sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PORT, output_value); // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = sendState ? 1 : 0; @@ -540,7 +540,7 @@ boolean Plugin_019(uint8_t function, struct EventStruct *event, String& string) // send task event: DO NOT SEND TASK EVENT //sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, SAFE_BUTTON_EVENT); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PORT, SAFE_BUTTON_EVENT); // reset Userdata so it displays the correct state value in the web page UserVar[event->BaseVarIndex] = tempUserVar; @@ -563,7 +563,7 @@ boolean Plugin_019(uint8_t function, struct EventStruct *event, String& string) // send task event sendData(event); // send monitor event - if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, -1); + if (currentStatus.monitor) sendMonitorEvent(monitorEventString, CONFIG_PORT, -1); savePortStatus(key, currentStatus); } diff --git a/src/_P073_7DGT.ino b/src/_P073_7DGT.ino index dfdddf48b..5bcb74728 100644 --- a/src/_P073_7DGT.ino +++ b/src/_P073_7DGT.ino @@ -114,7 +114,7 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) F("TM1637 - 4 digit (dots)"), F("TM1637 - 6 digit"), F("MAX7219 - 8 digit") }; - addFormSelector(F("Display Type"), F("plugin_073_displtype"), 4, displtype, nullptr, PCONFIG(0)); + addFormSelector(F("Display Type"), F("displtype"), 4, displtype, nullptr, PCONFIG(0)); } { const __FlashStringHelper *displout[] = { F("Manual"), @@ -123,10 +123,10 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) F("Clock 12h - Blink"), F("Clock 12h - No Blink"), F("Date") }; - addFormSelector(F("Display Output"), F("plugin_073_displout"), 6, displout, nullptr, PCONFIG(1)); + addFormSelector(F("Display Output"), F("displout"), 6, displout, nullptr, PCONFIG(1)); } - addFormNumericBox(F("Brightness"), F("plugin_073_brightness"), PCONFIG(2), 0, 15); + addFormNumericBox(F("Brightness"), F("brightness"), PCONFIG(2), 0, 15); addUnit(F("0..15")); # ifdef P073_EXTRA_FONTS @@ -135,16 +135,16 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) F("Siekoo"), F("Siekoo with uppercase 'CHNORUX'"), F("dSEG7") }; - addFormSelector(F("Font set"), F("plugin_073_fontset"), 4, fontset, nullptr, PCONFIG(4)); + addFormSelector(F("Font set"), F("fontset"), 4, fontset, nullptr, PCONFIG(4)); addFormNote(F("Check documentation for examples of the font sets.")); } # endif // P073_EXTRA_FONTS addFormSubHeader(F("Options")); - addFormCheckBox(F("Text show periods as dot"), F("plugin_073_periods"), bitRead(PCONFIG_LONG(0), P073_OPTION_PERIOD)); + addFormCheckBox(F("Text show periods as dot"), F("periods"), bitRead(PCONFIG_LONG(0), P073_OPTION_PERIOD)); - addFormCheckBox(F("Hide ° for Temperatures"), F("plugin_073_hide_degree"), bitRead(PCONFIG_LONG(0), P073_OPTION_HIDEDEGREE)); + addFormCheckBox(F("Hide ° for Temperatures"), F("hide_degree"), bitRead(PCONFIG_LONG(0), P073_OPTION_HIDEDEGREE)); # ifdef P073_7DDT_COMMAND addFormNote(F("Commands 7dt,<temp> and 7ddt,<temp1>,<temp2>")); # else // ifdef P073_7DDT_COMMAND @@ -152,38 +152,38 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) # endif // P073_7DDT_COMMAND # ifdef P073_SCROLL_TEXT - addFormCheckBox(F("Scroll text > display width"), F("plugin_073_scroll_text"), bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLTEXT)); - addFormCheckBox(F("Scroll text in from right"), F("plugin_073_scroll_full"), bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLFULL)); + addFormCheckBox(F("Scroll text > display width"), F("scroll_text"), bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLTEXT)); + addFormCheckBox(F("Scroll text in from right"), F("scroll_full"), bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLFULL)); if (PCONFIG(3) == 0) { PCONFIG(3) = 10; } - addFormNumericBox(F("Scroll speed (0.1 sec/step)"), F("plugin_073_scrollspeed"), PCONFIG(3), 1, 600); + addFormNumericBox(F("Scroll speed (0.1 sec/step)"), F("scrollspeed"), PCONFIG(3), 1, 600); addUnit(F("1..600 = 0.1..60 sec/step")); # endif // P073_SCROLL_TEXT addFormSubHeader(F("Options for MAX7219 - 8 digit")); bool bRightAlign = bitRead(PCONFIG_LONG(0), P073_OPTION_RIGHTALIGN); - addFormCheckBox(F("Right-align Temperature (7dt)"), F("plugin_073_temp_rightalign"), bRightAlign); + addFormCheckBox(F("Right-align Temperature (7dt)"), F("temp_rightalign"), bRightAlign); success = true; break; } case PLUGIN_WEBFORM_SAVE: { - PCONFIG(0) = getFormItemInt(F("plugin_073_displtype")); - PCONFIG(1) = getFormItemInt(F("plugin_073_displout")); - PCONFIG(2) = getFormItemInt(F("plugin_073_brightness")); + PCONFIG(0) = getFormItemInt(F("displtype")); + PCONFIG(1) = getFormItemInt(F("displout")); + PCONFIG(2) = getFormItemInt(F("brightness")); uint32_t lSettings = 0; - bitWrite(lSettings, P073_OPTION_PERIOD, isFormItemChecked(F("plugin_073_periods"))); - bitWrite(lSettings, P073_OPTION_HIDEDEGREE, isFormItemChecked(F("plugin_073_hide_degree"))); - bitWrite(lSettings, P073_OPTION_RIGHTALIGN, isFormItemChecked(F("plugin_073_temp_rightalign"))); + bitWrite(lSettings, P073_OPTION_PERIOD, isFormItemChecked(F("periods"))); + bitWrite(lSettings, P073_OPTION_HIDEDEGREE, isFormItemChecked(F("hide_degree"))); + bitWrite(lSettings, P073_OPTION_RIGHTALIGN, isFormItemChecked(F("temp_rightalign"))); # ifdef P073_SCROLL_TEXT - bitWrite(lSettings, P073_OPTION_SCROLLTEXT, isFormItemChecked(F("plugin_073_scroll_text"))); - bitWrite(lSettings, P073_OPTION_SCROLLFULL, isFormItemChecked(F("plugin_073_scroll_full"))); - PCONFIG(3) = getFormItemInt(F("plugin_073_scrollspeed")); + bitWrite(lSettings, P073_OPTION_SCROLLTEXT, isFormItemChecked(F("scroll_text"))); + bitWrite(lSettings, P073_OPTION_SCROLLFULL, isFormItemChecked(F("scroll_full"))); + PCONFIG(3) = getFormItemInt(F("scrollspeed")); # endif // P073_SCROLL_TEXT # ifdef P073_EXTRA_FONTS - PCONFIG(4) = getFormItemInt(F("plugin_073_fontset")); + PCONFIG(4) = getFormItemInt(F("fontset")); # endif // P073_EXTRA_FONTS PCONFIG_LONG(0) = lSettings; @@ -356,8 +356,10 @@ bool p073_plugin_write(struct EventStruct *event, return false; } - String cmd = parseString(string, 1); - String text = parseStringToEndKeepCase(string, 2); + const String cmd = parseString(string, 1); + if (cmd.length() < 3 || cmd[0] != '7') return false; + + const String text = parseStringToEndKeepCase(string, 2); if (cmd.equals("7dn")) { return p073_plugin_write_7dn(event, text); @@ -508,11 +510,11 @@ bool p073_plugin_write_7dt(struct EventStruct *event, return false; } - double p073_temptemp = 0; + float p073_temptemp = 0; bool p073_tempflagdot = false; if (!text.isEmpty()) { - validDoubleFromString(text, p073_temptemp); + validFloatFromString(text, p073_temptemp); } if (loglevelActiveFor(LOG_LEVEL_INFO)) { @@ -581,15 +583,15 @@ bool p073_plugin_write_7ddt(struct EventStruct *event, return false; } - double p073_lefttemp = 0.0; - double p073_righttemp = 0.0; + float p073_lefttemp = 0.0f; + float p073_righttemp = 0.0f; bool p073_tempflagdot = false; if (!text.isEmpty()) { - validDoubleFromString(parseString(text, 1), p073_lefttemp); + validFloatFromString(parseString(text, 1), p073_lefttemp); if (text.indexOf(',') > -1) { - validDoubleFromString(parseString(text, 2), p073_righttemp); + validFloatFromString(parseString(text, 2), p073_righttemp); } } @@ -619,25 +621,25 @@ bool p073_plugin_write_7ddt(struct EventStruct *event, { uint8_t firstDot = -1; // No decimals is no dots uint8_t secondDot = -1; - double hideFactor = P073_data->hideDegree ? 10.0 : 1.0; + float hideFactor = P073_data->hideDegree ? 10.0f : 1.0f; bool firstDecimals = false; bool secondDecimals = false; - if ((p073_lefttemp > 999.99 * hideFactor) || (p073_lefttemp < -99.99 * hideFactor)) { - p073_lefttemp = -101.0 * hideFactor; // Triggers on -100 + if ((p073_lefttemp > 999.99f * hideFactor) || (p073_lefttemp < -99.99f * hideFactor)) { + p073_lefttemp = -101.0f * hideFactor; // Triggers on -100 } else { - if ((p073_lefttemp < 100.0 * hideFactor) && (p073_lefttemp > -10.0 * hideFactor)) { - p073_lefttemp = round(p073_lefttemp * 10.0); + if ((p073_lefttemp < 100.0f * hideFactor) && (p073_lefttemp > -10.0f * hideFactor)) { + p073_lefttemp = round(p073_lefttemp * 10.0f); firstDot = P073_data->hideDegree ? 2 : 1; firstDecimals = true; } } - if ((p073_righttemp > 999.99 * hideFactor) || (p073_righttemp < -99.99 * hideFactor)) { - p073_righttemp = -101.0 * hideFactor; + if ((p073_righttemp > 999.99f * hideFactor) || (p073_righttemp < -99.99f * hideFactor)) { + p073_righttemp = -101.0f * hideFactor; } else { - if ((p073_righttemp < 100.0 * hideFactor) && (p073_righttemp > -10.0 * hideFactor)) { - p073_righttemp = round(p073_righttemp * 10.0); + if ((p073_righttemp < 100.0f * hideFactor) && (p073_righttemp > -10.0f * hideFactor)) { + p073_righttemp = round(p073_righttemp * 10.0f); secondDot = P073_data->hideDegree ? 6 : 5; secondDecimals = true; } diff --git a/src/_P098_PWM_motor.ino b/src/_P098_PWM_motor.ino index 20eac42bf..33ff5eeb1 100644 --- a/src/_P098_PWM_motor.ino +++ b/src/_P098_PWM_motor.ino @@ -169,7 +169,7 @@ boolean Plugin_098(uint8_t function, struct EventStruct *event, String& string) { # define P098_PWM_MODE_TYPES static_cast(P098_config_struct::PWM_mode_type::MAX_TYPE) - String options[P098_PWM_MODE_TYPES]; + const __FlashStringHelper * options[P098_PWM_MODE_TYPES]; int optionValues[P098_PWM_MODE_TYPES]; for (int i = 0; i < P098_PWM_MODE_TYPES; ++i) { diff --git a/src/_P119_ITG3205_Gyro.ino b/src/_P119_ITG3205_Gyro.ino index df6eab3a2..cb83c60eb 100644 --- a/src/_P119_ITG3205_Gyro.ino +++ b/src/_P119_ITG3205_Gyro.ino @@ -111,10 +111,11 @@ boolean Plugin_119(uint8_t function, struct EventStruct *event, String& string) addUnit(F("1..100")); const __FlashStringHelper *frequencyOptions[] = { - F("10x per second"), - F("50x per second") }; + F("10"), + F("50") }; int frequencyValues[] = { P119_FREQUENCY_10, P119_FREQUENCY_50 }; addFormSelector(F("Measuring frequency"), F("p119_frequency"), 2, frequencyOptions, frequencyValues, P119_FREQUENCY); + addUnit(F("Hz")); success = true; break; diff --git a/src/src/ESPEasyCore/ESPEasyGPIO.cpp b/src/src/ESPEasyCore/ESPEasyGPIO.cpp index 8ef57cff2..e3bc0aaf1 100644 --- a/src/src/ESPEasyCore/ESPEasyGPIO.cpp +++ b/src/src/ESPEasyCore/ESPEasyGPIO.cpp @@ -456,7 +456,7 @@ void GPIO_Monitor10xSec() it->second.state = currentState; //update state ONLY if task flag=false otherwise it will not be picked up by 10xSEC function // send event if not task, otherwise is sent in the task PLUGIN_TEN_PER_SECOND if (it->second.monitor) { - sendMonitorEvent(String(eventString).c_str(), gpioPort, currentState); + sendMonitorEvent(eventString, gpioPort, currentState); } } } @@ -467,7 +467,7 @@ void GPIO_Monitor10xSec() } // prefix should be either "GPIO", "PCF", "MCP" -void sendMonitorEvent(const char* prefix, int port, int8_t state) +void sendMonitorEvent(const __FlashStringHelper * prefix, int port, int8_t state) { String eventString = prefix; eventString += '#'; diff --git a/src/src/ESPEasyCore/ESPEasyGPIO.h b/src/src/ESPEasyCore/ESPEasyGPIO.h index 540f89264..47119777d 100644 --- a/src/src/ESPEasyCore/ESPEasyGPIO.h +++ b/src/src/ESPEasyCore/ESPEasyGPIO.h @@ -67,7 +67,7 @@ void GPIO_PCF_WriteAllPins(uint8_t Par1, uint8_t Par2); void GPIO_Monitor10xSec(); // prefix should be either "GPIO", "PCF", "MCP" -void sendMonitorEvent(const char* prefix, int port, int8_t state); +void sendMonitorEvent(const __FlashStringHelper * prefix, int port, int8_t state); bool checkValidPortRange(pluginID_t pluginID, int port); bool checkValidPortAddress(pluginID_t pluginID, uint8_t address); diff --git a/src/src/PluginStructs/P120_data_struct.cpp b/src/src/PluginStructs/P120_data_struct.cpp index 6556761de..49c7f2ef4 100644 --- a/src/src/PluginStructs/P120_data_struct.cpp +++ b/src/src/PluginStructs/P120_data_struct.cpp @@ -528,10 +528,11 @@ bool P120_data_struct::plugin_webform_load(struct EventStruct *event) { addUnit(F("1..100")); const __FlashStringHelper *frequencyOptions[] = { - F("10x per second"), - F("50x per second") }; + F("10"), + F("50") }; int frequencyValues[] = { P120_FREQUENCY_10, P120_FREQUENCY_50 }; addFormSelector(F("Measuring frequency"), F("p120_frequency"), 2, frequencyOptions, frequencyValues, P120_FREQUENCY); + addUnit(F("Hz")); addFormNote(F("Values X/Y/Z are updated 1x per second, Controller updates & Value-events are based on 'Interval' setting.")); } diff --git a/src/src/WebServer/HardwarePage.cpp b/src/src/WebServer/HardwarePage.cpp index 5a6f12c51..856e79849 100644 --- a/src/src/WebServer/HardwarePage.cpp +++ b/src/src/WebServer/HardwarePage.cpp @@ -81,7 +81,7 @@ void handle_hardware() { // do not add the pin state select for these pins. } else { if (validGpio(gpio)) { - String int_pinlabel = "p"; + String int_pinlabel('p'); int_pinlabel += gpio; Settings.setPinBootState(gpio, static_cast(getFormItemInt(int_pinlabel))); } @@ -167,7 +167,7 @@ void handle_hardware() { // Script to show GPIO pins for User-defined SPI GPIOs html_add_script(F("function spiOptionChanged(elem) {var spipinstyle = elem.value == 9 ? '' : 'none';document.getElementById('tr_spipinsclk').style.display = spipinstyle;document.getElementById('tr_spipinmiso').style.display = spipinstyle;document.getElementById('tr_spipinmosi').style.display = spipinstyle;}"), false); - const String spi_options[] = { + const __FlashStringHelper * spi_options[] = { getSPI_optionToString(SPI_Options_e::None), getSPI_optionToString(SPI_Options_e::Vspi), getSPI_optionToString(SPI_Options_e::Hspi), diff --git a/src/src/WebServer/Markup_Forms.cpp b/src/src/WebServer/Markup_Forms.cpp index acd09cb7e..67c03e124 100644 --- a/src/src/WebServer/Markup_Forms.cpp +++ b/src/src/WebServer/Markup_Forms.cpp @@ -462,6 +462,29 @@ void addFormSelector(const String & label, ); } +void addFormSelector_script(const __FlashStringHelper * label, + const __FlashStringHelper * id, + int optionCount, + const __FlashStringHelper * options[], + const int indices[], + const String attr[], + int selectedIndex, + const __FlashStringHelper * onChangeCall + #ifdef ENABLE_TOOLTIPS + , const String& tooltip + #endif // ifdef ENABLE_TOOLTIPS + ) +{ + addRowLabel_tr_id(label, id); + do_addSelector_Head(id, F("wide"), onChangeCall, false + #ifdef ENABLE_TOOLTIPS + , tooltip + #endif // ifdef ENABLE_TOOLTIPS + ); + addSelector_options(optionCount, options, indices, attr, selectedIndex); + addSelector_Foot(); +} + void addFormSelector_script(const String & label, const String & id, int optionCount, @@ -469,7 +492,7 @@ void addFormSelector_script(const String & label, const int indices[], const String attr[], int selectedIndex, - const String& onChangeCall + const __FlashStringHelper * onChangeCall #ifdef ENABLE_TOOLTIPS , const String& tooltip #endif // ifdef ENABLE_TOOLTIPS @@ -582,6 +605,12 @@ bool getCheckWebserverArg_int(const String& key, int& value) { return validIntFromString(valueStr, value); } +bool update_whenset_FormItemInt(const __FlashStringHelper * key, + int & value) +{ + return update_whenset_FormItemInt(String(key), value); +} + bool update_whenset_FormItemInt(const String& key, int& value) { int tmpVal; @@ -592,6 +621,13 @@ bool update_whenset_FormItemInt(const String& key, int& value) { return false; } +bool update_whenset_FormItemInt(const __FlashStringHelper * key, + uint8_t& value) +{ + return update_whenset_FormItemInt(String(key), value); +} + + bool update_whenset_FormItemInt(const String& key, uint8_t& value) { int tmpVal; diff --git a/src/src/WebServer/Markup_Forms.h b/src/src/WebServer/Markup_Forms.h index a1b9456ae..60f87881a 100644 --- a/src/src/WebServer/Markup_Forms.h +++ b/src/src/WebServer/Markup_Forms.h @@ -17,7 +17,7 @@ void addFormSeparator(int clspan); // Add a note as row start // ******************************************************************************** void addFormNote(const __FlashStringHelper * text); -void addFormNote(const String& text, const String& id = ""); +void addFormNote(const String& text, const String& id = EMPTY_STRING); // ******************************************************************************** // Create Forms @@ -128,7 +128,7 @@ void addFormTextBox(const __FlashStringHelper * label, int maxlength, bool readonly = false, bool required = false, - const String& pattern = ""); + const String& pattern = EMPTY_STRING); void addFormTextBox(const String& label, const String& id, @@ -136,7 +136,7 @@ void addFormTextBox(const String& label, int maxlength, bool readonly = false, bool required = false, - const String& pattern = "" + const String& pattern = EMPTY_STRING #ifdef ENABLE_TOOLTIPS , const String& tooltip = EMPTY_STRING @@ -254,15 +254,6 @@ void addFormSelector(const String& label, int selectedIndex, boolean reloadonchange); -void addFormSelector_script(const String& label, - const String& id, - int optionCount, - const __FlashStringHelper * options[], - const int indices[], - const String attr[], - int selectedIndex, - const String& onChangeCall); - void addFormSelector(const String& label, const String& id, @@ -270,7 +261,12 @@ void addFormSelector(const String& label, const String options[], const int indices[], int selectedIndex, - bool reloadonchange); + bool reloadonchange + #ifdef ENABLE_TOOLTIPS + , + const String& tooltip = EMPTY_STRING + #endif + ); void addFormSelector(const String& label, const String& id, @@ -286,6 +282,21 @@ void addFormSelector(const String& label, #endif ); +void addFormSelector_script(const __FlashStringHelper * label, + const __FlashStringHelper * id, + int optionCount, + const __FlashStringHelper * options[], + const int indices[], + const String attr[], + int selectedIndex, + const __FlashStringHelper * onChangeCall + #ifdef ENABLE_TOOLTIPS + , + const String& tooltip = EMPTY_STRING + #endif + ); + + void addFormSelector_script(const String& label, const String& id, int optionCount, @@ -293,7 +304,7 @@ void addFormSelector_script(const String& label, const int indices[], const String attr[], int selectedIndex, - const String& onChangeCall + const __FlashStringHelper * onChangeCall #ifdef ENABLE_TOOLTIPS , const String& tooltip = EMPTY_STRING @@ -317,9 +328,15 @@ int getFormItemInt(const String& key, int defaultValue); bool getCheckWebserverArg_int(const String& key, int & value); +bool update_whenset_FormItemInt(const __FlashStringHelper * key, + int & value); + bool update_whenset_FormItemInt(const String& key, int & value); +bool update_whenset_FormItemInt(const __FlashStringHelper * key, + uint8_t & value); + bool update_whenset_FormItemInt(const String& key, uint8_t & value); diff --git a/src/src/WebServer/WebServer.cpp b/src/src/WebServer/WebServer.cpp index 24ba549b5..5ebfe96a3 100644 --- a/src/src/WebServer/WebServer.cpp +++ b/src/src/WebServer/WebServer.cpp @@ -76,6 +76,10 @@ void safe_strncpy_webserver_arg(char *dest, const String& arg, size_t max_size) } } +void safe_strncpy_webserver_arg(char *dest, const __FlashStringHelper * arg, size_t max_size) { + safe_strncpy_webserver_arg(dest, String(arg), max_size); +} + void sendHeadandTail(const __FlashStringHelper * tmplName, boolean Tail, boolean rebooting) { // This function is called twice per serving a web page. // So it must keep track of the timer longer than the scope of this function. diff --git a/src/src/WebServer/WebServer.h b/src/src/WebServer/WebServer.h index f09d60681..3800753be 100644 --- a/src/src/WebServer/WebServer.h +++ b/src/src/WebServer/WebServer.h @@ -20,6 +20,8 @@ void safe_strncpy_webserver_arg(char *dest, const String& arg, size_t max_size); +void safe_strncpy_webserver_arg(char *dest, const __FlashStringHelper * arg, size_t max_size); + void sendHeadandTail(const __FlashStringHelper * tmplName, boolean Tail = false, boolean rebooting = false);