diff options
author | Robert Pelnar <robert.pelnar@seznam.cz> | 2017-11-20 22:09:54 +0300 |
---|---|---|
committer | Robert Pelnar <robert.pelnar@seznam.cz> | 2017-11-20 22:09:54 +0300 |
commit | b8525f80435748c24c9ce63805d9363c1b031f67 (patch) | |
tree | 539b03c84e449e0fcc84686359d97462467f7b4e /ArduinoAddons | |
parent | aee62750e79ca2b5f21aeba2003b72fcce140032 (diff) |
Print class printf function (experimental, disabled by default)
LiquidCrystal VT100 escape codes (EraseScreen, CursorHome, ...)
Stream support for lcd and uart, fprintf and printf (stdout=uartout)
Dcodes enabled, code reduced, printf used
Splash screen with esc codes
Diffstat (limited to 'ArduinoAddons')
-rwxr-xr-x | ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.cpp | 45 | ||||
-rwxr-xr-x | ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.h | 12 |
2 files changed, 56 insertions, 1 deletions
diff --git a/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.cpp b/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.cpp index 5df56306e..17dc50c10 100755 --- a/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.cpp +++ b/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.cpp @@ -262,3 +262,48 @@ size_t Print::printFloat(double number, uint8_t digits) return n; } + + +//printf +#ifdef _Print_printf + +#include <stdarg.h> + +#define PRINTF_BUF 80 // define the tmp buffer size (change if desired) + +void Print::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 Print::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 + +#endif //_Print_printf
\ No newline at end of file diff --git a/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.h b/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.h index 7b53aa4d1..20cf53780 100755 --- a/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.h +++ b/ArduinoAddons/Arduino_1.6.x/hardware/marlin/avr/cores/arduino/Print.h @@ -31,6 +31,8 @@ #define OCT 8 #define BIN 2 +//#define _Print_printf + class Print { private: @@ -79,6 +81,14 @@ class Print size_t println(double, int = 2); size_t println(const Printable&); size_t println(void); -}; +//printf +#ifdef _Print_printf + void printf(const char *format, ...); +#ifdef F // check to see if F() macro is available + void printf(const __FlashStringHelper *format, ...); #endif +#endif //_Print_printf +}; + +#endif
\ No newline at end of file |