Add MY_DEBUGDEVICE to redirect debug output (#1006)

* Add MY_DEBUGDEVICE to redirect debug output

MY_DEBUGDEVICE, if defined, will replace MY_SERIALDEVICE
for the purpose of printing debug messages. This only
applies to debugging.
This commit is contained in:
Lee Nelson
2017-12-03 19:34:58 +01:00
committed by Mikael Falkvidd
parent 8d9af98a55
commit bfcb125e72
8 changed files with 64 additions and 30 deletions
+8 -5
View File
@@ -170,17 +170,20 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ...)
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(" ");
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(" ");
#endif
va_list args;
va_start(args, fmt);
@@ -191,10 +194,10 @@ void hwDebugPrint(const char *fmt, ...)
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end(args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
// Disable flush since current STM32duino implementation performs a reset
// instead of an actual flush
//MY_SERIALDEVICE.flush();
//MY_DEBUGDEVICE.flush();
#else
(void)fmt;
#endif