Revert F() and move char* to FlashStringHelper

This commit is contained in:
fvanroie 2023-05-09 16:13:39 +02:00
parent af24bedf6d
commit 6ccd10dbe0
6 changed files with 149 additions and 42 deletions

View File

@ -437,13 +437,13 @@ void haspProgressMsg(const char* msg)
} */
}
// #ifdef ARDUINO
// // Sets the value string of the global progress bar
// void haspProgressMsg(const __FlashStringHelper* msg)
// {
// haspProgressMsg(String(msg).c_str());
// }
// #endif
#ifdef ARDUINO
// Sets the value string of the global progress bar
void haspProgressMsg(const __FlashStringHelper* msg)
{
haspProgressMsg(String(msg).c_str());
}
#endif
/*Add a custom apply callback*/
static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t name)
@ -829,20 +829,20 @@ bool haspSetConfig(const JsonObject& settings)
JsonVariant color_str;
bool changed = false;
changed |= configSet(haspStartPage, settings[FPSTR(FP_CONFIG_STARTPAGE)], F("haspStartPage"));
changed |= configSet(haspStartDim, settings[FPSTR(FP_CONFIG_STARTDIM)], F("haspStartDim"));
changed |= configSet(haspStartPage, settings[FPSTR(FP_CONFIG_STARTPAGE)], "haspStartPage");
changed |= configSet(haspStartDim, settings[FPSTR(FP_CONFIG_STARTDIM)], "haspStartDim");
{ // Theme related settings
// Set from Hue first
bool theme_changed = false;
theme_changed |= configSet(haspThemeId, settings[FPSTR(FP_CONFIG_THEME)], F("haspThemeId"));
theme_changed |= configSet(haspThemeHue, settings[FPSTR(FP_CONFIG_HUE)], F("haspThemeHue"));
theme_changed |= configSet(haspThemeId, settings[FPSTR(FP_CONFIG_THEME)], "haspThemeId");
theme_changed |= configSet(haspThemeHue, settings[FPSTR(FP_CONFIG_HUE)], "haspThemeHue");
color_primary = lv_color_hsv_to_rgb(haspThemeHue, 100, 100);
color_secondary = lv_color_hsv_to_rgb(20, 60, 100);
// Check for color1 and color2
theme_changed |= configSet(color_primary, settings[FPSTR(FP_CONFIG_COLOR1)], F("haspColor1"));
theme_changed |= configSet(color_secondary, settings[FPSTR(FP_CONFIG_COLOR2)], F("haspColor2"));
theme_changed |= configSet(color_primary, settings[FPSTR(FP_CONFIG_COLOR1)], "haspColor1");
theme_changed |= configSet(color_secondary, settings[FPSTR(FP_CONFIG_COLOR2)], "haspColor2");
changed |= theme_changed;
// if(theme_changed) hasp_set_theme(haspThemeId); // LVGL is not inited at config load time

View File

@ -105,8 +105,8 @@ void hasp_set_theme(uint8_t themeid);
#endif
void haspProgressMsg(const char* msg);
// #ifdef ARDUINO
// void haspProgressMsg(const __FlashStringHelper* msg);
// #endif
#ifdef ARDUINO
void haspProgressMsg(const __FlashStringHelper* msg);
#endif
#endif /*HASP_H*/

View File

@ -10,12 +10,12 @@
#include "hasp_gui.h"
#include "hal/hasp_hal.h"
//#include "hasp_ota.h" included in conf
//#include "hasp_filesystem.h" included in conf
//#include "hasp_telnet.h" included in conf
//#include "hasp_gpio.h" included in conf
// #include "hasp_ota.h" included in conf
// #include "hasp_filesystem.h" included in conf
// #include "hasp_telnet.h" included in conf
// #include "hasp_gpio.h" included in conf
//#include "hasp_eeprom.h"
// #include "hasp_eeprom.h"
#if HASP_USE_EEPROM > 0
#include "EEPROM.h"
@ -29,13 +29,94 @@ extern uint32_t dispatchLastMillis;
extern gui_conf_t gui_settings;
extern dispatch_conf_t dispatch_settings;
void confDebugSet(const char* fstr_name)
void confDebugSet(const __FlashStringHelper* fstr_name)
{
/*char buffer[128];
snprintf_P(buffer, sizeof(buffer), PSTR(" * %s set"), name);
debugPrintln(buffer);*/
LOG_VERBOSE(TAG_CONF, F(D_BULLET "%S set"), fstr_name);
}
void confDebugSet(const char* fstr_name)
{
/*char buffer[128];
snprintf_P(buffer, sizeof(buffer), PSTR(" * %s set"), name);
debugPrintln(buffer);*/
LOG_VERBOSE(TAG_CONF, F(D_BULLET "%s set"), fstr_name);
}
bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
{
if(!setting.isNull()) {
bool val = setting.as<bool>();
if(value != val) {
confDebugSet(fstr_name);
value = val;
return true;
}
}
return false;
}
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(fstr_name);
value = val;
return true;
}
}
return false;
}
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(fstr_name);
value = val;
return true;
}
}
return false;
}
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(fstr_name);
value = val;
return true;
}
}
return false;
}
bool configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
{
if(!setting.isNull()) {
int32_t val = setting.as<int32_t>();
if(value != val) {
confDebugSet(fstr_name);
value = val;
return true;
}
}
return false;
}
bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
{
lv_color32_t c32;
if(!setting.isNull() && Parser::haspPayloadToColor(setting.as<const char*>(), c32)) {
lv_color_t val = lv_color_make(c32.ch.red, c32.ch.green, c32.ch.blue);
if(value.full != val.full) {
confDebugSet(fstr_name);
value = val;
return true;
}
}
return false;
}
bool configSet(bool& value, const JsonVariant& setting, const char* fstr_name)
{
@ -110,6 +191,7 @@ bool configSet(lv_color_t& value, const JsonVariant& setting, const char* fstr_n
}
return false;
}
void configSetupDebug(JsonDocument& settings)
{
debugSetup(settings[FPSTR(FP_DEBUG)]);
@ -118,7 +200,7 @@ void configSetupDebug(JsonDocument& settings)
void configStorePasswords(JsonDocument& settings, String& wifiPass, String& mqttPass, String& httpPass)
{
const char* pass = F("pass");
const char* pass = ("pass");
wifiPass = settings[FPSTR(FP_WIFI)][pass].as<String>();
mqttPass = settings[FPSTR(FP_MQTT)][pass].as<String>();
@ -127,7 +209,7 @@ void configStorePasswords(JsonDocument& settings, String& wifiPass, String& mqtt
void configRestorePasswords(JsonDocument& settings, String& wifiPass, String& mqttPass, String& httpPass)
{
const char* pass = F("pass");
const char* pass = ("pass");
if(!settings[FPSTR(FP_WIFI)][pass].isNull()) settings[FPSTR(FP_WIFI)][pass] = wifiPass;
if(!settings[FPSTR(FP_MQTT)][pass].isNull()) settings[FPSTR(FP_MQTT)][pass] = mqttPass;
@ -287,7 +369,7 @@ void configWrite()
bool writefile = false;
bool changed = false;
const char* module;
const __FlashStringHelper* module;
#if HASP_USE_WIFI > 0
module = FPSTR(FP_WIFI);
@ -453,7 +535,7 @@ void configSetup()
configRead(settings, true);
}
//#if HASP_USE_SPIFFS > 0
// #if HASP_USE_SPIFFS > 0
LOG_INFO(TAG_DEBG, F("Loading debug settings"));
debugSetConfig(settings[FPSTR(FP_DEBUG)]);
LOG_INFO(TAG_GPIO, F("Loading GUI settings"));
@ -494,7 +576,7 @@ void configSetup()
LOG_INFO(TAG_CONF, F(D_CONFIG_LOADED));
}
//#endif
// #endif
}
void configLoop(void)

View File

@ -23,12 +23,12 @@ void configOutput(const JsonObject& settings, uint8_t tag);
bool configClearEeprom(void);
/* ===== Getter and Setter Functions ===== */
// bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_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 configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
// bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_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 configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(bool& value, const JsonVariant& setting, const char* fstr_name);
bool configSet(int8_t& value, const JsonVariant& setting, const char* fstr_name);
bool configSet(uint8_t& value, const JsonVariant& setting, const char* fstr_name);

View File

@ -25,14 +25,14 @@
bool debugAnsiCodes = false;
// inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput)
// {
// #ifdef ARDUINO
// if(debugAnsiCodes) _logOutput->print(code);
// #else
// if(debugAnsiCodes) debug_print(_logOutput, code);
// #endif
// }
inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput)
{
#ifdef ARDUINO
if(debugAnsiCodes) _logOutput->print(code);
#else
if(debugAnsiCodes) debug_print(_logOutput, code);
#endif
}
inline void debugSendAnsiCode(const char* code, Print* _logOutput)
{

View File

@ -169,6 +169,15 @@ static void add_form_button(String& str, const char* label, const char* action)
str += "</a>";
}
static void add_form_button(String& str, const char* label, const __FlashStringHelper* action)
{
str += "<a href='";
str += action;
str += "'>";
str += label;
str += "</a>";
}
static String http_get_content_type(const String& path)
{
char buffer[sizeof(mime::mimeTable[0].mimeType)];
@ -208,6 +217,22 @@ bool http_is_authenticated()
return true;
}
// Check authentication and create Log entry
bool http_is_authenticated(const __FlashStringHelper* notused)
{
if(!http_is_authenticated()) return false;
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
LOG_VERBOSE(TAG_HTTP, D_HTTP_SENDING_PAGE, webServer.uri().c_str(),
webServer.client().remoteIP().toString().c_str());
#else
// LOG_INFO(TAG_HTTP,D_HTTP_SENDING_PAGE, page,
// String(webServer.client().remoteIP()).c_str());
#endif
return true;
}
// Check authentication and create Log entry
bool http_is_authenticated(const char* notused)
{
@ -640,7 +665,7 @@ static void webHandleApi()
}
settings = doc.to<JsonObject>();
const char* module;
const __FlashStringHelper* module;
module = FPSTR(FP_HASP);
settings.createNestedObject(module);