diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2012-04-03 10:52:38 -0400 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2012-04-03 10:52:38 -0400 |
commit | dd55096901b163b315948e0ddee3706464b3ec26 (patch) | |
tree | fafdbb0759ad23598ff48d9423fc940c2170760c /cores | |
parent | a984b581a8ad093b55ec9f2d4677afdd77bf4705 (diff) |
added a short delay and comment to boolean operator in CDC
Delay fixes problem where the port has been configured but not quite opened. Federico found that 10 ms was the minimum time needed to avoid problems.
Diffstat (limited to 'cores')
-rw-r--r-- | cores/arduino/CDC.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index 1275304..c1e646d 100644 --- a/cores/arduino/CDC.cpp +++ b/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; |