[Cleanup] Save resources by moving static strings to flash

This commit is contained in:
TD-er
2020-11-16 13:20:45 +01:00
parent 5db268d3a9
commit decd45687f
15 changed files with 29 additions and 24 deletions
+1 -1
View File
@@ -274,7 +274,7 @@ String resultToSourceCode(const decode_results * const results) {
/// @deprecated This is only for those that want this legacy format.
String resultToTimingInfo(const decode_results * const results) {
String output = "";
String value = "";
String value;
// Reserve some space for the string to reduce heap fragmentation.
output.reserve(2048); // 2KB should cover most cases.
value.reserve(6); // Max value should be 2^17 = 131072
@@ -79,7 +79,7 @@ String rn2xx3_helper::base16encode(const String& input_c)
if (input[i] == '\0') { break; }
char buffer[3];
sprintf(buffer, "%02x", static_cast<int>(input[i]));
sprintf_P(buffer, PSTR("%02x"), static_cast<int>(input[i]));
output += buffer[0];
output += buffer[1];
}
@@ -95,7 +95,7 @@ String rn2xx3_helper::base16encode(const byte *data, uint8_t size)
for (unsigned i = 0; i < size; i++)
{
sprintf(buffer, "%02X", data[i]);
sprintf_P(buffer, PSTR("%02X"), data[i]);
dataToTx += buffer[0];
dataToTx += buffer[1];
}
+3 -3
View File
@@ -25,11 +25,11 @@ bool WakeOnLan::stringToArray(uint8_t* _macAddress, const char* _macString) {
unsigned int tempMACAddress[6];
if (strlen(_macString) == 12) // FFFFFFFFFFFF
sprintf(macFormat, "%%2x%%2x%%2x%%2x%%2x%%2x");
sprintf_P(macFormat, PSTR("%%2x%%2x%%2x%%2x%%2x%%2x"));
else if (strlen(_macString) == 14) // FFFF-FFFF-FFFF
sprintf(macFormat, "%%2x%%2x%c%%2x%%2x%c%%2x%%2x", _macString[4], _macString[9]);
sprintf_P(macFormat, PSTR("%%2x%%2x%c%%2x%%2x%c%%2x%%2x"), _macString[4], _macString[9]);
else if (strlen(_macString) == 17) // FF-FF-FF-FF-FF-FF
sprintf(macFormat, "%%2x%c%%2x%c%%2x%c%%2x%c%%2x%c%%2x", _macString[2], _macString[5], _macString[8], _macString[11], _macString[14]);
sprintf_P(macFormat, PSTR("%%2x%c%%2x%c%%2x%c%%2x%c%%2x%c%%2x"), _macString[2], _macString[5], _macString[8], _macString[11], _macString[14]);
else
return false;
+1 -1
View File
@@ -545,7 +545,7 @@ static char* to_string(int num) {
if (abs(num) >= CRON_MAX_NUM_TO_SRING) return NULL;
char* str = (char*) cron_malloc(CRON_NUM_OF_DIGITS(num) + 1);
if (!str) return NULL;
int res = sprintf(str, "%d", num);
int res = sprintf_P(str, PSTR("%d"), num);
if (res < 0) {
cron_free(str);
return NULL;
+4 -3
View File
@@ -12,7 +12,9 @@
#define CPLUGIN_NAME_002 "Domoticz MQTT"
#include "src/Commands/InternalCommands.h"
#include "src/ESPEasyCore/ESPEasyRules.h"
#include "src/Globals/Settings.h"
#include "src/Helpers/PeriodicalActions.h"
#include "src/Helpers/StringParser.h"
#include <ArduinoJson.h>
@@ -102,7 +104,7 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&
// We need the index of the controller we are: 0...CONTROLLER_MAX
if (Settings.TaskDeviceEnabled[x] && (Settings.TaskDeviceID[ControllerID][x] == idx)) // get idx for our controller index
{
String action = "";
String action;
switch (Settings.TaskDeviceNumber[x]) {
case 1: // temp solution, if input switch, update state
@@ -115,7 +117,6 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String&
}
case 29: // temp solution, if plugin 029, set gpio
{
action = "";
int baseVar = x * VARS_PER_TASK;
if (strcasecmp_P(switchtype, PSTR("dimmer")) == 0)
+1 -1
View File
@@ -108,7 +108,7 @@ bool do_process_c004_delay_queue(int controller_number, const C004_queue_element
{
postDataStr += F("&field");
postDataStr += element.idx + x;
postDataStr += "=";
postDataStr += '=';
postDataStr += formatUserVarNoCheck(element.TaskIndex, x);
}
}
+1 -1
View File
@@ -138,7 +138,7 @@ bool CPlugin_005(CPlugin::Function function, struct EventStruct *event, String&
String tmppubname = pubname;
tmppubname.replace(F("%valname%"), ExtraTaskSettings.TaskDeviceValueNames[x]);
String value = "";
String value;
// Small optimization so we don't try to copy potentially large strings
if (event->sensorType == Sensor_VType::SENSOR_TYPE_STRING) {
MQTTpublish(event->ControllerIndex, tmppubname.c_str(), event->String2.c_str(), mqtt_retainFlag);
+1 -1
View File
@@ -700,7 +700,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
parseControllerVariables(pubname, event, false);
LoadTaskSettings(event->TaskIndex);
String value = "";
String value;
byte valueCount = getValueCountForTask(event->TaskIndex);
for (byte x = 0; x < valueCount; x++)
{
+4 -4
View File
@@ -188,10 +188,10 @@ boolean Plugin_042(byte function, struct EventStruct *event, String& string)
// Color Selection
char hexvalue[7] = {0};
sprintf(hexvalue, "%02X%02X%02X", // Create Hex value for color
PCONFIG(0),
PCONFIG(1),
PCONFIG(2));
sprintf_P(hexvalue, F("%02X%02X%02X"), // Create Hex value for color
PCONFIG(0),
PCONFIG(1),
PCONFIG(2));
// http://jscolor.com/examples/
addHtml(F("<TR><TD>Color:<TD><input class=\"jscolor {onFineChange:'update(this)'}\" value='"));
+1 -1
View File
@@ -129,7 +129,7 @@ struct P073_data_struct : public PluginTaskData_base {
void FillBufferWithTemp(long temperature) {
ClearBuffer();
char p073_digit[8];
sprintf(p073_digit, "%7d", static_cast<int>(temperature));
sprintf_P(p073_digit, PSTR("%7d"), static_cast<int>(temperature));
int p073_numlenght = strlen(p073_digit);
for (int i = 0; i < p073_numlenght; i++) {
@@ -64,7 +64,7 @@ String LoRa_base16Encode(byte *data, size_t size) {
char buffer[3];
for (unsigned i=0; i<size; i++)
{
sprintf(buffer, "%02X", data[i]);
sprintf_P(buffer, PSTR("%02X"), data[i]);
output += buffer[0];
output += buffer[1];
}
+1 -1
View File
@@ -455,7 +455,7 @@ void parse_string_commands(String &line) {
&& validIntFromString(arg2, iarg2)) {
float val = (100.0 * iarg1) / (1.0 * iarg2);
char sval[10];
sprintf(sval, "%02d", (int)val);
sprintf_P(sval, PSTR("%02d"), (int)val);
replacement = String(sval);
}
*/
+1 -1
View File
@@ -531,7 +531,7 @@ void htmlStrongEscape(String& html)
else
{
char s[4];
sprintf(s, "%03d", static_cast<int>(html[i]));
sprintf_P(s, PSTR("%03d"), static_cast<int>(html[i]));
escaped += "&#";
escaped += s;
escaped += ";";
+1 -1
View File
@@ -60,7 +60,7 @@ void replSunSetTimeString(const String& format, String& s, boolean useURLencode)
String timeReplacement_leadZero(int value)
{
char valueString[5] = { 0 };
sprintf(valueString, "%02d", value);
sprintf_P(valueString, PSTR("%02d"), value);
return valueString;
}
+6 -2
View File
@@ -5,12 +5,16 @@
#include "../../ESPEasy_common.h"
#include "../ControllerQueue/DelayQueueElements.h"
#include "../ESPEasyCore/Controller.h"
#include "../ESPEasyCore/ESPEasyNetwork.h"
#include "../Globals/CPlugins.h"
#include "../Globals/ESPEasy_Scheduler.h"
#include "../Helpers/_CPlugin_Helper_webform.h"
#include "../Helpers/Misc.h"
#include "../Helpers/Numerical.h"
#include "../Helpers/StringConverter.h"
#include "../ControllerQueue/DelayQueueElements.h"
#include "../Helpers/_CPlugin_Helper_webform.h"
struct ControllerSettingsStruct;
class WiFiUDP;