Noiasca Buffer Print
Print to an internal buffer
|
The Noiasca Buffer Print is a library very similar to Print.h but will buffer outputs until flush is called. Despite other libraries, this class calls flush at the end of each print call. The objective is to have an replacement for the Print.h which collects data and sends data to an interface not bytewise with single writes but as one stream with several bytes. Like the Print.h library NoiascaBufferPrint.h is not a stand alone library, but can be used with other classes.
All print functions call the function .add instead of .write
add() adds the value to the internal buffer. add() doesn't output - in other words add() doesn't call write().
It is not needed that add() is implemented in the derived class
flush() empties the buffer and streams to your class flush() needs to be implemented in the derived class
write() exists similar to the Print.h library. write() is used for the bytewise output to your class. write() doesn't use the internal buffer - but you could implement that in your class. write() needs to be implemented in the derived class (like with Print.h).
print() and println() have now an additional boolean parameter autoflush (default true). By default print() and println() will flush the buffer as last statement. If you want several print()/println() in the buffer, just add false. In this case - don't forget to flush().
There should be no need for an explicit flush() in your local write function because each print ends with a flush(). But you could implement a trailing flush() in your write().
If write() should be buffered also - implement it in the derived class. In this case don't forget to flush after write() also.
Currently this library doesn't implement "printable" interface.
When you define your class, don't inherit from Print.h but from NoiascaBufferPrint.h. You will need to implement two member functions in your class:
The example 01_hello_world shows a simple sketch using a buffered print to the serial interface.
The newest version of this library can be downloaded from https://werner.rothschopf.net/microcontroller/202111_arduino_bufferprint.htm .
In the Arduino IDE use the Menu
Sketch / Include Library / Add .ZIP Library
to install the library.