-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cpp
81 lines (76 loc) · 1.5 KB
/
Logger.cpp
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
78
79
80
81
#include "Logger.h"
void Logger::setPrefix(const char *_prefix)
{
#if LOG_LEVEL > 0
strcpy(prefix,_prefix);
#endif
}
void Logger::print(const char *format, va_list args)
{
#if LOG_LEVEL > 0
for (; *format != 0; ++format)
{
if(*format == '%')
{
++format;
printf(*format, &args);
}
else
{
_logOutput->print(*format);
}
}
#endif
}
void Logger::printf(const char format, va_list *args) {
#ifndef DISABLE_LOGGING
if (format == '%')
{
_logOutput->print(format);
}
else if (format == 's')
{
register char *s = (char *)va_arg(*args, int);
_logOutput->print(s);
}
else if (format == 'd')
{
_logOutput->print(va_arg(*args, int), DEC);
}
else if (format == 'f')
{
_logOutput->print(va_arg(*args, double));
}
else if (format == 'c')
{
_logOutput->print((char) va_arg(*args, int));
}
else if (format == 't')
{
if (va_arg(*args, int) == 1)
{
_logOutput->print(F("true"));
}
else
{
_logOutput->print(F("false"));
}
}
#endif
}
#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else // __ARM__
extern char *__brkval;
#endif // __arm__
int Logger::freeMemory() {
char top;
#ifdef __arm__
return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
return &top - __brkval;
#else // __arm__
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__
}