From a984b581a8ad093b55ec9f2d4677afdd77bf4705 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sun, 1 Apr 2012 12:54:35 -0400 Subject: added Boolean operators to HardwareSerial and CDC to test whether the port is ready to send data. Mostly useful for Leonardo - simple way to test whether the port is actually opened by an application and ready to receive data. For Serial objects attached to real UARTs always returns true. --- cores/arduino/CDC.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cores/arduino/CDC.cpp') diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index 7206aa6..1275304 100644 --- a/cores/arduino/CDC.cpp +++ b/cores/arduino/CDC.cpp @@ -213,6 +213,12 @@ size_t Serial_::write(uint8_t c) return 0; } +Serial_::operator bool() { + if (_usbLineInfo.lineState > 0) + return true; + return false; +} + Serial_ Serial; #endif -- cgit v1.2.3-18-g5258