[Cleanup] Add FlashStringHelper function wrappers to reduce build size

This commit is contained in:
TD-er
2021-05-24 22:24:18 +02:00
parent a5fab90ebd
commit 3965abc62d
10 changed files with 108 additions and 44 deletions
+1 -1
View File
@@ -298,7 +298,7 @@ void P002_performRead(struct EventStruct *event, int& value) {
#endif // if defined(ESP32)
}
void P002_formatStatistics(const String& label, int raw, float float_value) {
void P002_formatStatistics(const __FlashStringHelper * label, int raw, float float_value) {
addRowLabel(label);
addHtmlInt(raw);
html_add_estimate_symbol();
+20 -20
View File
@@ -35,8 +35,8 @@ void handle_factoryreset() {
addFormHeader(F("Factory Reset"));
#ifndef LIMIT_BUILD_SIZE
if (web_server.hasArg("fdm")) {
DeviceModel model = static_cast<DeviceModel>(getFormItemInt("fdm"));
if (web_server.hasArg(F("fdm"))) {
DeviceModel model = static_cast<DeviceModel>(getFormItemInt(F("fdm")));
if (modelMatchingFlashSize(model)) {
setFactoryDefault(model);
@@ -46,11 +46,11 @@ void handle_factoryreset() {
if (web_server.hasArg(F("savepref"))) {
// User choose a pre-defined config and wants to save it as the new default.
ResetFactoryDefaultPreference.keepUnitName(isFormItemChecked("kun"));
ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked("kw"));
ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked("knet"));
ResetFactoryDefaultPreference.keepNTP(isFormItemChecked("kntp"));
ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked("klog"));
ResetFactoryDefaultPreference.keepUnitName(isFormItemChecked(F("kun")));
ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked(F("kw")));
ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked(F("knet")));
ResetFactoryDefaultPreference.keepNTP(isFormItemChecked(F("kntp")));
ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog")));
applyFactoryDefaultPref();
addHtmlError(SaveSettings());
}
@@ -111,7 +111,7 @@ void handle_factoryreset() {
void addPreDefinedConfigSelector() {
DeviceModel active_model = ResetFactoryDefaultPreference.getDeviceModel();
addSelector_Head_reloadOnChange("fdm");
addSelector_Head_reloadOnChange(F("fdm"));
for (byte x = 0; x < DeviceModel_MAX; ++x) {
DeviceModel model = static_cast<DeviceModel>(x);
@@ -134,32 +134,32 @@ void handle_factoryreset_json() {
TXBuffer.startJsonStream();
addHtml('{');
#ifndef LIMIT_BUILD_SIZE
if (web_server.hasArg("fdm")) {
DeviceModel model = static_cast<DeviceModel>(getFormItemInt("fdm"));
if (web_server.hasArg(F("fdm"))) {
DeviceModel model = static_cast<DeviceModel>(getFormItemInt(F("fdm")));
if (modelMatchingFlashSize(model)) {
setFactoryDefault(model);
}
}
if (web_server.hasArg("kun")) {
ResetFactoryDefaultPreference.keepUnitName(isFormItemChecked("kun"));
if (web_server.hasArg(F("kun"))) {
ResetFactoryDefaultPreference.keepUnitName(isFormItemChecked(F("kun")));
}
if (web_server.hasArg("kw")) {
ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked("kw"));
if (web_server.hasArg(F("kw"))) {
ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked(F("kw")));
}
if (web_server.hasArg("knet")) {
ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked("knet"));
if (web_server.hasArg(F("knet"))) {
ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked(F("knet")));
}
if (web_server.hasArg("kntp")) {
ResetFactoryDefaultPreference.keepNTP(isFormItemChecked("kntp"));
if (web_server.hasArg(F("kntp"))) {
ResetFactoryDefaultPreference.keepNTP(isFormItemChecked(F("kntp")));
}
if (web_server.hasArg("klog")) {
ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked("klog"));
if (web_server.hasArg(F("klog"))) {
ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog")));
}
#endif
String error;
+4
View File
@@ -462,6 +462,10 @@ void addTextArea(const String& id, const String& value, int maxlength, int rows,
// adds a Help Button with points to the the given Wiki Subpage
// If url starts with "RTD", it will be considered as a Read-the-docs link
void addHelpButton(const __FlashStringHelper * url) {
addHelpButton(String(url));
}
void addHelpButton(const String& url) {
#ifndef WEBPAGE_TEMPLATE_HIDE_HELP_BUTTON
if (url.startsWith("RTD")) {
+1
View File
@@ -116,6 +116,7 @@ void addTextArea(const String& id, const String& value, int maxlength, int rows,
// adds a Help Button with points to the the given Wiki Subpage
// If url starts with "RTD", it will be considered as a Read-the-docs link
void addHelpButton(const __FlashStringHelper * url);
void addHelpButton(const String& url);
void addRTDHelpButton(const String& url);
+30 -14
View File
@@ -6,25 +6,31 @@
#include "../Static/WebStaticData.h"
void addButton(const String& url, const String& label) {
addButton(url, label, "");
void addButton(const __FlashStringHelper * url, const __FlashStringHelper * label) {
addButton(url, label, F(""));
}
void addButton(const String& url, const String& label, const String& classes) {
addButton(url, label, classes, true);
void addButton(const __FlashStringHelper * url, const __FlashStringHelper * label, const __FlashStringHelper * classes, bool enabled)
{
html_add_button_prefix(classes, enabled);
addHtml(url);
addHtml(F("'>"));
addHtml(label);
addHtml(F("</a>"));
}
void addButton(const String& url, const String& label)
{
addButton(url, label, F(""));
}
void addButton(const String& url, const String& label, const String& classes, bool enabled)
{
html_add_button_prefix(classes, enabled);
String html;
html.reserve(8 + url.length() + label.length());
html += url;
html += "'>";
html += label;
html += F("</a>");
addHtml(html);
addHtml(url);
addHtml(F("'>"));
addHtml(label);
addHtml(F("</a>"));
}
void addButtonWithSvg(const String& url, const String& label)
@@ -121,12 +127,22 @@ void addWideButton(const String& url, const String& label, const String& classes
void addSubmitButton()
{
addSubmitButton(F("Submit"), "");
addSubmitButton(F("Submit"), F(""));
}
// add submit button with different label and name
void addSubmitButton(const __FlashStringHelper * value, const __FlashStringHelper * name)
{
addSubmitButton(value, name, F(""));
}
void addSubmitButton(const String& value, const String& name) {
addSubmitButton(value, name, "");
addSubmitButton(value, name, F(""));
}
void addSubmitButton(const __FlashStringHelper * value, const __FlashStringHelper * name, const __FlashStringHelper * classes)
{
addSubmitButton(String(value), String(name), String(classes));
}
void addSubmitButton(const String& value, const String& name, const String& classes)
+6 -3
View File
@@ -4,12 +4,13 @@
#include "../WebServer/common.h"
void addButton(const __FlashStringHelper * url, const __FlashStringHelper * label);
void addButton(const __FlashStringHelper * url, const __FlashStringHelper * label, const __FlashStringHelper * classes, bool enabled = true);
void addButton(const String& url, const String& label);
void addButton(const String& url, const String& label, const String& classes);
void addButton(const String& url, const String& label, const String& classes, bool enabled);
void addButton(const String& url, const String& label, const String& classes, bool enabled = true);
void addButtonWithSvg(const String& url, const String& label);
@@ -28,8 +29,10 @@ void addWideButton(const String& url, const String& label, const String& classes
void addSubmitButton();
// add submit button with different label and name
void addSubmitButton(const __FlashStringHelper * value, const __FlashStringHelper * name);
void addSubmitButton(const String& value, const String& name);
void addSubmitButton(const __FlashStringHelper * value, const __FlashStringHelper * name, const __FlashStringHelper * classes);
void addSubmitButton(const String& value, const String& name, const String& classes);
// add copy to clipboard button
+27 -5
View File
@@ -29,9 +29,14 @@ void addFormSeparator(int clspan)
// ********************************************************************************
// Add a note as row start
// ********************************************************************************
void addFormNote(const __FlashStringHelper * text)
{
addFormNote(String(text));
}
void addFormNote(const String& text, const String& id)
{
addRowLabel_tr_id("", id);
addRowLabel_tr_id(F(""), id);
addHtmlDiv(F("note"), String(F("Note: ")) + text);
}
@@ -198,7 +203,7 @@ void addFormPinSelectI2C(const String& label, const String& id, int choice)
void addFormSelectorI2C(const String& id, int addressCount, const int addresses[], int selectedIndex)
{
addRowLabel_tr_id(F("I2C Address"), id);
do_addSelector_Head(id, "", "", false);
do_addSelector_Head(id, F(""), F(""), false);
for (byte x = 0; x < addressCount; x++)
{
@@ -207,7 +212,7 @@ void addFormSelectorI2C(const String& id, int addressCount, const int addresses[
if (x == 0) {
option += F(" - (default)");
}
addSelector_Item(option, addresses[x], addresses[x] == selectedIndex, false, "");
addSelector_Item(option, addresses[x], addresses[x] == selectedIndex, false, F(""));
}
addSelector_Foot();
}
@@ -251,7 +256,7 @@ void addFormSelector_script(const String& label,
const String& onChangeCall)
{
addRowLabel_tr_id(label, id);
do_addSelector_Head(id, "", onChangeCall, false);
do_addSelector_Head(id, F(""), onChangeCall, false);
addSelector_options(optionCount, options, indices, attr, selectedIndex);
addSelector_Foot();
}
@@ -323,7 +328,9 @@ void addFormPinStateSelect(int gpio, int choice)
// ********************************************************************************
// Retrieve return values from form/checkbox.
// ********************************************************************************
int getFormItemInt(const __FlashStringHelper * key, int defaultValue) {
return getFormItemInt(String(key), defaultValue);
}
int getFormItemInt(const String& key, int defaultValue) {
int value = defaultValue;
@@ -360,6 +367,11 @@ bool update_whenset_FormItemInt(const String& key, byte& value) {
// Note: Checkbox values will not appear in POST Form data if unchecked.
// So if webserver does not have an argument for a checkbox form, it means it should be considered unchecked.
bool isFormItemChecked(const __FlashStringHelper * id)
{
return isFormItemChecked(String(id));
}
bool isFormItemChecked(const String& id)
{
return web_server.arg(id) == F("on");
@@ -370,6 +382,11 @@ bool isFormItemChecked(const LabelType::Enum& id)
return isFormItemChecked(getInternalLabel(id));
}
int getFormItemInt(const __FlashStringHelper * id)
{
return getFormItemInt(String(id), 0);
}
int getFormItemInt(const String& id)
{
return getFormItemInt(id, 0);
@@ -380,6 +397,11 @@ int getFormItemInt(const LabelType::Enum& id)
return getFormItemInt(getInternalLabel(id), 0);
}
float getFormItemFloat(const __FlashStringHelper * id)
{
return getFormItemFloat(String(id));
}
float getFormItemFloat(const String& id)
{
const String val = web_server.arg(id);
+5 -1
View File
@@ -14,6 +14,7 @@ void addFormSeparator(int clspan);
// ********************************************************************************
// Add a note as row start
// ********************************************************************************
void addFormNote(const __FlashStringHelper * text);
void addFormNote(const String& text, const String& id = "");
// ********************************************************************************
@@ -133,6 +134,7 @@ void addFormPinStateSelect(int gpio, int choice);
// ********************************************************************************
int getFormItemInt(const __FlashStringHelper * key, int defaultValue);
int getFormItemInt(const String& key, int defaultValue);
bool getCheckWebserverArg_int(const String& key, int& value);
@@ -143,13 +145,15 @@ bool update_whenset_FormItemInt(const String& key, byte& value);
// Note: Checkbox values will not appear in POST Form data if unchecked.
// So if webserver does not have an argument for a checkbox form, it means it should be considered unchecked.
bool isFormItemChecked(const __FlashStringHelper * id);
bool isFormItemChecked(const String& id);
bool isFormItemChecked(const LabelType::Enum& id);
int getFormItemInt(const __FlashStringHelper * id);
int getFormItemInt(const String& id);
int getFormItemInt(const LabelType::Enum& id);
float getFormItemFloat(const __FlashStringHelper * id);
float getFormItemFloat(const String& id);
float getFormItemFloat(const LabelType::Enum& id);
+10
View File
@@ -178,6 +178,16 @@ void handle_tools() {
// ********************************************************************************
// Web Interface debug page
// ********************************************************************************
void addWideButtonPlusDescription(const __FlashStringHelper * url,
const __FlashStringHelper * buttonText,
const __FlashStringHelper * description)
{
html_TR_TD_height(30);
addWideButton(url, buttonText);
html_TD();
addHtml(description);
}
void addWideButtonPlusDescription(const String& url, const String& buttonText, const String& description)
{
html_TR_TD_height(30);
+4
View File
@@ -16,6 +16,10 @@ void handle_tools();
// ********************************************************************************
// Web Interface debug page
// ********************************************************************************
void addWideButtonPlusDescription(const __FlashStringHelper * url,
const __FlashStringHelper * buttonText,
const __FlashStringHelper * description);
void addWideButtonPlusDescription(const String& url,
const String& buttonText,
const String& description);