Index

auto-plow / c7eae65

A wheelchair motor-propelled battery-powered ESP32-driven remote control snow plow.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
630 Nov 2018 18:364a63c8cInclude Arduino core filesJoshua1930N

Blob @ auto-plow / include / arduino / Print.h

text/plain2963 bytesdownload raw
1/*
2 Print.h - Base class that provides print() and println()
3 Copyright (c) 2008 David A. Mellis. All right reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef Print_h
21#define Print_h
22
23#include <inttypes.h>
24#include <stdio.h> // for size_t
25
26#include "WString.h"
27#include "Printable.h"
28
29#define DEC 10
30#define HEX 16
31#define OCT 8
32#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
33#undef BIN
34#endif
35#define BIN 2
36
37class Print
38{
39 private:
40 int write_error;
41 size_t printNumber(unsigned long, uint8_t);
42 size_t printFloat(double, uint8_t);
43 protected:
44 void setWriteError(int err = 1) { write_error = err; }
45 public:
46 Print() : write_error(0) {}
47
48 int getWriteError() { return write_error; }
49 void clearWriteError() { setWriteError(0); }
50
51 virtual size_t write(uint8_t) = 0;
52 size_t write(const char *str) {
53 if (str == NULL) return 0;
54 return write((const uint8_t *)str, strlen(str));
55 }
56 virtual size_t write(const uint8_t *buffer, size_t size);
57 size_t write(const char *buffer, size_t size) {
58 return write((const uint8_t *)buffer, size);
59 }
60
61 // default to zero, meaning "a single write may block"
62 // should be overriden by subclasses with buffering
63 virtual int availableForWrite() { return 0; }
64
65 size_t print(const __FlashStringHelper *);
66 size_t print(const String &);
67 size_t print(const char[]);
68 size_t print(char);
69 size_t print(unsigned char, int = DEC);
70 size_t print(int, int = DEC);
71 size_t print(unsigned int, int = DEC);
72 size_t print(long, int = DEC);
73 size_t print(unsigned long, int = DEC);
74 size_t print(double, int = 2);
75 size_t print(const Printable&);
76
77 size_t println(const __FlashStringHelper *);
78 size_t println(const String &s);
79 size_t println(const char[]);
80 size_t println(char);
81 size_t println(unsigned char, int = DEC);
82 size_t println(int, int = DEC);
83 size_t println(unsigned int, int = DEC);
84 size_t println(long, int = DEC);
85 size_t println(unsigned long, int = DEC);
86 size_t println(double, int = 2);
87 size_t println(const Printable&);
88 size_t println(void);
89
90 virtual void flush() { /* Empty implementation for backward compatibility */ }
91};
92
93#endif
94