File tree 3 files changed +17
-0
lines changed
hardware/arduino/avr/cores/arduino
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,7 @@ read KEYWORD2 Serial_Read
177
177
print KEYWORD2 Serial_Print
178
178
println KEYWORD2 Serial_Println
179
179
available KEYWORD2 Serial_Available
180
+ availableForWrite KEYWORD2
180
181
flush KEYWORD2 Serial_Flush
181
182
setTimeout KEYWORD2
182
183
find KEYWORD2
Original file line number Diff line number Diff line change @@ -176,6 +176,21 @@ int HardwareSerial::read(void)
176
176
}
177
177
}
178
178
179
+ int HardwareSerial::availableForWrite (void )
180
+ {
181
+ #if (SERIAL_TX_BUFFER_SIZE>256)
182
+ uint8_t oldSREG = SREG;
183
+ cli ();
184
+ #endif
185
+ tx_buffer_index_t head = _tx_buffer_head;
186
+ tx_buffer_index_t tail = _tx_buffer_tail;
187
+ #if (SERIAL_TX_BUFFER_SIZE>256)
188
+ SREG = oldSREG;
189
+ #endif
190
+ if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
191
+ return tail - head - 1 ;
192
+ }
193
+
179
194
void HardwareSerial::flush ()
180
195
{
181
196
// If we have never written a byte, no need to flush. This special
Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ class HardwareSerial : public Stream
112
112
virtual int available (void );
113
113
virtual int peek (void );
114
114
virtual int read (void );
115
+ int availableForWrite (void );
115
116
virtual void flush (void );
116
117
virtual size_t write (uint8_t );
117
118
inline size_t write (unsigned long n) { return write ((uint8_t )n); }
You can’t perform that action at this time.
0 commit comments