Skip to content

Commit

Permalink
[Build] Reduce build size by doing less flash string conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Sep 19, 2022
1 parent 19ee72d commit 01bee9e
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 290 deletions.
40 changes: 14 additions & 26 deletions src/_P001_Switch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,10 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("SW : GPIO=");
log += CONFIG_PIN1;
log += F(" State=");
log += state ? '1' : '0';
log += output_value == 3 ? F(" Doubleclick=") : F(" Output value=");
log += output_value;
addLogMove(LOG_LEVEL_INFO, log);
addLogMove(LOG_LEVEL_INFO,
concat(F("SW : GPIO="), CONFIG_PIN1) +
concat(F(" State="), state ? '1' : '0') +
concat(output_value == 3 ? F(" Doubleclick=") : F(" Output value="), output_value));
}
# endif // ifndef BUILD_NO_DEBUG

Expand Down Expand Up @@ -574,13 +571,10 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("SW : LongPress: GPIO= ");
log += CONFIG_PIN1;
log += F(" State=");
log += state ? '1' : '0';
log += F(" Output value=");
log += output_value;
addLogMove(LOG_LEVEL_INFO, log);
addLogMove(LOG_LEVEL_INFO,
concat(F("SW : LongPress: GPIO= "), CONFIG_PIN1) +
concat(F(" State="), state ? '1' : '0') +
concat(F(" Output value="), output_value));
}
# endif // ifndef BUILD_NO_DEBUG

Expand Down Expand Up @@ -609,11 +603,9 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("SW : SafeButton: false positive detected. GPIO= ");
log += CONFIG_PIN1;
log += F(" State=");
log += tempUserVar;
addLogMove(LOG_LEVEL_INFO, log);
addLogMove(LOG_LEVEL_INFO,
concat(F("SW : SafeButton: false positive detected. GPIO= "), CONFIG_PIN1) +
concat(F(" State="), tempUserVar));
}
# endif // ifndef BUILD_NO_DEBUG

Expand Down Expand Up @@ -668,9 +660,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("SW : State ");
log += UserVar[event->BaseVarIndex];
addLogMove(LOG_LEVEL_INFO, log);
addLogMove(LOG_LEVEL_INFO, concat(F("SW : State "), static_cast<int>(UserVar[event->BaseVarIndex])));
}
# endif // ifndef BUILD_NO_DEBUG
success = true;
Expand All @@ -679,7 +669,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_WRITE:
{
String command = parseString(string, 1);
const String command(parseString(string, 1));

// WARNING: don't read "globalMapPortStatus[key]" here, as it will create a new entry if key does not exist

Expand All @@ -689,9 +679,7 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)

// @giig1967g deprecated since 2019-11-26
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
String log = F("inputswitchstate is deprecated");
log += string;
addLogMove(LOG_LEVEL_ERROR, log);
addLogMove(LOG_LEVEL_ERROR, concat(F("inputswitchstate is deprecated"), string));
}

/* portStatusStruct tempStatus;
Expand Down
8 changes: 4 additions & 4 deletions src/_P016_IR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
html_TD();
{ // Decode type
addSelector(getPluginCustomArgName(rowCnt + 0), protocolCount, &decodeTypes[0], &decodeTypeOptions[0], nullptr,
static_cast<int>(line.CodeDecodeType), false, true, EMPTY_STRING);
static_cast<int>(line.CodeDecodeType), false, true, F(""));
}
html_TD();
addCheckBox(getPluginCustomArgName(rowCnt + 1), bitRead(line.CodeFlags, P16_FLAGS_REPEAT));
Expand All @@ -421,12 +421,12 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
if (line.Code > 0) {
strCode = uint64ToString(line.Code, 16); // convert code to hex for display
}
addTextBox(getPluginCustomArgName(rowCnt + 2), strCode, P16_Cchars - 1, false, false, P016_HEX_INPUT_PATTERN, EMPTY_STRING);
addTextBox(getPluginCustomArgName(rowCnt + 2), strCode, P16_Cchars - 1, false, false, P016_HEX_INPUT_PATTERN, F(""));

html_TD();
{
addSelector(getPluginCustomArgName(rowCnt + 3), protocolCount, &decodeTypes[0], &decodeTypeOptions[0], nullptr,
static_cast<int>(line.AlternativeCodeDecodeType), false, true, EMPTY_STRING);
static_cast<int>(line.AlternativeCodeDecodeType), false, true, F(""));
}
html_TD();
addCheckBox(getPluginCustomArgName(rowCnt + 4), bitRead(line.AlternativeCodeFlags, P16_FLAGS_REPEAT));
Expand All @@ -436,7 +436,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
if (line.AlternativeCode > 0) {
strCode = uint64ToString(line.AlternativeCode, 16); // convert code to hex for display
}
addTextBox(getPluginCustomArgName(rowCnt + 5), strCode, P16_Cchars - 1, false, false, P016_HEX_INPUT_PATTERN, EMPTY_STRING);
addTextBox(getPluginCustomArgName(rowCnt + 5), strCode, P16_Cchars - 1, false, false, P016_HEX_INPUT_PATTERN, F(""));

html_TR(); // Separate row for the command input

Expand Down
4 changes: 2 additions & 2 deletions src/_P087_SerialProxy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ void P087_html_show_matchForms(struct EventStruct *event) {
options[P087_Filter_Comp::Equal] = F("==");
options[P087_Filter_Comp::NotEqual] = F("!=");
int optionValues[2] = { P087_Filter_Comp::Equal, P087_Filter_Comp::NotEqual };
addSelector(id, 2, options, optionValues, nullptr, static_cast<int>(comparator), false, true, EMPTY_STRING);
addSelector(id, 2, options, optionValues, nullptr, static_cast<int>(comparator), false, true, F(""));
break;
}
case 2:
{
// Compare with
addTextBox(id, filter, 32, false, false, EMPTY_STRING, EMPTY_STRING);
addTextBox(id, filter, 32, false, false, EMPTY_STRING, F(""));
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/_P094_CULReader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void P094_html_show_matchForms(struct EventStruct *event) {
options[i] = P094_data_struct::P094_FilterValueType_toString(filterValueType);
optionValues[i] = filterValueType;
}
addSelector(id, P094_FILTER_VALUE_Type_NR_ELEMENTS, options, optionValues, nullptr, capture, false, true, EMPTY_STRING);
addSelector(id, P094_FILTER_VALUE_Type_NR_ELEMENTS, options, optionValues, nullptr, capture, false, true, F(""));
}

break;
Expand All @@ -426,13 +426,13 @@ void P094_html_show_matchForms(struct EventStruct *event) {
options[i] = P094_data_struct::P094_FilterComp_toString(enumValue);
optionValues[i] = enumValue;
}
addSelector(id, P094_FILTER_COMP_NR_ELEMENTS, options, optionValues, nullptr, comparator, false, true, EMPTY_STRING);
addSelector(id, P094_FILTER_COMP_NR_ELEMENTS, options, optionValues, nullptr, comparator, false, true, F(""));
break;
}
case 3:
{
// Compare with
addTextBox(id, filter, 8, false, false, EMPTY_STRING, EMPTY_STRING);
addTextBox(id, filter, 8, false, false, EMPTY_STRING, F(""));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P099_XPT2046Touch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ boolean Plugin_099(uint8_t function, struct EventStruct *event, String& string)
addTextBox(getPluginCustomArgName(objectNr),
String(P099_data->StoredSettings.TouchObjects[objectNr].objectname),
P099_MaxObjectNameLength - 1,
false, false, EMPTY_STRING, EMPTY_STRING);
false, false, EMPTY_STRING, F(""));
html_TD();
addNumericBox(getPluginCustomArgName(objectNr + 100), P099_data->StoredSettings.TouchObjects[objectNr].top_left.x, 0, 65535);
html_TD();
Expand Down
6 changes: 3 additions & 3 deletions src/_P131_NeoPixelMatrix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string)
false,
false,
EMPTY_STRING,
EMPTY_STRING);
F(""));

String opts = parseString(strings[varNr], 2);
uint32_t optBits = 0;
Expand All @@ -248,7 +248,7 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string)
html_TD(); // Pixels per step, offset with -1
addNumericBox(getPluginCustomArgName(varNr + 400), get4BitFromUL(optBits, P131_OPTBITS_SCROLLSTEP) + 1, 1, P131_MAX_SCROLL_STEPS
# if FEATURE_TOOLTIPS
, EMPTY_STRING, F("Scroll 1..16 pixels / step")
, F(""), F("Scroll 1..16 pixels / step")
# endif // if FEATURE_TOOLTIPS
);

Expand All @@ -260,7 +260,7 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string)
html_TD(); // Speed 0.1 seconds per step
addNumericBox(getPluginCustomArgName(varNr + 500), scrollSpeed, 1, P131_MAX_SCROLL_SPEED
# if FEATURE_TOOLTIPS
, EMPTY_STRING, F("Scroll-speed in 0.1 seconds / step")
, F(""), F("Scroll-speed in 0.1 seconds / step")
# endif // if FEATURE_TOOLTIPS
);

Expand Down
2 changes: 1 addition & 1 deletion src/_Plugin_Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool pluginOptionalTaskIndexArgumentMatch(taskIndex_t taskIndex, const String& s
}

bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex,
const String& newline,
const __FlashStringHelper * newline,
String& description)
{
struct EventStruct TempEvent(taskIndex);
Expand Down
8 changes: 4 additions & 4 deletions src/_Plugin_Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ int getFormItemIntCustomArgName(int varNr);
// The call to PLUGIN_WEBFORM_SHOW_VALUES should only return success = true when no regular values should be displayed
// Note that the varNr of the custom values should not conflict with the existing variable numbers (e.g. start at VARS_PER_TASK)
void pluginWebformShowValue(taskIndex_t taskIndex,
uint8_t varNr,
uint8_t varNr,
const __FlashStringHelper * label,
const String& value,
bool addTrailingBreak = false);

void pluginWebformShowValue(taskIndex_t taskIndex,
uint8_t varNr,
uint8_t varNr,
const String& label,
const String& value,
bool addTrailingBreak = false);
Expand All @@ -144,10 +144,10 @@ void pluginWebformShowValue(const String& valName,
// Return if parameter at given paramNr matches given taskIndex.
bool pluginOptionalTaskIndexArgumentMatch(taskIndex_t taskIndex,
const String& string,
uint8_t paramNr);
uint8_t paramNr);

bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex,
const String& newline,
const __FlashStringHelper * newline,
String& description);

int getValueCountForTask(taskIndex_t taskIndex);
Expand Down
9 changes: 4 additions & 5 deletions src/src/Commands/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ String Command_GetORSetIP(struct EventStruct *event,
hasArgument = true;

if (!str2ip(TmpStr1, IP)) {
String result = F("Invalid parameter: ");
result += TmpStr1;
return return_result(event, result);
return return_result(event, concat(F("Invalid parameter: "), TmpStr1));
}
}
}
Expand Down Expand Up @@ -114,8 +112,7 @@ String Command_GetORSetString(struct EventStruct *event,
hasArgument = true;

if (TmpStr1.length() > len) {
String result = targetDescription;
result += F(" is too large. max size is ");
String result = concat(targetDescription, F(" is too large. max size is "));
result += len;
serialPrintln();
return return_result(event, result);
Expand Down Expand Up @@ -167,6 +164,7 @@ String Command_GetORSetBool(struct EventStruct *event,
return return_command_success();
}

#if FEATURE_ETHERNET
String Command_GetORSetETH(struct EventStruct *event,
const __FlashStringHelper * targetDescription,
const __FlashStringHelper * valueToString,
Expand Down Expand Up @@ -211,6 +209,7 @@ String Command_GetORSetETH(struct EventStruct *event,
}
return return_result(event, result);
}
#endif

String Command_GetORSetInt8_t(struct EventStruct *event,
const __FlashStringHelper * targetDescription,
Expand Down
2 changes: 2 additions & 0 deletions src/src/Commands/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ String Command_GetORSetBool(struct EventStruct *event,
bool *value,
int arg);

#if FEATURE_ETHERNET
String Command_GetORSetETH(struct EventStruct *event,
const __FlashStringHelper * targetDescription,
const __FlashStringHelper * valueToString,
const char *Line,
uint8_t *value,
int arg);
#endif

String Command_GetORSetInt8_t(struct EventStruct *event,
const __FlashStringHelper * targetDescription,
Expand Down
16 changes: 4 additions & 12 deletions src/src/Commands/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,17 @@ void debugPortStatus(std::map<uint32_t, portStatusStruct>::iterator it)
createLogPortStatus(it);
}

void logPortStatus(const String& from) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log;

log = F("PortStatus structure: Called from=");
log += from;
log += F(" Count=");
log += globalMapPortStatus.size();
addLogMove(LOG_LEVEL_INFO, log);
const __FlashStringHelper * Command_logPortStatus(struct EventStruct *event, const char *Line)
{
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLogMove(LOG_LEVEL_INFO, concat(F("PortStatus structure: Called from=Rules Count="), globalMapPortStatus.size()));
}

for (std::map<uint32_t, portStatusStruct>::iterator it = globalMapPortStatus.begin(); it != globalMapPortStatus.end(); ++it) {
debugPortStatus(it);
}
}

const __FlashStringHelper * Command_logPortStatus(struct EventStruct *event, const char *Line)
{
logPortStatus("Rules");
return return_command_success();
}
#endif // BUILD_NO_DIAGNOSTIC_COMMANDS
1 change: 0 additions & 1 deletion src/src/Commands/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const __FlashStringHelper * Command_logentry(struct EventStruct *event, const ch
const __FlashStringHelper * Command_JSONPortStatus(struct EventStruct *event, const char* Line);
//void createLogPortStatus(std::map< uint32_t, portStatusStruct >::iterator it);
//void debugPortStatus(std::map< uint32_t, portStatusStruct >::iterator it);
void logPortStatus(const String& from);
const __FlashStringHelper * Command_logPortStatus(struct EventStruct *event, const char* Line);
#endif

Expand Down
Loading

0 comments on commit 01bee9e

Please sign in to comment.