[Cleanup] Use flash strings where needed or chars for single char string

This commit is contained in:
TD-er
2022-02-05 10:40:46 +01:00
parent 401de1f492
commit 4a9d0bcaae
32 changed files with 99 additions and 91 deletions
+11 -9
View File
@@ -3,30 +3,32 @@
#define DETECT_BAUDATE_TIMEOUT 250
#include <Arduino.h>
String ESPeasySerial::getLogString() const {
String log;
log.reserve(48);
log = "ESPEasy serial: ";
log = F("ESPEasy serial: ");
if (isI2Cserial()) {
log += "I2C: addr:";
log += F("I2C: addr:");
log += String(_receivePin);
log += " ch:";
log += _transmitPin == 0 ? "A" : "B";
log += F(" ch:");
log += _transmitPin == 0 ? 'A' : 'B';
} else {
if (isSWserial()) {
log += "SW";
log += F("SW");
} else {
log += "HW";
log += F("HW");
}
log += ": rx:";
log += F(": rx:");
log += String(_receivePin);
log += " tx:";
log += F(" tx:");
log += String(_transmitPin);
}
log += " baud:";
log += F(" baud:");
log += String(_baud);
return log;
}
+11 -8
View File
@@ -802,7 +802,7 @@ String IthoCC1101::getLastIDstr(bool ashex) {
for (uint8_t i = 0; i < 3; i++) {
if (ashex) str += String(inIthoPacket.deviceId[i], HEX);
else str += String(inIthoPacket.deviceId[i]);
if (i < 2) str += ",";
if (i < 2) str += ',';
}
return str;
}
@@ -816,11 +816,13 @@ int * IthoCC1101::getLastID() {
}
String IthoCC1101::getLastMessagestr(bool ashex) {
String str = "Length=" + String(inMessage.length) + ".";
String str = F("Length=");
str += inMessage.length;
str += '.';
for (uint8_t i = 0; i < inMessage.length; i++) {
if (ashex) str += String(inMessage.data[i], HEX);
else str += String(inMessage.data[i]);
if (i < inMessage.length - 1) str += ":";
if (i < inMessage.length - 1) str += ':';
}
return str;
}
@@ -829,22 +831,23 @@ String IthoCC1101::LastMessageDecoded() {
String str;
if (inIthoPacket.length > 11) {
str += "Device type?: " + String(inIthoPacket.deviceType);
str += " - CMD: ";
str += F("Device type?: ");
str += String(inIthoPacket.deviceType);
str += F(" - CMD: ");
for (int i = 4; i < inIthoPacket.length; i++) {
str += String(inIthoPacket.dataDecoded[i]);
if (i < inIthoPacket.length - 1) str += ",";
if (i < inIthoPacket.length - 1) str += ',';
}
}
else {
for (uint8_t i = 0; i < inIthoPacket.length; i++) {
str += String(inIthoPacket.dataDecoded[i]);
if (i < inIthoPacket.length - 1) str += ",";
if (i < inIthoPacket.length - 1) str += ',';
}
}
str += "\n";
str += '\n';
return str;
}
+1 -1
View File
@@ -345,7 +345,7 @@ private:
if (error.length() > 0) {
String log = F("RN2483: ");
log += command;
log += ": ";
log += F(": ");
log += error;
addLog(LOG_LEVEL_INFO, log);
}
+9 -9
View File
@@ -161,11 +161,11 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string)
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log += F(" HSV converted to RGB(W):");
log += rgbw[0];
log += ",";
log += ',';
log += rgbw[1];
log += ",";
log += ',';
log += rgbw[2];
log += ",";
log += ',';
log += rgbw[3];
addLog(LOG_LEVEL_INFO,log);
}
@@ -200,11 +200,11 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string)
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log += F(" HSV converted to RGB(W):");
log += rgbw[0];
log += ",";
log += ',';
log += rgbw[1];
log += ",";
log += ',';
log += rgbw[2];
log += ",";
log += ',';
log += rgbw[3];
addLog(LOG_LEVEL_INFO,log);
}
@@ -247,11 +247,11 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string)
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log += F(" HSV converted to RGB(W):");
log += rgbw[0];
log += ",";
log += ',';
log += rgbw[1];
log += ",";
log += ',';
log += rgbw[2];
log += ",";
log += ',';
log += rgbw[3];
addLog(LOG_LEVEL_INFO,log);
}
+1 -1
View File
@@ -308,7 +308,7 @@ boolean Plugin_064(uint8_t function, struct EventStruct *event, String& string)
case DIR_FAR: log += F("FAR"); break;
default: log += F("NONE"); break;
}
log += " (";
log += F(" (");
log += gesture;
log += ')';
+6 -6
View File
@@ -1384,9 +1384,9 @@ bool p073_plugin_write_7dst(struct EventStruct *event) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("7DGT : Show Time=");
log += event->Par1;
log += ":";
log += ':';
log += event->Par2;
log += ":";
log += ':';
log += event->Par3;
addLog(LOG_LEVEL_INFO, log);
}
@@ -1427,9 +1427,9 @@ bool p073_plugin_write_7dsd(struct EventStruct *event) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("7DGT : Show Date=");
log += event->Par1;
log += "-";
log += '-';
log += event->Par2;
log += "-";
log += '-';
log += event->Par3;
addLog(LOG_LEVEL_INFO, log);
}
@@ -1662,9 +1662,9 @@ void tm1637_i2cAck(uint8_t clk_pin, uint8_t dio_pin) {
String log = F("7DGT : Comm ACK=");
if (dummyAck == 0) {
log += "TRUE";
log += F("TRUE");
} else {
log += "FALSE";
log += F("FALSE");
}
addLog(LOG_LEVEL_DEBUG, log);
# endif // ifdef P073_DEBUG
+2 -2
View File
@@ -440,9 +440,9 @@ boolean Plugin_075(uint8_t function, struct EventStruct *event, String& string)
log.reserve(70); // Prevent re-allocation
log = F("NEXTION075 : code: ");
log += __buffer[1];
log += ",";
log += ',';
log += __buffer[2];
log += ",";
log += ',';
log += __buffer[3];
addLog(LOG_LEVEL_INFO, log);
#endif
+2 -2
View File
@@ -293,9 +293,9 @@ float p078_readVal(uint8_t query, uint8_t node, unsigned int model) {
log += node;
log += ',';
log += model;
log += ") ";
log += F(") ");
log += p078_getQueryString(query);
log += ": ";
log += F(": ");
log += _tempvar;
addLog(LOG_LEVEL_INFO, log);
}
+2 -1
View File
@@ -370,7 +370,8 @@ boolean Plugin_096(uint8_t function, struct EventStruct *event, String& string)
#ifndef BUILD_NO_DEBUG
s.add(usecPassedSince(statisticsTimerStart));
tmpString += "<br/> Display timings = " + toString(s.getAvg());
tmpString += F("<br/> Display timings = ");
tmpString += toString(s.getAvg());
#endif
P096_data->eInkScreen.clearBuffer();
P096_data->plugin_096_sequence_in_progress = false;
@@ -179,7 +179,7 @@ struct ControllerDelayHandlerStruct {
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
const cpluginID_t cpluginID = getCPluginID_from_ControllerIndex(element.controller_idx);
String log = get_formatted_Controller_number(cpluginID);
log += " : queue full";
log += F(" : queue full");
addLog(LOG_LEVEL_DEBUG, log);
}
#endif // ifndef BUILD_NO_DEBUG
@@ -158,7 +158,7 @@ bool ControllerSettingsStruct::beginPacket(WiFiUDP& client) {
String ControllerSettingsStruct::getHostPortString() const {
String result = getHost();
result += ":";
result += ':';
result += Port;
return result;
}
+1 -1
View File
@@ -75,7 +75,7 @@ String LogStruct::formatLine(int index, const String& lineEnd) {
String output;
output += timeStamp[index];
output += " : ";
output += F(" : ");
output += Message[index];
output += lineEnd;
return output;
+2 -1
View File
@@ -156,7 +156,8 @@ bool Modbus::handle() {
break;
}
LogString += "value: "; LogString += result;
LogString += F("value: ");
LogString += result;
// if ((systemTimePresent()) && (hour() == 0)) errcnt = 0;
+1 -1
View File
@@ -146,7 +146,7 @@ String WiFi_AP_Candidate::toString(const String& separator) const {
if (rssi == -1) {
result += F(" (RTC) ");
} else {
result += " (";
result += F(" (");
result += rssi;
result += F("dBm) ");
}
+1 -1
View File
@@ -809,7 +809,7 @@ void parseCompleteNonCommentLine(String& line, const String& event,
log += codeBlock ? 0 : 1;
log += match ? 0 : 1;
log += isCommand ? 0 : 1;
log += ": ";
log += F(": ");
log += line;
addLog(LOG_LEVEL_DEBUG_DEV, log);
}
@@ -311,7 +311,7 @@ void processConnect() {
const LongTermTimer::Duration connect_duration = WiFiEventData.last_wifi_connect_attempt_moment.timeDiff(WiFiEventData.lastConnectMoment);
String log = F("WIFI : Connected! AP: ");
log += WiFi.SSID();
log += " (";
log += F(" (");
log += WiFi.BSSIDstr();
log += F(") Ch: ");
log += RTC.lastWiFiChannel;
@@ -375,7 +375,7 @@ void processGotIP() {
log += F("DHCP IP: ");
}
log += formatIP(ip);
log += " (";
log += F(" (");
log += NetworkGetHostname();
log += F(") GW: ");
log += formatIP(gw);
+2 -2
View File
@@ -167,7 +167,7 @@ void ESPEasy_setup()
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("\n\n\rINIT : Booting version: ");
log += getValue(LabelType::GIT_BUILD);
log += " (";
log += F(" (");
log += getSystemLibraryString();
log += ')';
addLog(LOG_LEVEL_INFO, log);
@@ -352,7 +352,7 @@ void ESPEasy_setup()
log += deviceCount + 1;
log += ' ';
log += getPluginDescriptionString();
log += " (";
log += F(" (");
log += getSystemLibraryString();
log += ')';
addLog(LOG_LEVEL_INFO, log);
+6 -5
View File
@@ -3,6 +3,7 @@
#include "../ESPEasyCore/ESPEasy_Log.h"
#include "../Globals/Settings.h"
#include "../Globals/Statistics.h"
#include "../Helpers/Memory.h"
@@ -25,7 +26,7 @@ void checkRAM(const String &flashString, int a ) {
void checkRAM(const String& flashString, const String &a ) {
String s = flashString;
s += " (";
s += F(" (");
s += a;
s += ')';
checkRAM(s);
@@ -106,7 +107,7 @@ void RamTracker::registerRamState(const String& s) { // store function
for (int i = 0; i < TRACEENTRIES; i++) { // tranfer cyclic buffer strings and mem values to this trace
traces[bestCase] += nextAction[readPtr];
traces[bestCase] += "-> ";
traces[bestCase] += F("-> ");
traces[bestCase] += String(nextActionStartMemory[readPtr]);
traces[bestCase] += ' ';
readPtr++;
@@ -126,13 +127,13 @@ void RamTracker::getTraceBuffer() {
#ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_DEV)) {
String retval = "Memtrace\n";
String retval = F("Memtrace\n");
for (int i = 0; i < TRACES; i++) {
retval += String(i);
retval += ": lowest: ";
retval += F(": lowest: ");
retval += String(tracesMemory[i]);
retval += " ";
retval += ' ';
retval += traces[i];
addLog(LOG_LEVEL_DEBUG_DEV, retval);
retval.clear();
+1 -1
View File
@@ -317,7 +317,7 @@ bool ESPEasy_time::getNtpTime(double& unixTime_d)
useNTPpool = true;
}
log += " (";
log += F(" (");
log += timeServerIP.toString();
log += ')';
+6 -6
View File
@@ -82,12 +82,12 @@ String timeLong2String(unsigned long lngTime)
}
String weekDays = F("AllSunMonTueWedThuFriSatWrkWkd");
time = weekDays.substring(x * 3, x * 3 + 3);
time += ",";
time += ',';
x = (lngTime >> 12) & 0xf;
if (x == 0xf) {
time += "*";
time += '*';
}
else if (x == 0xe) {
time += '-';
@@ -99,7 +99,7 @@ String timeLong2String(unsigned long lngTime)
x = (lngTime >> 8) & 0xf;
if (x == 0xf) {
time += "*";
time += '*';
}
else if (x == 0xe) {
time += '-';
@@ -108,12 +108,12 @@ String timeLong2String(unsigned long lngTime)
time += x;
}
time += ":";
time += ':';
x = (lngTime >> 4) & 0xf;
if (x == 0xf) {
time += "*";
time += '*';
}
else if (x == 0xe) {
time += '-';
@@ -125,7 +125,7 @@ String timeLong2String(unsigned long lngTime)
x = (lngTime) & 0xf;
if (x == 0xf) {
time += "*";
time += '*';
}
else if (x == 0xe) {
time += '-';
+1 -1
View File
@@ -304,7 +304,7 @@ void SendValueLogger(taskIndex_t TaskIndex)
logger += ExtraTaskSettings.TaskDeviceValueNames[varNr];
logger += ',';
logger += formatUserVarNoCheck(TaskIndex, varNr);
logger += "\r\n";
logger += F("\r\n");
}
addLog(LOG_LEVEL_DEBUG, logger);
}
+3 -3
View File
@@ -142,12 +142,12 @@ String ModbusRTU_struct::getDevice_description(uint8_t slaveAddress) {
if (label.length() > 0) {
// description += MEI_objectid_to_name(object_id);
description += label;
description += ": ";
description += F(": ");
}
if (obj_text.length() > 0) {
description += obj_text;
description += " - ";
description += F(" - ");
}
}
}
@@ -290,7 +290,7 @@ String ModbusRTU_struct::parse_modbus_MEI_response(unsigned int& object_value_in
if (i != 0) {
// Append to existing description
result += ", ";
result += F(", ");
}
result += object_value;
}
+2 -2
View File
@@ -150,13 +150,13 @@ void runOncePerSecond()
event.reserve(21);
event = F("Clock#Time=");
event += node_time.weekday_str();
event += ",";
event += ',';
if (node_time.hour() < 10) {
event += '0';
}
event += node_time.hour();
event += ":";
event += ':';
if (node_time.minute() < 10) {
event += '0';
+1 -1
View File
@@ -235,7 +235,7 @@ String formatToHex_decimal(unsigned long value) {
String formatToHex_decimal(unsigned long value, unsigned long factor) {
String result = formatToHex(value);
result += " (";
result += F(" (");
if (factor > 1) {
result += formatHumanReadable(value, factor);
+1 -1
View File
@@ -172,7 +172,7 @@ String getPluginDescriptionString() {
result += F(" [Development]");
#endif // ifdef PLUGIN_BUILD_DEV
#ifdef PLUGIN_DESCR
result += " [";
result += F(" [");
result += F(PLUGIN_DESCR);
result += ']';
#endif // ifdef PLUGIN_DESCR
+3 -3
View File
@@ -146,12 +146,12 @@ String formatDomoticzSensorType(struct EventStruct *event) {
// http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Wind
values = formatUserVarDomoticz(event, 0); // WB = Wind bearing (0-359)
values += getBearing(UserVar[event->BaseVarIndex]); // WD = Wind direction (S, SW, NNW, etc.)
values += ";"; // Needed after getBearing
values += ';'; // Needed after getBearing
// Domoticz expects the wind speed in (m/s * 10)
values += toString((UserVar[event->BaseVarIndex + 1] * 10), ExtraTaskSettings.TaskDeviceValueDecimals[1]);
values += ";"; // WS = 10 * Wind speed [m/s]
values += ';'; // WS = 10 * Wind speed [m/s]
values += toString((UserVar[event->BaseVarIndex + 2] * 10), ExtraTaskSettings.TaskDeviceValueDecimals[2]);
values += ";"; // WG = 10 * Gust [m/s]
values += ';'; // WG = 10 * Gust [m/s]
values += formatUserVarDomoticz(0); // Temperature
values += formatUserVarDomoticz(0); // Temperature Windchill
break;
+10 -10
View File
@@ -140,7 +140,7 @@ String get_user_agent_request_header_field() {
request.reserve(agent_size);
request = F("User-Agent: ");
request += get_user_agent_string();
request += "\r\n";
request += F("\r\n");
agent_size = request.length();
return request;
}
@@ -166,27 +166,27 @@ String do_create_http_request(
if (!uri.startsWith("/")) { request += '/'; }
request += uri;
request += F(" HTTP/1.1");
request += "\r\n";
request += F("\r\n");
if (content_length >= 0) {
request += F("Content-Length: ");
request += content_length;
request += "\r\n";
request += F("\r\n");
}
request += F("Host: ");
request += hostportString;
request += "\r\n";
request += F("\r\n");
request += auth_header;
// Add request header as fall back.
// When adding another "accept" header, it may be interpreted as:
// "if you have XXX, send it; or failing that, just give me what you've got."
request += F("Accept: */*;q=0.1");
request += "\r\n";
request += F("\r\n");
request += additional_options;
request += get_user_agent_request_header_field();
request += F("Connection: close\r\n");
request += "\r\n";
request += F("\r\n");
if (request.length() > static_cast<size_t>(estimated_size + est_size_error)) {
est_size_error = request.length() - estimated_size;
}
@@ -347,9 +347,9 @@ bool send_via_http(const String& logIdentifier, WiFiClient& client, const String
log += logIdentifier;
log += F(" Error: could not write to client (");
log += written;
log += "/";
log += '/';
log += postStr.length();
log += ")";
log += ')';
addLog(LOG_LEVEL_ERROR, log);
}
success = false;
@@ -361,9 +361,9 @@ bool send_via_http(const String& logIdentifier, WiFiClient& client, const String
log += logIdentifier;
log += F(" written to client (");
log += written;
log += "/";
log += '/';
log += postStr.length();
log += ")";
log += ')';
addLog(LOG_LEVEL_DEBUG, log);
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ void handleNotFound() {
message += (web_server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += web_server.args();
message += "\n";
message += '\n';
for (uint8_t i = 0; i < web_server.args(); i++) {
message += F(" NAME:");
+1 -1
View File
@@ -595,7 +595,7 @@ void handle_devicess_ShowAllTasksTable(uint8_t page)
{
String html;
html.reserve(16);
html += " (";
html += F(" (");
html += Settings.TaskDeviceID[controllerNr][x];
html += ')';
+1 -1
View File
@@ -32,7 +32,7 @@ void handle_download()
String str = F("attachment; filename=config_");
str += Settings.Name;
str += "_U";
str += F("_U");
str += Settings.Unit;
str += F("_Build");
str += BUILD;
+2 -2
View File
@@ -166,7 +166,7 @@ void handle_root() {
html.reserve(64);
html += freeMem;
#ifndef BUILD_NO_RAM_TRACKER
html += " (";
html += F(" (");
html += lowestRAM;
html += F(" - ");
html += lowestRAMfunction;
@@ -185,7 +185,7 @@ void handle_root() {
html.reserve(64);
html += String(getCurrentFreeStack());
#ifndef BUILD_NO_RAM_TRACKER
html += " (";
html += F(" (");
html += String(lowestFreeStack);
html += F(" - ");
html += String(lowestFreeStackfunction);
+4 -4
View File
@@ -321,7 +321,7 @@ void handle_sysinfo_basicInfo() {
html.reserve(64);
html += getLastBootCauseString();
html += " (";
html += F(" (");
html += RTC.bootCounter;
html += ')';
addHtml(html);
@@ -347,7 +347,7 @@ void handle_sysinfo_memory() {
html += freeMem;
# ifndef BUILD_NO_RAM_TRACKER
html += " (";
html += F(" (");
html += lowestRAM;
html += F(" - ");
html += lowestRAMfunction;
@@ -379,7 +379,7 @@ void handle_sysinfo_memory() {
html.reserve(64);
html += getCurrentFreeStack();
# ifndef BUILD_NO_RAM_TRACKER
html += " (";
html += F(" (");
html += lowestFreeStack;
html += F(" - ");
html += lowestFreeStackfunction;
@@ -452,7 +452,7 @@ void handle_sysinfo_Network() {
html.reserve(64);
html += WiFi.SSID();
html += " (";
html += F(" (");
html += WiFi.BSSIDstr();
html += ')';
addHtml(html);