Silence unused-variable warning (#2872)
[ExpressLRS.git] / src / lib / logging / logging.cpp
blob7a7ed81af8509f7acca4ea44e177415bb42d8284
1 #include "targets.h"
2 #include <cstdarg>
3 #include "logging.h"
5 #ifdef LOG_USE_PROGMEM
6 #define GETCHAR pgm_read_byte(fmt)
7 #else
8 #define GETCHAR *fmt
9 #endif
11 void debugPrintf(const char* fmt, ...)
13 char c;
14 const char *v;
15 char buf[21];
16 va_list vlist;
17 va_start(vlist,fmt);
19 c = GETCHAR;
20 while(c) {
21 if (c == '%') {
22 fmt++;
23 c = GETCHAR;
24 v = buf;
25 buf[0] = 0;
26 switch (c) {
27 case 's':
28 v = va_arg(vlist, const char *);
29 break;
30 case 'd':
31 itoa(va_arg(vlist, int32_t), buf, DEC);
32 break;
33 case 'u':
34 utoa(va_arg(vlist, uint32_t), buf, DEC);
35 break;
36 case 'x':
37 utoa(va_arg(vlist, uint32_t), buf, HEX);
38 break;
39 #if !defined(PLATFORM_STM32)
40 case 'f':
42 float val = va_arg(vlist, double);
43 itoa((int32_t)val, buf, DEC);
44 strcat(buf, ".");
45 int32_t decimals = abs((int32_t)(val * 1000)) % 1000;
46 itoa(decimals, buf + strlen(buf), DEC);
48 break;
49 #endif
50 default:
51 break;
53 LOGGING_UART.write((uint8_t*)v, strlen(v));
54 } else {
55 LOGGING_UART.write(c);
57 fmt++;
58 c = GETCHAR;
60 va_end(vlist);
63 #if defined(DEBUG_INIT)
64 // Create a UART to send DBGLN to during preinit
65 void debugCreateInitLogger()
67 #if defined(PLATFORM_ESP32)
68 TxBackpack = new HardwareSerial(1);
69 ((HardwareSerial *)TxBackpack)->begin(460800, SERIAL_8N1, 3, 1);
70 #else
71 TxBackpack = new HardwareSerial(0);
72 ((HardwareSerial *)TxBackpack)->begin(460800, SERIAL_8N1);
73 #endif
76 void debugFreeInitLogger()
78 ((HardwareSerial *)TxBackpack)->end();
79 delete (HardwareSerial *)TxBackpack;
81 #endif