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
+7 -4
View File
@@ -167,17 +167,20 @@ void hwRandomNumberInit(void)
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(F(" "));
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(F(" "));
#endif
va_list args;
va_start(args, fmt);
@@ -188,7 +191,7 @@ void hwDebugPrint(const char *fmt, ...)
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end(args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
(void)fmt;
#endif