-
Notifications
You must be signed in to change notification settings - Fork 41
/
fpm_logging.h
77 lines (58 loc) · 2.56 KB
/
fpm_logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @file fpm_logging.h
*
* - Setup necessary to direct stdout to the Arduino Serial library, which
* enables 'printf'.
* - Select logging level.
*/
#ifndef FPM_LOGGING_H_
#define FPM_LOGGING_H_
#define FPM_LOG_LEVEL_SILENT 0
#define FPM_LOG_LEVEL_ERROR 1
#define FPM_LOG_LEVEL_INFO 2
#define FPM_LOG_LEVEL_VERBOSE 3
#define FPM_LOG_LEVEL_V_VERBOSE 4
/* Set this macro to any one of the log levels above,
* arranged in order of increasing verbosity
*
* Note: setting FPM_LOG_LEVEL_VERBOSE may cause sensor data transfers to fail, especially at high baud rates
*/
#define FPM_LOG_LEVEL FPM_LOG_LEVEL_INFO
#if (FPM_LOG_LEVEL != FPM_LOG_LEVEL_SILENT)
#define FPM_LOG(level, fmt, ...) \
do { if (level <= FPM_LOG_LEVEL) printf(fmt, ##__VA_ARGS__); } while (0)
#define FPM_LOGLN(level, fmt, ...) \
do { if (level <= FPM_LOG_LEVEL) printf("[+]" fmt "\r\n", ##__VA_ARGS__); } while (0)
#define FPM_LOG_ERROR(fmt, ...) FPM_LOG(FPM_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
#define FPM_LOG_INFO(fmt, ...) FPM_LOG(FPM_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
#define FPM_LOG_VERBOSE(fmt, ...) FPM_LOG(FPM_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
#define FPM_LOG_V_VERBOSE(fmt, ...) FPM_LOG(FPM_LOG_LEVEL_V_VERBOSE, fmt, ##__VA_ARGS__)
#define FPM_LOGLN_ERROR(fmt, ...) FPM_LOGLN(FPM_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
#define FPM_LOGLN_INFO(fmt, ...) FPM_LOGLN(FPM_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
#define FPM_LOGLN_VERBOSE(fmt, ...) FPM_LOGLN(FPM_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
#define FPM_LOGLN_V_VERBOSE(fmt, ...) FPM_LOGLN(FPM_LOG_LEVEL_V_VERBOSE, fmt, ##__VA_ARGS__)
#if defined(ARDUINO_ARCH_AVR)
#include <Arduino.h>
static int uart_putchar(char c, FILE *stream)
{
Serial.write(c);
return 0;
}
#endif
void printf_begin(void)
{
#if defined(ARDUINO_ARCH_AVR)
fdevopen(&uart_putchar, NULL);
#endif
}
#else
#define FPM_LOG_ERROR(fmt, ...)
#define FPM_LOG_INFO(fmt, ...)
#define FPM_LOG_VERBOSE(fmt, ...)
#define FPM_LOG_V_VERBOSE(fmt, ...)
#define FPM_LOGLN_ERROR(fmt, ...)
#define FPM_LOGLN_INFO(fmt, ...)
#define FPM_LOGLN_VERBOSE(fmt, ...)
#define FPM_LOGLN_V_VERBOSE(fmt, ...)
#endif /* (FPM_LOG_LEVEL != FPM_LOG_LEVEL_SILENT) */
#endif