aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2009-12-25 20:20:27 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2009-12-25 20:20:27 +0000
commit85de48989da4009dced261ac326c70bad0ba0684 (patch)
tree8e3ffb75472d9f7a6b7e86a11768314e7c00d7c3 /cores
parentfe28586154ac07105f22408619199a7b05dee389 (diff)
Adding precision parameter for printing of floats / doubles. Restructured the print() and println() functions a bit.
Diffstat (limited to 'cores')
-rwxr-xr-xcores/arduino/Print.cpp91
-rwxr-xr-xcores/arduino/Print.h34
2 files changed, 58 insertions, 67 deletions
diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp
index 74d0e5b..fb5afc1 100755
--- a/cores/arduino/Print.cpp
+++ b/cores/arduino/Print.cpp
@@ -42,70 +42,61 @@ void Print::write(const uint8_t *buffer, size_t size)
write(*buffer++);
}
-void Print::print(uint8_t b)
-{
- this->write(b);
-}
-
-void Print::print(char c)
-{
- print((byte) c);
-}
-
void Print::print(const char str[])
{
write(str);
}
-void Print::print(int n)
+void Print::print(char c, int base)
{
- print((long) n);
+ print((long) c, base);
}
-void Print::print(unsigned int n)
+void Print::print(unsigned char b, int base)
{
- print((unsigned long) n);
+ print((unsigned long) b, base);
}
-void Print::print(long n)
+void Print::print(int n, int base)
{
- if (n < 0) {
- print('-');
- n = -n;
- }
- printNumber(n, 10);
+ print((long) n, base);
}
-void Print::print(unsigned long n)
+void Print::print(unsigned int n, int base)
{
- printNumber(n, 10);
+ print((unsigned long) n, base);
}
void Print::print(long n, int base)
{
- if (base == 0)
- print((char) n);
- else if (base == 10)
- print(n);
- else
+ if (base == 0) {
+ write(n);
+ } else if (base == 10) {
+ if (n < 0) {
+ print('-');
+ n = -n;
+ }
+ printNumber(n, 10);
+ } else {
printNumber(n, base);
+ }
}
-void Print::print(double n)
+void Print::print(unsigned long n, int base)
{
- printFloat(n, 2);
+ if (base == 0) write(n);
+ else printNumber(n, base);
}
-void Print::println(void)
+void Print::print(double n, int digits)
{
- print('\r');
- print('\n');
+ printFloat(n, digits);
}
-void Print::println(char c)
+void Print::println(void)
{
- print(c);
- println();
+ print('\r');
+ print('\n');
}
void Print::println(const char c[])
@@ -114,45 +105,45 @@ void Print::println(const char c[])
println();
}
-void Print::println(uint8_t b)
+void Print::println(char c, int base)
{
- print(b);
+ print(c, base);
println();
}
-void Print::println(int n)
+void Print::println(unsigned char b, int base)
{
- print(n);
+ print(b, base);
println();
}
-void Print::println(unsigned int n)
+void Print::println(int n, int base)
{
- print(n);
+ print(n, base);
println();
}
-void Print::println(long n)
+void Print::println(unsigned int n, int base)
{
- print(n);
- println();
+ print(n, base);
+ println();
}
-void Print::println(unsigned long n)
+void Print::println(long n, int base)
{
- print(n);
- println();
+ print(n, base);
+ println();
}
-void Print::println(long n, int base)
+void Print::println(unsigned long n, int base)
{
print(n, base);
println();
}
-void Print::println(double n)
+void Print::println(double n, int digits)
{
- print(n);
+ print(n, digits);
println();
}
diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h
index a69e85d..8a1e2b8 100755
--- a/cores/arduino/Print.h
+++ b/cores/arduino/Print.h
@@ -38,25 +38,25 @@ class Print
virtual void write(uint8_t) = 0;
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
- void print(char);
+
void print(const char[]);
- void print(uint8_t);
- void print(int);
- void print(unsigned int);
- void print(long);
- void print(unsigned long);
- void print(long, int);
- void print(double);
- void println(void);
- void println(char);
+ void print(char, int = BYTE);
+ void print(unsigned char, int = BYTE);
+ void print(int, int = DEC);
+ void print(unsigned int, int = DEC);
+ void print(long, int = DEC);
+ void print(unsigned long, int = DEC);
+ void print(double, int = 2);
+
void println(const char[]);
- void println(uint8_t);
- void println(int);
- void println(unsigned int);
- void println(long);
- void println(unsigned long);
- void println(long, int);
- void println(double);
+ void println(char, int = BYTE);
+ void println(unsigned char, int = BYTE);
+ void println(int, int = DEC);
+ void println(unsigned int, int = DEC);
+ void println(long, int = DEC);
+ void println(unsigned long, int = DEC);
+ void println(double, int = 2);
+ void println(void);
};
#endif