File tree 3 files changed +18
-3
lines changed
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)
624
624
return 1 ;
625
625
}
626
626
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
+
627
637
// Hardware serial is always connected regardless.
628
638
HardwareSerial::operator int () {
629
639
return 1 ;
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ class HardwareSerial : public Stream
122
122
void begin (unsigned long baudRate, uint8_t address);
123
123
void end ();
124
124
virtual int available (void );
125
+ virtual int availableForWrite ();
125
126
virtual int peek ();
126
127
virtual int read (void );
127
128
virtual void flush (void );
Original file line number Diff line number Diff line change @@ -42,10 +42,10 @@ class Print
42
42
void setWriteError (int err = 1 ) { write_error = err; }
43
43
public:
44
44
Print () : write_error(0 ) {}
45
-
45
+
46
46
int getWriteError () { return write_error; }
47
47
void clearWriteError () { setWriteError (0 ); }
48
-
48
+
49
49
virtual size_t write (uint8_t ) = 0;
50
50
size_t write (const char *str) {
51
51
if (str == NULL ) return 0 ;
@@ -55,7 +55,11 @@ class Print
55
55
size_t write (const char *buffer, size_t size) {
56
56
return write ((const uint8_t *)buffer, size);
57
57
}
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
+
59
63
size_t print (const __FlashStringHelper *);
60
64
size_t print (const String &);
61
65
size_t print (const char []);
You can’t perform that action at this time.
0 commit comments