From 2148ee77778b53c58ded13b4f69931b2c106f6e7 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:24:00 +0100 Subject: [PATCH] Xplatform changes --- src/hasp_config.h | 17 ++++---- src/hasp_debug.h | 88 +++++++++++++++++++++++++++++++++-------- src/hasp_filesystem.cpp | 55 ++++++++++++++------------ 3 files changed, 110 insertions(+), 50 deletions(-) diff --git a/src/hasp_config.h b/src/hasp_config.h index 31ea0df3..76cd5448 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -18,7 +18,7 @@ void configStart(void); void configStop(void); /* ===== Special Event Processors ===== */ -void configWriteConfig(void); +void configWrite(void); void configOutput(const JsonObject & settings, uint8_t tag = TAG_CONF); bool configClearEeprom(void); @@ -62,16 +62,15 @@ const char FP_GPIO_CONFIG[] PROGMEM = "config"; const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; -const char FP_WIFI[] PROGMEM = "wifi"; -const char FP_MQTT[] PROGMEM = "mqtt"; -const char FP_HTTP[] PROGMEM = "http"; -const char FP_GPIO[] PROGMEM = "gpio"; -const char FP_MDNS[] PROGMEM = "mdns"; -const char FP_HASP[] PROGMEM = "hasp"; -const char FP_GUI[] PROGMEM = "gui"; +const char FP_WIFI[] PROGMEM = "wifi"; +const char FP_MQTT[] PROGMEM = "mqtt"; +const char FP_HTTP[] PROGMEM = "http"; +const char FP_GPIO[] PROGMEM = "gpio"; +const char FP_MDNS[] PROGMEM = "mdns"; +const char FP_HASP[] PROGMEM = "hasp"; +const char FP_GUI[] PROGMEM = "gui"; const char FP_DEBUG[] PROGMEM = "debug"; - #endif #endif // HASP_USE_CONFIG \ No newline at end of file diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 0c182a04..3cc1794a 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -5,12 +5,14 @@ #define HASP_DEBUG_H #include "ArduinoJson.h" -#include "ArduinoLog.h" #include "hasp_macro.h" #include "lvgl.h" #include "lang/lang.h" +#ifndef WINDOWS +#include "ArduinoLog.h" + /* ===== Default Event Processors ===== */ void debugPreSetup(JsonObject settings); void debugSetup(); @@ -20,30 +22,84 @@ void debugStart(void); void debugStop(void); /* ===== Special Event Processors ===== */ -void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, - const char * descr); -void debugPrintHaspHeader(Print * output); +void debugLvglLogEvent(lv_log_level_t level, const char *file, uint32_t line, const char *funcname, + const char *descr); +void debugPrintHaspHeader(Print *output); void debugStartSyslog(void); void debugStopSyslog(void); // void syslogSend(uint8_t log, const char * debugText); +#else +#include + +#define LOG_FATAL(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_ERROR(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_WARNING(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_NOTICE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_TRACE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_VERBOSE(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_DEBUG(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) +#define LOG_INFO(x, ...) printf(__VA_ARGS__); std::cout << std::endl; fflush(stdout) + +/* json keys used in the configfile */ +// const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; +// const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim"; +// const char FP_CONFIG_THEME[] PROGMEM = "theme"; +// const char FP_CONFIG_HUE[] PROGMEM = "hue"; +// const char FP_CONFIG_ZIFONT[] PROGMEM = "font"; +// const char FP_CONFIG_PAGES[] PROGMEM = "pages"; +// const char FP_CONFIG_ENABLE[] PROGMEM = "enable"; +// const char FP_CONFIG_HOST[] PROGMEM = "host"; +// const char FP_CONFIG_PORT[] PROGMEM = "port"; +// const char FP_CONFIG_NAME[] PROGMEM = "name"; +// const char FP_CONFIG_USER[] PROGMEM = "user"; +// const char FP_CONFIG_PASS[] PROGMEM = "pass"; +// const char FP_CONFIG_SSID[] PROGMEM = "ssid"; +// const char FP_CONFIG_GROUP[] PROGMEM = "group"; +// const char FP_CONFIG_BAUD[] PROGMEM = "baud"; +// const char FP_CONFIG_LOG[] PROGMEM = "log"; +// const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto"; +// const char FP_GUI_ROTATION[] PROGMEM = "rotate"; +// const char FP_GUI_INVERT[] PROGMEM = "invert"; +// const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; +// const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; +// const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2"; +// const char FP_GUI_CALIBRATION[] PROGMEM = "calibration"; +// const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl"; +// const char FP_GUI_POINTER[] PROGMEM = "cursor"; +// const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; +// const char FP_GPIO_CONFIG[] PROGMEM = "config"; + +// const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; + +// const char FP_WIFI[] PROGMEM = "wifi"; +// const char FP_MQTT[] PROGMEM = "mqtt"; +// const char FP_HTTP[] PROGMEM = "http"; +// const char FP_GPIO[] PROGMEM = "gpio"; +// const char FP_MDNS[] PROGMEM = "mdns"; +// const char FP_HASP[] PROGMEM = "hasp"; +// const char FP_GUI[] PROGMEM = "gui"; +// const char FP_DEBUG[] PROGMEM = "debug"; + +#endif /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 -bool debugGetConfig(const JsonObject & settings); -bool debugSetConfig(const JsonObject & settings); +bool debugGetConfig(const JsonObject &settings); +bool debugSetConfig(const JsonObject &settings); #endif // void debugPrintPrefix(int level, Print * _logOutput); // void debugPrintSuffix(int level, Print * _logOutput); // void debugSendOuput(const char * buffer); -enum { +enum +{ TAG_MAIN = 0, TAG_HASP = 1, TAG_ATTR = 2, TAG_MSGR = 3, TAG_OOBE = 4, - TAG_HAL = 5, + TAG_HAL = 5, TAG_DRVR = 6, TAG_DEBG = 10, @@ -52,8 +108,8 @@ enum { TAG_TASM = 13, TAG_CONF = 20, - TAG_GUI = 21, - TAG_TFT = 22, + TAG_GUI = 21, + TAG_TFT = 22, TAG_EPRM = 30, TAG_FILE = 31, @@ -61,12 +117,12 @@ enum { TAG_FWUP = 50, - TAG_ETH = 60, - TAG_WIFI = 61, - TAG_HTTP = 62, - TAG_OTA = 63, - TAG_MDNS = 64, - TAG_MQTT = 65, + TAG_ETH = 60, + TAG_WIFI = 61, + TAG_HTTP = 62, + TAG_OTA = 63, + TAG_MDNS = 64, + TAG_MQTT = 65, TAG_MQTT_PUB = 66, TAG_MQTT_RCV = 67, diff --git a/src/hasp_filesystem.cpp b/src/hasp_filesystem.cpp index a4544532..c8d915f8 100644 --- a/src/hasp_filesystem.cpp +++ b/src/hasp_filesystem.cpp @@ -1,21 +1,24 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ -#include -#include "ArduinoJson.h" -#include "ArduinoLog.h" +#include "hasp_conf.h" // include first -#include "hasp_conf.h" -#include "hasp_debug.h" -#include "hasp_filesystem.h" +#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + + #include + #include "ArduinoJson.h" + #include "ArduinoLog.h" + + #include "hasp_debug.h" + #include "hasp_filesystem.h" void filesystemInfo() { // Get all information of your SPIFFS -#if 0 + #if 0 FSInfo fs_info; SPIFFS.info(fs_info); - Serial.println("File sistem info."); + Serial.println("File system info."); Serial.print("Total space: "); Serial.print(fs_info.totalBytes); @@ -61,61 +64,63 @@ void filesystemInfo() Serial.print("Max path lenght: "); // Serial.println(SPIFFS.maxPathLength()); -#endif + #endif } void filesystemList() { -#if HASP_USE_SPIFFS > 0 -#if defined(ARDUINO_ARCH_ESP8266) + #if HASP_USE_SPIFFS > 0 + #if defined(ARDUINO_ARCH_ESP8266) if(!SPIFFS.begin()) { -#else + #else if(!SPIFFS.begin(true)) { -#endif + #endif LOG_ERROR(TAG_FILE, F("Flash file system not mouted.")); } else { LOG_VERBOSE(TAG_FILE, F("Listing files on the internal flash:")); -#if defined(ARDUINO_ARCH_ESP32) + #if defined(ARDUINO_ARCH_ESP32) File root = SPIFFS.open("/"); File file = root.openNextFile(); while(file) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size()); file = root.openNextFile(); } -#endif -#if defined(ARDUINO_ARCH_ESP8266) + #endif + #if defined(ARDUINO_ARCH_ESP8266) Dir dir = SPIFFS.openDir("/"); while(dir.next()) { LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); } -#endif + #endif } -#endif + #endif } bool filesystemSetup(void) { // no SPIFFS settings, as settings depend on SPIFFS // no Logging, because it depends on the configuration file - + // Logging is defered until debugging has started // FS success or failure is printed at that time ! -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 -#if defined(ARDUINO_ARCH_ESP8266) + #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + #if defined(ARDUINO_ARCH_ESP8266) if(!HASP_FS.begin()) { -#else + #else if(!HASP_FS.begin(true)) { -#endif + #endif // LOG_ERROR(TAG_FILE, F("SPI flash init failed. Unable to mount FS.")); return false; } else { // LOG_INFO(TAG_FILE, F("SPI Flash FS mounted")); return true; } -#endif + #endif return false; -} \ No newline at end of file +} + +#endif \ No newline at end of file