Closed
Description
Sometimes one wants to know the amount of free places in the transmit buffer
The function to check this is straightforward.
int room()
{
return (SERIAL_BUFFER_SIZE + tx_buffer.head - tx_buffer.tail) % SERIAL_BUFFER_SIZE;
}
// % can be optimized with an if ()
this makes it possible to check and fill up the ring buffer to the max (esp when using low baud rates) without overflow.
The name room() is not as ambiguous as space which already has a meaning in serial communication. Available() is already used for receive.