mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Merge pull request #2193 from PaulStoffregen/ide-1.5.x
Add availableForWrite() to HardwareSerial
This commit is contained in:
commit
e5c7cb9de1
@ -177,6 +177,7 @@ read KEYWORD2 Serial_Read
|
||||
print KEYWORD2 Serial_Print
|
||||
println KEYWORD2 Serial_Println
|
||||
available KEYWORD2 Serial_Available
|
||||
availableForWrite KEYWORD2
|
||||
flush KEYWORD2 Serial_Flush
|
||||
setTimeout KEYWORD2
|
||||
find KEYWORD2
|
||||
|
@ -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
|
||||
|
@ -112,6 +112,7 @@ class HardwareSerial : public Stream
|
||||
virtual int available(void);
|
||||
virtual int peek(void);
|
||||
virtual int read(void);
|
||||
int availableForWrite(void);
|
||||
virtual void flush(void);
|
||||
virtual size_t write(uint8_t);
|
||||
inline size_t write(unsigned long n) { return write((uint8_t)n); }
|
||||
|
Loading…
Reference in New Issue
Block a user