SafeString  4.1.44
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
BufferedInput.h File Reference
#include <Print.h>
#include <Printable.h>
#include "SafeString.h"
#include "SafeStringNameSpaceStart.h"
#include "SafeStringNameSpaceEnd.h"

Go to the source code of this file.

Classes

class  BufferedInput
 To create a BufferedInput use the macro createBufferedInput see the detailed description. More...
 

Macros

#define createBufferedInput(name, size)   uint8_t name ## _INPUT_BUFFER[(size)]; BufferedInput name(sizeof(name ## _INPUT_BUFFER),name ## _INPUT_BUFFER);
 BufferedInput.h by Matthew Ford (c)2020 Forward Computing and Control Pty. More...
 

Macro Definition Documentation

◆ createBufferedInput

#define createBufferedInput (   name,
  size 
)    uint8_t name ## _INPUT_BUFFER[(size)]; BufferedInput name(sizeof(name ## _INPUT_BUFFER),name ## _INPUT_BUFFER);

BufferedInput.h by Matthew Ford (c)2020 Forward Computing and Control Pty.

Ltd. This code is not warranted to be fit for any purpose. You may only use it at your own risk. This code may be freely used for both private and commercial use. Provide this copyright is maintained. Usage: createBufferedInput( input, 64); // buffered input called input with an extra buffer size of 64 chars

Then in setup() input.connect(Serial); // connect the buffered input to Serial to read from

Then in loop() use input instead of Serial e.g. void loop() { put this line at the top of the loop, must be called each loop to transfer the available chars from the Serial RX buffer into this buffer before the RX buffer overflows input.nextByteIn(); ... if (input.available()) { int c = input.read(); } // read from input instead of Serial ... input.print(" this is the msg"); // can also write to input, not buffered, writes directly to Serial. ... }

Sizing the buffer: input.maxBufferUsed() returns the high water mark of this buffer and input.maxStreamAvailable() returns the high water mark of the Serial RX buffer. Both are reset to zero by the call. If maxBufferUsed() reaches the buffer size, increase the size. If maxStreamAvailable() approaches the Serial RX buffer size, call nextByteIn() more often.

Definition at line 47 of file BufferedInput.h.