diff --git a/libraries/FastSerial/FastSerial.cpp b/libraries/FastSerial/FastSerial.cpp index ffead4a509..e83978aadb 100644 --- a/libraries/FastSerial/FastSerial.cpp +++ b/libraries/FastSerial/FastSerial.cpp @@ -209,6 +209,19 @@ FastSerial::read(void) return(c); } +int +FastSerial::peek(void) +{ + + // if the head and tail are equal, the buffer is empty + if (!_open || (_rxBuffer->head == _rxBuffer->tail)) + return(-1); + + // pull character from tail + return(_rxBuffer->bytes[_rxBuffer->tail]); +} + + void FastSerial::flush(void) { diff --git a/libraries/FastSerial/FastSerial.h b/libraries/FastSerial/FastSerial.h index 82a4c652f7..ac3413c2af 100644 --- a/libraries/FastSerial/FastSerial.h +++ b/libraries/FastSerial/FastSerial.h @@ -100,6 +100,7 @@ public: virtual void end(void); virtual int available(void); virtual int read(void); + virtual int peek(void); virtual void flush(void); virtual void write(uint8_t c); using BetterStream::write;