Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Printit.h
00001 /* 00002 Print.h - Base class that provides print() and println() 00003 Copyright (c) 2008 David A. Mellis. All right reserved. 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #ifndef Printit_h 00021 #define Printit_h 00022 00023 #include <inttypes.h> 00024 //#include <stdio.h> // for size_t 00025 00026 #include "WString.h" 00027 #include "Printable.h" 00028 00029 #define DEC 10 00030 #define HEX 16 00031 #define OCT 8 00032 #define BIN 2 00033 00034 class Print 00035 { 00036 public: 00037 Print() : write_error(0) {} 00038 00039 int getWriteError() { 00040 return write_error; 00041 } 00042 void clearWriteError() { 00043 setWriteError(0); 00044 } 00045 00046 virtual size_t write(uint8_t) = 0; 00047 size_t write(const char *str) { 00048 if (str == NULL) return 0; 00049 return write((const uint8_t *)str, strlen(str)); 00050 } 00051 virtual size_t write(const uint8_t *buffer, size_t size); 00052 size_t write(const char *buffer, size_t size) { 00053 return write((const uint8_t *)buffer, size); 00054 } 00055 #if 0 00056 size_t print(const __FlashStringHelper *); 00057 #endif 00058 public: 00059 //size_t print(const String &); 00060 size_t print(char *str); 00061 size_t print(char); 00062 size_t print(unsigned char, int = DEC); 00063 size_t print(int, int = DEC); 00064 size_t print(unsigned int, int = DEC); 00065 size_t print(long, int = DEC); 00066 size_t print(unsigned long, int = DEC); 00067 size_t print(double, int = 2); 00068 size_t print(const Printable&); 00069 #if 0 00070 size_t println(const __FlashStringHelper *); 00071 #endif 00072 //size_t println(const String &s); 00073 size_t println(char *str); 00074 size_t println(char); 00075 size_t println(unsigned char, int = DEC); 00076 size_t println(int, int = DEC); 00077 size_t println(unsigned int, int = DEC); 00078 size_t println(long, int = DEC); 00079 size_t println(unsigned long, int = DEC); 00080 size_t println(double, int = 2); 00081 size_t println(const Printable&); 00082 size_t println(void); 00083 00084 //private: 00085 int write_error; 00086 size_t printNumber(unsigned long, uint8_t); 00087 size_t printFloat(double, uint8_t); 00088 //protected: 00089 void setWriteError(int err = 1) { 00090 write_error = err; 00091 } 00092 }; 00093 00094 #endif 00095
Generated on Thu Jul 14 2022 22:36:21 by
