From 0fd1228e27cf555440a36519d5d41651aa89df68 Mon Sep 17 00:00:00 2001 From: "DrZiplok@gmail.com" Date: Sat, 27 Nov 2010 01:49:10 +0000 Subject: [PATCH] Add ::peek for compatibility with trunk Arduino. git-svn-id: https://arducopter.googlecode.com/svn/trunk@943 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/FastSerial/FastSerial.cpp | 13 +++++++++++++ libraries/FastSerial/FastSerial.h | 1 + 2 files changed, 14 insertions(+) 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;