diff --git a/libraries/FastSerial/BetterStream.cpp b/libraries/FastSerial/BetterStream.cpp index a12c3902dc..38e12fa7a9 100644 --- a/libraries/FastSerial/BetterStream.cpp +++ b/libraries/FastSerial/BetterStream.cpp @@ -12,6 +12,7 @@ // Enhancements to the Arduino Stream class. // +#include #include "BetterStream.h" // Stream extensions//////////////////////////////////////////////////////////// @@ -52,3 +53,9 @@ BetterStream::_printf_P(const prog_char *fmt, ...) va_end(ap); } +int +BetterStream::space(void) +{ + // by default claim that there is always space + return(INT_MAX); +} diff --git a/libraries/FastSerial/BetterStream.h b/libraries/FastSerial/BetterStream.h index e9b16a00d0..d782a0966e 100644 --- a/libraries/FastSerial/BetterStream.h +++ b/libraries/FastSerial/BetterStream.h @@ -28,6 +28,8 @@ public: void _printf_P(const prog_char *, ...); __attribute__ ((format(__printf__, 2, 3))); + virtual int space(void); + #define printf_P(fmt, ...) _printf_P((const prog_char *)fmt, ## __VA_ARGS__) private: diff --git a/libraries/FastSerial/FastSerial.cpp b/libraries/FastSerial/FastSerial.cpp index 3e91a2f2da..3368ca1c51 100644 --- a/libraries/FastSerial/FastSerial.cpp +++ b/libraries/FastSerial/FastSerial.cpp @@ -142,6 +142,13 @@ int FastSerial::available(void) return ((_rxBuffer->head - _rxBuffer->tail) & _rxBuffer->mask); } +int FastSerial::space(void) +{ + if (!_open) + return (-1); + return (((_rxBuffer->tail - _rxBuffer->head) & _rxBuffer->mask) - 1); +} + int FastSerial::read(void) { uint8_t c; diff --git a/libraries/FastSerial/FastSerial.h b/libraries/FastSerial/FastSerial.h index 267372c138..9f008bb962 100644 --- a/libraries/FastSerial/FastSerial.h +++ b/libraries/FastSerial/FastSerial.h @@ -110,6 +110,7 @@ public: virtual void begin(long baud); virtual void end(void); virtual int available(void); + virtual int space(void); virtual int read(void); virtual int peek(void); virtual void flush(void);