From 58715f454c1ccbcfa0771a5ab6c6f5e483ebc9a2 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 10 Mar 2021 15:21:30 +0800 Subject: [PATCH] add consolePrintf for C style code --- src/SerialConsole.cpp | 12 ++++++++++-- src/SerialConsole.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp index 9bb539fa5..ad1cf642a 100644 --- a/src/SerialConsole.cpp +++ b/src/SerialConsole.cpp @@ -1,13 +1,21 @@ #include "SerialConsole.h" +#include "NodeDB.h" #include "PowerFSM.h" #include "configuration.h" -#include "NodeDB.h" #include #define Port Serial SerialConsole console; +void consolePrintf(const char *format, ...) +{ + va_list arg; + va_start(arg, format); + console.vprintf(format, arg); + va_end(arg); +} + SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port) { canWrite = false; // We don't send packets to our port until it has talked to us first @@ -29,7 +37,7 @@ void SerialConsole::init() void SerialConsole::handleToRadio(const uint8_t *buf, size_t len) { // Turn off debug serial printing once the API is activated, because other threads could print and corrupt packets - if(!radioConfig.preferences.debug_log_enabled) + if (!radioConfig.preferences.debug_log_enabled) setDestination(&noopPrint); canWrite = true; diff --git a/src/SerialConsole.h b/src/SerialConsole.h index 17cb16943..b4f076286 100644 --- a/src/SerialConsole.h +++ b/src/SerialConsole.h @@ -32,4 +32,7 @@ class SerialConsole : public StreamAPI, public RedirectablePrint virtual void onConnectionChanged(bool connected); }; +// A simple wrapper to allow non class aware code write to the console +void consolePrintf(const char *format, ...); + extern SerialConsole console;