arduino / arduino/ArduinoCore-API

add peek(size_t pos) Stream/HardwareSerial

Ouverte
#45 1 commentaire 0 réactions 1 personne assignée Réclamée par @cmaglie Voir sur GitHub
Langage dominant
C++
Étoiles
306
Forks
150
Métriques de merge des PR
Aucune PR mergée en 30 j

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];
}
}
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.