Skip to content

Add room() function to Serial Class to see free TXbuffer space (HWS & SWS) #1408

Closed
@RobTillaart

Description

@RobTillaart

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CoreRelated to the code for the standard Arduino API

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions