Skip to content

Commit e8aa18f

Browse files
committed
Merge pull request #980 from jeremybrodt/dtr
Using "Data Terminal Ready" signal to determine when the host is connected.
2 parents 31a3cff + bbe2e0c commit e8aa18f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libraries/USBDevice/USBSerial/USBCDC.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ static uint8_t cdc_line_coding[7]= {0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08};
2727
#define CDC_GET_LINE_CODING 0x21
2828
#define CDC_SET_CONTROL_LINE_STATE 0x22
2929

30+
// Control Line State bits
31+
#define CLS_DTR (1 << 0)
32+
#define CLS_RTS (1 << 1)
33+
3034
#define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
3135

3236
USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking): USBDevice(vendor_id, product_id, product_release) {
@@ -54,10 +58,13 @@ bool USBCDC::USBCallback_request(void) {
5458
transfer->remaining = 7;
5559
transfer->notify = true;
5660
success = true;
57-
terminal_connected = true;
5861
break;
5962
case CDC_SET_CONTROL_LINE_STATE:
60-
terminal_connected = false;
63+
if (transfer->setup.wValue & CLS_DTR) {
64+
terminal_connected = true;
65+
} else {
66+
terminal_connected = false;
67+
}
6168
success = true;
6269
break;
6370
default:

0 commit comments

Comments
 (0)