-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintfWrapper.cpp
80 lines (59 loc) · 1.89 KB
/
PrintfWrapper.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
/*
Route.cpp
Author: Ton Swieb
This library is free software; you can redistribute it and/or
modify it as you like.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "PrintfWrapper.h"
PrintfWrapper::PrintfWrapper(Stream* stream, int bufferLength) : stream(stream), bufferLength(bufferLength) {}
void PrintfWrapper::printf(char *fmt, ... ){
va_list args;
va_start (args, fmt );
printf(fmt,args);
va_end (args);
}
void PrintfWrapper::printfln(char *fmt, ... ){
va_list args;
va_start (args, fmt );
printf(fmt,args);
va_end (args);
stream->print("\n");
}
void PrintfWrapper::printf(char *fmt, va_list args) {
char buf[bufferLength]; // resulting string limited to 128 chars
vsnprintf(buf, bufferLength, fmt, args);
stream->print(buf);
}
void PrintfWrapper::printfln(char *fmt, va_list args) {
printf(fmt,args);
stream->print("\n");
}
void PrintfWrapper::printf_P(const __FlashStringHelper *fmt, ... ) {
va_list args;
va_start (args, fmt);
printf_P(fmt, args);
va_end(args);
}
void PrintfWrapper::printfln_P(const __FlashStringHelper *fmt, ... ) {
va_list args;
va_start (args, fmt);
printf_P(fmt, args);
va_end(args);
stream->print("\n");
}
void PrintfWrapper::printf_P(const __FlashStringHelper *fmt, va_list args ) {
char buf[bufferLength]; // resulting string limited to 128 chars
#ifdef __AVR__
vsnprintf_P(buf, sizeof(buf), (const char *)fmt, args); // progmem for AVR
#else
vsnprintf(buf, sizeof(buf), (const char *)fmt, args); // for the rest of the world
#endif
stream->print(buf);
}
void PrintfWrapper::printfln_P(const __FlashStringHelper *fmt, va_list args ) {
printf_P(fmt,args);
stream->print("\n");
}