Change ConfigSet parameter from PSTR() to F()

This commit is contained in:
fvanroie 2020-11-11 22:13:26 +01:00
parent 9a751d7d65
commit 9162ee122b
9 changed files with 63 additions and 61 deletions

View File

@ -1081,10 +1081,10 @@ bool haspSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(haspStartPage, settings[FPSTR(F_CONFIG_STARTPAGE)], PSTR("haspStartPage")); changed |= configSet(haspStartPage, settings[FPSTR(F_CONFIG_STARTPAGE)], F("haspStartPage"));
changed |= configSet(haspStartDim, settings[FPSTR(F_CONFIG_STARTDIM)], PSTR("haspStartDim")); changed |= configSet(haspStartDim, settings[FPSTR(F_CONFIG_STARTDIM)], F("haspStartDim"));
changed |= configSet(haspThemeId, settings[FPSTR(F_CONFIG_THEME)], PSTR("haspThemeId")); changed |= configSet(haspThemeId, settings[FPSTR(F_CONFIG_THEME)], F("haspThemeId"));
changed |= configSet(haspThemeHue, settings[FPSTR(F_CONFIG_HUE)], PSTR("haspThemeHue")); changed |= configSet(haspThemeHue, settings[FPSTR(F_CONFIG_HUE)], F("haspThemeHue"));
if(!settings[FPSTR(F_CONFIG_PAGES)].isNull()) { if(!settings[FPSTR(F_CONFIG_PAGES)].isNull()) {
changed |= strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)]) != 0; changed |= strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)]) != 0;

View File

@ -25,44 +25,44 @@
#include "EEPROM.h" #include "EEPROM.h"
#endif #endif
void confDebugSet(const char * name) void confDebugSet(const __FlashStringHelper * fstr_name)
{ {
/*char buffer[128]; /*char buffer[128];
snprintf(buffer, sizeof(buffer), PSTR(" * %s set"), name); snprintf(buffer, sizeof(buffer), PSTR(" * %s set"), name);
debugPrintln(buffer);*/ debugPrintln(buffer);*/
Log.trace(TAG_CONF, F(" * %s set"), name); Log.trace(TAG_CONF, F(" * %S set"), fstr_name);
} }
bool configSet(int8_t & value, const JsonVariant & setting, const char * name) bool configSet(int8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name)
{ {
if(!setting.isNull()) { if(!setting.isNull()) {
int8_t val = setting.as<int8_t>(); int8_t val = setting.as<int8_t>();
if(value != val) { if(value != val) {
confDebugSet(name); confDebugSet(fstr_name);
value = val; value = val;
return true; return true;
} }
} }
return false; return false;
} }
bool configSet(uint8_t & value, const JsonVariant & setting, const char * name) bool configSet(uint8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name)
{ {
if(!setting.isNull()) { if(!setting.isNull()) {
uint8_t val = setting.as<uint8_t>(); uint8_t val = setting.as<uint8_t>();
if(value != val) { if(value != val) {
confDebugSet(name); confDebugSet(fstr_name);
value = val; value = val;
return true; return true;
} }
} }
return false; return false;
} }
bool configSet(uint16_t & value, const JsonVariant & setting, const char * name) bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name)
{ {
if(!setting.isNull()) { if(!setting.isNull()) {
uint16_t val = setting.as<uint16_t>(); uint16_t val = setting.as<uint16_t>();
if(value != val) { if(value != val) {
confDebugSet(name); confDebugSet(fstr_name);
value = val; value = val;
return true; return true;
} }
@ -267,7 +267,7 @@ void configWriteConfig()
if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui")); if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui"));
changed = guiGetConfig(settings[F("gui")]); changed = guiGetConfig(settings[F("gui")]);
if(changed) { if(changed) {
Log.verbose(TAG_GUI,settingsChanged.c_str()); Log.verbose(TAG_GUI, settingsChanged.c_str());
writefile = true; writefile = true;
} }

View File

@ -41,9 +41,9 @@ void configGetConfig(JsonDocument & settings);
void configWriteConfig(); void configWriteConfig();
void configOutput(const JsonObject & settings); void configOutput(const JsonObject & settings);
bool configSet(int8_t & value, const JsonVariant & setting, const char * name); bool configSet(int8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name);
bool configSet(uint8_t & value, const JsonVariant & setting, const char * name); bool configSet(uint8_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name);
bool configSet(uint16_t & value, const JsonVariant & setting, const char * name); bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name);
bool configClear(); bool configClear();
#endif #endif

View File

@ -95,22 +95,21 @@ bool debugAnsiCodes = true;
unsigned long debugLastMillis = 0; unsigned long debugLastMillis = 0;
uint16_t debugTelePeriod = 300; uint16_t debugTelePeriod = 300;
String debugHaspHeader() /* Send the HASP header and version to the output device specified
*/
void debugHaspHeader(Print * output)
{ {
String header((char *)0); if(debugAnsiCodes) output->println(TERM_COLOR_YELLOW);
header.reserve(256); output->println(F(""
if(debugAnsiCodes) header += TERM_COLOR_YELLOW;
header += F("\r\n"
" _____ _____ _____ _____\r\n" " _____ _____ _____ _____\r\n"
" | | | _ | __| _ |\r\n" " | | | _ | __| _ |\r\n"
" | | |__ | __|\r\n" " | | |__ | __|\r\n"
" |__|__|__|__|_____|__|\r\n" " |__|__|__|__|_____|__|\r\n"
" Home Automation Switch Plate\r\n"); " Home Automation Switch Plate"));
char buffer[128]; char buffer[128];
snprintf(buffer, sizeof(buffer), PSTR(" Open Hardware edition v%u.%u.%u\r\n"), HASP_VERSION_MAJOR, snprintf(buffer, sizeof(buffer), PSTR(" Open Hardware edition v%u.%u.%u\r\n"), HASP_VERSION_MAJOR,
HASP_VERSION_MINOR, HASP_VERSION_REVISION); HASP_VERSION_MINOR, HASP_VERSION_REVISION);
header += buffer; output->println(buffer);
return header;
} }
void debugStart() void debugStart()
@ -204,10 +203,10 @@ bool debugSetConfig(const JsonObject & settings)
bool changed = false; bool changed = false;
/* Serial Settings*/ /* Serial Settings*/
changed |= configSet(debugSerialBaud, settings[FPSTR(F_CONFIG_BAUD)], PSTR("debugSerialBaud")); changed |= configSet(debugSerialBaud, settings[FPSTR(F_CONFIG_BAUD)], F("debugSerialBaud"));
/* Teleperiod Settings*/ /* Teleperiod Settings*/
changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], PSTR("debugTelePeriod")); changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
/* Syslog Settings*/ /* Syslog Settings*/
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
@ -215,9 +214,9 @@ bool debugSetConfig(const JsonObject & settings)
changed |= strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)]) != 0; changed |= strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)]) != 0;
strncpy(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)], sizeof(debugSyslogHost)); strncpy(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)], sizeof(debugSyslogHost));
} }
changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("debugSyslogPort")); changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], F("debugSyslogPort"));
changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], PSTR("debugSyslogProtocol")); changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], PSTR("debugSyslogFacility")); changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], F("debugSyslogFacility"));
#endif #endif
return changed; return changed;
@ -507,8 +506,9 @@ void debugPreSetup(JsonObject settings)
// Print Header // Print Header
Serial.println(); Serial.println();
Serial.println(debugHaspHeader()); debugHaspHeader(&Serial);
Serial.println(); // Serial.println(debugHaspHeader());
// Serial.println();
Serial.flush(); Serial.flush();
Log.trace(TAG_DEBG, ("Serial started at %u baud"), baudrate); Log.trace(TAG_DEBG, ("Serial started at %u baud"), baudrate);

View File

@ -791,11 +791,11 @@ bool guiSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], PSTR("guiTickPeriod")); changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod"));
changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], PSTR("guiBacklightPin")); changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
changed |= configSet(guiSleepTime1, settings[FPSTR(F_GUI_IDLEPERIOD1)], PSTR("guiSleepTime1")); changed |= configSet(guiSleepTime1, settings[FPSTR(F_GUI_IDLEPERIOD1)], F("guiSleepTime1"));
changed |= configSet(guiSleepTime2, settings[FPSTR(F_GUI_IDLEPERIOD2)], PSTR("guiSleepTime2")); changed |= configSet(guiSleepTime2, settings[FPSTR(F_GUI_IDLEPERIOD2)], F("guiSleepTime2"));
changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], PSTR("guiRotation")); changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], F("guiRotation"));
if(!settings[FPSTR(F_GUI_POINTER)].isNull()) { if(!settings[FPSTR(F_GUI_POINTER)].isNull()) {
if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) { if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) {

View File

@ -1889,7 +1889,7 @@ bool httpSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(httpPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("httpPort")); changed |= configSet(httpPort, settings[FPSTR(F_CONFIG_PORT)], F("httpPort"));
if(!settings[FPSTR(F_CONFIG_USER)].isNull()) { if(!settings[FPSTR(F_CONFIG_USER)].isNull()) {
changed |= strcmp(httpUser, settings[FPSTR(F_CONFIG_USER)]) != 0; changed |= strcmp(httpUser, settings[FPSTR(F_CONFIG_USER)]) != 0;

View File

@ -105,7 +105,7 @@ bool mdnsSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(mdnsEnabled, settings[FPSTR(F_CONFIG_ENABLE)], PSTR("mdnsEnabled")); changed |= configSet(mdnsEnabled, settings[FPSTR(F_CONFIG_ENABLE)], F("mdnsEnabled"));
return changed; return changed;
} }

View File

@ -537,7 +537,7 @@ bool mqttSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(mqttPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("mqttPort")); changed |= configSet(mqttPort, settings[FPSTR(F_CONFIG_PORT)], F("mqttPort"));
if(!settings[FPSTR(F_CONFIG_NAME)].isNull()) { if(!settings[FPSTR(F_CONFIG_NAME)].isNull()) {
changed |= strcmp(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)]) != 0; changed |= strcmp(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)]) != 0;

View File

@ -58,7 +58,8 @@ void telnetClientDisconnect()
void telnetClientLogon() void telnetClientLogon()
{ {
telnetClient.println(); telnetClient.println();
telnetClient.println(debugHaspHeader().c_str()); // Send version header debugHaspHeader(&telnetClient);
// telnetClient.println(debugHaspHeader().c_str()); // Send version header
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
telnetLoginAttempt = 0; // Reset attempt counter telnetLoginAttempt = 0; // Reset attempt counter
Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true); Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true);
@ -80,10 +81,10 @@ void telnetAcceptClient()
telnetClient = telnetServer->available(); // ready for new client telnetClient = telnetServer->available(); // ready for new client
// Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); // Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
if(!telnetClient) { if(!telnetClient) {
Log.notice(TAG_TELN,F("Client NOT connected")); Log.notice(TAG_TELN, F("Client NOT connected"));
return; return;
} }
Log.notice(TAG_TELN,F("Client connected")); Log.notice(TAG_TELN, F("Client connected"));
/* Avoid a buffer here */ /* Avoid a buffer here */
telnetClient.print(0xFF); // DO TERMINAL-TYPE telnetClient.print(0xFF); // DO TERMINAL-TYPE
@ -132,7 +133,8 @@ static void telnetProcessLine()
telnetLoginState = TELNET_UNAUTHENTICATED; telnetLoginState = TELNET_UNAUTHENTICATED;
telnetLoginAttempt++; // Subsequent attempt telnetLoginAttempt++; // Subsequent attempt
telnetClient.println(F("Authorization failed!\r\n")); telnetClient.println(F("Authorization failed!\r\n"));
// Log.warning(TAG_TELN,F("Incorrect login attempt from %s"), telnetClient.remoteIP().toString().c_str()); // Log.warning(TAG_TELN,F("Incorrect login attempt from %s"),
// telnetClient.remoteIP().toString().c_str());
if(telnetLoginAttempt >= 3) { if(telnetLoginAttempt >= 3) {
telnetClientDisconnect(); telnetClientDisconnect();
} else { } else {
@ -200,7 +202,7 @@ void telnetSetup()
// if(!telnetServer) telnetServer = new EthernetServer(telnetPort); // if(!telnetServer) telnetServer = new EthernetServer(telnetPort);
// if(telnetServer) { // if(telnetServer) {
telnetServer->begin(); telnetServer->begin();
Log.notice(TAG_TELN,F("Debug telnet console started")); Log.notice(TAG_TELN, F("Debug telnet console started"));
// } else { // } else {
// Log.error(TAG_TELN,F("Failed to start telnet server")); // Log.error(TAG_TELN,F("Failed to start telnet server"));
//} //}
@ -217,9 +219,9 @@ void telnetSetup()
telnetClient.setNoDelay(true); telnetClient.setNoDelay(true);
//} //}
Log.notice(TAG_TELN,F("Debug telnet console started")); Log.notice(TAG_TELN, F("Debug telnet console started"));
} else { } else {
Log.error(TAG_TELN,F("Failed to start telnet server")); Log.error(TAG_TELN, F("Failed to start telnet server"));
} }
#endif #endif
} }
@ -229,21 +231,21 @@ void IRAM_ATTR telnetLoop()
{ // Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303 { // Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303
#if defined(STM32F4xx) #if defined(STM32F4xx)
Ethernet.schedule(); Ethernet.schedule();
// if(telnetServer) // if(telnetServer)
{ // client is connected { // client is connected
EthernetClient client = telnetServer->available(); EthernetClient client = telnetServer->available();
if(client) { if(client) {
if(!telnetClient || !telnetClient.connected()) { if(!telnetClient || !telnetClient.connected()) {
//telnetAcceptClient(client); // telnetAcceptClient(client);
telnetClient = client; // ready for new client telnetClient = client; // ready for new client
// Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); // Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
if(!telnetClient) { if(!telnetClient) {
Log.notice(TAG_TELN,F("Client NOT connected")); Log.notice(TAG_TELN, F("Client NOT connected"));
return; return;
} }
Log.notice(TAG_TELN,F("Client connected")); Log.notice(TAG_TELN, F("Client connected"));
/* Avoid a buffer here */ /* Avoid a buffer here */
// telnetClient.print(0xFF); // DO TERMINAL-TYPE // telnetClient.print(0xFF); // DO TERMINAL-TYPE
@ -251,7 +253,7 @@ Ethernet.schedule();
// telnetClient.print(0x1B); // telnetClient.print(0x1B);
} else { } else {
//client.stop(); // have client, block new connections // client.stop(); // have client, block new connections
} }
} }
} }
@ -300,8 +302,8 @@ bool telnetSetConfig(const JsonObject & settings)
configOutput(settings); configOutput(settings);
bool changed = false; bool changed = false;
changed |= configSet(telnetEnabled, settings[FPSTR(F_CONFIG_ENABLE)], PSTR("telnetEnabled")); changed |= configSet(telnetEnabled, settings[FPSTR(F_CONFIG_ENABLE)], F("telnetEnabled"));
changed |= configSet(telnetPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("telnetPort")); changed |= configSet(telnetPort, settings[FPSTR(F_CONFIG_PORT)], F("telnetPort"));
return changed; return changed;
} }