diff --git a/platformio.ini b/platformio.ini index 7b7bc44e..7e7353cd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,14 +30,15 @@ default_envs = framework = arduino upload_speed = 921600 monitor_speed = 115200 + ; -- Shared library dependencies in all environments lib_deps = - lvgl/lvgl @ ^7.7.2 ; Not in library yet - bodmer/TFT_eSPI @ ^2.3.4 ; Tft SPI drivers - PubSubClient @ ^2.8.0 ; MQTT client - ArduinoJson @ ^6.17.2 ; Json(l) parser - StreamUtils @ ^1.5.0 ; for EEPromStream - AceButton @ ^1.7.0 + lvgl/lvgl @ ^7.7.2 ; from PIO library + bodmer/TFT_eSPI @ ^2.3.4 ; Tft SPI drivers + bxparks/AceButton @ ^1.7.1 ; GPIO button library + bblanchon/ArduinoJson @ ^6.17.2 ; Json(l) parser + bblanchon/StreamUtils @ ^1.5.0 ; for EEPromStream + knolleary/PubSubClient @ ^2.8.0 ; MQTT client https://github.com/fvanroie/ConsoleInput.git https://github.com/andrethomas/TasmotaSlave.git ; ------ Unused / Test libraries @@ -47,17 +48,17 @@ lib_deps = ;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip ;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip -lib_ignore = - https://github.com/littlevgl/lvgl.git +; lib_ignore = +; https://github.com/littlevgl/lvgl.git build_flags = ;-Os ; Code Size Optimization -Og ; Code Debug Optimization ;-w ; Suppress warnings - -D CORE_DEBUG_LEVEL=1 ; 0=Silent, 1=Errors - -I include ; include lv_conf.h and hasp_conf.h + -D CORE_DEBUG_LEVEL=2 ; 0=Silent, 1=Errors, 2=Warnings + -I include ; include lv_conf.h and hasp_conf.h ; -- littlevgl build options ------------------------------ - -D LV_CONF_INCLUDE_SIMPLE + -D LV_CONF_INCLUDE_SIMPLE ; for lvgl -D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers ; -- littlevgl build options ------------------------------ -D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 0b4b7a75..2c6bf47c 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -1,6 +1,18 @@ /* MIT License - Copyright (c) 2020 Francis Van Roie For full license information read the LICENSE file in the project folder */ +/* =========================================================================== + +- Log.fatal() - A fatal exception is caught, the program should halt with while(1){} +- Log.error() - An important but non-fatal error occured, this error should be checked and not ignored +- Log.warning() - Send at the end of a function to indicate failure of the sub process, can be ignored + +- Log.notice() - Information at the START of an action to notify another function is now running + - Log.trace() - Send at the END of a function to indicate successful completion of the sub process + - Log.verbose() - Send DEBUG information DURING a subprocess + +=========================================================================== */ + #include "ArduinoJson.h" #include "ArduinoLog.h" #include "ConsoleInput.h" @@ -139,7 +151,12 @@ void debugSetup() { // memset(serialInputBuffer, 0, sizeof(serialInputBuffer)); // serialInputIndex = 0; + Log.error(TAG_DEBG, F("Setting the console parser")); console.setLineCallback(dispatchTextLine); +} + +void debugStartSyslog() +{ #if HASP_USE_SYSLOG > 0 // syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD); @@ -150,16 +167,29 @@ void debugSetup() // syslog->defaultPriority(priority); if(strlen(debugSyslogHost) > 0) { - syslogClient = new WiFiUDP(); + if(!syslogClient) syslogClient = new WiFiUDP(); + if(syslogClient) { if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) { Log.registerOutput(2, syslogClient, LOG_LEVEL_VERBOSE, true); + Log.trace(TAG_DEBG, F("Syslog client started")); } + } else { + Log.error(TAG_DEBG, F("Failed to start syslog client")); } } #endif } +void debugStopSyslog() +{ +#if HASP_USE_SYSLOG > 0 + if(strlen(debugSyslogHost) > 0) { + Log.unregisterOutput(2); + } +#endif +} + void debugStop() { if(debugSerialStarted) Serial.flush(); @@ -561,7 +591,11 @@ void debugPrintSuffix(uint8_t tag, int level, Print * _logOutput) else _logOutput->println(); - _logOutput->print("hasp > "); + if(_logOutput == &Serial) { + console.update(); + } else { + _logOutput->print("hasp > "); + } // if(_logOutput == &Serial) debugPrintPrompt(); // syslogSend(level, debugOutput); @@ -638,19 +672,14 @@ void debugLoop() switch(keypress) { case ConsoleInput::KEY_PAGE_UP: - console.println(F("PAGE_UP pressed")); - dispatchPagePrev(); - break; - - case ConsoleInput::KEY_PAGE_DOWN: - console.println(F("PAGE_DOWN pressed")); dispatchPageNext(); break; + case ConsoleInput::KEY_PAGE_DOWN: + dispatchPagePrev(); + break; + case(ConsoleInput::KEY_FN)...(ConsoleInput::KEY_FN + 12): - console.print(F("F")); - console.print(keypress - ConsoleInput::KEY_FN); - console.println(F(" pressed")); haspSetPage(keypress - ConsoleInput::KEY_FN - 1); break; } diff --git a/src/hasp_debug.h b/src/hasp_debug.h index ae9d27cd..7d6dfd73 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -7,6 +7,31 @@ #include "ArduinoJson.h" #include "lvgl.h" +void debugHaspHeader(Print * output); + +void debugPreSetup(JsonObject settings); +void debugSetup(); +void debugLoop(void); +void debugEverySecond(void); +void debugStart(void); +void debugStop(void); + +void debugStartSyslog(void); +void debugStopSyslog(void); + +void serialPrintln(String & debugText, uint8_t level); +void serialPrintln(const char * debugText, uint8_t level); + +void syslogSend(uint8_t log, const char * debugText); + +bool debugGetConfig(const JsonObject & settings); +bool debugSetConfig(const JsonObject & settings); + +// void debugPrintPrefix(int level, Print * _logOutput); +// void debugPrintSuffix(int level, Print * _logOutput); +// void debugSendOuput(const char * buffer); +void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, const char * descr); + enum { TAG_MAIN = 0, TAG_HASP = 1, @@ -44,26 +69,4 @@ enum { TAG_FONT = 92 }; -void debugHaspHeader(Print * output); - -void debugPreSetup(JsonObject settings); -void debugSetup(); -void debugLoop(void); -void debugEverySecond(void); -void debugStart(void); -void debugStop(void); - -void serialPrintln(String & debugText, uint8_t level); -void serialPrintln(const char * debugText, uint8_t level); - -void syslogSend(uint8_t log, const char * debugText); - -bool debugGetConfig(const JsonObject & settings); -bool debugSetConfig(const JsonObject & settings); - -// void debugPrintPrefix(int level, Print * _logOutput); -// void debugPrintSuffix(int level, Print * _logOutput); -// void debugSendOuput(const char * buffer); -void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, const char * descr); - #endif \ No newline at end of file diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp index 1877dd4a..1c7e3df4 100644 --- a/src/hasp_dispatch.cpp +++ b/src/hasp_dispatch.cpp @@ -142,7 +142,7 @@ void dispatchCommand(const char * topic, const char * payload) if(strlen(payload) == 0) { // dispatchTextLine(topic); // Could cause an infinite loop! } - Log.warning(TAG_MSGR, F(LOG_CMND_CTR "Command not found %s => %s"), topic, payload); + Log.warning(TAG_MSGR, F("Command '%s' not found => %s"), topic, payload); } } diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp index 4a11feb8..3202d2b9 100644 --- a/src/hasp_gpio.cpp +++ b/src/hasp_gpio.cpp @@ -119,6 +119,9 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 for(i = 0; i < HASP_NUM_INPUTS; i++) { if(!button[i]) { + Log.notice(TAG_GPIO, F("Creating Button%d on pin %d (index %d) mode %d default %d"), i, pin, index, + input_mode, default_state); + button[i] = new AceButton(pin, default_state, index); // button[i]->init(pin, default_state, index); @@ -134,15 +137,15 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 buttonConfig->clearFeature( ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses - Log.trace(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + Log.trace(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, + input_mode, default_state); gpioUsedInputCount = i + 1; return; } } } - Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, - HASP_NUM_INPUTS); + Log.error(TAG_GPIO, F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, + index, HASP_NUM_INPUTS); } void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t index) @@ -165,15 +168,15 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, buttonConfig->clearFeature( ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses - Log.trace(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, - input_mode, default_state); + Log.trace(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, + input_mode, default_state); gpioUsedInputCount = i + 1; return; } } } - Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, - HASP_NUM_INPUTS); + Log.error(TAG_GPIO, F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, + index, HASP_NUM_INPUTS); } void gpioSetup() @@ -420,8 +423,8 @@ bool gpioSavePinConfig(uint8_t config_num, uint8_t pin, uint8_t type, uint8_t gr gpioConfig[config_num].type = type; gpioConfig[config_num].group = group; gpioConfig[config_num].gpio_function = pinfunc; - Log.notice(TAG_GPIO,F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, group, - pinfunc); + Log.notice(TAG_GPIO, F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, + group, pinfunc); return true; } @@ -576,7 +579,7 @@ bool gpioGetConfig(const JsonObject & settings) if(i < HASP_NUM_GPIO_CONFIG) { uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) | (gpioConfig[i].gpio_function << 24); - Log.trace(TAG_GPIO,F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as()); + Log.trace(TAG_GPIO, F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as()); if(cur_val != v.as()) changed = true; v.set(cur_val);