From c8b8b8724cc94cdd9290033d76513c8f816ad862 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 26 Feb 2011 13:58:03 -0500 Subject: Removing BYTE keyword (use Serial.write() instead). --- cores/arduino/Print.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 4ee556d..eb1a8de 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -55,9 +55,9 @@ void Print::print(const char str[]) write(str); } -void Print::print(char c, int base) +void Print::print(char c) { - print((long) c, base); + write(c); } void Print::print(unsigned char b, int base) @@ -119,9 +119,9 @@ void Print::println(const char c[]) println(); } -void Print::println(char c, int base) +void Print::println(char c) { - print(c, base); + print(c); println(); } -- cgit v1.2.3-18-g5258 From 218eb5e80706b53c691da133461830c895e0c8ff Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 1 Mar 2011 20:00:16 -0500 Subject: Moving wiring.h contents into Arduino.h. --- cores/arduino/Print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index eb1a8de..62d93a3 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -23,7 +23,7 @@ #include #include #include -#include "wiring.h" +#include "Arduino.h" #include "Print.h" -- cgit v1.2.3-18-g5258 From ffe7bc53c1862866bf38e01174bd35d20632608c Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 27 Mar 2011 15:06:20 -0400 Subject: Adding F("foo") syntax for flash strings. --- cores/arduino/Print.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 62d93a3..eac145f 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -43,6 +43,16 @@ void Print::write(const uint8_t *buffer, size_t size) write(*buffer++); } +void Print::print(const __FlashStringHelper *ifsh) +{ + const prog_char *p = (const prog_char *)ifsh; + while (1) { + unsigned char c = pgm_read_byte(p++); + if (c == 0) return; + write(c); + } +} + void Print::print(const String &s) { for (int i = 0; i < s.length(); i++) { @@ -101,10 +111,16 @@ void Print::print(double n, int digits) printFloat(n, digits); } +void Print::println(const __FlashStringHelper *ifsh) +{ + print(ifsh); + println(); +} + void Print::println(void) { print('\r'); - print('\n'); + print('\n'); } void Print::println(const String &s) -- cgit v1.2.3-18-g5258 From 5e5cce81240b39c6068380cd786ac59c2ce88c07 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 7 May 2011 18:17:32 -0400 Subject: Optimizing printing of numbers (writing a single buffer). Fix from Bill Greiman via Limor. --- cores/arduino/Print.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index eac145f..0a580b7 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -179,25 +179,23 @@ void Print::println(double n, int digits) // Private Methods ///////////////////////////////////////////////////////////// -void Print::printNumber(unsigned long n, uint8_t base) -{ - unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. - unsigned long i = 0; +void Print::printNumber(unsigned long n, uint8_t base) { + char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. + char *str = &buf[sizeof(buf) - 1]; - if (n == 0) { - print('0'); - return; - } + *str = '\0'; + + // prevent crash if called with base == 1 + if (base < 2) base = 10; - while (n > 0) { - buf[i++] = n % base; + do { + unsigned long m = n; n /= base; - } + char c = m - base * n; + *--str = c < 10 ? c + '0' : c + 'A' - 10; + } while(n); - for (; i > 0; i--) - print((char) (buf[i - 1] < 10 ? - '0' + buf[i - 1] : - 'A' + buf[i - 1] - 10)); + write(str); } void Print::printFloat(double number, uint8_t digits) -- cgit v1.2.3-18-g5258 From a239d2c541094ef5445159360ae5d2d6a93dbf00 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 4 Jun 2011 09:19:17 -0400 Subject: Added Printable interface class to allow printing of classes such as IPAddress --- cores/arduino/Print.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 0a580b7..06ac52a 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -117,6 +117,11 @@ void Print::println(const __FlashStringHelper *ifsh) println(); } +void Print::print(const Printable& x) +{ + x.printTo(*this); +} + void Print::println(void) { print('\r'); @@ -177,6 +182,12 @@ void Print::println(double n, int digits) println(); } +void Print::println(const Printable& x) +{ + print(x); + println(); +} + // Private Methods ///////////////////////////////////////////////////////////// void Print::printNumber(unsigned long n, uint8_t base) { -- cgit v1.2.3-18-g5258 From f282cbaf968f7142ef5abb68a92e970c3d5eea35 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 23 Aug 2011 19:12:03 -0400 Subject: write(), print(), and println() now return number of bytes written. The type is long, and negative values indicate errors. Needs more testing. http://code.google.com/p/arduino/issues/detail?id=551 --- cores/arduino/Print.cpp | 194 +++++++++++++++++++++++++++++------------------- 1 file changed, 117 insertions(+), 77 deletions(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 06ac52a..58b1032 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -30,167 +30,196 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -void Print::write(const char *str) +long Print::write(const char *str) { - while (*str) - write(*str++); + long n = 0; + while (*str) { + if (write(*str++) <= 0) break; + n++; + } + return n; } /* default implementation: may be overridden */ -void Print::write(const uint8_t *buffer, size_t size) +long Print::write(const uint8_t *buffer, size_t size) { - while (size--) - write(*buffer++); + long n = 0; + while (size--) { + if (write(*buffer++) <= 0) break; + n++; + } + return n; } -void Print::print(const __FlashStringHelper *ifsh) +long Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; + long n = 0; while (1) { unsigned char c = pgm_read_byte(p++); - if (c == 0) return; - write(c); + if (c == 0) break; + if (write(c) <= 0) break; + n++; } + return n; } -void Print::print(const String &s) +long Print::print(const String &s) { + long n = 0; for (int i = 0; i < s.length(); i++) { - write(s[i]); + if (write(s[i]) < 0) break; + n++; } + return n; } -void Print::print(const char str[]) +long Print::print(const char str[]) { - write(str); + return write(str); } -void Print::print(char c) +long Print::print(char c) { - write(c); + return write(c); } -void Print::print(unsigned char b, int base) +long Print::print(unsigned char b, int base) { - print((unsigned long) b, base); + return print((unsigned long) b, base); } -void Print::print(int n, int base) +long Print::print(int n, int base) { - print((long) n, base); + return print((long) n, base); } -void Print::print(unsigned int n, int base) +long Print::print(unsigned int n, int base) { - print((unsigned long) n, base); + return print((unsigned long) n, base); } -void Print::print(long n, int base) +long Print::print(long n, int base) { if (base == 0) { - write(n); + return write(n); } else if (base == 10) { if (n < 0) { - print('-'); + long t = print('-'); + if (t <= 0) return t; n = -n; + return printNumber(n, 10) + 1; } - printNumber(n, 10); + return printNumber(n, 10); } else { - printNumber(n, base); + return printNumber(n, base); } } -void Print::print(unsigned long n, int base) +long Print::print(unsigned long n, int base) { - if (base == 0) write(n); - else printNumber(n, base); + if (base == 0) return write(n); + else return printNumber(n, base); } -void Print::print(double n, int digits) +long Print::print(double n, int digits) { - printFloat(n, digits); + return printFloat(n, digits); } -void Print::println(const __FlashStringHelper *ifsh) +long Print::println(const __FlashStringHelper *ifsh) { - print(ifsh); - println(); + long n = print(ifsh); + if (n >= 0) n += println(); + return n; } -void Print::print(const Printable& x) +long Print::print(const Printable& x) { - x.printTo(*this); + return x.printTo(*this); } -void Print::println(void) +long Print::println(void) { - print('\r'); - print('\n'); + long t = print('\r'); + if (t <= 0) return t; + if (print('\n') <= 0) return 1; + return 2; } -void Print::println(const String &s) +long Print::println(const String &s) { - print(s); - println(); + long n = print(s); + if (n >= 0) n += println(); + return n; } -void Print::println(const char c[]) +long Print::println(const char c[]) { - print(c); - println(); + long n = print(c); + if (n >= 0) n += println(); + return n; } -void Print::println(char c) +long Print::println(char c) { - print(c); - println(); + long n = print(c); + if (n > 0) n += println(); + return n; } -void Print::println(unsigned char b, int base) +long Print::println(unsigned char b, int base) { - print(b, base); - println(); + long n = print(b, base); + if (n >= 0) n += println(); + return n; } -void Print::println(int n, int base) +long Print::println(int num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(unsigned int n, int base) +long Print::println(unsigned int num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(long n, int base) +long Print::println(long num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(unsigned long n, int base) +long Print::println(unsigned long num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(double n, int digits) +long Print::println(double num, int digits) { - print(n, digits); - println(); + long n = print(num, digits); + if (n >= 0) n += println(); + return n; } -void Print::println(const Printable& x) +long Print::println(const Printable& x) { - print(x); - println(); + long n = print(x); + if (n >= 0) n += println(); + return n; } // Private Methods ///////////////////////////////////////////////////////////// -void Print::printNumber(unsigned long n, uint8_t base) { +long Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -206,15 +235,17 @@ void Print::printNumber(unsigned long n, uint8_t base) { *--str = c < 10 ? c + '0' : c + 'A' - 10; } while(n); - write(str); + return write(str); } -void Print::printFloat(double number, uint8_t digits) +long Print::printFloat(double number, uint8_t digits) { + long n = 0, t; + // Handle negative numbers if (number < 0.0) { - print('-'); + if ((n = print('-')) <= 0) return n; number = -number; } @@ -228,18 +259,27 @@ void Print::printFloat(double number, uint8_t digits) // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; - print(int_part); + if ((t = print(int_part)) < 0) return n; + + n += t; // Print the decimal point, but only if there are digits beyond - if (digits > 0) - print("."); + if (digits > 0) { + t = print("."); + if (t <= 0) return n; + n += t; + } // Extract digits from the remainder one at a time while (digits-- > 0) { remainder *= 10.0; int toPrint = int(remainder); - print(toPrint); + t = print(toPrint); + if (t <= 0) return n; + n += t; remainder -= toPrint; } + + return n; } -- cgit v1.2.3-18-g5258 From 0635790dd111e91e5c488acc599cc404dc707abd Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 14:20:41 -0400 Subject: Changing from long to ssize_t (int) for write(), print(), println() return. --- cores/arduino/Print.cpp | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 58b1032..192d9a3 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -30,9 +30,9 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -long Print::write(const char *str) +ssize_t Print::write(const char *str) { - long n = 0; + ssize_t n = 0; while (*str) { if (write(*str++) <= 0) break; n++; @@ -41,9 +41,9 @@ long Print::write(const char *str) } /* default implementation: may be overridden */ -long Print::write(const uint8_t *buffer, size_t size) +ssize_t Print::write(const uint8_t *buffer, size_t size) { - long n = 0; + ssize_t n = 0; while (size--) { if (write(*buffer++) <= 0) break; n++; @@ -51,10 +51,10 @@ long Print::write(const uint8_t *buffer, size_t size) return n; } -long Print::print(const __FlashStringHelper *ifsh) +ssize_t Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; - long n = 0; + ssize_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) break; @@ -64,9 +64,9 @@ long Print::print(const __FlashStringHelper *ifsh) return n; } -long Print::print(const String &s) +ssize_t Print::print(const String &s) { - long n = 0; + ssize_t n = 0; for (int i = 0; i < s.length(); i++) { if (write(s[i]) < 0) break; n++; @@ -74,38 +74,38 @@ long Print::print(const String &s) return n; } -long Print::print(const char str[]) +ssize_t Print::print(const char str[]) { return write(str); } -long Print::print(char c) +ssize_t Print::print(char c) { return write(c); } -long Print::print(unsigned char b, int base) +ssize_t Print::print(unsigned char b, int base) { return print((unsigned long) b, base); } -long Print::print(int n, int base) +ssize_t Print::print(int n, int base) { return print((long) n, base); } -long Print::print(unsigned int n, int base) +ssize_t Print::print(unsigned int n, int base) { return print((unsigned long) n, base); } -long Print::print(long n, int base) +ssize_t Print::print(long n, int base) { if (base == 0) { return write(n); } else if (base == 10) { if (n < 0) { - long t = print('-'); + int t = print('-'); if (t <= 0) return t; n = -n; return printNumber(n, 10) + 1; @@ -116,110 +116,110 @@ long Print::print(long n, int base) } } -long Print::print(unsigned long n, int base) +ssize_t Print::print(unsigned long n, int base) { if (base == 0) return write(n); else return printNumber(n, base); } -long Print::print(double n, int digits) +ssize_t Print::print(double n, int digits) { return printFloat(n, digits); } -long Print::println(const __FlashStringHelper *ifsh) +ssize_t Print::println(const __FlashStringHelper *ifsh) { - long n = print(ifsh); + ssize_t n = print(ifsh); if (n >= 0) n += println(); return n; } -long Print::print(const Printable& x) +ssize_t Print::print(const Printable& x) { return x.printTo(*this); } -long Print::println(void) +ssize_t Print::println(void) { - long t = print('\r'); + ssize_t t = print('\r'); if (t <= 0) return t; if (print('\n') <= 0) return 1; return 2; } -long Print::println(const String &s) +ssize_t Print::println(const String &s) { - long n = print(s); + ssize_t n = print(s); if (n >= 0) n += println(); return n; } -long Print::println(const char c[]) +ssize_t Print::println(const char c[]) { - long n = print(c); + ssize_t n = print(c); if (n >= 0) n += println(); return n; } -long Print::println(char c) +ssize_t Print::println(char c) { - long n = print(c); + ssize_t n = print(c); if (n > 0) n += println(); return n; } -long Print::println(unsigned char b, int base) +ssize_t Print::println(unsigned char b, int base) { - long n = print(b, base); + ssize_t n = print(b, base); if (n >= 0) n += println(); return n; } -long Print::println(int num, int base) +ssize_t Print::println(int num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(unsigned int num, int base) +ssize_t Print::println(unsigned int num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(long num, int base) +ssize_t Print::println(long num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(unsigned long num, int base) +ssize_t Print::println(unsigned long num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(double num, int digits) +ssize_t Print::println(double num, int digits) { - long n = print(num, digits); + ssize_t n = print(num, digits); if (n >= 0) n += println(); return n; } -long Print::println(const Printable& x) +ssize_t Print::println(const Printable& x) { - long n = print(x); + ssize_t n = print(x); if (n >= 0) n += println(); return n; } // Private Methods ///////////////////////////////////////////////////////////// -long Print::printNumber(unsigned long n, uint8_t base) { +ssize_t Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -238,9 +238,9 @@ long Print::printNumber(unsigned long n, uint8_t base) { return write(str); } -long Print::printFloat(double number, uint8_t digits) +ssize_t Print::printFloat(double number, uint8_t digits) { - long n = 0, t; + ssize_t n = 0, t; // Handle negative numbers if (number < 0.0) -- cgit v1.2.3-18-g5258 From 5130a1329462aa36d5f18e31851d3d9d5086e411 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 16:08:14 -0400 Subject: Moving write errors out of return value into separate API methods. write(), print(), println() now return size_t (and don't use negative values to signal errors). Print adds writeError() for checking for write errors, clearWriteError() to reset the flag to false, and a protected setWriteError() for signalling errors. http://code.google.com/p/arduino/issues/detail?id=598 --- cores/arduino/Print.cpp | 144 ++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 78 deletions(-) (limited to 'cores/arduino/Print.cpp') diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 192d9a3..8190d4f 100755 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -30,85 +30,80 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -ssize_t Print::write(const char *str) +size_t Print::write(const char *str) { - ssize_t n = 0; + size_t n = 0; while (*str) { - if (write(*str++) <= 0) break; - n++; + n += write(*str++); } return n; } /* default implementation: may be overridden */ -ssize_t Print::write(const uint8_t *buffer, size_t size) +size_t Print::write(const uint8_t *buffer, size_t size) { - ssize_t n = 0; + size_t n = 0; while (size--) { - if (write(*buffer++) <= 0) break; - n++; + n += write(*buffer++); } return n; } -ssize_t Print::print(const __FlashStringHelper *ifsh) +size_t Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; - ssize_t n = 0; + size_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) break; - if (write(c) <= 0) break; - n++; + n += write(c); } return n; } -ssize_t Print::print(const String &s) +size_t Print::print(const String &s) { - ssize_t n = 0; + size_t n = 0; for (int i = 0; i < s.length(); i++) { - if (write(s[i]) < 0) break; - n++; + n += write(s[i]); } return n; } -ssize_t Print::print(const char str[]) +size_t Print::print(const char str[]) { return write(str); } -ssize_t Print::print(char c) +size_t Print::print(char c) { return write(c); } -ssize_t Print::print(unsigned char b, int base) +size_t Print::print(unsigned char b, int base) { return print((unsigned long) b, base); } -ssize_t Print::print(int n, int base) +size_t Print::print(int n, int base) { return print((long) n, base); } -ssize_t Print::print(unsigned int n, int base) +size_t Print::print(unsigned int n, int base) { return print((unsigned long) n, base); } -ssize_t Print::print(long n, int base) +size_t Print::print(long n, int base) { if (base == 0) { return write(n); } else if (base == 10) { if (n < 0) { int t = print('-'); - if (t <= 0) return t; n = -n; - return printNumber(n, 10) + 1; + return printNumber(n, 10) + t; } return printNumber(n, 10); } else { @@ -116,110 +111,109 @@ ssize_t Print::print(long n, int base) } } -ssize_t Print::print(unsigned long n, int base) +size_t Print::print(unsigned long n, int base) { if (base == 0) return write(n); else return printNumber(n, base); } -ssize_t Print::print(double n, int digits) +size_t Print::print(double n, int digits) { return printFloat(n, digits); } -ssize_t Print::println(const __FlashStringHelper *ifsh) +size_t Print::println(const __FlashStringHelper *ifsh) { - ssize_t n = print(ifsh); - if (n >= 0) n += println(); + size_t n = print(ifsh); + n += println(); return n; } -ssize_t Print::print(const Printable& x) +size_t Print::print(const Printable& x) { return x.printTo(*this); } -ssize_t Print::println(void) +size_t Print::println(void) { - ssize_t t = print('\r'); - if (t <= 0) return t; - if (print('\n') <= 0) return 1; - return 2; + size_t n = print('\r'); + n += print('\n'); + return n; } -ssize_t Print::println(const String &s) +size_t Print::println(const String &s) { - ssize_t n = print(s); - if (n >= 0) n += println(); + size_t n = print(s); + n += println(); return n; } -ssize_t Print::println(const char c[]) +size_t Print::println(const char c[]) { - ssize_t n = print(c); - if (n >= 0) n += println(); + size_t n = print(c); + n += println(); return n; } -ssize_t Print::println(char c) +size_t Print::println(char c) { - ssize_t n = print(c); - if (n > 0) n += println(); + size_t n = print(c); + n += println(); return n; } -ssize_t Print::println(unsigned char b, int base) +size_t Print::println(unsigned char b, int base) { - ssize_t n = print(b, base); - if (n >= 0) n += println(); + size_t n = print(b, base); + n += println(); return n; } -ssize_t Print::println(int num, int base) +size_t Print::println(int num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(unsigned int num, int base) +size_t Print::println(unsigned int num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(long num, int base) +size_t Print::println(long num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(unsigned long num, int base) +size_t Print::println(unsigned long num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(double num, int digits) +size_t Print::println(double num, int digits) { - ssize_t n = print(num, digits); - if (n >= 0) n += println(); + size_t n = print(num, digits); + n += println(); return n; } -ssize_t Print::println(const Printable& x) +size_t Print::println(const Printable& x) { - ssize_t n = print(x); - if (n >= 0) n += println(); + size_t n = print(x); + n += println(); return n; } // Private Methods ///////////////////////////////////////////////////////////// -ssize_t Print::printNumber(unsigned long n, uint8_t base) { +size_t Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -238,14 +232,14 @@ ssize_t Print::printNumber(unsigned long n, uint8_t base) { return write(str); } -ssize_t Print::printFloat(double number, uint8_t digits) +size_t Print::printFloat(double number, uint8_t digits) { - ssize_t n = 0, t; + size_t n = 0; // Handle negative numbers if (number < 0.0) { - if ((n = print('-')) <= 0) return n; + n += print('-'); number = -number; } @@ -259,15 +253,11 @@ ssize_t Print::printFloat(double number, uint8_t digits) // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; - if ((t = print(int_part)) < 0) return n; - - n += t; + n += print(int_part); // Print the decimal point, but only if there are digits beyond if (digits > 0) { - t = print("."); - if (t <= 0) return n; - n += t; + n += print("."); } // Extract digits from the remainder one at a time @@ -275,9 +265,7 @@ ssize_t Print::printFloat(double number, uint8_t digits) { remainder *= 10.0; int toPrint = int(remainder); - t = print(toPrint); - if (t <= 0) return n; - n += t; + n += print(toPrint); remainder -= toPrint; } -- cgit v1.2.3-18-g5258