Xplatform changes

This commit is contained in:
fvanroie 2021-02-16 17:24:00 +01:00
parent 52eef3f657
commit 2148ee7777
3 changed files with 110 additions and 50 deletions

View File

@ -18,7 +18,7 @@ void configStart(void);
void configStop(void); void configStop(void);
/* ===== Special Event Processors ===== */ /* ===== Special Event Processors ===== */
void configWriteConfig(void); void configWrite(void);
void configOutput(const JsonObject & settings, uint8_t tag = TAG_CONF); void configOutput(const JsonObject & settings, uint8_t tag = TAG_CONF);
bool configClearEeprom(void); 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_HASP_CONFIG_FILE[] PROGMEM = "/config.json";
const char FP_WIFI[] PROGMEM = "wifi"; const char FP_WIFI[] PROGMEM = "wifi";
const char FP_MQTT[] PROGMEM = "mqtt"; const char FP_MQTT[] PROGMEM = "mqtt";
const char FP_HTTP[] PROGMEM = "http"; const char FP_HTTP[] PROGMEM = "http";
const char FP_GPIO[] PROGMEM = "gpio"; const char FP_GPIO[] PROGMEM = "gpio";
const char FP_MDNS[] PROGMEM = "mdns"; const char FP_MDNS[] PROGMEM = "mdns";
const char FP_HASP[] PROGMEM = "hasp"; const char FP_HASP[] PROGMEM = "hasp";
const char FP_GUI[] PROGMEM = "gui"; const char FP_GUI[] PROGMEM = "gui";
const char FP_DEBUG[] PROGMEM = "debug"; const char FP_DEBUG[] PROGMEM = "debug";
#endif #endif
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG

View File

@ -5,12 +5,14 @@
#define HASP_DEBUG_H #define HASP_DEBUG_H
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "ArduinoLog.h"
#include "hasp_macro.h" #include "hasp_macro.h"
#include "lvgl.h" #include "lvgl.h"
#include "lang/lang.h" #include "lang/lang.h"
#ifndef WINDOWS
#include "ArduinoLog.h"
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void debugPreSetup(JsonObject settings); void debugPreSetup(JsonObject settings);
void debugSetup(); void debugSetup();
@ -20,30 +22,84 @@ void debugStart(void);
void debugStop(void); void debugStop(void);
/* ===== Special Event Processors ===== */ /* ===== Special Event Processors ===== */
void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, void debugLvglLogEvent(lv_log_level_t level, const char *file, uint32_t line, const char *funcname,
const char * descr); const char *descr);
void debugPrintHaspHeader(Print * output); void debugPrintHaspHeader(Print *output);
void debugStartSyslog(void); void debugStartSyslog(void);
void debugStopSyslog(void); void debugStopSyslog(void);
// void syslogSend(uint8_t log, const char * debugText); // void syslogSend(uint8_t log, const char * debugText);
#else
#include <iostream>
#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 ===== */ /* ===== Read/Write Configuration ===== */
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
bool debugGetConfig(const JsonObject & settings); bool debugGetConfig(const JsonObject &settings);
bool debugSetConfig(const JsonObject & settings); bool debugSetConfig(const JsonObject &settings);
#endif #endif
// void debugPrintPrefix(int level, Print * _logOutput); // void debugPrintPrefix(int level, Print * _logOutput);
// void debugPrintSuffix(int level, Print * _logOutput); // void debugPrintSuffix(int level, Print * _logOutput);
// void debugSendOuput(const char * buffer); // void debugSendOuput(const char * buffer);
enum { enum
{
TAG_MAIN = 0, TAG_MAIN = 0,
TAG_HASP = 1, TAG_HASP = 1,
TAG_ATTR = 2, TAG_ATTR = 2,
TAG_MSGR = 3, TAG_MSGR = 3,
TAG_OOBE = 4, TAG_OOBE = 4,
TAG_HAL = 5, TAG_HAL = 5,
TAG_DRVR = 6, TAG_DRVR = 6,
TAG_DEBG = 10, TAG_DEBG = 10,
@ -52,8 +108,8 @@ enum {
TAG_TASM = 13, TAG_TASM = 13,
TAG_CONF = 20, TAG_CONF = 20,
TAG_GUI = 21, TAG_GUI = 21,
TAG_TFT = 22, TAG_TFT = 22,
TAG_EPRM = 30, TAG_EPRM = 30,
TAG_FILE = 31, TAG_FILE = 31,
@ -61,12 +117,12 @@ enum {
TAG_FWUP = 50, TAG_FWUP = 50,
TAG_ETH = 60, TAG_ETH = 60,
TAG_WIFI = 61, TAG_WIFI = 61,
TAG_HTTP = 62, TAG_HTTP = 62,
TAG_OTA = 63, TAG_OTA = 63,
TAG_MDNS = 64, TAG_MDNS = 64,
TAG_MQTT = 65, TAG_MQTT = 65,
TAG_MQTT_PUB = 66, TAG_MQTT_PUB = 66,
TAG_MQTT_RCV = 67, TAG_MQTT_RCV = 67,

View File

@ -1,21 +1,24 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie /* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */ For full license information read the LICENSE file in the project folder */
#include <Arduino.h> #include "hasp_conf.h" // include first
#include "ArduinoJson.h"
#include "ArduinoLog.h"
#include "hasp_conf.h" #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
#include "hasp_debug.h"
#include "hasp_filesystem.h" #include <Arduino.h>
#include "ArduinoJson.h"
#include "ArduinoLog.h"
#include "hasp_debug.h"
#include "hasp_filesystem.h"
void filesystemInfo() void filesystemInfo()
{ // Get all information of your SPIFFS { // Get all information of your SPIFFS
#if 0 #if 0
FSInfo fs_info; FSInfo fs_info;
SPIFFS.info(fs_info); SPIFFS.info(fs_info);
Serial.println("File sistem info."); Serial.println("File system info.");
Serial.print("Total space: "); Serial.print("Total space: ");
Serial.print(fs_info.totalBytes); Serial.print(fs_info.totalBytes);
@ -61,61 +64,63 @@ void filesystemInfo()
Serial.print("Max path lenght: "); Serial.print("Max path lenght: ");
// Serial.println(SPIFFS.maxPathLength()); // Serial.println(SPIFFS.maxPathLength());
#endif #endif
} }
void filesystemList() void filesystemList()
{ {
#if HASP_USE_SPIFFS > 0 #if HASP_USE_SPIFFS > 0
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
if(!SPIFFS.begin()) { if(!SPIFFS.begin()) {
#else #else
if(!SPIFFS.begin(true)) { if(!SPIFFS.begin(true)) {
#endif #endif
LOG_ERROR(TAG_FILE, F("Flash file system not mouted.")); LOG_ERROR(TAG_FILE, F("Flash file system not mouted."));
} else { } else {
LOG_VERBOSE(TAG_FILE, F("Listing files on the internal flash:")); 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 root = SPIFFS.open("/");
File file = root.openNextFile(); File file = root.openNextFile();
while(file) { while(file) {
LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size()); LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size());
file = root.openNextFile(); file = root.openNextFile();
} }
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir("/"); Dir dir = SPIFFS.openDir("/");
while(dir.next()) { while(dir.next()) {
LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); LOG_VERBOSE(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize());
} }
#endif #endif
} }
#endif #endif
} }
bool filesystemSetup(void) bool filesystemSetup(void)
{ {
// no SPIFFS settings, as settings depend on SPIFFS // no SPIFFS settings, as settings depend on SPIFFS
// no Logging, because it depends on the configuration file // no Logging, because it depends on the configuration file
// Logging is defered until debugging has started // Logging is defered until debugging has started
// FS success or failure is printed at that time ! // FS success or failure is printed at that time !
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
if(!HASP_FS.begin()) { if(!HASP_FS.begin()) {
#else #else
if(!HASP_FS.begin(true)) { if(!HASP_FS.begin(true)) {
#endif #endif
// LOG_ERROR(TAG_FILE, F("SPI flash init failed. Unable to mount FS.")); // LOG_ERROR(TAG_FILE, F("SPI flash init failed. Unable to mount FS."));
return false; return false;
} else { } else {
// LOG_INFO(TAG_FILE, F("SPI Flash FS mounted")); // LOG_INFO(TAG_FILE, F("SPI Flash FS mounted"));
return true; return true;
} }
#endif #endif
return false; return false;
} }
#endif