From 437025c6eeaca9df5b48e8abe086edc2a16353b9 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Fri, 6 Apr 2012 21:23:17 -0400 Subject: [PATCH] Revert "Revert "added a short delay and comment to boolean operator in CDC"" This reverts commit 200eefb4e2ac7796c5c901e8fd9369c85ec544c5. --- hardware/arduino/cores/arduino/CDC.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/cores/arduino/CDC.cpp b/hardware/arduino/cores/arduino/CDC.cpp index 1275304b0..c1e646d2d 100644 --- a/hardware/arduino/cores/arduino/CDC.cpp +++ b/hardware/arduino/cores/arduino/CDC.cpp @@ -213,10 +213,19 @@ size_t Serial_::write(uint8_t c) return 0; } +// This operator is a convenient way for a sketch to check whether the +// port has actually been configured and opened by the host (as opposed +// to just being connected to the host). It can be used, for example, in +// setup() before printing to ensure that an application on the host is +// actually ready to receive and display the data. +// We add a short delay before returning to fix a bug observed by Federico +// where the port is configured (lineState != 0) but not quite opened. Serial_::operator bool() { - if (_usbLineInfo.lineState > 0) - return true; - return false; + bool result = false; + if (_usbLineInfo.lineState > 0) + result = true; + delay(10); + return result; } Serial_ Serial;