File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -624,6 +624,16 @@ size_t HardwareSerial::write(uint8_t theChar)
624624 return 1 ;
625625}
626626
627+ // Hardware serial has a buffer of length 1
628+ int HardwareSerial::availableForWrite () {
629+ if (uart->uxSta .reg & (1 << _UARTSTA_UTXBF)) {
630+ return 0 ;
631+ }
632+ else {
633+ return 1 ;
634+ }
635+ }
636+
627637// Hardware serial is always connected regardless.
628638HardwareSerial::operator int () {
629639 return 1 ;
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ class HardwareSerial : public Stream
122122 void begin (unsigned long baudRate, uint8_t address);
123123 void end ();
124124 virtual int available (void );
125+ virtual int availableForWrite ();
125126 virtual int peek ();
126127 virtual int read (void );
127128 virtual void flush (void );
Original file line number Diff line number Diff line change @@ -42,10 +42,10 @@ class Print
4242 void setWriteError (int err = 1 ) { write_error = err; }
4343 public:
4444 Print () : write_error(0 ) {}
45-
45+
4646 int getWriteError () { return write_error; }
4747 void clearWriteError () { setWriteError (0 ); }
48-
48+
4949 virtual size_t write (uint8_t ) = 0;
5050 size_t write (const char *str) {
5151 if (str == NULL ) return 0 ;
@@ -55,7 +55,11 @@ class Print
5555 size_t write (const char *buffer, size_t size) {
5656 return write ((const uint8_t *)buffer, size);
5757 }
58-
58+
59+ // default to zero, meaning "a single write may block"
60+ // should be overriden by subclasses with buffering
61+ virtual int availableForWrite () { return 0 ; }
62+
5963 size_t print (const __FlashStringHelper *);
6064 size_t print (const String &);
6165 size_t print (const char []);
You can’t perform that action at this time.
0 commit comments