From 2ef6860d8af25d70b05f61a5f5700e96ecd0cd05 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 14 Jun 2015 00:31:29 -0700 Subject: WIP on new Print --- wirish/include/wirish/Print.h | 110 ++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 53 deletions(-) (limited to 'wirish/include/wirish/Print.h') diff --git a/wirish/include/wirish/Print.h b/wirish/include/wirish/Print.h index 5fd0b7a..ca3e7e8 100644 --- a/wirish/include/wirish/Print.h +++ b/wirish/include/wirish/Print.h @@ -1,67 +1,71 @@ -/* - * Print.h - Base class that provides print() and println() - * Copyright (c) 2008 David A. Mellis. All right reserved. +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2015 Bryan Newbold * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + *****************************************************************************/ + +/* + * Arduino-compatible UART printing implementation. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA. + * This replaces the old copyleft Print class implementation copied from + * Arduino. * - * Modified 12 April 2011 by Marti Bolivar + * This file is a "clean" implementation using only the API documentation + * (for HardwareSerial) without directly copying from the Arduino source. */ #ifndef _WIRISH_PRINT_H_ #define _WIRISH_PRINT_H_ -#include - -enum { - BYTE = 0, - BIN = 2, - OCT = 8, - DEC = 10, - HEX = 16 -}; - +/* See HardwareSerial for docs on these functions. */ class Print { public: - virtual void write(uint8 ch) = 0; - virtual void write(const char *str); - virtual void write(const void *buf, uint32 len); - void print(char); - void print(const char[]); - void print(uint8, int=DEC); - void print(int, int=DEC); - void print(unsigned int, int=DEC); - void print(long, int=DEC); - void print(unsigned long, int=DEC); - void print(long long, int=DEC); - void print(unsigned long long, int=DEC); - void print(double, int=2); - void println(void); - void println(char); - void println(const char[]); - void println(uint8, int=DEC); - void println(int, int=DEC); - void println(unsigned int, int=DEC); - void println(long, int=DEC); - void println(unsigned long, int=DEC); - void println(long long, int=DEC); - void println(unsigned long long, int=DEC); - void println(double, int=2); + void print(unsigned char b); + void print(char c); + void print(const char* str); + void print(int n); + void print(unsigned int n); + void print(long n); + void print(unsigned long n); + void print(long n, int base); + void print(double n); + void println(unsigned char b); + void println(char c); + void println(const char* str); + void println(int n); + void println(unsigned int n); + void println(long n); + void println(unsigned long n); + void println(long n, int base); + void println(double n); + void write(const char* str); + void write(void* buf, unsigned int size); + + /* This is the one function that an implementing class needs */ + virtual void write(unsigned char ch); private: - void printNumber(unsigned long long, uint8); - void printFloat(double, uint8); -}; + void print_unsigned(unsigned long n, int base); + void print_signed(long n, int base); +} #endif -- cgit v1.2.3