AceTime  0.5.2
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
logging.h
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 /*
7  * Implement logging::printf() that accept formatting strings like printf(). I
8  * finally got tired of writing multiple lines of SERIAL_PORT_MONITOR.print()
9  * for debugging.
10  *
11  * NOTE: These *must* be implemented as inline function to allow the compiler
12  * to remove unused functions from the binary. For some reason, on AVR, ESP8266
13  * and ESP32 compilers, link-time-optimization does not seem to work well.
14  * These functions are defined in a .cpp file, they are included in the binary,
15  * even if they are not reference at all by anything. This causes
16  * the binary to be about 700 (AVR) to 1000 (ESP32) bytes larger in flash
17  * memory. Being inlined here means that <Arduino.h> must be included here,
18  * which can cause some problems in files that try to clobber macros defined in
19  * <Ardhino.h>.
20  */
21 
22 #ifndef ACE_TIME_COMMON_LOGGING_H
23 #define ACE_TIME_COMMON_LOGGING_H
24 
25 #include <stdarg.h>
26 #include <Arduino.h>
27 
28 namespace ace_time {
29 namespace logging {
30 
31 inline void vprintf(const char *fmt, va_list args) {
32  char buf[192];
33  vsnprintf(buf, 192, fmt, args);
34  SERIAL_PORT_MONITOR.print(buf);
35 }
36 
38 inline void print(const char* fmt, ...) {
39  va_list args;
40  va_start(args, fmt);
41  vprintf(fmt, args);
42  va_end(args);
43 }
44 
49 inline void println(const char *fmt, ... ) {
50  va_list args;
51  va_start(args, fmt);
52  vprintf(fmt, args);
53  va_end(args);
54  SERIAL_PORT_MONITOR.println();
55 }
56 
58 inline void println() {
59  SERIAL_PORT_MONITOR.println();
60 }
61 
62 }
63 }
64 
65 #endif