From 3f77427ecdcda5bc9dcceb7f79ec278e9cfcb42f Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 8 Jun 2011 16:39:04 -0400 Subject: Update Print to match Arduino master. Add base argument to integral Print methods, defaulting to DEC so as not to break backwards compatibility. Add precision argument to floating-point Print methods. These changes increase compatibility with the Arduino Print implementation. --- wirish/Print.cpp | 77 ++++++++++++++++++++++++++------------------------------ wirish/Print.h | 34 ++++++++++++------------- 2 files changed, 51 insertions(+), 60 deletions(-) diff --git a/wirish/Print.cpp b/wirish/Print.cpp index 9130c9c..58c7cc7 100644 --- a/wirish/Print.cpp +++ b/wirish/Print.cpp @@ -59,58 +59,56 @@ void Print::write(const void *buffer, uint32 size) { } } -void Print::print(uint8 b) { - this->write(b); +void Print::print(uint8 b, int base) { + print((uint64)b, base); } void Print::print(char c) { - print((uint8)c); + write(c); } void Print::print(const char str[]) { write(str); } -void Print::print(int n) { - print((long long)n); +void Print::print(int n, int base) { + print((long long)n, base); } -void Print::print(unsigned int n) { - print((unsigned long long)n); +void Print::print(unsigned int n, int base) { + print((unsigned long long)n, base); } -void Print::print(long n) { - print((long long)n); +void Print::print(long n, int base) { + print((long long)n, base); } -void Print::print(unsigned long n) { - print((unsigned long long)n); +void Print::print(unsigned long n, int base) { + print((unsigned long long)n, base); } -void Print::print(long long n) { +void Print::print(long long n, int base) { + if (base == BYTE) { + write((uint8)n); + return; + } if (n < 0) { print('-'); n = -n; } - printNumber(n, 10); -} - -void Print::print(unsigned long long n) { - printNumber(n, 10); + printNumber(n, base); } void Print::print(unsigned long long n, int base) { - if (base == 0) { - print((char)n); - } else if (base == 10) { - print(n); + if (base == BYTE) { + write((uint8)n); } else { printNumber(n, base); } } -void Print::print(double n) { - printFloat(n, 2); +void Print::print(double n, int digits) { + printFloat(n, digits); } void Print::println(void) { @@ -128,38 +126,33 @@ void Print::println(const char c[]) { println(); } -void Print::println(uint8 b) { - print(b); - println(); -} - -void Print::println(int n) { - print(n); +void Print::println(uint8 b, int base) { + print(b, base); println(); } -void Print::println(unsigned int n) { - print(n); +void Print::println(int n, int base) { + print(n, base); println(); } -void Print::println(long n) { - print((long long)n); +void Print::println(unsigned int n, int base) { + print(n, base); println(); } -void Print::println(unsigned long n) { - print((unsigned long long)n); +void Print::println(long n, int base) { + print((long long)n, base); println(); } -void Print::println(long long n) { - print(n); +void Print::println(unsigned long n, int base) { + print((unsigned long long)n, base); println(); } -void Print::println(unsigned long long n) { - print(n); +void Print::println(long long n, int base) { + print(n, base); println(); } @@ -168,8 +161,8 @@ void Print::println(unsigned long long n, int base) { println(); } -void Print::println(double n) { - print(n); +void Print::println(double n, int digits) { + print(n, digits); println(); } diff --git a/wirish/Print.h b/wirish/Print.h index 73d82e7..c0c63cb 100644 --- a/wirish/Print.h +++ b/wirish/Print.h @@ -40,27 +40,25 @@ public: virtual void write(const void *buf, uint32 len); void print(char); void print(const char[]); - void print(uint8); - void print(int); - void print(unsigned int); - void print(long); - void print(unsigned long); - void print(long long); - void print(unsigned long long); - void print(unsigned long long, int); - void print(double); + 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); - void println(int); - void println(unsigned int); - void println(long); - void println(unsigned long); - void println(long long); - void println(unsigned long long); - void println(unsigned long long, int); - void println(double); + 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); private: void printNumber(unsigned long long, uint8); void printFloat(double, uint8); -- cgit v1.2.3