Skip to content

Commit e196eca

Browse files
authored
Merge pull request #2909 from TD-er/bugfix/reduce_build_size
[Build Size] Replace all TXBuffer += calls where possible
2 parents c47a0df + 9b5defe commit e196eca

31 files changed

+1889
-1041
lines changed

lib/ccronexpr/ccronexpr_test.c

Lines changed: 409 additions & 0 deletions
Large diffs are not rendered by default.

src/WebServer.ino

Lines changed: 164 additions & 116 deletions
Large diffs are not rendered by default.

src/WebServer_AdvancedConfigPage.ino

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void handle_advanced() {
8282
}
8383
}
8484

85-
TXBuffer += F("<form method='post'>");
85+
addHtml(F("<form method='post'>"));
8686
html_table_class_normal();
8787

8888
addFormHeader(F("Advanced Settings"), F("RTDTools/Tools.html#advanced"));
@@ -150,10 +150,10 @@ void handle_advanced() {
150150
// TODO sort settings in groups or move to other pages/groups
151151
addFormSubHeader(F("Special and Experimental Settings"));
152152

153-
addFormNumericBox(F("Fixed IP Octet"), F("ip"), Settings.IP_Octet, 0, 255);
153+
addFormNumericBox(F("Fixed IP Octet"), F("ip"), Settings.IP_Octet, 0, 255);
154154

155-
addFormNumericBox(F("WD I2C Address"), F("wdi2caddress"), Settings.WDI2CAddress, 0, 127);
156-
TXBuffer += F(" (decimal)");
155+
addFormNumericBox(F("WD I2C Address"), F("wdi2caddress"), Settings.WDI2CAddress, 0, 127);
156+
addHtml(F(" (decimal)"));
157157

158158
addFormNumericBox(F("I2C ClockStretchLimit"), F("wireclockstretchlimit"), Settings.WireClockStretchLimit); // TODO define limits
159159
#if defined(FEATURE_ARDUINO_OTA)
@@ -164,8 +164,8 @@ void handle_advanced() {
164164
#endif // if defined(ESP32)
165165

166166
#ifdef USES_SSDP
167-
addFormCheckBox_disabled(F("Use SSDP"), F("usessdp"), Settings.UseSSDP);
168-
#endif
167+
addFormCheckBox_disabled(F("Use SSDP"), F("usessdp"), Settings.UseSSDP);
168+
#endif // ifdef USES_SSDP
169169

170170
addFormNumericBox(getLabel(LabelType::CONNECTION_FAIL_THRESH), F("cft"), Settings.ConnectionFailuresThreshold, 0, 100);
171171
#ifdef ESP8266
@@ -192,7 +192,7 @@ void handle_advanced() {
192192
html_TR_TD();
193193
html_TD();
194194
addSubmitButton();
195-
TXBuffer += F("<input type='hidden' name='edit' value='1'>");
195+
addHtml(F("<input type='hidden' name='edit' value='1'>"));
196196
html_end_table();
197197
html_end_form();
198198
sendHeadandTail_stdtemplate(true);
@@ -224,10 +224,10 @@ void addFormDstSelect(bool isStart, uint16_t choice) {
224224
}
225225
TimeChangeRule rule(isStart ? tmpstart : tmpend, 0);
226226
addRowLabel(weeklabel);
227-
addSelector(weekid, 5, week, weekValues, NULL, rule.week, false);
228-
TXBuffer += F("<BR>");
229-
addSelector(dowid, 7, dow, dowValues, NULL, rule.dow, false);
230-
TXBuffer += F("<BR>");
227+
addSelector(weekid, 5, week, weekValues, NULL, rule.week, false);
228+
html_BR();
229+
addSelector(dowid, 7, dow, dowValues, NULL, rule.dow, false);
230+
html_BR();
231231
addSelector(monthid, 12, month, monthValues, NULL, rule.month, false);
232232

233233
addFormNumericBox(hourlabel, hourid, rule.hour, 0, 23);
@@ -263,8 +263,8 @@ void addFormLogFacilitySelect(const String& label, const String& id, int choice)
263263
void addLogFacilitySelect(const String& name, int choice)
264264
{
265265
String options[12] =
266-
{ F("Kernel"), F("User"), F("Daemon"), F("Message"), F("Local0"), F("Local1"),
267-
F("Local2"), F("Local3"), F("Local4"), F("Local5"), F("Local6"), F("Local7") };
266+
{ F("Kernel"), F("User"), F("Daemon"), F("Message"), F("Local0"), F("Local1"),
267+
F("Local2"), F("Local3"), F("Local4"), F("Local5"), F("Local6"), F("Local7") };
268268
int optionValues[12] = { 0, 1, 3, 5, 16, 17, 18, 19, 20, 21, 22, 23 };
269269

270270
addSelector(name, 12, options, optionValues, NULL, choice, false);

src/WebServer_CacheControllerPages.ino

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifdef USES_C016
22

33
// ********************************************************************************
4-
// URLs needed for C016_CacheController
4+
// URLs needed for C016_CacheController
55
// to help dump the content of the binary log files
66
// ********************************************************************************
77
void handle_dumpcache() {
@@ -19,19 +19,19 @@ void handle_dumpcache() {
1919
float val4;
2020

2121
TXBuffer.startStream();
22-
TXBuffer += F("UNIX timestamp;contr. idx;sensortype;taskindex;value count");
22+
addHtml(F("UNIX timestamp;contr. idx;sensortype;taskindex;value count"));
2323

2424
for (taskIndex_t i = 0; i < TASKS_MAX; ++i) {
2525
LoadTaskSettings(i);
2626

2727
for (int j = 0; j < VARS_PER_TASK; ++j) {
28-
TXBuffer += ';';
29-
TXBuffer += ExtraTaskSettings.TaskDeviceName;
30-
TXBuffer += '#';
31-
TXBuffer += ExtraTaskSettings.TaskDeviceValueNames[j];
28+
addHtml(";");
29+
addHtml(ExtraTaskSettings.TaskDeviceName);
30+
addHtml("#");
31+
addHtml(ExtraTaskSettings.TaskDeviceValueNames[j]);
3232
}
3333
}
34-
TXBuffer += F("<BR>");
34+
html_BR();
3535
float csv_values[VARS_PER_TASK * TASKS_MAX];
3636

3737
for (int i = 0; i < VARS_PER_TASK * TASKS_MAX; ++i) {
@@ -40,64 +40,71 @@ void handle_dumpcache() {
4040

4141
while (C016_getCSVline(timestamp, controller_idx, TaskIndex, sensorType,
4242
valueCount, val1, val2, val3, val4)) {
43-
TXBuffer += timestamp;
44-
TXBuffer += ';';
45-
TXBuffer += controller_idx;
46-
TXBuffer += ';';
47-
TXBuffer += sensorType;
48-
TXBuffer += ';';
49-
TXBuffer += TaskIndex;
50-
TXBuffer += ';';
51-
TXBuffer += valueCount;
43+
{
44+
String html;
45+
html.reserve(64);
46+
html += timestamp;
47+
html += ';';
48+
html += controller_idx;
49+
html += ';';
50+
html += sensorType;
51+
html += ';';
52+
html += TaskIndex;
53+
html += ';';
54+
html += valueCount;
55+
addHtml(html);
56+
}
5257
int valindex = TaskIndex * VARS_PER_TASK;
5358
csv_values[valindex++] = val1;
5459
csv_values[valindex++] = val2;
5560
csv_values[valindex++] = val3;
5661
csv_values[valindex++] = val4;
5762

5863
for (int i = 0; i < VARS_PER_TASK * TASKS_MAX; ++i) {
59-
TXBuffer += ';';
64+
String html;
65+
html.reserve(12);
66+
html += ';';
6067

6168
if (csv_values[i] == 0.0) {
62-
TXBuffer += '0';
69+
html += '0';
6370
} else {
64-
TXBuffer += String(csv_values[i], 6);
71+
html += String(csv_values[i], 6);
6572
}
73+
addHtml(html);
6674
}
67-
TXBuffer += F("<BR>");
75+
html_BR();
6876
delay(0);
6977
}
7078
TXBuffer.endStream();
71-
7279
}
7380

7481
void handle_cache_json() {
7582
if (!isLoggedIn()) { return; }
7683

7784
TXBuffer.startJsonStream();
78-
TXBuffer += F("{\"columns\": [");
85+
addHtml(F("{\"columns\": ["));
7986

80-
// TXBuffer += F("UNIX timestamp;contr. idx;sensortype;taskindex;value count");
87+
// addHtml(F("UNIX timestamp;contr. idx;sensortype;taskindex;value count"));
8188
stream_to_json_value(F("UNIX timestamp"));
82-
TXBuffer += ',';
89+
addHtml(",");
8390
stream_to_json_value(F("UTC timestamp"));
84-
TXBuffer += ',';
91+
addHtml(",");
8592
stream_to_json_value(F("task index"));
8693

8794
for (taskIndex_t i = 0; i < TASKS_MAX; ++i) {
8895
LoadTaskSettings(i);
8996

9097
for (int j = 0; j < VARS_PER_TASK; ++j) {
9198
String label = ExtraTaskSettings.TaskDeviceName;
92-
label += '#';
93-
label += ExtraTaskSettings.TaskDeviceValueNames[j];
94-
TXBuffer += ',';
99+
label += '#';
100+
label += ExtraTaskSettings.TaskDeviceValueNames[j];
101+
addHtml(",");
95102
stream_to_json_value(label);
96103
}
97104
}
98-
TXBuffer += F("],\n");
105+
addHtml(F("],\n"));
99106
C016_startCSVdump();
100-
TXBuffer += F("\"files\": [");
107+
addHtml(F("\"files\": ["));
101108
bool islast = false;
102109
int filenr = 0;
103110

@@ -106,15 +113,15 @@ void handle_cache_json() {
106113

107114
if (currentFile.length() > 0) {
108115
if (filenr != 0) {
109-
TXBuffer += ',';
116+
addHtml(",");
110117
}
111118
stream_to_json_value(currentFile);
112119
++filenr;
113120
}
114121
}
115-
TXBuffer += F("],\n");
122+
addHtml(F("],\n"));
116123
stream_last_json_object_value(F("nrfiles"), String(filenr));
117-
TXBuffer += F("\n");
124+
addHtml(F("\n"));
118125
TXBuffer.endStream();
119126
}
120127

src/WebServer_ConfigPage.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void handle_config() {
3838

3939
if (CPluginCall(CPlugin::Function::CPLUGIN_GOT_INVALID, 0)) { // inform controllers that the old name will be invalid from now on.
4040
#ifdef USES_MQTT
41-
MQTTDisconnect(); // disconnect form MQTT Server if invalid message was sent succesfull.
41+
MQTTDisconnect(); // disconnect form MQTT Server if invalid message was sent succesfull.
4242
#endif // USES_MQTT
4343
}
4444
#ifdef USES_MQTT

src/WebServer_ControlPage.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ void handle_control() {
1919
#endif // ifndef BUILD_NO_DEBUG
2020

2121
bool handledCmd = false;
22+
2223
// in case of event, store to buffer and return...
2324
String command = parseString(webrequest, 1);
24-
if (command == F("event") || command == F("asyncevent"))
25+
26+
if ((command == F("event")) || (command == F("asyncevent")))
2527
{
2628
eventQueue.add(parseStringToEnd(webrequest, 2));
27-
handledCmd = true;
29+
handledCmd = true;
2830
}
2931
else if (command.equalsIgnoreCase(F("taskrun")) ||
3032
command.equalsIgnoreCase(F("taskvalueset")) ||
@@ -39,7 +41,7 @@ void handle_control() {
3941

4042
if (handledCmd) {
4143
TXBuffer.startStream("*");
42-
TXBuffer += "OK";
44+
addHtml(F("OK"));
4345
TXBuffer.endStream();
4446
return;
4547
}
@@ -55,10 +57,10 @@ void handle_control() {
5557
}
5658

5759
if (unknownCmd) {
58-
TXBuffer += F("Unknown or restricted command!");
60+
addHtml(F("Unknown or restricted command!"));
5961
}
6062
else {
61-
TXBuffer += printWebString;
63+
addHtml(printWebString);
6264
}
6365

6466
TXBuffer.endStream();

src/WebServer_ControllerPage.ino

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ void handle_controllers() {
5454
if (mustInit) {
5555
// Init controller plugin using the new settings.
5656
protocolIndex_t ProtocolIndex = getProtocolIndex_from_ControllerIndex(controllerindex);
57+
5758
if (validProtocolIndex(ProtocolIndex)) {
5859
struct EventStruct TempEvent;
5960
TempEvent.ControllerIndex = controllerindex;
6061
String dummy;
61-
byte cfunction = Settings.ControllerEnabled[controllerindex] ? CPlugin::Function::CPLUGIN_INIT : CPlugin::Function::CPLUGIN_EXIT;
62+
byte cfunction = Settings.ControllerEnabled[controllerindex] ? CPlugin::Function::CPLUGIN_INIT : CPlugin::Function::CPLUGIN_EXIT;
6263
CPluginCall(ProtocolIndex, static_cast<CPlugin::Function>(cfunction), &TempEvent, dummy);
6364
}
6465
}
@@ -88,6 +89,7 @@ void handle_controllers_clearLoadDefaults(byte controllerindex, ControllerSettin
8889
// Protocol has changed and it was not an empty one.
8990
// reset (some) default-settings
9091
protocolIndex_t ProtocolIndex = getProtocolIndex(Settings.Protocol[controllerindex]);
92+
9193
if (!validProtocolIndex(ProtocolIndex)) {
9294
return;
9395
}
@@ -129,6 +131,7 @@ void handle_controllers_CopySubmittedSettings(byte controllerindex, ControllerSe
129131
}
130132

131133
protocolIndex_t ProtocolIndex = getProtocolIndex_from_ControllerIndex(controllerindex);
134+
132135
if (validProtocolIndex(ProtocolIndex)) {
133136
struct EventStruct TempEvent;
134137
TempEvent.ControllerIndex = controllerindex;
@@ -160,48 +163,53 @@ void handle_controllers_ShowAllControllersTable()
160163
const bool cplugin_set = Settings.Protocol[x] != INVALID_C_PLUGIN_ID;
161164

162165

163-
164166
LoadControllerSettings(x, ControllerSettings);
165167
html_TR_TD();
168+
166169
if (cplugin_set && !supportedCPluginID(Settings.Protocol[x])) {
167170
html_add_button_prefix(F("red"), true);
168171
} else {
169172
html_add_button_prefix();
170-
}
171-
TXBuffer += F("controllers?index=");
172-
TXBuffer += x + 1;
173-
TXBuffer += F("'>");
174-
if (cplugin_set) {
175-
TXBuffer += F("Edit");
176-
} else {
177-
TXBuffer += F("Add");
178173
}
179-
TXBuffer += F("</a>");
180-
html_TD();
181-
TXBuffer += getControllerSymbol(x);
174+
{
175+
String html;
176+
html.reserve(32);
177+
html += F("controllers?index=");
178+
html += x + 1;
179+
html += F("'>");
180+
181+
if (cplugin_set) {
182+
html += F("Edit");
183+
} else {
184+
html += F("Add");
185+
}
186+
html += F("</a><TD>");
187+
html += getControllerSymbol(x);
188+
addHtml(html);
189+
}
182190
html_TD();
183191

184192
if (cplugin_set)
185193
{
186194
addEnabled(Settings.ControllerEnabled[x]);
187195

188196
html_TD();
189-
TXBuffer += getCPluginNameFromCPluginID(Settings.Protocol[x]);
197+
addHtml(getCPluginNameFromCPluginID(Settings.Protocol[x]));
190198
html_TD();
191199
{
192200
const protocolIndex_t ProtocolIndex = getProtocolIndex_from_ControllerIndex(x);
193201
String hostDescription;
194202
CPluginCall(ProtocolIndex, CPlugin::Function::CPLUGIN_WEBFORM_SHOW_HOST_CONFIG, 0, hostDescription);
195203

196204
if (hostDescription.length() != 0) {
197-
TXBuffer += hostDescription;
205+
addHtml(hostDescription);
198206
} else {
199-
TXBuffer += ControllerSettings.getHost();
207+
addHtml(ControllerSettings.getHost());
200208
}
201209
}
202210

203211
html_TD();
204-
TXBuffer += ControllerSettings.Port;
212+
addHtml(String(ControllerSettings.Port));
205213
}
206214
else {
207215
html_TD(3);
@@ -271,9 +279,11 @@ void handle_controllers_ControllerSettingsPage(controllerIndex_t controllerindex
271279
addControllerParameterForm(ControllerSettings, controllerindex, CONTROLLER_MAX_RETRIES);
272280
addControllerParameterForm(ControllerSettings, controllerindex, CONTROLLER_FULL_QUEUE_ACTION);
273281
}
282+
274283
if (Protocol[ProtocolIndex].usesCheckReply) {
275284
addControllerParameterForm(ControllerSettings, controllerindex, CONTROLLER_CHECK_REPLY);
276285
}
286+
277287
if (Protocol[ProtocolIndex].usesTimeout) {
278288
addControllerParameterForm(ControllerSettings, controllerindex, CONTROLLER_TIMEOUT);
279289
}

0 commit comments

Comments
 (0)