@@ -29,6 +29,7 @@ typedef struct
29
29
u8 bParityType;
30
30
u8 bDataBits;
31
31
u8 lineState;
32
+ u8 prevLineState;
32
33
} LineInfo;
33
34
34
35
static volatile LineInfo _usbLineInfo = { 57600 , 0x00 , 0x00 , 0x00 , 0x00 };
@@ -221,7 +222,7 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
221
222
// TODO - ZE - check behavior on different OSes and test what happens if an
222
223
// open connection isn't broken cleanly (cable is yanked out, host dies
223
224
// or locks up, or host virtual serial port hangs)
224
- if (_usbLineInfo. lineState > 0 ) {
225
+ if (this ) {
225
226
int r = USB_Send (CDC_TX,buffer,size);
226
227
if (r > 0 ) {
227
228
return r;
@@ -240,12 +241,18 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
240
241
// setup() before printing to ensure that an application on the host is
241
242
// actually ready to receive and display the data.
242
243
// We add a short delay before returning to fix a bug observed by Federico
243
- // where the port is configured (lineState != 0) but not quite opened.
244
+ // where the port is configured (lineState != 0) but not quite opened. This
245
+ // only happens when the line state transitions from ==0 to >0 otherwise you
246
+ // get a nasty delay when one isn't needed.
244
247
Serial_::operator bool () {
245
248
bool result = false ;
246
- if (_usbLineInfo.lineState > 0 )
249
+ if (_usbLineInfo.lineState > 0 ) {
247
250
result = true ;
248
- delay (10 );
251
+ if (_usbLineInfo.prevLineState == 0 ) {
252
+ delay (10 );
253
+ }
254
+ }
255
+ _usbLineInfo.prevLineState = _usbLineInfo.lineState ;
249
256
return result;
250
257
}
251
258
0 commit comments