Inherits Stream.
To create a BufferedOutput use the macro createBufferedOutput see the detailed description.
The createBufferedOutput macro takes 2, 3 or 4 arguments.
createBufferedOutput(name, size); creates a BufferedOutput called name which can buffer upto size chars without blocking and then will block once the buffer fills up.
This default blocking when the buffer is full is not recommended.
Add a call to
bufferedOutput.nextByteOut();
at the top of the loop() to release the buffered chars. You can add more of these calls through out the loop() code if needed.
Most BufferedOutput methods also release the buffered chars.
createBufferedOutput(name, size, mode ); creates a BufferedOutput called name which can buffer upto size chars without blocking and mode determines what to do when the buffer is full.
mode can be one of BLOCK_IF_FULL, DROP_UNTIL_EMPTY or DROP_IF_FULL
BLOCK_IF_FULL just blocks until some chars can be sent to the output stream, so freeing up space in the buffer to accept more output. This mode is not recommended, but can be used for testing to force ALL output to be sent.
DROP_UNTIL_EMPTY will drop further output until all the output currently in the full buffer is sent to the output stream.
DROP_IF_FULL will drop further output until enough chars have been sent to the output stream to free up space for the output printed to the buffer.
If any chars are dropped then ~~ is added to the output sent so you can see where there is missing output.
This 3 argument version uses the default AllOrNothing == true setting. If the whole print(..) cannot fit in the buffer none of it is sent.
createBufferedOutput(name, size, mode, allOrNothing ); creates a BufferedOutput called name which can buffer upto size chars without blocking and mode determines what to do when the buffer is full and how to handle prints that do not entirely fit in the buffer.
AllOrNothing true will drop the entire print( ) if it will not completely fit in the buffer.
AllOrNothing false will only drop the part of the print( ) that will not fit in the buffer.
See Arduino Serial I/O for the Real World - BufferedOutput for an example of its use.
Definition at line 78 of file BufferedOutput.h.
use createBufferedOutput(name, size, mode); instead BufferedOutput(size_t _bufferSize, uint8_t *_buf, BufferedOutputMode = BLOCK_IF_FULL, bool allOrNothing = true);
buf – the user allocated buffer to store the bytes, must be at least bufferSize long. Defaults to an internal 8 char buffer if buf is omitted or NULL bufferSize – number of bytes to buffer,max bufferSize is limited to 32766. Defaults to an internal 8 char buffer if bufferSize is < 8 or is omitted mode – BLOCK_IF_FULL (default), DROP_UNTIL_EMPTY or DROP_IF_FULL BLOCK_IF_FULL, like normal print, but with a buffer. Use this to see ALL the output, but will block the loop() when the output buffer fills DROP_UNTIL_EMPTY, when the output buffer is full, drop any more chars until it completely empties. ~~<CR><NL> is inserted in the output to show chars were dropped. Useful when there too much output. It allow multiple prints to be output consecutively to give meaning full output avaliableForWrite() will return 0 from when the buffer fills until is empties DROP_IF_FULL, when the output buffer is full, drop any more chars until here is space. ~~<CR><NL> is inserted in the output to show chars were dropped. allOrNothing – defaults to true, If true AND output buffer not empty then if write(buf,size) will not all fit don't output any of it. Else if false OR output buffer is empty then write(buf,size) will output partial data to fill output buffer. allOrNothing setting is ignored if mode is BLOCK_IF_FULL