From bcc5488cbcddc8c3d7125fb59ac7edc054673ebc Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Fri, 18 Jul 2014 07:01:26 -0700 Subject: Add availableForWrite() to HardwareSerial --- cores/arduino/HardwareSerial.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cores/arduino/HardwareSerial.cpp') diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index ed29641..29a3366 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -176,6 +176,21 @@ int HardwareSerial::read(void) } } +int HardwareSerial::availableForWrite(void) +{ +#if (SERIAL_TX_BUFFER_SIZE>256) + uint8_t oldSREG = SREG; + cli(); +#endif + tx_buffer_index_t head = _tx_buffer_head; + tx_buffer_index_t tail = _tx_buffer_tail; +#if (SERIAL_TX_BUFFER_SIZE>256) + SREG = oldSREG; +#endif + if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail; + return tail - head - 1; +} + void HardwareSerial::flush() { // If we have never written a byte, no need to flush. This special -- cgit v1.2.3-18-g5258