Skip to content
Open
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
Next Next commit
Added fast USB read function readBlock
  • Loading branch information
sined23 authored and facchinm committed Jan 24, 2017
commit 90d1eb78f07ebfd735ca5c7d242acec2864ae457
13 changes: 13 additions & 0 deletions cores/arduino/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ size_t Stream::readBytes(char *buffer, size_t length)
return count;
}

// the same as readBytes only super fast
size_t Stream::readBlock(char *buffer, size_t length)
{
size_t count = 0;
int n;
_startMillis = millis();
while (count < length && millis() - _startMillis < _timeout) {
n = SerialUSB.readb(buffer+count, length-count);
count += (size_t)n;
if (n) _startMillis = millis();
}
return count;
}

// as readBytes with terminator character
// terminates if length characters have been read, timeout, or if the terminator character detected
Expand Down