hadif azli
/
TEST123
BLYNK TEST
Printit.h@0:d8f4c441e032, 2016-06-10 (annotated)
- Committer:
- lixianyu
- Date:
- Fri Jun 10 15:20:20 2016 +0000
- Revision:
- 0:d8f4c441e032
u8glib???????????i2c???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:d8f4c441e032 | 1 | /* |
lixianyu | 0:d8f4c441e032 | 2 | Print.h - Base class that provides print() and println() |
lixianyu | 0:d8f4c441e032 | 3 | Copyright (c) 2008 David A. Mellis. All right reserved. |
lixianyu | 0:d8f4c441e032 | 4 | |
lixianyu | 0:d8f4c441e032 | 5 | This library is free software; you can redistribute it and/or |
lixianyu | 0:d8f4c441e032 | 6 | modify it under the terms of the GNU Lesser General Public |
lixianyu | 0:d8f4c441e032 | 7 | License as published by the Free Software Foundation; either |
lixianyu | 0:d8f4c441e032 | 8 | version 2.1 of the License, or (at your option) any later version. |
lixianyu | 0:d8f4c441e032 | 9 | |
lixianyu | 0:d8f4c441e032 | 10 | This library is distributed in the hope that it will be useful, |
lixianyu | 0:d8f4c441e032 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lixianyu | 0:d8f4c441e032 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lixianyu | 0:d8f4c441e032 | 13 | Lesser General Public License for more details. |
lixianyu | 0:d8f4c441e032 | 14 | |
lixianyu | 0:d8f4c441e032 | 15 | You should have received a copy of the GNU Lesser General Public |
lixianyu | 0:d8f4c441e032 | 16 | License along with this library; if not, write to the Free Software |
lixianyu | 0:d8f4c441e032 | 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lixianyu | 0:d8f4c441e032 | 18 | */ |
lixianyu | 0:d8f4c441e032 | 19 | |
lixianyu | 0:d8f4c441e032 | 20 | #ifndef Printit_h |
lixianyu | 0:d8f4c441e032 | 21 | #define Printit_h |
lixianyu | 0:d8f4c441e032 | 22 | |
lixianyu | 0:d8f4c441e032 | 23 | #include <inttypes.h> |
lixianyu | 0:d8f4c441e032 | 24 | //#include <stdio.h> // for size_t |
lixianyu | 0:d8f4c441e032 | 25 | |
lixianyu | 0:d8f4c441e032 | 26 | #include "WString.h" |
lixianyu | 0:d8f4c441e032 | 27 | #include "Printable.h" |
lixianyu | 0:d8f4c441e032 | 28 | |
lixianyu | 0:d8f4c441e032 | 29 | #define DEC 10 |
lixianyu | 0:d8f4c441e032 | 30 | #define HEX 16 |
lixianyu | 0:d8f4c441e032 | 31 | #define OCT 8 |
lixianyu | 0:d8f4c441e032 | 32 | #define BIN 2 |
lixianyu | 0:d8f4c441e032 | 33 | |
lixianyu | 0:d8f4c441e032 | 34 | class Print |
lixianyu | 0:d8f4c441e032 | 35 | { |
lixianyu | 0:d8f4c441e032 | 36 | public: |
lixianyu | 0:d8f4c441e032 | 37 | Print() : write_error(0) {} |
lixianyu | 0:d8f4c441e032 | 38 | |
lixianyu | 0:d8f4c441e032 | 39 | int getWriteError() { |
lixianyu | 0:d8f4c441e032 | 40 | return write_error; |
lixianyu | 0:d8f4c441e032 | 41 | } |
lixianyu | 0:d8f4c441e032 | 42 | void clearWriteError() { |
lixianyu | 0:d8f4c441e032 | 43 | setWriteError(0); |
lixianyu | 0:d8f4c441e032 | 44 | } |
lixianyu | 0:d8f4c441e032 | 45 | |
lixianyu | 0:d8f4c441e032 | 46 | virtual size_t write(uint8_t) = 0; |
lixianyu | 0:d8f4c441e032 | 47 | size_t write(const char *str) { |
lixianyu | 0:d8f4c441e032 | 48 | if (str == NULL) return 0; |
lixianyu | 0:d8f4c441e032 | 49 | return write((const uint8_t *)str, strlen(str)); |
lixianyu | 0:d8f4c441e032 | 50 | } |
lixianyu | 0:d8f4c441e032 | 51 | virtual size_t write(const uint8_t *buffer, size_t size); |
lixianyu | 0:d8f4c441e032 | 52 | size_t write(const char *buffer, size_t size) { |
lixianyu | 0:d8f4c441e032 | 53 | return write((const uint8_t *)buffer, size); |
lixianyu | 0:d8f4c441e032 | 54 | } |
lixianyu | 0:d8f4c441e032 | 55 | #if 0 |
lixianyu | 0:d8f4c441e032 | 56 | size_t print(const __FlashStringHelper *); |
lixianyu | 0:d8f4c441e032 | 57 | #endif |
lixianyu | 0:d8f4c441e032 | 58 | public: |
lixianyu | 0:d8f4c441e032 | 59 | //size_t print(const String &); |
lixianyu | 0:d8f4c441e032 | 60 | size_t print(char *str); |
lixianyu | 0:d8f4c441e032 | 61 | size_t print(char); |
lixianyu | 0:d8f4c441e032 | 62 | size_t print(unsigned char, int = DEC); |
lixianyu | 0:d8f4c441e032 | 63 | size_t print(int, int = DEC); |
lixianyu | 0:d8f4c441e032 | 64 | size_t print(unsigned int, int = DEC); |
lixianyu | 0:d8f4c441e032 | 65 | size_t print(long, int = DEC); |
lixianyu | 0:d8f4c441e032 | 66 | size_t print(unsigned long, int = DEC); |
lixianyu | 0:d8f4c441e032 | 67 | size_t print(double, int = 2); |
lixianyu | 0:d8f4c441e032 | 68 | size_t print(const Printable&); |
lixianyu | 0:d8f4c441e032 | 69 | #if 0 |
lixianyu | 0:d8f4c441e032 | 70 | size_t println(const __FlashStringHelper *); |
lixianyu | 0:d8f4c441e032 | 71 | #endif |
lixianyu | 0:d8f4c441e032 | 72 | //size_t println(const String &s); |
lixianyu | 0:d8f4c441e032 | 73 | size_t println(char *str); |
lixianyu | 0:d8f4c441e032 | 74 | size_t println(char); |
lixianyu | 0:d8f4c441e032 | 75 | size_t println(unsigned char, int = DEC); |
lixianyu | 0:d8f4c441e032 | 76 | size_t println(int, int = DEC); |
lixianyu | 0:d8f4c441e032 | 77 | size_t println(unsigned int, int = DEC); |
lixianyu | 0:d8f4c441e032 | 78 | size_t println(long, int = DEC); |
lixianyu | 0:d8f4c441e032 | 79 | size_t println(unsigned long, int = DEC); |
lixianyu | 0:d8f4c441e032 | 80 | size_t println(double, int = 2); |
lixianyu | 0:d8f4c441e032 | 81 | size_t println(const Printable&); |
lixianyu | 0:d8f4c441e032 | 82 | size_t println(void); |
lixianyu | 0:d8f4c441e032 | 83 | |
lixianyu | 0:d8f4c441e032 | 84 | //private: |
lixianyu | 0:d8f4c441e032 | 85 | int write_error; |
lixianyu | 0:d8f4c441e032 | 86 | size_t printNumber(unsigned long, uint8_t); |
lixianyu | 0:d8f4c441e032 | 87 | size_t printFloat(double, uint8_t); |
lixianyu | 0:d8f4c441e032 | 88 | //protected: |
lixianyu | 0:d8f4c441e032 | 89 | void setWriteError(int err = 1) { |
lixianyu | 0:d8f4c441e032 | 90 | write_error = err; |
lixianyu | 0:d8f4c441e032 | 91 | } |
lixianyu | 0:d8f4c441e032 | 92 | }; |
lixianyu | 0:d8f4c441e032 | 93 | |
lixianyu | 0:d8f4c441e032 | 94 | #endif |
lixianyu | 0:d8f4c441e032 | 95 |