From a89a0dfe23a9e0f32fcb42880887c95832ed263c Mon Sep 17 00:00:00 2001 From: ladyada Date: Sun, 21 Apr 2019 01:54:21 -0400 Subject: [PATCH] tweaks to make gamebuino meta compile --- cores/arduino/Print.cpp | 14 ++++++++++++-- cores/arduino/Print.h | 13 ++++--------- platform.txt | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 136329cc..6257542c 100644 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -186,6 +186,16 @@ size_t Print::println(const Printable& x) return n; } +void Print::printf(const char format[], ...) +{ + char buf[PRINTF_BUF]; + va_list ap; + va_start(ap, format); + vsnprintf(buf, sizeof(buf), format, ap); + write(buf); + va_end(ap); +} + // Private Methods ///////////////////////////////////////////////////////////// size_t Print::printNumber(unsigned long n, uint8_t base) @@ -238,14 +248,14 @@ size_t Print::printFloat(double number, uint8_t digits) // Print the decimal point, but only if there are digits beyond if (digits > 0) { - n += print('.'); + n += print("."); } // Extract digits from the remainder one at a time while (digits-- > 0) { remainder *= 10.0; - unsigned int toPrint = (unsigned int)(remainder); + unsigned int toPrint = (unsigned int)remainder; n += print(toPrint); remainder -= toPrint; } diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index dfb645cb..f45ae601 100644 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -21,6 +21,8 @@ #include #include // for size_t +#include // for printf +#define PRINTF_BUF 80 #include "WString.h" #include "Printable.h" @@ -28,9 +30,6 @@ #define DEC 10 #define HEX 16 #define OCT 8 -#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar -#undef BIN -#endif #define BIN 2 class Print @@ -57,10 +56,6 @@ class Print return write((const uint8_t *)buffer, size); } - // default to zero, meaning "a single write may block" - // should be overriden by subclasses with buffering - virtual int availableForWrite() { return 0; } - size_t print(const __FlashStringHelper *); size_t print(const String &); size_t print(const char[]); @@ -85,8 +80,8 @@ class Print size_t println(double, int = 2); size_t println(const Printable&); size_t println(void); - - virtual void flush() { /* Empty implementation for backward compatibility */ } + + void printf(const char[], ...); }; #endif diff --git a/platform.txt b/platform.txt index cd8061e0..547381fe 100644 --- a/platform.txt +++ b/platform.txt @@ -33,13 +33,13 @@ compiler.warning_flags.all=-Wall -Wextra compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD +compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}""" compiler.c.elf.cmd=arm-none-eabi-gcc compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps compiler.S.cmd=arm-none-eabi-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD +compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}""" compiler.ar.cmd=arm-none-eabi-ar compiler.ar.flags=rcs compiler.objcopy.cmd=arm-none-eabi-objcopy