From 716fba8dd98f54dcd816fa69cafdcb681b54ab11 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 2 Jan 2017 11:17:30 +0000 Subject: Add Print::availableForWrite If available() is in the base Stream class, then availableForWrite() should be in the base Print class --- cores/arduino/HardwareSerial.h | 2 +- cores/arduino/Print.h | 7 ++++++- cores/arduino/USBAPI.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index 8a5bf95..17000c2 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -124,7 +124,7 @@ class HardwareSerial : public Stream virtual int available(void); virtual int peek(void); virtual int read(void); - int availableForWrite(void); + virtual int availableForWrite(void); virtual void flush(void); virtual size_t write(uint8_t); inline size_t write(unsigned long n) { return write((uint8_t)n); } diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index d099a3b..4d8a2f5 100644 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -22,6 +22,7 @@ #include #include // for size_t +#include // for INT_MAX #include "WString.h" #include "Printable.h" @@ -57,7 +58,11 @@ class Print size_t write(const char *buffer, size_t size) { 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[]); diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 358444e..479ced9 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -98,7 +98,7 @@ public: virtual int available(void); virtual int peek(void); virtual int read(void); - int availableForWrite(void); + virtual int availableForWrite(void); virtual void flush(void); virtual size_t write(uint8_t); virtual size_t write(const uint8_t*, size_t); -- cgit v1.2.3-18-g5258