From d1118f310e06e1325429a2680ef1f08cc6c421ab Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 28 Apr 2020 01:20:04 +0200 Subject: [PATCH] Updates for stmf407vg --- src/hasp_debug.cpp | 32 +++++++++++++++++++---------- src/main.cpp | 50 ++++++++++------------------------------------ 2 files changed, 31 insertions(+), 51 deletions(-) diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 28ba7c27..60a59892 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -1,20 +1,24 @@ #include "ArduinoJson.h" #include "ArduinoLog.h" #include "lvgl.h" -#include "time.h" +//#include "time.h" #include "hasp_conf.h" #if defined(ARDUINO_ARCH_ESP8266) #include // sntp_servermode_dhcp() #include -#else -#include -#endif #include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#include +#endif #include "hasp_hal.h" +#if HASP_USE_MQTT>0 #include "hasp_mqtt.h" +#endif + #include "hasp_debug.h" #include "hasp_config.h" #include "hasp_dispatch.h" @@ -70,6 +74,7 @@ Syslog * syslog; // Serial Settings uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10 bool debugSerialStarted = false; +bool debugAnsiCodes = true; //#define TERM_COLOR_Black "\u001b[30m" #define TERM_COLOR_GRAY "\e[37m" @@ -212,20 +217,20 @@ static void debugPrintTimestamp(int level, Print * _logOutput) time_t rawtime; struct tm * timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); + //time(&rawtime); + //timeinfo = localtime(&rawtime); // strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S.", timeinfo); // Serial.println(buffer); debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput); - if(timeinfo->tm_year >= 120) { + /* if(timeinfo->tm_year >= 120) { char buffer[64]; strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S.", timeinfo); // Literal String _logOutput->print(buffer); _logOutput->printf(PSTR("%03lu]"), millis() % 1000); - } else { + } else */ { _logOutput->printf(PSTR("[%20.3f]"), (float)millis() / 1000); } } @@ -233,7 +238,7 @@ static void debugPrintTimestamp(int level, Print * _logOutput) static void debugPrintHaspMemory(int level, Print * _logOutput) { size_t maxfree = halGetMaxFreeBlock(); - uint32_t totalfree = ESP.getFreeHeap(); + uint32_t totalfree = halGetFreeHeap(); uint8_t frag = halGetHeapFragmentation(); /* Print HASP Memory Info */ @@ -325,12 +330,17 @@ void debugPreSetup(JsonObject settings) uint32_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as() * 10; if(baudrate == 0) baudrate = SERIAL_SPEED; if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */ + +#ifdef STM32_CORE_VERSION_MAJOR + Serial.setRx(PA3); // User Serial2 + Serial.setTx(PA2); +#endif Serial.begin(baudrate); /* prepare for possible serial debug */ delay(10); + Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true); debugSerialStarted = true; Serial.println(); - Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true); - Log.trace(F("Serial started at %u baud"), baudrate); + Log.trace(("Serial started at %u baud"), baudrate); } } diff --git a/src/main.cpp b/src/main.cpp index cf5f2ac3..5bb44c72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,45 +10,6 @@ #include "hasp_oobe.h" #include "hasp_gpio.h" -#if HASP_USE_SPIFFS -#if defined(ARDUINO_ARCH_ESP32) -#include "SPIFFS.h" -#endif -#include // Include the SPIFFS library -#endif - -#if HASP_USE_EEPROM -#include "hasp_eeprom.h" -#endif - -#if HASP_USE_WIFI -#include "hasp_wifi.h" -#endif - -#if HASP_USE_MQTT -#include "hasp_mqtt.h" -#endif - -#if HASP_USE_HTTP -#include "hasp_http.h" -#endif - -#if HASP_USE_TELNET -#include "hasp_telnet.h" -#endif - -#if HASP_USE_MDNS -#include "hasp_mdns.h" -#endif - -#if HASP_USE_BUTTON -#include "hasp_button.h" -#endif - -#if HASP_USE_OTA -#include "hasp_ota.h" -#endif - bool isConnected; uint8_t mainLoopCounter = 0; unsigned long mainLastLoopTime = 0; @@ -181,16 +142,25 @@ void loop() /* Run Every 5 Seconds */ if(mainLoopCounter == 0 || mainLoopCounter == 4) { +#if HASP_USE_HTTP httpEvery5Seconds(); +#endif + +#if HASP_USE_WIFI isConnected = wifiEvery5Seconds(); + +#if HASP_USE_MQTT mqttEvery5Seconds(isConnected); +#endif + +#endif } /* Update counters */ mainLastLoopTime += 1000; mainLoopCounter++; if(mainLoopCounter >= 10) { - mainLoopCounter = 0; + mainLoopCounter = 0; } }