From 86321beb5ddff8d46a78e1b61b10b9fd547be6ad Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 May 2023 15:05:32 +0200 Subject: [PATCH] Remove F() and move FlashStringHelper to char* --- src/drv/tft/tft_driver_lovyangfx.cpp | 88 ++++---- src/hasp/hasp.cpp | 14 +- src/hasp/hasp.h | 6 +- src/hasp_config.cpp | 20 +- src/hasp_config.h | 18 +- src/hasp_debug.cpp | 11 +- src/sys/svc/hasp_http.cpp | 316 +++++++++++++-------------- 7 files changed, 249 insertions(+), 224 deletions(-) diff --git a/src/drv/tft/tft_driver_lovyangfx.cpp b/src/drv/tft/tft_driver_lovyangfx.cpp index da26fa7f..f3ecfc16 100644 --- a/src/drv/tft/tft_driver_lovyangfx.cpp +++ b/src/drv/tft/tft_driver_lovyangfx.cpp @@ -19,11 +19,21 @@ namespace dev { -void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) +// void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) +// { +// if(pin != -1) { +// char buffer[64]; +// snprintf_P(buffer, sizeof(buffer), PSTR("%-12s: %s (GPIO %02d)"), String(pinfunction).c_str(), +// haspDevice.gpio_name(pin).c_str(), pin); +// LOG_VERBOSE(TAG_TFT, buffer); +// } +// } + +void tftPinInfo(const char* pinfunction, int8_t pin) { if(pin != -1) { char buffer[64]; - snprintf_P(buffer, sizeof(buffer), PSTR("%-12s: %s (GPIO %02d)"), String(pinfunction).c_str(), + snprintf_P(buffer, sizeof(buffer), PSTR("%-12s: %s (GPIO %02d)"), pinfunction, haspDevice.gpio_name(pin).c_str(), pin); LOG_VERBOSE(TAG_TFT, buffer); } @@ -187,7 +197,7 @@ static lgfx::Bus_SPI* init_spi_bus(Preferences* prefs) static void configure_panel(lgfx::Panel_Device* panel, Preferences* prefs) { - auto cfg = panel->config(); // Get the structure for display panel settings. + auto cfg = panel->config(); // Get the structure for display panel settings. cfg.pin_cs = prefs->getInt("cs", TFT_CS); // CS required cfg.pin_rst = prefs->getInt("rst", TFT_RST); // RST sum development board RST linkage @@ -201,27 +211,27 @@ static void configure_panel(lgfx::Panel_Device* panel, Preferences* prefs) cfg.memory_width = prefs->getUInt("memory_width", cfg.panel_width); // Maximum width supported by driver IC cfg.memory_height = prefs->getUInt("memory_height", cfg.panel_height); // Maximum height supported by driver IC - cfg.offset_x = prefs->getUInt("offset_x", 0); // Amount of offset in the X direction of the panel - cfg.offset_y = prefs->getUInt("offset_y", 0); // Amount of offset in the Y direction of the panel + cfg.offset_x = prefs->getUInt("offset_x", 0); // Amount of offset in the X direction of the panel + cfg.offset_y = prefs->getUInt("offset_y", 0); // Amount of offset in the Y direction of the panel cfg.offset_rotation = - prefs->getUInt("offset_rotation", TFT_OFFSET_ROTATION); // Offset of the rotation 0 ~ 7 (4 ~ 7 is upside down) + prefs->getUInt("offset_rotation", TFT_OFFSET_ROTATION); // Offset of the rotation 0 ~ 7 (4 ~ 7 is upside down) cfg.dummy_read_pixel = prefs->getUInt("dummy_read_pixel", 8); // Number of dummy read bits before pixel read cfg.dummy_read_bits = prefs->getUInt("dummy_read_bits", 1); // bits of dummy read before reading data other than pixels cfg.readable = prefs->getBool("readable", false); // true if data can be read -#ifdef INVERT_COLORS // This is configurable un Web UI +#ifdef INVERT_COLORS // This is configurable un Web UI cfg.invert = prefs->getBool("invert", INVERT_COLORS != 0); // true if the light and darkness of the panel is reversed #else - cfg.invert = prefs->getBool("invert", false); // true if the light and darkness of the panel is reversed + cfg.invert = prefs->getBool("invert", false); // true if the light and darkness of the panel is reversed #endif #ifdef TFT_RGB_ORDER cfg.rgb_order = prefs->getBool("rgb_order", TFT_RGB_ORDER != 0); // true if the red and blue of the panel are swapped #else - cfg.rgb_order = prefs->getBool("rgb_order", false); // true if the red and blue of the panel are swapped + cfg.rgb_order = prefs->getBool("rgb_order", false); // true if the red and blue of the panel are swapped #endif cfg.dlen_16bit = prefs->getBool("dlen_16bit", false); // true for panels that send data length in 16-bit units cfg.bus_shared = prefs->getBool("bus_shared", true); // true if the bus is shared with the SD card @@ -495,44 +505,44 @@ void LovyanGfx::init(int w, int h) #elif 0 && defined(LILYGOPI) auto _panel_instance = new lgfx::Panel_ST7796(); - auto _bus_instance = new lgfx::Bus_SPI(); + auto _bus_instance = new lgfx::Bus_SPI(); auto _touch_instance = new lgfx::Touch_FT5x06(); { - auto cfg = _bus_instance->config(); - cfg.spi_host = VSPI_HOST; - cfg.spi_mode = 0; - cfg.freq_write = 40000000; - cfg.freq_read = 16000000; - cfg.spi_3wire = false; - cfg.use_lock = true; + auto cfg = _bus_instance->config(); + cfg.spi_host = VSPI_HOST; + cfg.spi_mode = 0; + cfg.freq_write = 40000000; + cfg.freq_read = 16000000; + cfg.spi_3wire = false; + cfg.use_lock = true; cfg.dma_channel = 1; - cfg.pin_sclk = 18; - cfg.pin_mosi = 19; - cfg.pin_miso = 23; - cfg.pin_dc = 27; + cfg.pin_sclk = 18; + cfg.pin_mosi = 19; + cfg.pin_miso = 23; + cfg.pin_dc = 27; _bus_instance->config(cfg); _panel_instance->setBus(_bus_instance); } { - auto cfg = _panel_instance->config(); - cfg.pin_cs = 5; - cfg.pin_rst = -1; - cfg.pin_busy = -1; - cfg.memory_width = 320; - cfg.memory_height = 480; - cfg.panel_width = 320; - cfg.panel_height = 480; - cfg.offset_x = 0; - cfg.offset_y = 0; - cfg.offset_rotation = 0; + auto cfg = _panel_instance->config(); + cfg.pin_cs = 5; + cfg.pin_rst = -1; + cfg.pin_busy = -1; + cfg.memory_width = 320; + cfg.memory_height = 480; + cfg.panel_width = 320; + cfg.panel_height = 480; + cfg.offset_x = 0; + cfg.offset_y = 0; + cfg.offset_rotation = 0; cfg.dummy_read_pixel = 8; - cfg.dummy_read_bits = 1; - cfg.readable = true; - cfg.invert = false; - cfg.rgb_order = false; - cfg.dlen_16bit = false; - cfg.bus_shared = true; + cfg.dummy_read_bits = 1; + cfg.readable = true; + cfg.invert = false; + cfg.rgb_order = false; + cfg.dlen_16bit = false; + cfg.bus_shared = true; _panel_instance->config(cfg); } @@ -554,7 +564,7 @@ void LovyanGfx::init(int w, int h) lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, ~0, axp_i2c_freq); // LDO2 enable lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x92, 0x00, 0xF8, axp_i2c_freq); // GPIO1 OpenDrain (M5Tough TOUCH) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq); // GPIO4 enable + lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq); // GPIO4 enable if(/*use_reset*/ true) { lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST) lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0, ~0x02, diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 5c2ce09a..7f541b32 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -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) diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 4b9b5217..c67dca11 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -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*/ diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index cb091b9e..1573299e 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -29,7 +29,7 @@ extern uint32_t dispatchLastMillis; extern gui_conf_t gui_settings; extern dispatch_conf_t dispatch_settings; -void confDebugSet(const __FlashStringHelper* fstr_name) +void confDebugSet(const char* fstr_name) { /*char buffer[128]; snprintf_P(buffer, sizeof(buffer), PSTR(" * %s set"), name); @@ -37,7 +37,7 @@ void confDebugSet(const __FlashStringHelper* fstr_name) LOG_VERBOSE(TAG_CONF, F(D_BULLET "%S set"), fstr_name); } -bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(bool& value, const JsonVariant& setting, const char* fstr_name) { if(!setting.isNull()) { bool val = setting.as(); @@ -49,7 +49,7 @@ bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelpe } return false; } -bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(int8_t& value, const JsonVariant& setting, const char* fstr_name) { if(!setting.isNull()) { int8_t val = setting.as(); @@ -61,7 +61,7 @@ bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHel } return false; } -bool configSet(uint8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(uint8_t& value, const JsonVariant& setting, const char* fstr_name) { if(!setting.isNull()) { uint8_t val = setting.as(); @@ -73,7 +73,7 @@ bool configSet(uint8_t& value, const JsonVariant& setting, const __FlashStringHe } return false; } -bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(uint16_t& value, const JsonVariant& setting, const char* fstr_name) { if(!setting.isNull()) { uint16_t val = setting.as(); @@ -85,7 +85,7 @@ bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringH } return false; } -bool configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(int32_t& value, const JsonVariant& setting, const char* fstr_name) { if(!setting.isNull()) { int32_t val = setting.as(); @@ -97,7 +97,7 @@ bool configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHe } return false; } -bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name) +bool configSet(lv_color_t& value, const JsonVariant& setting, const char* fstr_name) { lv_color32_t c32; if(!setting.isNull() && Parser::haspPayloadToColor(setting.as(), c32)) { @@ -118,7 +118,7 @@ void configSetupDebug(JsonDocument& settings) void configStorePasswords(JsonDocument& settings, String& wifiPass, String& mqttPass, String& httpPass) { - const __FlashStringHelper* pass = F("pass"); + const char* pass = F("pass"); wifiPass = settings[FPSTR(FP_WIFI)][pass].as(); mqttPass = settings[FPSTR(FP_MQTT)][pass].as(); @@ -127,7 +127,7 @@ void configStorePasswords(JsonDocument& settings, String& wifiPass, String& mqtt void configRestorePasswords(JsonDocument& settings, String& wifiPass, String& mqttPass, String& httpPass) { - const __FlashStringHelper* pass = F("pass"); + const char* pass = F("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 +287,7 @@ void configWrite() bool writefile = false; bool changed = false; - const __FlashStringHelper* module; + const char* module; #if HASP_USE_WIFI > 0 module = FPSTR(FP_WIFI); diff --git a/src/hasp_config.h b/src/hasp_config.h index 00d24d58..eda3d400 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -23,12 +23,18 @@ 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); +bool configSet(uint16_t& value, const JsonVariant& setting, const char* fstr_name); +bool configSet(int32_t& value, const JsonVariant& setting, const char* fstr_name); +bool configSet(lv_color_t& value, const JsonVariant& setting, const char* fstr_name); void configMaskPasswords(JsonDocument& settings); /* ===== Read/Write Configuration ===== */ diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 99117cce..408997d8 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -25,7 +25,16 @@ bool debugAnsiCodes = false; -inline void debugSendAnsiCode(const __FlashStringHelper* code, Print* _logOutput) +// 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) { #ifdef ARDUINO if(debugAnsiCodes) _logOutput->print(code); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 46d9aec2..058846af 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -160,13 +160,13 @@ String getOption(String& value, String& label, String& current_value) return buffer; } -static void add_form_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* action) +static void add_form_button(String& str, const char* label, const char* action) { - str += F(""); + str += "'>"; str += label; - str += F(""); + str += ""; } static String http_get_content_type(const String& path) @@ -200,7 +200,7 @@ bool http_is_authenticated() if(http_config.password[0] != '\0') { // Request HTTP auth if httpPassword is set if(!webServer.authenticate(http_config.username, http_config.password)) { webServer.requestAuthentication(); - LOG_WARNING(TAG_HTTP, F(D_TELNET_INCORRECT_LOGIN_ATTEMPT), + LOG_WARNING(TAG_HTTP, D_TELNET_INCORRECT_LOGIN_ATTEMPT, webServer.client().remoteIP().toString().c_str()); return false; } @@ -209,15 +209,15 @@ bool http_is_authenticated() } // Check authentication and create Log entry -bool http_is_authenticated(const __FlashStringHelper* notused) +bool http_is_authenticated(const char* notused) { if(!http_is_authenticated()) return false; #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - LOG_VERBOSE(TAG_HTTP, F(D_HTTP_SENDING_PAGE), webServer.uri().c_str(), + LOG_VERBOSE(TAG_HTTP, D_HTTP_SENDING_PAGE, webServer.uri().c_str(), webServer.client().remoteIP().toString().c_str()); #else - // LOG_INFO(TAG_HTTP,F(D_HTTP_SENDING_PAGE), page, + // LOG_INFO(TAG_HTTP,D_HTTP_SENDING_PAGE, page, // String(webServer.client().remoteIP()).c_str()); #endif @@ -240,7 +240,7 @@ static void webSendFooter() static void http_send_cache_header(int size, int age = 3600) { webServer.sendHeader("Content-Length", (String)(size)); - webServer.sendHeader(F("Cache-Control"), (String)(F("public, max-age=")) + (String)(age)); + webServer.sendHeader("Cache-Control", (String)(F("public, max-age=")) + (String)(age)); } static int http_send_cached(int statuscode, const char* contenttype, const char* data, size_t size, int age = 3600) @@ -263,7 +263,7 @@ static int http_send_static_file(const uint8_t* start, const uint8_t* end, Strin static int http_send_static_gzip_file(const uint8_t* start, const uint8_t* end, String& contentType) { - webServer.sendHeader(F("Content-Encoding"), F("gzip")); + webServer.sendHeader("Content-Encoding", "gzip"); return http_send_static_file(start, end, contentType); } @@ -337,9 +337,9 @@ static void http_send_etag(String& etag) newTag = "\""; newTag += etag; newTag += "\""; - webServer.sendHeader(F("Cache-Control"), F("no-cache, must-revalidate, public")); - webServer.sendHeader(F("Expires"), F("Fri, 30 Oct 1998 14:19:41 GMT")); - webServer.sendHeader(F("ETag"), newTag); + webServer.sendHeader("Cache-Control", F("no-cache, must-revalidate, public")); + webServer.sendHeader("Expires", F("Fri, 30 Oct 1998 14:19:41 GMT")); + webServer.sendHeader("ETag", newTag); } bool http_save_config() @@ -378,7 +378,7 @@ bool http_save_config() updated = httpSetConfig(settings.as()); // Password might have changed - if(!http_is_authenticated(F("config"))) return updated; + if(!http_is_authenticated("config")) return updated; #if HASP_USE_WIFI > 0 } else if(save == FP_WIFI) { @@ -392,7 +392,7 @@ bool http_save_config() static void http_handle_root() { - if(!http_is_authenticated(F("root"))) return; + if(!http_is_authenticated("root")) return; bool updated = http_save_config(); const char* html[20]; @@ -420,7 +420,7 @@ static void http_handle_root() //////////////////////////////////////////////////////////////////////////////////////////////////// static void http_handle_reboot() { // http://plate01/reboot - if(!http_is_authenticated(F("reboot"))) return; + if(!http_is_authenticated("reboot")) return; const char* html[20]; int i = 0; @@ -441,21 +441,21 @@ static void http_handle_reboot() //////////////////////////////////////////////////////////////////////////////////////////////////// static void http_handle_screenshot() { // http://plate01/screenshot - if(!http_is_authenticated(F("screenshot"))) return; + if(!http_is_authenticated("screenshot")) return; { // Execute actions - if(webServer.hasArg(F("a"))) { - if(webServer.arg(F("a")) == F("next")) { + if(webServer.hasArg("a")) { + if(webServer.arg("a") == "next") { dispatch_page_next(LV_SCR_LOAD_ANIM_NONE); - } else if(webServer.arg(F("a")) == F("prev")) { + } else if(webServer.arg("a") == "prev") { dispatch_page_prev(LV_SCR_LOAD_ANIM_NONE); - } else if(webServer.arg(F("a")) == F("back")) { + } else if(webServer.arg("a") == "back") { dispatch_page_back(LV_SCR_LOAD_ANIM_NONE); } } // Check if screenshot bitmap is dirty - if(webServer.hasArg(F("d"))) { + if(webServer.hasArg("d")) { if(guiScreenshotIsDirty()) webServer.send(200, F("text/text"), "1"); else @@ -479,7 +479,7 @@ static void http_handle_screenshot() } // Send actual bitmap - if(webServer.hasArg(F("q"))) { + if(webServer.hasArg("q")) { lv_disp_t* disp = lv_disp_get_default(); etag = (String)(modified); http_send_etag(etag); // Send new tag with modification version @@ -534,7 +534,7 @@ static void add_license(JsonObject& obj, const char* title, const char* year, co static void webHandleApi() { // http://plate01/api - if(!http_is_authenticated(F("api"))) return; + if(!http_is_authenticated("api")) return; DynamicJsonDocument doc(2048); String contentType = http_get_content_type(F(".json")); @@ -542,7 +542,7 @@ static void webHandleApi() endpoint = webServer.pathArg(0); if(!strcasecmp(endpoint.c_str(), "files")) { - String path = webServer.arg(F("dir")); + String path = webServer.arg("dir"); webServer.send(200, contentType.c_str(), filesystem_list(HASP_FS, path.c_str(), 5).c_str()); } else if(!strcasecmp(endpoint.c_str(), "info")) { @@ -640,7 +640,7 @@ static void webHandleApi() } settings = doc.to(); - const __FlashStringHelper* module; + const char* module; module = FPSTR(FP_HASP); settings.createNestedObject(module); @@ -717,7 +717,7 @@ static void webHandleApi() static void webHandleApiConfig() { // http://plate01/about - if(!http_is_authenticated(F("api"))) return; + if(!http_is_authenticated("api")) return; if(webServer.method() != HTTP_GET && webServer.method() != HTTP_POST) { return; @@ -861,7 +861,7 @@ static void webHandleApiConfig() //////////////////////////////////////////////////////////////////////////////////////////////////// static void http_handle_about() { // http://plate01/about - if(!http_is_authenticated(F("about"))) return; + if(!http_is_authenticated("about")) return; const char* form = R"(