Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: USB_SERIAL_con_main MPU6050_DMP_test_for1549 servo_controller_1549
Fork of USBDevice by
Revision 6:d0945750af57, committed 2012-12-20
- Comitter:
- samux
- Date:
- Thu Dec 20 17:05:37 2012 +0000
- Parent:
- 5:d27e4c226965
- Child:
- 7:f8f057664123
- Commit message:
- USBSerial: detect when a terminal is connected
Changed in this revision
--- a/USBSerial/USBCDC.cpp Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBCDC.cpp Thu Dec 20 17:05:37 2012 +0000
@@ -30,6 +30,7 @@
#define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
+ terminal_connected = false;
USBDevice::connect();
}
@@ -52,8 +53,11 @@
case CDC_SET_LINE_CODING:
transfer->remaining = 7;
success = true;
+ terminal_connected = true;
break;
case CDC_SET_CONTROL_LINE_STATE:
+ if (terminal_connected)
+ terminal_connected = false;
success = true;
break;
default:
--- a/USBSerial/USBCDC.h Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBCDC.h Thu Dec 20 17:05:37 2012 +0000
@@ -99,9 +99,11 @@
* @returns true if successful
*/
bool readEP_NB(uint8_t * buffer, uint32_t * size);
-
+
+protected:
virtual bool USBCallback_request();
virtual bool USBCallback_setConfiguration(uint8_t configuration);
+ volatile bool terminal_connected;
};
--- a/USBSerial/USBSerial.cpp Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBSerial.cpp Thu Dec 20 17:05:37 2012 +0000
@@ -20,6 +20,8 @@
#include "USBSerial.h"
int USBSerial::_putc(int c) {
+ if (!terminal_connected)
+ return 0;
send((uint8_t *)&c, 1);
return 1;
}
