forked from espressif/arduino-esp32
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint.h
118 lines (101 loc) · 3.48 KB
/
Print.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
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. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef Print_h
#definePrint_h
#include<stdint.h>
#include<stdio.h>
#include<stddef.h>
#include"WString.h"
#include"Printable.h"
#defineDEC10
#defineHEX16
#defineOCT8
#defineBIN2
classPrint {
private:
int write_error;
size_tprintNumber(unsignedlong, uint8_t);
size_tprintNumber(unsignedlonglong, uint8_t);
size_tprintFloat(double, uint8_t);
protected:
voidsetWriteError(int err = 1) {
write_error = err;
}
public:
Print() : write_error(0) {}
virtual~Print() {}
intgetWriteError() {
return write_error;
}
voidclearWriteError() {
setWriteError(0);
}
virtualsize_twrite(uint8_t) = 0;
size_twrite(constchar *str) {
if (str == NULL) {
return0;
}
returnwrite((constuint8_t *)str, strlen(str));
}
virtualsize_twrite(constuint8_t *buffer, size_t size);
size_twrite(constchar *buffer, size_t size) {
returnwrite((constuint8_t *)buffer, size);
}
size_tvprintf(constchar *format, va_list arg);
size_tprintf(constchar *format, ...) __attribute__((format(printf, 2, 3)));
size_tprintf(const __FlashStringHelper *ifsh, ...);
// add availableForWrite to make compatible with Arduino Print.h
// default to zero, meaning "a single write may block"
// should be overridden by subclasses with buffering
virtualintavailableForWrite() {
return0;
}
size_tprint(const __FlashStringHelper *ifsh) {
returnprint(reinterpret_cast<constchar *>(ifsh));
}
size_tprint(const String &);
size_tprint(constchar[]);
size_tprint(char);
size_tprint(unsignedchar, int = DEC);
size_tprint(int, int = DEC);
size_tprint(unsignedint, int = DEC);
size_tprint(long, int = DEC);
size_tprint(unsignedlong, int = DEC);
size_tprint(longlong, int = DEC);
size_tprint(unsignedlonglong, int = DEC);
size_tprint(double, int = 2);
size_tprint(const Printable &);
size_tprint(structtm *timeinfo, constchar *format = NULL);
size_tprintln(const __FlashStringHelper *ifsh) {
returnprintln(reinterpret_cast<constchar *>(ifsh));
}
size_tprintln(const String &s);
size_tprintln(constchar[]);
size_tprintln(char);
size_tprintln(unsignedchar, int = DEC);
size_tprintln(int, int = DEC);
size_tprintln(unsignedint, int = DEC);
size_tprintln(long, int = DEC);
size_tprintln(unsignedlong, int = DEC);
size_tprintln(longlong, int = DEC);
size_tprintln(unsignedlonglong, int = DEC);
size_tprintln(double, int = 2);
size_tprintln(const Printable &);
size_tprintln(structtm *timeinfo, constchar *format = NULL);
size_tprintln(void);
virtualvoidflush() { /* Empty implementation for backward compatibility */ }
};
#endif