JM9 XRCU Board 0.1.3a
Libraries API Reference
Loading...
Searching...
No Matches
Print.h
1/*
2 Copyright (c) 2016 Arduino LLC. All right reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#ifndef Print_h
20#define Print_h
21
22#include <inttypes.h>
23#include <stdio.h> // for size_t
24#include <stdarg.h> // for printf
25
26#include "WString.h"
27#include "Printable.h"
28
29#define DEC 10
30#define HEX 16
31#define OCT 8
32#define BIN 2
33
34class Print {
35 private:
36 int write_error;
37 size_t printNumber(unsigned long, uint8_t);
38 size_t printULLNumber(unsigned long long, uint8_t);
39 template <class T>
40 size_t printFloat(T, uint8_t);
41 protected:
42 void setWriteError(int err = 1)
43 {
44 write_error = err;
45 }
46 public:
47 Print() : write_error(0) {}
48
49 int getWriteError()
50 {
51 return write_error;
52 }
53 void clearWriteError()
54 {
55 setWriteError(0);
56 }
57
58 virtual size_t write(uint8_t) = 0;
59 size_t write(const char *str)
60 {
61 if (str == NULL) {
62 return 0;
63 }
64 return write((const uint8_t *)str, strlen(str));
65 }
66 virtual size_t write(const uint8_t *buffer, size_t size);
67 size_t write(const char *buffer, size_t size)
68 {
69 return write((const uint8_t *)buffer, size);
70 }
71
72 // default to zero, meaning "a single write may block"
73 // should be overridden by subclasses with buffering
74 virtual int availableForWrite()
75 {
76 return 0;
77 }
78
79 size_t print(const __FlashStringHelper *);
80 size_t print(const String &);
81 size_t print(const char[]);
82 size_t print(char);
83 size_t print(unsigned char, int = DEC);
84 size_t print(int, int = DEC);
85 size_t print(unsigned int, int = DEC);
86 size_t print(long, int = DEC);
87 size_t print(unsigned long, int = DEC);
88 size_t print(long long, int = DEC);
89 size_t print(unsigned long long, int = DEC);
90 size_t print(float, int = 2);
91 size_t print(double, int = 2);
92 size_t print(const Printable &);
93
94 size_t println(const __FlashStringHelper *);
95 size_t println(const String &s);
96 size_t println(const char[]);
97 size_t println(char);
98 size_t println(unsigned char, int = DEC);
99 size_t println(int, int = DEC);
100 size_t println(unsigned int, int = DEC);
101 size_t println(long, int = DEC);
102 size_t println(unsigned long, int = DEC);
103 size_t println(long long, int = DEC);
104 size_t println(unsigned long long, int = DEC);
105 size_t println(float, int = 2);
106 size_t println(double, int = 2);
107 size_t println(const Printable &);
108 size_t println(void);
109
110 int printf(const char *format, ...);
111 int printf(const __FlashStringHelper *format, ...);
112 int vprintf(const __FlashStringHelper *format, va_list ap);
113 int vprintf(const char *format, va_list ap);
114
115 virtual void flush() { /* Empty implementation for backward compatibility */ }
116};
117
118#endif
Definition Printable.h:33