From 1e2b0ffd14789c325362159439f3f3b00db1f48d Mon Sep 17 00:00:00 2001 From: LDP-Soft <117711872+LDP-Soft@users.noreply.github.com> Date: Tue, 8 Nov 2022 00:37:47 -0600 Subject: [PATCH 1/2] Update HardwareSerial.h --- cores/arduino/HardwareSerial.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index 6ff29d0b9..ee946b1b1 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -123,6 +123,7 @@ class HardwareSerial : public Stream void end(); virtual int available(void); virtual int peek(void); + virtual int peekLast(void); virtual int read(void); virtual int availableForWrite(void); virtual void flush(void); From d8a904ff0cda8679171e390a0199b31e88b3a0f7 Mon Sep 17 00:00:00 2001 From: LDP-Soft <117711872+LDP-Soft@users.noreply.github.com> Date: Tue, 8 Nov 2022 00:38:54 -0600 Subject: [PATCH 2/2] Update HardwareSerial.cpp --- cores/arduino/HardwareSerial.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 561127f9f..4606db06b 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -177,6 +177,11 @@ int HardwareSerial::peek(void) } } +int HardwareSerial::peekLast(void) +{ + return _rx_buffer_head==_rx_buffer_tail ? -1 : _rx_buffer[(SERIAL_RX_BUFFER_SIZE+_rx_buffer_tail-1)%SERIAL_RX_BUFFER_SIZE]; +} + int HardwareSerial::read(void) { // if the head isn't ahead of the tail, we don't have any characters