arduino / arduino/ArduinoCore-API

add peek(size_t pos) Stream/HardwareSerial

Open
#45 1 comment 0 reactions 1 assignee Claimed by @cmaglie View on GitHub
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

It would be nice, if the Stream-Interface could be changed/extended with a peek method that takes a position/offset. I often have the need to search/wait, until a certain charakter is received - before i process the message. If course, storing in a temporary buffer works as well, but uses more memory and often complicates things...

Most simple way would be to add a default argument to peek
int peek(size_t = 0);

```
int HardwareSerial::peek(size_t pos)
{
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
return _rx_buffer->buffer[(_rx_buffer->tail+pos)%SERIAL_BUFFER_SIZE];
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.