From 1b9135e35528c43f1a21560d53f92e836ab5074f Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 8 Feb 2023 17:03:01 +0100 Subject: [PATCH] Don't use console if Serial port is disabled --- src/hasp_debug.h | 2 +- src/log/hasp_debug.cpp | 9 +++++---- src/sys/svc/hasp_console.cpp | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hasp_debug.h b/src/hasp_debug.h index fbe058a7..b805004e 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -140,7 +140,7 @@ void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, co IRAM_ATTR void debugLoop(void); void debugEverySecond(void); void debugStart(void); -void debugStartSerial(void); +bool debugStartSerial(void); void debugStop(void); void debugPrintHaspHeader(Print* output); void debugPrintTag(uint8_t tag, Print* _logOutput); diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index 8722bfce..6898bb57 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -16,7 +16,7 @@ #include "hasp_conf.h" #include "ConsoleInput.h" #include "lvgl.h" -//#include "time.h" +// #include "time.h" #include #if defined(ARDUINO_ARCH_ESP8266) @@ -373,15 +373,15 @@ void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput) } // Start Serial Port at correct -void debugStartSerial() +bool debugStartSerial() { if(debugSerialBaud < 0) { LOG_WARNING(TAG_DEBG, F(D_SERVICE_DISABLED " (%u Bps)"), debugSerialBaud); - // return; + return false; } uint32_t baudrate = debugSerialBaud; - if(baudrate < 9600) baudrate = SERIAL_SPEED; + if(baudrate < 9600) baudrate = SERIAL_SPEED; // 9600 baud minimum #if defined(STM32F4xx) || defined(STM32F7xx) #ifndef STM32_SERIAL1 // Define what Serial port to use for log output @@ -400,6 +400,7 @@ void debugStartSerial() LOG_INFO(TAG_DEBG, F(D_SERVICE_STARTED " @ %u bps"), debugSerialBaud); LOG_INFO(TAG_DEBG, F(D_INFO_ENVIRONMENT ": " PIOENV)); + return true; } // Do NOT call Log function before debugSetup is called diff --git a/src/sys/svc/hasp_console.cpp b/src/sys/svc/hasp_console.cpp index 2ca2902b..8ecaaf7f 100644 --- a/src/sys/svc/hasp_console.cpp +++ b/src/sys/svc/hasp_console.cpp @@ -107,7 +107,10 @@ void consoleStart() LOG_TRACE(TAG_MSGR, F(D_SERVICE_STARTING)); console = new ConsoleInput(bufferedSerialClient, HASP_CONSOLE_BUFFER); if(console) { - debugStartSerial(); // open Serial port + if(!debugStartSerial()) { // failed to open Serial port + LOG_INFO(TAG_CONS, F(D_SERVICE_DISABLED)); + return; + } /* Now register logger for serial */ Log.registerOutput(0, bufferedSerialClient, HASP_LOG_LEVEL, true);