Harry Cadena / Mbed 2 deprecated LiquidCrystal_I2C

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Print.h Source File

Print.h

00001 /*
00002  Print.h - Base class that provides print() and println()
00003  Copyright (c) 2008 David A. Mellis.  All right reserved.
00004  This library is free software; you can redistribute it and/or
00005  modify it under the terms of the GNU Lesser General Public
00006  License as published by the Free Software Foundation; either
00007  version 2.1 of the License, or (at your option) any later version.
00008  This library is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  Lesser General Public License for more details.
00012  You should have received a copy of the GNU Lesser General Public
00013  License along with this library; if not, write to the Free Software
00014  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00015  */
00016 
00017 #ifndef Print_h
00018 #define Print_h
00019 
00020 #include <stdint.h>
00021 #include <string>
00022 #include <string.h>
00023 
00024 #define DEC 10
00025 #define HEX 16
00026 #define OCT 8
00027 #define BIN 2
00028 
00029 class Print {
00030     private:
00031         int write_error;
00032         size_t printNumber(unsigned long, uint8_t);
00033         size_t printFloat(double, uint8_t);
00034     protected:
00035         inline void setWriteError(int err = 1) {
00036             write_error = err;
00037         }
00038     public:
00039         Print() :
00040                 write_error(0) {
00041         }
00042 
00043         int getWriteError() {
00044             return write_error;
00045         }
00046         void clearWriteError() {
00047             setWriteError(0);
00048         }
00049 
00050         virtual size_t write(uint8_t) = 0;
00051         size_t write(const char *str) {
00052             if(str == NULL)
00053                 return 0;
00054         return write((const uint8_t *) str, strlen(str));
00055         }
00056         virtual size_t write(const uint8_t *buffer, size_t size);
00057         size_t write(const char *buffer, size_t size) {
00058             return write((const uint8_t *) buffer, size);
00059         }
00060         // These handle ambiguity for write(0) case, because (0) can be a pointer or an integer
00061         inline size_t write(short t) { return write((uint8_t)t); }
00062         inline size_t write(unsigned short t) { return write((uint8_t)t); }
00063         inline size_t write(int t) { return write((uint8_t)t); }
00064         inline size_t write(unsigned int t) { return write((uint8_t)t); }
00065         inline size_t write(long t) { return write((uint8_t)t); }
00066         inline size_t write(unsigned long t) { return write((uint8_t)t); }
00067         // Enable write(char) to fall through to write(uint8_t)
00068         inline size_t write(char c) { return write((uint8_t) c); }
00069         inline size_t write(int8_t c) { return write((uint8_t) c); }
00070 
00071         size_t printf(const char * format, ...)  __attribute__ ((format (printf, 2, 3)));
00072         size_t print(const std::string &);
00073         size_t print(const char[]);
00074         size_t print(char);
00075         size_t print(unsigned char, int = DEC);
00076         size_t print(int, int = DEC);
00077         size_t print(unsigned int, int = DEC);
00078         size_t print(long, int = DEC);
00079         size_t print(unsigned long, int = DEC);
00080         size_t print(double, int = 2);
00081 
00082         size_t println(const std::string &s);
00083         size_t println(const char[]);
00084         size_t println(char);
00085         size_t println(unsigned char, int = DEC);
00086         size_t println(int, int = DEC);
00087         size_t println(unsigned int, int = DEC);
00088         size_t println(long, int = DEC);
00089         size_t println(unsigned long, int = DEC);
00090         size_t println(double, int = 2);
00091         size_t println(void);
00092 
00093         virtual void flush() { /* Empty implementation for backward compatibility */ }
00094 };
00095 
00096 #endif