From b24d8b077ae20c466ce358fd3a65ad63ade1f905 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Mon, 4 May 2020 00:42:01 +0200 Subject: [PATCH] Move serial input from gui to debug --- include/hasp_conf.h | 2 +- src/hasp_debug.cpp | 41 +++++++++++++++++++++++++++++++---------- src/hasp_gui.cpp | 23 +---------------------- src/main.cpp | 1 + 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 3ba35170..14366c88 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -48,7 +48,7 @@ #include "hasp_spiffs.h" #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) -#include "lv_zifont.h" +//#include "lv_zifont.h" #endif #endif diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 8448eb98..61ccf0cf 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -71,6 +71,8 @@ Syslog * syslog; #endif // USE_SYSLOG // Serial Settings +uint8_t serialInputIndex = 0; // Empty buffer +char serialInputBuffer[1024]; uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10 bool debugSerialStarted = false; bool debugAnsiCodes = true; @@ -96,10 +98,10 @@ String debugHaspHeader() header.reserve(256); if(debugAnsiCodes) header += TERM_COLOR_YELLOW; header += F(" _____ _____ _____ _____\r\n" - " | | | _ | __| _ |\r\n" - " | | |__ | __|\r\n" - " |__|__|__|__|_____|__|\r\n" - " Home Automation Switch Plate\r\n"); + " | | | _ | __| _ |\r\n" + " | | |__ | __|\r\n" + " |__|__|__|__|_____|__|\r\n" + " Home Automation Switch Plate\r\n"); char buffer[128]; snprintf(buffer, sizeof(buffer), PSTR(" Open Hardware edition v%u.%u.%u\r\n"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION); @@ -232,8 +234,8 @@ static void debugPrintTimestamp(int level, Print * _logOutput) _logOutput->printf(PSTR("%03lu]"), millis() % 1000); } else */ { - uint32_t msecs = millis(); - _logOutput->printf(PSTR("[%16d.%03d]"), msecs/1000, msecs%1000 ); + uint32_t msecs = millis(); + _logOutput->printf(PSTR("[%16d.%03d]"), msecs / 1000, msecs % 1000); } } @@ -334,10 +336,10 @@ void debugPreSetup(JsonObject settings) if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */ #if defined(STM32F4xx) - #ifndef STM32_SERIAL1 // Define what Serial port to use for log output - Serial.setRx(PA3); // User Serial2 +#ifndef STM32_SERIAL1 // Define what Serial port to use for log output + Serial.setRx(PA3); // User Serial2 Serial.setTx(PA2); - #endif +#endif #endif Serial.begin(baudrate); /* prepare for possible serial debug */ delay(10); @@ -378,7 +380,26 @@ void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const cha #endif void debugLoop() -{} +{ + while(Serial.available()) { + char ch = Serial.read(); + Serial.print(ch); + if(ch == 13 || ch == 10) { + serialInputBuffer[serialInputIndex] = 0; + if(serialInputIndex > 0) dispatchCommand(serialInputBuffer); + serialInputIndex = 0; + } else { + if(serialInputIndex < sizeof(serialInputBuffer) - 1) { + serialInputBuffer[serialInputIndex++] = ch; + } + serialInputBuffer[serialInputIndex] = 0; + if(strcmp(serialInputBuffer, "jsonl=") == 0) { + dispatchJsonl(Serial); + serialInputIndex = 0; + } + } + } +} /*void printLocalTime() { diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 06c21d2e..76c9d8e6 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -76,9 +76,6 @@ static uint8_t guiRotation = TFT_ROTATION; static Ticker tick; /* timer for interrupt handler */ #else static Ticker tick(lv_tick_handler,guiTickPeriod); -uint8_t serialInputIndex = 0; // Empty buffer -char serialInputBuffer[1024]; - #endif static TFT_eSPI tft; // = TFT_eSPI(); /* TFT instance */ static uint16_t calData[5] = {0, 65535, 0, 65535, 0}; @@ -817,26 +814,8 @@ void IRAM_ATTR guiLoop() { #if defined(STM32F4xx) tick.update(); - - while(Serial.available()) { - char ch = Serial.read(); - Serial.print(ch); - if (ch == 13 ||ch == 10) { - serialInputBuffer[serialInputIndex] = 0; - if (serialInputIndex>0) dispatchCommand(serialInputBuffer); - serialInputIndex=0; - }else{ - if(serialInputIndex < sizeof(serialInputBuffer) - 1) { - serialInputBuffer[serialInputIndex++] = ch; - } - serialInputBuffer[serialInputIndex] = 0; - if (strcmp(serialInputBuffer,"jsonl=")==0){ - dispatchJsonl(Serial); - serialInputIndex=0; - } - } - } #endif + //lv_tick_handler(); lv_task_handler(); /* let the GUI do its work */ guiCheckSleep(); diff --git a/src/main.cpp b/src/main.cpp index c4a259d8..041d6aa2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,6 +109,7 @@ void loop() guiLoop(); /* Application Loops */ // haspLoop(); + debugLoop(); #if HASP_USE_GPIO gpioLoop();