Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Stream::find(char)
  • Loading branch information
pbouchet committed Mar 7, 2012
commit 4cd29d075c52c6d5554d917877ea05a781d249f3
13 changes: 13 additions & 0 deletions hardware/arduino/cores/arduino/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
_timeout = timeout;
}

// find returns true if the target character is found
bool Stream::find(char target)
{
int c = 0;
do {
c = timedRead();
if ((char)c == target)
return true;
} while (c >= 0);
// if c is -1, it means a timeout occured
return false;
}

// find returns true if the target string is found
bool Stream::find(char *target)
{
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Stream : public Print

void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second

bool find(char target); // reads data from the stream until the target character is found
// returns true if target character is found, false if timed out (see setTimeout)

bool find(char *target); // reads data from the stream until the target string is found
// returns true if target string is found, false if timed out (see setTimeout)

Expand Down