Skip to content

Commit 437025c

Browse files
committed
Revert "Revert "added a short delay and comment to boolean operator in CDC""
This reverts commit 200eefb.
1 parent 74b6126 commit 437025c

File tree

1 file changed

+12
-3
lines changed
  • hardware/arduino/cores/arduino

1 file changed

+12
-3
lines changed

hardware/arduino/cores/arduino/CDC.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,19 @@ size_t Serial_::write(uint8_t c)
213213
return 0;
214214
}
215215

216+
// This operator is a convenient way for a sketch to check whether the
217+
// port has actually been configured and opened by the host (as opposed
218+
// to just being connected to the host). It can be used, for example, in
219+
// setup() before printing to ensure that an application on the host is
220+
// actually ready to receive and display the data.
221+
// We add a short delay before returning to fix a bug observed by Federico
222+
// where the port is configured (lineState != 0) but not quite opened.
216223
Serial_::operator bool() {
217-
if (_usbLineInfo.lineState > 0)
218-
return true;
219-
return false;
224+
bool result = false;
225+
if (_usbLineInfo.lineState > 0)
226+
result = true;
227+
delay(10);
228+
return result;
220229
}
221230

222231
Serial_ Serial;

0 commit comments

Comments
 (0)