AceTime
1.7.3
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.
src
ace_time
common
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. If
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 the binary to
16
* be about 700 (AVR) to 1000 (ESP32) bytes larger in flash memory. Being
17
* inlined here means that <Arduino.h> must be included here, which can cause
18
* some problems in files that try to clobber macros defined in <Ardhino.h>.
19
*/
20
21
#ifndef ACE_TIME_COMMON_LOGGING_H
22
#define ACE_TIME_COMMON_LOGGING_H
23
24
#include <stdio.h>
// vsnprintf(), vprintf()
25
#include <stdarg.h>
// va_list, va_start(), va_end()
26
#include <Arduino.h>
// SERIAL_PORT_MONITOR
27
#ifndef SERIAL_PORT_MONITOR
28
#define SERIAL_PORT_MONITOR Serial
29
#endif
30
31
namespace
ace_time {
32
namespace
logging {
33
34
static
const
int
BUF_SIZE = 192;
35
36
inline
void
vprintf(
const
char
*fmt, va_list args) {
37
char
buf[BUF_SIZE];
38
vsnprintf(buf, BUF_SIZE, fmt, args);
39
SERIAL_PORT_MONITOR.print(buf);
40
}
41
46
inline
void
printf(
const
char
* fmt, ...) {
47
va_list args;
48
va_start(args, fmt);
49
vprintf(fmt, args);
50
va_end(args);
51
}
52
53
}
54
}
55
56
#endif
Generated by
1.8.17