aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/HardwareSerial.cpp
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-07-04 23:31:55 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-07-04 23:31:55 +0000
commitd3cb43c1c981ee3726d26c05ec3e42fffaa080c6 (patch)
tree61c23e7f21927311c04853da13a0f25a550d8c8c /cores/arduino/HardwareSerial.cpp
parent2c32369685d38f7367328d470571dd2f9a1104c7 (diff)
Adding a peek() function to Stream and HardwareSerial (Serial).
Diffstat (limited to 'cores/arduino/HardwareSerial.cpp')
-rwxr-xr-xcores/arduino/HardwareSerial.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index 638b6d1..f8cdebe 100755
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -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