MySensors Library & Examples  2.3.2-36-g2e00bf6
Print.h
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  Modified August 2016 by Marcelo Aquino <[email protected]> for MySensors use
20  */
21 
22 #ifndef Print_h
23 #define Print_h
24 
25 #include <stdint.h>
26 #include <string>
27 #include <string.h>
28 
29 #if !DOXYGEN
30 #define DEC 10
31 #define HEX 16
32 #define OCT 8
33 #define BIN 2
34 
35 class Print
36 {
37 private:
38  int write_error;
39  size_t printNumber(unsigned long n, uint8_t base);
40  size_t printFloat(double number, uint8_t digits);
41 
42 protected:
43  void setWriteError(int err = 1)
44  {
45  write_error = err;
46  }
47 
48 public:
49  Print() : write_error(0) {}
50 
51  int getWriteError()
52  {
53  return write_error;
54  }
55  void clearWriteError()
56  {
57  setWriteError(0);
58  }
59 
60  virtual size_t write(uint8_t) = 0;
61  size_t write(const char *str)
62  {
63  if (str == NULL) {
64  return 0;
65  }
66  return write((const uint8_t *) str, strlen(str));
67  }
68  virtual size_t write(const uint8_t *buffer, size_t size);
69  size_t write(const char *buffer, size_t size)
70  {
71  return write((const uint8_t *) buffer, size);
72  }
73 
74  size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
75  size_t print(const std::string &);
76  size_t print(const char[]);
77  size_t print(char);
78  size_t print(unsigned char, int = DEC);
79  size_t print(int, int = DEC);
80  size_t print(unsigned int, int = DEC);
81  size_t print(long, int = DEC);
82  size_t print(unsigned long, int = DEC);
83  size_t print(double, int = 2);
84 
85  size_t println(const std::string &s);
86  size_t println(const char[]);
87  size_t println(char);
88  size_t println(unsigned char, int = DEC);
89  size_t println(int, int = DEC);
90  size_t println(unsigned int, int = DEC);
91  size_t println(long, int = DEC);
92  size_t println(unsigned long, int = DEC);
93  size_t println(double, int = 2);
94  size_t println(void);
95 };
96 
97 #endif
98 #endif
__attribute__
FW config structure, stored in eeprom.
Definition: MyOTAFirmwareUpdate.h:117