arduino-emulator
Loading...
Searching...
No Matches
Print.h
1/*
2 Print.h - Base class that provides print() and println()
3 Copyright (c) 2016 Arduino LLC. 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#pragma once
21
22#include <inttypes.h>
23#include <stdio.h> // for size_t
24
25#include "String.h"
26#include "Printable.h"
27
28#define DEC 10
29#define HEX 16
30#define OCT 8
31#define BIN 2
32
33namespace arduino {
34
35class Print
36{
37 private:
38 int write_error;
39 size_t printNumber(unsigned long, uint8_t);
40 size_t printULLNumber(unsigned long long, uint8_t);
41 size_t printFloat(double, int);
42 protected:
43 void setWriteError(int err = 1) { write_error = err; }
44 public:
45 Print() : write_error(0) {}
46
47 int getWriteError() { return write_error; }
48 void clearWriteError() { setWriteError(0); }
49
50 virtual size_t write(uint8_t) = 0;
51 size_t write(const char *str) {
52 if (str == NULL) return 0;
53 return write((const uint8_t *)str, strlen(str));
54 }
55 virtual size_t write(const uint8_t *buffer, size_t size);
56 size_t write(const char *buffer, size_t size) {
57 return write((const uint8_t *)buffer, size);
58 }
59
60 // default to zero, meaning "a single write may block"
61 // should be overridden by subclasses with buffering
62 virtual int availableForWrite() { return 0; }
63
64 size_t print(const __FlashStringHelper *);
65 size_t print(const String &);
66 size_t print(const char[]);
67 size_t print(char);
68 size_t print(unsigned char, int = DEC);
69 size_t print(int, int = DEC);
70 size_t print(unsigned int, int = DEC);
71 size_t print(long, int = DEC);
72 size_t print(unsigned long, int = DEC);
73 size_t print(long long, int = DEC);
74 size_t print(unsigned long long, int = DEC);
75 size_t print(double, int = 2);
76 size_t print(const Printable&);
77
78 size_t println(const __FlashStringHelper *);
79 size_t println(const String &s);
80 size_t println(const char[]);
81 size_t println(char);
82 size_t println(unsigned char, int = DEC);
83 size_t println(int, int = DEC);
84 size_t println(unsigned int, int = DEC);
85 size_t println(long, int = DEC);
86 size_t println(unsigned long, int = DEC);
87 size_t println(long long, int = DEC);
88 size_t println(unsigned long long, int = DEC);
89 size_t println(double, int = 2);
90 size_t println(const Printable&);
91 size_t println(void);
92
93 virtual void flush() { /* Empty implementation for backward compatibility */ }
94};
95
96}
97using arduino::Print;
Definition DMAPool.h:103
Definition Print.h:36
Definition Printable.h:35
Definition String.h:53
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31