mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Change ConfigSet parameter from PSTR() to F()
This commit is contained in:
parent
9a751d7d65
commit
9162ee122b
@ -1081,10 +1081,10 @@ bool haspSetConfig(const JsonObject & settings)
|
||||
configOutput(settings);
|
||||
bool changed = false;
|
||||
|
||||
changed |= configSet(haspStartPage, settings[FPSTR(F_CONFIG_STARTPAGE)], PSTR("haspStartPage"));
|
||||
changed |= configSet(haspStartDim, settings[FPSTR(F_CONFIG_STARTDIM)], PSTR("haspStartDim"));
|
||||
changed |= configSet(haspThemeId, settings[FPSTR(F_CONFIG_THEME)], PSTR("haspThemeId"));
|
||||
changed |= configSet(haspThemeHue, settings[FPSTR(F_CONFIG_HUE)], PSTR("haspThemeHue"));
|
||||
changed |= configSet(haspStartPage, settings[FPSTR(F_CONFIG_STARTPAGE)], F("haspStartPage"));
|
||||
changed |= configSet(haspStartDim, settings[FPSTR(F_CONFIG_STARTDIM)], F("haspStartDim"));
|
||||
changed |= configSet(haspThemeId, settings[FPSTR(F_CONFIG_THEME)], F("haspThemeId"));
|
||||
changed |= configSet(haspThemeHue, settings[FPSTR(F_CONFIG_HUE)], F("haspThemeHue"));
|
||||
|
||||
if(!settings[FPSTR(F_CONFIG_PAGES)].isNull()) {
|
||||
changed |= strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)]) != 0;
|
||||
|
@ -25,44 +25,44 @@
|
||||
#include "EEPROM.h"
|
||||
#endif
|
||||
|
||||
void confDebugSet(const char * name)
|
||||
void confDebugSet(const __FlashStringHelper * fstr_name)
|
||||
{
|
||||
/*char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer), PSTR(" * %s set"), name);
|
||||
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()) {
|
||||
int8_t val = setting.as<int8_t>();
|
||||
if(value != val) {
|
||||
confDebugSet(name);
|
||||
confDebugSet(fstr_name);
|
||||
value = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
uint8_t val = setting.as<uint8_t>();
|
||||
if(value != val) {
|
||||
confDebugSet(name);
|
||||
confDebugSet(fstr_name);
|
||||
value = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
uint16_t val = setting.as<uint16_t>();
|
||||
if(value != val) {
|
||||
confDebugSet(name);
|
||||
confDebugSet(fstr_name);
|
||||
value = val;
|
||||
return true;
|
||||
}
|
||||
@ -267,7 +267,7 @@ void configWriteConfig()
|
||||
if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui"));
|
||||
changed = guiGetConfig(settings[F("gui")]);
|
||||
if(changed) {
|
||||
Log.verbose(TAG_GUI,settingsChanged.c_str());
|
||||
Log.verbose(TAG_GUI, settingsChanged.c_str());
|
||||
writefile = true;
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ void configGetConfig(JsonDocument & settings);
|
||||
void configWriteConfig();
|
||||
void configOutput(const JsonObject & settings);
|
||||
|
||||
bool configSet(int8_t & value, const JsonVariant & setting, const char * name);
|
||||
bool configSet(uint8_t & value, const JsonVariant & setting, const char * name);
|
||||
bool configSet(uint16_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 __FlashStringHelper * fstr_name);
|
||||
bool configSet(uint16_t & value, const JsonVariant & setting, const __FlashStringHelper * fstr_name);
|
||||
bool configClear();
|
||||
|
||||
#endif
|
@ -95,22 +95,21 @@ bool debugAnsiCodes = true;
|
||||
unsigned long debugLastMillis = 0;
|
||||
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);
|
||||
header.reserve(256);
|
||||
if(debugAnsiCodes) header += TERM_COLOR_YELLOW;
|
||||
header += F("\r\n"
|
||||
" _____ _____ _____ _____\r\n"
|
||||
" | | | _ | __| _ |\r\n"
|
||||
" | | |__ | __|\r\n"
|
||||
" |__|__|__|__|_____|__|\r\n"
|
||||
" Home Automation Switch Plate\r\n");
|
||||
if(debugAnsiCodes) output->println(TERM_COLOR_YELLOW);
|
||||
output->println(F(""
|
||||
" _____ _____ _____ _____\r\n"
|
||||
" | | | _ | __| _ |\r\n"
|
||||
" | | |__ | __|\r\n"
|
||||
" |__|__|__|__|_____|__|\r\n"
|
||||
" Home Automation Switch Plate"));
|
||||
char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer), PSTR(" Open Hardware edition v%u.%u.%u\r\n"), HASP_VERSION_MAJOR,
|
||||
HASP_VERSION_MINOR, HASP_VERSION_REVISION);
|
||||
header += buffer;
|
||||
return header;
|
||||
output->println(buffer);
|
||||
}
|
||||
|
||||
void debugStart()
|
||||
@ -204,10 +203,10 @@ bool debugSetConfig(const JsonObject & settings)
|
||||
bool changed = false;
|
||||
|
||||
/* Serial Settings*/
|
||||
changed |= configSet(debugSerialBaud, settings[FPSTR(F_CONFIG_BAUD)], PSTR("debugSerialBaud"));
|
||||
changed |= configSet(debugSerialBaud, settings[FPSTR(F_CONFIG_BAUD)], F("debugSerialBaud"));
|
||||
|
||||
/* Teleperiod Settings*/
|
||||
changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], PSTR("debugTelePeriod"));
|
||||
changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
|
||||
|
||||
/* Syslog Settings*/
|
||||
#if HASP_USE_SYSLOG > 0
|
||||
@ -215,9 +214,9 @@ bool debugSetConfig(const JsonObject & settings)
|
||||
changed |= strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)]) != 0;
|
||||
strncpy(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)], sizeof(debugSyslogHost));
|
||||
}
|
||||
changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("debugSyslogPort"));
|
||||
changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], PSTR("debugSyslogProtocol"));
|
||||
changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], PSTR("debugSyslogFacility"));
|
||||
changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], F("debugSyslogPort"));
|
||||
changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
|
||||
changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], F("debugSyslogFacility"));
|
||||
#endif
|
||||
|
||||
return changed;
|
||||
@ -507,8 +506,9 @@ void debugPreSetup(JsonObject settings)
|
||||
|
||||
// Print Header
|
||||
Serial.println();
|
||||
Serial.println(debugHaspHeader());
|
||||
Serial.println();
|
||||
debugHaspHeader(&Serial);
|
||||
// Serial.println(debugHaspHeader());
|
||||
// Serial.println();
|
||||
Serial.flush();
|
||||
|
||||
Log.trace(TAG_DEBG, ("Serial started at %u baud"), baudrate);
|
||||
|
@ -791,11 +791,11 @@ bool guiSetConfig(const JsonObject & settings)
|
||||
configOutput(settings);
|
||||
bool changed = false;
|
||||
|
||||
changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], PSTR("guiTickPeriod"));
|
||||
changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], PSTR("guiBacklightPin"));
|
||||
changed |= configSet(guiSleepTime1, settings[FPSTR(F_GUI_IDLEPERIOD1)], PSTR("guiSleepTime1"));
|
||||
changed |= configSet(guiSleepTime2, settings[FPSTR(F_GUI_IDLEPERIOD2)], PSTR("guiSleepTime2"));
|
||||
changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], PSTR("guiRotation"));
|
||||
changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod"));
|
||||
changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
|
||||
changed |= configSet(guiSleepTime1, settings[FPSTR(F_GUI_IDLEPERIOD1)], F("guiSleepTime1"));
|
||||
changed |= configSet(guiSleepTime2, settings[FPSTR(F_GUI_IDLEPERIOD2)], F("guiSleepTime2"));
|
||||
changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], F("guiRotation"));
|
||||
|
||||
if(!settings[FPSTR(F_GUI_POINTER)].isNull()) {
|
||||
if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) {
|
||||
@ -916,7 +916,7 @@ static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area,
|
||||
my_flush_cb(disp, area, color_p);
|
||||
}
|
||||
|
||||
/** Take Screenshot.
|
||||
/** Take Screenshot.
|
||||
*
|
||||
* Flush buffer into a binary file.
|
||||
*
|
||||
|
@ -1889,7 +1889,7 @@ bool httpSetConfig(const JsonObject & settings)
|
||||
configOutput(settings);
|
||||
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()) {
|
||||
changed |= strcmp(httpUser, settings[FPSTR(F_CONFIG_USER)]) != 0;
|
||||
|
@ -105,7 +105,7 @@ bool mdnsSetConfig(const JsonObject & settings)
|
||||
configOutput(settings);
|
||||
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;
|
||||
}
|
@ -537,7 +537,7 @@ bool mqttSetConfig(const JsonObject & settings)
|
||||
configOutput(settings);
|
||||
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()) {
|
||||
changed |= strcmp(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)]) != 0;
|
||||
|
@ -58,9 +58,10 @@ void telnetClientDisconnect()
|
||||
void telnetClientLogon()
|
||||
{
|
||||
telnetClient.println();
|
||||
telnetClient.println(debugHaspHeader().c_str()); // Send version header
|
||||
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
|
||||
telnetLoginAttempt = 0; // Reset attempt counter
|
||||
debugHaspHeader(&telnetClient);
|
||||
// telnetClient.println(debugHaspHeader().c_str()); // Send version header
|
||||
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
|
||||
telnetLoginAttempt = 0; // Reset attempt counter
|
||||
Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true);
|
||||
// Log.notice(TAG_TELN,F("Client login from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
telnetClient.flush();
|
||||
@ -80,10 +81,10 @@ void telnetAcceptClient()
|
||||
telnetClient = telnetServer->available(); // ready for new client
|
||||
// Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
if(!telnetClient) {
|
||||
Log.notice(TAG_TELN,F("Client NOT connected"));
|
||||
Log.notice(TAG_TELN, F("Client NOT connected"));
|
||||
return;
|
||||
}
|
||||
Log.notice(TAG_TELN,F("Client connected"));
|
||||
Log.notice(TAG_TELN, F("Client connected"));
|
||||
|
||||
/* Avoid a buffer here */
|
||||
telnetClient.print(0xFF); // DO TERMINAL-TYPE
|
||||
@ -132,7 +133,8 @@ static void telnetProcessLine()
|
||||
telnetLoginState = TELNET_UNAUTHENTICATED;
|
||||
telnetLoginAttempt++; // Subsequent attempt
|
||||
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) {
|
||||
telnetClientDisconnect();
|
||||
} else {
|
||||
@ -200,7 +202,7 @@ void telnetSetup()
|
||||
// if(!telnetServer) telnetServer = new EthernetServer(telnetPort);
|
||||
// if(telnetServer) {
|
||||
telnetServer->begin();
|
||||
Log.notice(TAG_TELN,F("Debug telnet console started"));
|
||||
Log.notice(TAG_TELN, F("Debug telnet console started"));
|
||||
// } else {
|
||||
// Log.error(TAG_TELN,F("Failed to start telnet server"));
|
||||
//}
|
||||
@ -217,9 +219,9 @@ void telnetSetup()
|
||||
telnetClient.setNoDelay(true);
|
||||
//}
|
||||
|
||||
Log.notice(TAG_TELN,F("Debug telnet console started"));
|
||||
Log.notice(TAG_TELN, F("Debug telnet console started"));
|
||||
} else {
|
||||
Log.error(TAG_TELN,F("Failed to start telnet server"));
|
||||
Log.error(TAG_TELN, F("Failed to start telnet server"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -229,21 +231,21 @@ void IRAM_ATTR telnetLoop()
|
||||
{ // Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
Ethernet.schedule();
|
||||
// if(telnetServer)
|
||||
Ethernet.schedule();
|
||||
// if(telnetServer)
|
||||
{ // client is connected
|
||||
EthernetClient client = telnetServer->available();
|
||||
if(client) {
|
||||
if(!telnetClient || !telnetClient.connected()) {
|
||||
//telnetAcceptClient(client);
|
||||
// telnetAcceptClient(client);
|
||||
|
||||
telnetClient = client; // ready for new client
|
||||
// Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str());
|
||||
if(!telnetClient) {
|
||||
Log.notice(TAG_TELN,F("Client NOT connected"));
|
||||
Log.notice(TAG_TELN, F("Client NOT connected"));
|
||||
return;
|
||||
}
|
||||
Log.notice(TAG_TELN,F("Client connected"));
|
||||
Log.notice(TAG_TELN, F("Client connected"));
|
||||
|
||||
/* Avoid a buffer here */
|
||||
// telnetClient.print(0xFF); // DO TERMINAL-TYPE
|
||||
@ -251,7 +253,7 @@ Ethernet.schedule();
|
||||
// telnetClient.print(0x1B);
|
||||
|
||||
} 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);
|
||||
bool changed = false;
|
||||
|
||||
changed |= configSet(telnetEnabled, settings[FPSTR(F_CONFIG_ENABLE)], PSTR("telnetEnabled"));
|
||||
changed |= configSet(telnetPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("telnetPort"));
|
||||
changed |= configSet(telnetEnabled, settings[FPSTR(F_CONFIG_ENABLE)], F("telnetEnabled"));
|
||||
changed |= configSet(telnetPort, settings[FPSTR(F_CONFIG_PORT)], F("telnetPort"));
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user