Paul,
Do you think that there is any chance in getting the Arduino guys
to add printf() support to the Print() class
so that all device libraries that use Print can pick up printf() support?
If not, would you have any interest in adding it into Teensyduino?
BTW, this is a great example of the somewhat broken Arduino build methodology
in that there are core independent library headers and code that is being stuck
into the core directories.
I updated the Arduino Printf Playground page to show how to manually add this
and how to use it.
http://playground.arduino.cc/Main/Printf
It is as simple as dropping this code into the public section of the Print class definition.
Do you think that there is any chance in getting the Arduino guys
to add printf() support to the Print() class
so that all device libraries that use Print can pick up printf() support?
If not, would you have any interest in adding it into Teensyduino?
BTW, this is a great example of the somewhat broken Arduino build methodology
in that there are core independent library headers and code that is being stuck
into the core directories.
I updated the Arduino Printf Playground page to show how to manually add this
and how to use it.
http://playground.arduino.cc/Main/Printf
It is as simple as dropping this code into the public section of the Print class definition.
Code:
#include <stdarg.h>
#define PRINTF_BUF 80 // define the tmp buffer size (change if desired)
void printf(const char *format, ...)
{
char buf[PRINTF_BUF];
va_list ap;
va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap);
for(char *p = &buf[0]; *p; p++) // emulate cooked mode for newlines
{
if(*p == '\n')
write('\r');
write(*p);
}
va_end(ap);
}
#ifdef F // check to see if F() macro is available
void printf(const __FlashStringHelper *format, ...)
{
char buf[PRINTF_BUF];
va_list ap;
va_start(ap, format);
#ifdef __AVR__
vsnprintf_P(buf, sizeof(buf), (const char *)format, ap); // progmem for AVR
#else
vsnprintf(buf, sizeof(buf), (const char *)format, ap); // for the rest of the world
#endif
for(char *p = &buf[0]; *p; p++) // emulate cooked mode for newlines
{
if(*p == '\n')
write('\r');
write(*p);
}
va_end(ap);
}
#endif