diff --git a/src/hasp.cpp b/src/hasp.cpp index 83e9d7ff..015e32e3 100644 --- a/src/hasp.cpp +++ b/src/hasp.cpp @@ -1044,7 +1044,6 @@ void haspNewObject(const JsonObject & config) return; } - lv_obj_t * label; switch(objid) { /* ----- Basic Objects ------ */ case LV_HASP_BUTTON: { @@ -1053,7 +1052,7 @@ void haspNewObject(const JsonObject & config) // haspSetToggle(obj, toggle); // lv_btn_set_toggle(obj, toggle); // if(config[F("txt")]) { - label = lv_label_create(obj, NULL); + lv_obj_t * label = lv_label_create(obj, NULL); // lv_label_set_text(label, config[F("txt")].as().c_str()); // haspSetOpacity(obj, LV_OPA_COVER); //} @@ -1276,8 +1275,6 @@ void haspNewObject(const JsonObject & config) void haspLoadPage(String pages) { - char msg[128]; - if(!SPIFFS.begin()) { Log.error(F("HASP: FS not mounted. Failed to load %s"), pages.c_str()); return; @@ -1321,8 +1318,14 @@ bool haspGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set HASP Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool haspSetConfig(const JsonObject & settings) { configOutput(settings); diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 2ece77f7..a7c9e985 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -10,7 +10,6 @@ #endif #include -// #include "hasp_log.h" #include "hasp_hal.h" #include "hasp_mqtt.h" #include "hasp_debug.h" @@ -21,24 +20,46 @@ #include "user_config_override.h" #endif -#if HASP_USE_SYSLOG != 0 -#include "Syslog.h" - #if HASP_USE_TELNET != 0 #include "hasp_telnet.h" //#include "hasp_telnet.cpp" #endif +#if HASP_USE_SYSLOG != 0 +#include "Syslog.h" + #ifndef SYSLOG_SERVER #define SYSLOG_SERVER "" #endif + #ifndef SYSLOG_PORT #define SYSLOG_PORT 514 #endif + #ifndef APP_NAME #define APP_NAME "HASP" #endif +const char * syslogAppName = APP_NAME; +char debugSyslogHost[32] = SYSLOG_SERVER; +uint16_t debugSyslogPort = SYSLOG_PORT; +uint8_t debugSyslogFacility = 0; +uint8_t debugSyslogProtocol = 0; +extern char mqttNodeName[16]; + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP syslogClient; + +// Create a new syslog instance with LOG_KERN facility +// Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); +// Create a new empty syslog instance +Syslog * syslog; +#endif // USE_SYSLOG + +// Serial Settings +uint16_t debugSerialBaud = 11520; // Multiplied by 10 +bool debugSerialStarted = false; + //#define TERM_COLOR_Black "\u001b[30m" #define TERM_COLOR_GRAY "\e[37m" #define TERM_COLOR_RED "\e[91m" @@ -50,28 +71,6 @@ #define TERM_COLOR_WHITE "\e[97m" #define TERM_COLOR_RESET "\e[0m" -// unsigned char TERM_COLOR_CYAN[] = {27, '[', '3', '6', 'm'}; -// unsigned char TERM_COLOR_RESET[] = {27, '[', '0', 'm'}; - -const char * syslogAppName = APP_NAME; -char debugSyslogHost[32] = SYSLOG_SERVER; -uint16_t debugSyslogPort = SYSLOG_PORT; -uint8_t debugSyslogFacility = 0; -uint8_t debugSyslogProtocol = 0; -uint16_t debugSerialBaud = 11520; // Multiplied by 10 -bool debugSerialStarted = false; - -extern char mqttNodeName[16]; - -// A UDP instance to let us send and receive packets over UDP -WiFiUDP syslogClient; - -// Create a new syslog instance with LOG_KERN facility -// Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); -// Create a new empty syslog instance -Syslog * syslog; -#endif - unsigned long debugLastMillis = 0; uint16_t debugTelePeriod = 300; @@ -216,8 +215,14 @@ bool debugGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set DEBUG Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool debugSetConfig(const JsonObject & settings) { configOutput(settings); @@ -246,8 +251,9 @@ bool debugSetConfig(const JsonObject & settings) void printTimestamp(int level, Print * _logOutput) { char c[128]; - int m = snprintf(c, sizeof(c), PSTR("[%10.3fs] %5u/%5u %2u | "), float(millis()) / 1000, halGetMaxFreeBlock(), - ESP.getFreeHeap(), halGetHeapFragmentation()); + /*int m =*/ + snprintf(c, sizeof(c), PSTR("[%10.3fs] %5u/%5u %2u | "), float(millis()) / 1000, halGetMaxFreeBlock(), + ESP.getFreeHeap(), halGetHeapFragmentation()); #if LV_MEM_CUSTOM == 0 /* lv_mem_monitor_t mem_mon; diff --git a/src/hasp_eeprom.cpp b/src/hasp_eeprom.cpp index 2b130cbe..f5b9e785 100644 --- a/src/hasp_eeprom.cpp +++ b/src/hasp_eeprom.cpp @@ -34,7 +34,6 @@ void eepromWrite(uint16_t addr, std::string & data) std::string eepromRead(uint16_t addr) { - int i; char data[1024]; // Max 1024 Bytes int len = 0; unsigned char k; diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index f3c7a5fd..979f072b 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -67,13 +67,13 @@ static uint16_t calData[5] = {0, 65535, 0, 65535, 0}; bool guiCheckSleep() { uint32_t idle = lv_disp_get_inactive_time(NULL); - if(idle >= (guiSleepTime1 + guiSleepTime2) * 1000) { + if(idle >= (guiSleepTime1 + guiSleepTime2) * 1000U) { if(guiSleeping != 2) { dispatchIdle(F("LONG")); guiSleeping = 2; } return true; - } else if(idle >= guiSleepTime1 * 1000) { + } else if(idle >= guiSleepTime1 * 1000U) { if(guiSleeping != 1) { dispatchIdle(F("SHORT")); guiSleeping = 1; @@ -89,11 +89,24 @@ bool guiCheckSleep() #if LV_USE_LOG != 0 /* Serial debugging */ -void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * dsc) +void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, const char * descr) { - char buffer[128]; - snprintf(buffer, sizeof(buffer), PSTR("LVGL: %s@%d->%s"), file, line, dsc); - Log.warning(buffer); + switch(level) { + case LV_LOG_LEVEL_TRACE: + Log.trace(F("LVGL: %s:%u %s -> %s"), file, line, funcname, descr); + break; + case LV_LOG_LEVEL_INFO: + Log.notice(F("LVGL: %s:%u %s -> %s"), file, line, funcname, descr); + break; + case LV_LOG_LEVEL_WARN: + Log.warning(F("LVGL: %s:%u %s -> %s"), file, line, funcname, descr); + break; + case LV_LOG_LEVEL_ERROR: + Log.error(F("LVGL: %s:%u %s -> %s"), file, line, funcname, descr); + break; + default: + Log.verbose(F("LVGL: %s:%u %s -> %s"), file, line, funcname, descr); + } } #endif @@ -107,7 +120,7 @@ void tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * c (area->y2 - area->y1 + 1)); /* set the working window */ if(guiSnapshot != 0) { - int i = 0; + uint i = 0; uint8_t pixel[1024]; for(int y = area->y1; y <= area->y2; y++) { @@ -312,8 +325,8 @@ void guiSetup(JsonObject settings) Log.verbose(F("LVGL: VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize); #if LV_USE_LOG != 0 - Log.warning(F("LVGL: NOT Registering lvgl logging handler")); - // lv_log_register_print_cb(debugLvgl); /* register print function for debugging */ + Log.warning(F("LVGL: Registering lvgl logging handler")); + lv_log_register_print_cb(debugLvgl); /* register print function for debugging */ #endif /* Initialize PNG decoder */ @@ -479,8 +492,14 @@ bool guiGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set GUI Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool guiSetConfig(const JsonObject & settings) { configOutput(settings); @@ -523,6 +542,13 @@ bool guiSetConfig(const JsonObject & settings) return changed; } +/** Send Bitmap Header. + * + * Sends a header in BMP format for the size of the screen. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + **/ void guiSendBmpHeader() { uint8_t buffer[128]; @@ -609,7 +635,7 @@ void guiSendBmpHeader() } } -/** Flush buffer. +/** Take Screenshot. * * Flush buffer into a binary file. * @@ -617,12 +643,12 @@ void guiSendBmpHeader() * * @param[in] pFileName Output binary file name. * - */ + **/ void guiTakeScreenshot(const char * pFileName) { pFileOut = SPIFFS.open(pFileName, "w"); - if(pFileOut == NULL) { + if(pFileOut == 0) { Log.warning(F("GUI: %s cannot be opened"), pFileName); return; } diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 63ad27fc..edac871f 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -1951,8 +1951,14 @@ bool httpGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set HTTP Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool httpSetConfig(const JsonObject & settings) { configOutput(settings); diff --git a/src/hasp_mdns.cpp b/src/hasp_mdns.cpp index 6cf13ceb..92894cef 100644 --- a/src/hasp_mdns.cpp +++ b/src/hasp_mdns.cpp @@ -81,8 +81,14 @@ bool mdnsGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set MDNS Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool mdnsSetConfig(const JsonObject & settings) { configOutput(settings); diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp index 1628cf69..7e084ad8 100644 --- a/src/hasp_mqtt.cpp +++ b/src/hasp_mqtt.cpp @@ -310,29 +310,19 @@ void mqttCallback(char * topic, byte * payload, unsigned int length) char topicBuffer[128]; snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("%sstatus"), mqttNodeTopic); mqttClient.publish(topicBuffer, "ON", true); - Log.notice(F("MQTT: binary_sensor state: [status] : ON")); - // snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("MQTT: binary_sensor state: [%sstatus] : ON"), - // mqttNodeTopic); debugPrintln(topicBuffer); return; } } void mqttSubscribeTo(const char * format, const char * data) { - char buffer[128]; char topic[128]; snprintf_P(topic, sizeof(topic), format, data); if(mqttClient.subscribe(topic)) { Log.verbose(F("MQTT: * Subscribed to %s"), topic); - - // snprintf_P(buffer, sizeof(buffer), PSTR("MQTT: * Subscribed to %s"), topic); - // debugPrintln(buffer); } else { Log.error(F("MQTT: Failed to subscribe to %s"), topic); - - // snprintf_P(buffer, sizeof(buffer), PSTR("MQTT: %%sFailed to subscribe to %s"), topic); - // errorPrintln(buffer); } } @@ -461,7 +451,6 @@ void mqttSetup(const JsonObject & settings) mqttClient.setCallback(mqttCallback); Log.notice(F("MQTT: Setup Complete")); - // debugPrintln(F("MQTT: Setup Complete")); } void mqttLoop() @@ -499,7 +488,6 @@ void mqttStop() mqttClient.disconnect(); Log.notice(F("MQTT: Disconnected from broker")); - // debugPrintln(F("MQTT: Disconnected from broker")); } } @@ -516,8 +504,14 @@ bool mqttGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set MQTT Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool mqttSetConfig(const JsonObject & settings) { configOutput(settings); diff --git a/src/hasp_telnet.cpp b/src/hasp_telnet.cpp index c1ab30a8..5a306c3b 100644 --- a/src/hasp_telnet.cpp +++ b/src/hasp_telnet.cpp @@ -128,7 +128,7 @@ void telnetProcessInput() dispatchCommand(telnetInputBuffer); } } - telnetInputIndex = 0; + telnetInputIndex = 0; // reset input buffer index break; default: // If we have room left in our buffer add the current byte @@ -149,7 +149,7 @@ void telnetSetup(const JsonObject & settings) telnetClient = new WiFiClient; telnetServer->setNoDelay(true); telnetServer->begin(); - Log.notice(F("TELNET: Debug console enabled at telnet://%s"), WiFi.localIP().toString().c_str()); + Log.notice(F("TELNET: Debug telnet console started")); } else { Log.error(F("TELNET: Failed to start telnet server")); } @@ -197,6 +197,14 @@ bool telnetGetConfig(const JsonObject & settings) return true; } +/** Set TELNET Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool telnetSetConfig(const JsonObject & settings) { configOutput(settings); diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index cdad2466..67b9eefb 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -65,7 +65,6 @@ String wifiGetMacAddress(int start, const char * seperator) void wifiConnected(IPAddress ipaddress) { - char buffer[128]; bool isConnected = WiFi.status() == WL_CONNECTED; Log.notice(F("WIFI: Received IP address %s"), ipaddress.toString().c_str()); @@ -81,7 +80,6 @@ void wifiConnected(IPAddress ipaddress) void wifiDisconnected(const char * ssid, uint8_t reason) { - char buffer[128]; wifiReconnectCounter++; if(wifiReconnectCounter > 45) { Log.error(F("WIFI: Retries exceed %u: Rebooting..."), wifiReconnectCounter); @@ -192,8 +190,14 @@ bool wifiGetConfig(const JsonObject & settings) return true; } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +/** Set WIFI Configuration. + * + * Read the settings from json and sets the application variables. + * + * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements. + * + * @param[in] settings JsonObject with the config settings. + **/ bool wifiSetConfig(const JsonObject & settings) { configOutput(settings);