jung6717 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

more Print overloading #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

    add more overloaded functions to the Print class

        void Print::print(unsigned long n, int base)
        void Print::println(unsigned long n, int base)

Why?

    Specifying a base is non-intuitive with print/println

        Serial.println(4294959288); // works correctly
        Serial.println(4294959288,10); // fails

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

    No

Original issue reported on code.google.com by gabebear@gmail.com on 17 Jul 2009 at 10:22

GoogleCodeExporter commented 9 years ago
Here is a version I whipped up. It adds all the necessary overloads to make 
these
functions work.

Of course I couldn't stop fiddling, so:

I also refactors the functions to minimize run-time casting. Any function that
doesn't actually do anything but cast to another function is inlined.

The PrintNumber function is replaced by ultoa().

The only functional difference should be that "print(10,1)" no longer starts an
infinite loop, it now just acts like "print(10,0)" and prints a byte.

Original comment by gabebear@gmail.com on 17 Jul 2009 at 5:16

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The previous version had a problem with negatives... Ooops.

 I realized a lot of the declarations could be removed be using default parameters.

Original comment by gabebear@gmail.com on 19 Jul 2009 at 10:11

Attachments:

GoogleCodeExporter commented 9 years ago
The following olverloads should be added also

     void Print::print(double, uint8_t int digit)
     void Print::println(double, uint8_t digit)

for application that need more accurate more that default 2 digit

Original comment by rczo...@gmail.com on 14 Dec 2009 at 3:07

GoogleCodeExporter commented 9 years ago
I'd also add Print::printP and Print::printlnP (or some similar name) to print
strings stored in PROGMEM.

Original comment by ben.combee on 22 Dec 2009 at 10:37

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 23 Dec 2009 at 12:33

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 25 Dec 2009 at 8:20