mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Adding a peek() function to Stream and HardwareSerial (Serial).
This commit is contained in:
parent
934312682e
commit
31601ffe77
@ -163,6 +163,7 @@ Serial2 KEYWORD3 Serial
|
||||
Serial3 KEYWORD3 Serial
|
||||
begin KEYWORD2 Serial_Begin
|
||||
end KEYWORD2 Serial_End
|
||||
peek KEYWORD2 Serial_Peek
|
||||
read KEYWORD2 Serial_Read
|
||||
print KEYWORD2 Serial_Print
|
||||
println KEYWORD2 Serial_Println
|
||||
|
@ -178,6 +178,15 @@ uint8_t HardwareSerial::available(void)
|
||||
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
int HardwareSerial::peek(void)
|
||||
{
|
||||
if (_rx_buffer->head == _rx_buffer->tail) {
|
||||
return -1;
|
||||
} else {
|
||||
return _rx_buffer->buffer[_rx_buffer->tail];
|
||||
}
|
||||
}
|
||||
|
||||
int HardwareSerial::read(void)
|
||||
{
|
||||
// if the head isn't ahead of the tail, we don't have any characters
|
||||
|
@ -49,6 +49,7 @@ class HardwareSerial : public Stream
|
||||
void begin(long);
|
||||
void end();
|
||||
virtual uint8_t available(void);
|
||||
virtual int peek(void);
|
||||
virtual int read(void);
|
||||
virtual void flush(void);
|
||||
virtual void write(uint8_t);
|
||||
|
@ -27,6 +27,7 @@ class Stream : public Print
|
||||
{
|
||||
public:
|
||||
virtual uint8_t available() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user