arduino / arduino/ArduinoCore-API

add peek(size_t pos) Stream/HardwareSerial

Aperta
#45 1 commento 0 reazioni 1 assegnatario Rivendicata da @cmaglie Vedi su GitHub
Lingua principale
C++
Stelle
306
Fork
150
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.