#endif | #endif | ||||
#if ARDUINO >= 100 | |||||
static int printf_putchar(char c, FILE *fp) | |||||
{ | |||||
((class Print *)(fdev_get_udata(fp)))->write((uint8_t)c); | |||||
return 0; | |||||
} | |||||
int Print::printf(const char *format, ...) | |||||
{ | |||||
FILE f; | |||||
va_list ap; | |||||
fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE); | |||||
fdev_set_udata(&f, this); | |||||
va_start(ap, format); | |||||
return vfprintf(&f, format, ap); | |||||
} | |||||
int Print::printf(const __FlashStringHelper *format, ...) | |||||
{ | |||||
FILE f; | |||||
va_list ap; | |||||
fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE); | |||||
fdev_set_udata(&f, this); | |||||
va_start(ap, format); | |||||
return vfprintf_P(&f, (const char *)format, ap); | |||||
} | |||||
#endif | |||||
//#define USE_HACKER_DELIGHT_OPTIMIZATION | //#define USE_HACKER_DELIGHT_OPTIMIZATION | ||||
#define USE_STIMMER_OPTIMIZATION | #define USE_STIMMER_OPTIMIZATION | ||||
//#define USE_BENCHMARK_CODE | //#define USE_BENCHMARK_CODE |
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <stdio.h> // for size_t | #include <stdio.h> // for size_t | ||||
#include <stdarg.h> | |||||
#include "core_id.h" | #include "core_id.h" | ||||
#include "WString.h" | #include "WString.h" | ||||
#include "Printable.h" | #include "Printable.h" | ||||
size_t println(const Printable &obj) { return obj.printTo(*this) + println(); } | size_t println(const Printable &obj) { return obj.printTo(*this) + println(); } | ||||
int getWriteError() { return write_error; } | int getWriteError() { return write_error; } | ||||
void clearWriteError() { setWriteError(0); } | void clearWriteError() { setWriteError(0); } | ||||
int printf(const char *format, ...); | |||||
int printf(const __FlashStringHelper *format, ...); | |||||
protected: | protected: | ||||
void setWriteError(int err = 1) { write_error = err; } | void setWriteError(int err = 1) { write_error = err; } | ||||
private: | private: |