1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Adding precision parameter for printing of floats / doubles. Restructured the print() and println() functions a bit.

This commit is contained in:
David A. Mellis 2009-12-25 20:20:27 +00:00
parent a2ee999135
commit def86681b7
3 changed files with 66 additions and 72 deletions

View File

@ -42,58 +42,55 @@ void Print::write(const uint8_t *buffer, size_t size)
write(*buffer++); 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[]) void Print::print(const char str[])
{ {
write(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)
{ {
print((long) n, base);
}
void Print::print(unsigned int n, int base)
{
print((unsigned long) n, base);
}
void Print::print(long n, int base)
{
if (base == 0) {
write(n);
} else if (base == 10) {
if (n < 0) { if (n < 0) {
print('-'); print('-');
n = -n; n = -n;
} }
printNumber(n, 10); printNumber(n, 10);
} } else {
void Print::print(unsigned long n)
{
printNumber(n, 10);
}
void Print::print(long n, int base)
{
if (base == 0)
print((char) n);
else if (base == 10)
print(n);
else
printNumber(n, base); 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::print(double n, int digits)
{
printFloat(n, digits);
} }
void Print::println(void) void Print::println(void)
@ -102,45 +99,33 @@ void Print::println(void)
print('\n'); print('\n');
} }
void Print::println(char c)
{
print(c);
println();
}
void Print::println(const char c[]) void Print::println(const char c[])
{ {
print(c); print(c);
println(); println();
} }
void Print::println(uint8_t b) void Print::println(char c, int base)
{ {
print(b); print(c, base);
println(); println();
} }
void Print::println(int n) void Print::println(unsigned char b, int base)
{ {
print(n); print(b, base);
println(); println();
} }
void Print::println(unsigned int n) void Print::println(int n, int base)
{ {
print(n); print(n, base);
println(); println();
} }
void Print::println(long n) void Print::println(unsigned int n, int base)
{ {
print(n); print(n, base);
println();
}
void Print::println(unsigned long n)
{
print(n);
println(); println();
} }
@ -150,9 +135,15 @@ void Print::println(long n, int base)
println(); println();
} }
void Print::println(double n) void Print::println(unsigned long n, int base)
{ {
print(n); print(n, base);
println();
}
void Print::println(double n, int digits)
{
print(n, digits);
println(); println();
} }

View File

@ -38,25 +38,25 @@ class Print
virtual void write(uint8_t) = 0; virtual void write(uint8_t) = 0;
virtual void write(const char *str); virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size); virtual void write(const uint8_t *buffer, size_t size);
void print(char);
void print(const char[]); void print(const char[]);
void print(uint8_t); void print(char, int = BYTE);
void print(int); void print(unsigned char, int = BYTE);
void print(unsigned int); void print(int, int = DEC);
void print(long); void print(unsigned int, int = DEC);
void print(unsigned long); void print(long, int = DEC);
void print(long, int); void print(unsigned long, int = DEC);
void print(double); void print(double, int = 2);
void println(void);
void println(char);
void println(const char[]); void println(const char[]);
void println(uint8_t); void println(char, int = BYTE);
void println(int); void println(unsigned char, int = BYTE);
void println(unsigned int); void println(int, int = DEC);
void println(long); void println(unsigned int, int = DEC);
void println(unsigned long); void println(long, int = DEC);
void println(long, int); void println(unsigned long, int = DEC);
void println(double); void println(double, int = 2);
void println(void);
}; };
#endif #endif

View File

@ -50,12 +50,15 @@ UPDATES
* No longer disabling interrupts in delayMicroseconds(). * No longer disabling interrupts in delayMicroseconds().
* Fixed bug w/ micros() returning incorrect values from within an interrupt. * Fixed bug w/ micros() returning incorrect values from within an interrupt.
* Added Serial.end() command. * Added Serial.end() command.
* Added precision parameter for printing of floats / doubles.
* Fixed bug that broke use of analog inputs 8-15 on the Mega.
[environment] [environment]
* Synchronized with the Processing 1.0.9 code base, bringing various fixes, * Synchronized with the Processing 1.0.9 code base, bringing various fixes,
including a bug causing saving to fail when closing the last sketch. including to a bug causing saving to fail when closing the last sketch.
* Added support for third-party hardware in the SKETCHBOOK/hardware folder. * Added support for third-party hardware in the SKETCHBOOK/hardware folder,
It mirrors the current structure of the hardware folder in Arduino. mirroring the current structure of the hardware folder in Arduino.
* Added Ctrl-Shift-M / Command-Shift-M shortcut for serial monitor.
* Hold down shift when pressing the Verify / Compile or Upload toolbar * Hold down shift when pressing the Verify / Compile or Upload toolbar
buttons to generate verbose output (including command lines). buttons to generate verbose output (including command lines).
* Moving build (on upload) from the applet/ sub-folder of the sketch * Moving build (on upload) from the applet/ sub-folder of the sketch