From 65b4a24d639d3b4d03779ac33c9e7f684407ff81 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Tue, 7 Feb 2012 08:53:31 +0100 Subject: [PATCH] Introduce writeable call on HardwareSerial. Can be used e.g. to do some form of flow control between multiple Serial devices on an Arduino Mega. --- hardware/arduino/cores/arduino/HardwareSerial.cpp | 6 ++++++ hardware/arduino/cores/arduino/HardwareSerial.h | 1 + 2 files changed, 7 insertions(+) diff --git a/hardware/arduino/cores/arduino/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp index 9985b78c6e4..0adbe250d6f 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -380,6 +380,12 @@ void HardwareSerial::flush() ; } +bool HardwareSerial::writeable() +{ + int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; + return (i != _tx_buffer->tail); +} + size_t HardwareSerial::write(uint8_t c) { int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; diff --git a/hardware/arduino/cores/arduino/HardwareSerial.h b/hardware/arduino/cores/arduino/HardwareSerial.h index 176abe1e20b..413fe9a026b 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.h +++ b/hardware/arduino/cores/arduino/HardwareSerial.h @@ -55,6 +55,7 @@ class HardwareSerial : public Stream virtual int peek(void); virtual int read(void); virtual void flush(void); + virtual bool writeable(void); virtual size_t write(uint8_t); using Print::write; // pull in write(str) and write(buf, size) from Print };