pfodParser  3.61.0
The pfodParser library is handles commands sent from the Android pfodApp, pfodApp supports WiFi, BLE, Bluetooth and SMS connections
pfodNonBlockingInput.h
Go to the documentation of this file.
1 // NonBlockingInput.h
2 /*
3  (c)2019 Forward Computing and Control Pty. Ltd.
4  NSW Australia, www.forward.com.au
5  This code is not warranted to be fit for any purpose. You may only use it at your own risk.
6  This generated code may be freely used for both private and commercial use
7  provided this copyright is maintained.
8 */
9 #ifndef pfodNonBlockingInput_h
10 #define pfodNonBlockingInput_h
11 
12 #include <pfodDelay.h>
13 #include <pfodStream.h>
14 
15 class pfodNonBlockingInput : public Stream {
16  public:
21 
26 
31  void clearInput();
32 
33  // readFirstLine does not timeout or block
34  // returns -1 until the null terminated buffer contains length-1 chars or until read \r or \n. The \r or \n are not added to the buffer
35  // then returns number of chars read.
36  // an empty input line i.e. just \r or \n returns 0.
37  // if echo true then each char added to the buffer is echoed back to this stream
38  // buffer is null terminated after each call so you can check progress and apply an external timeout.
39  // clearInput is called when a non-zero is returned to clears any following input, e.g. \n of \r\n pair or any chars after buffer filled
40  int readInputLine( char *buffer, size_t length, bool echo = false); // read until full or get \r or \n
41  int readInputLine( uint8_t *buffer, size_t length, bool echo = false) {
42  return readInputLine((char *)buffer, length, echo); // read until full or get \r or \n
43  }
44 
45  // --------------------------------------------------------------
46  virtual size_t write(uint8_t);
47  virtual size_t write(const uint8_t *buf, size_t size);
48  virtual int available();
49  virtual int read();
50  virtual int peek();
51  virtual void flush(); // this blocks until write buffer empty
52  // availableForWrite() not available in ESP32 Stream (and others?);
53 
54  private:
55  void checkClearInput();
56  pfodDelay nonBlockingInputClearTimeOut;
57  const uint32_t NON_BLOCKING_INPUT_CLEAR_TIMEOUT_MS = 200; // 0.2sec
58  bool nonBlockingInput_clearFlag;
59  Stream* input;
60 };
61 #endif
virtual int available()
virtual void flush()
void clearInput()
Will clear any more input until nothing received for NON_BLOCKING_INPUT_CLEAR_TIMEOUT_MS,...
virtual size_t write(const uint8_t *buf, size_t size)
virtual int peek()
pfodNonBlockingInput()
constuctor
virtual size_t write(uint8_t)
int readInputLine(char *buffer, size_t length, bool echo=false)
pfodNonBlockingInput * connect(Stream *_io)
connect to Stream* to read from
int readInputLine(uint8_t *buffer, size_t length, bool echo=false)
virtual int read()