Commit 716fba8d authored by Eric Wieser's avatar Eric Wieser Committed by Cristian Maglie

Add Print::availableForWrite

If available() is in the base Stream class, then availableForWrite() should be in the base Print class
parent 2a4e2b96
...@@ -124,7 +124,7 @@ class HardwareSerial : public Stream ...@@ -124,7 +124,7 @@ class HardwareSerial : public Stream
virtual int available(void); virtual int available(void);
virtual int peek(void); virtual int peek(void);
virtual int read(void); virtual int read(void);
int availableForWrite(void); virtual int availableForWrite(void);
virtual void flush(void); virtual void flush(void);
virtual size_t write(uint8_t); virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); } inline size_t write(unsigned long n) { return write((uint8_t)n); }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> // for size_t #include <stdio.h> // for size_t
#include <limits.h> // for INT_MAX
#include "WString.h" #include "WString.h"
#include "Printable.h" #include "Printable.h"
...@@ -58,6 +59,10 @@ class Print ...@@ -58,6 +59,10 @@ class Print
return write((const uint8_t *)buffer, 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 __FlashStringHelper *);
size_t print(const String &); size_t print(const String &);
size_t print(const char[]); size_t print(const char[]);
......
...@@ -98,7 +98,7 @@ public: ...@@ -98,7 +98,7 @@ public:
virtual int available(void); virtual int available(void);
virtual int peek(void); virtual int peek(void);
virtual int read(void); virtual int read(void);
int availableForWrite(void); virtual int availableForWrite(void);
virtual void flush(void); virtual void flush(void);
virtual size_t write(uint8_t); virtual size_t write(uint8_t);
virtual size_t write(const uint8_t*, size_t); virtual size_t write(const uint8_t*, size_t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment