Skip to content

Commit 299ac12

Browse files
committed
Stream - new method clear() to clear the receive buffer
1 parent 331cdd9 commit 299ac12

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: api/Stream.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal)
8686
// Public Methods
8787
//////////////////////////////////////////////////////////////
8888

89+
void Stream::clear() {
90+
while (available())
91+
read();
92+
}
93+
8994
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
9095
{
9196
_timeout = timeout;

Diff for: api/Stream.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class Stream : public Print
6161
virtual int read() = 0;
6262
virtual int peek() = 0;
6363

64+
virtual void clear(); // clears the receive buffer
65+
6466
Stream() {_timeout=1000;}
6567

6668
// parsing methods
@@ -130,4 +132,4 @@ class Stream : public Print
130132

131133
}
132134

133-
using arduino::Stream;
135+
using arduino::Stream;

0 commit comments

Comments
 (0)