Merge pull request #270 from SukkoPera/Fix-ifSerial
Added "if serial" and deprecated isConnected()
This commit is contained in:
commit
385dfbf29c
|
@ -119,7 +119,7 @@ size_t n = 0;
|
|||
size_t USBSerial::write(const uint8 *buf, uint32 len)
|
||||
{
|
||||
size_t n = 0;
|
||||
if (!this->isConnected() || !buf) {
|
||||
if (!(bool) *this || !buf) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -190,10 +190,6 @@ uint8 USBSerial::pending(void) {
|
|||
return usb_cdcacm_get_pending();
|
||||
}
|
||||
|
||||
uint8 USBSerial::isConnected(void) {
|
||||
return usb_is_connected(USBLIB) && usb_is_configured(USBLIB) && usb_cdcacm_get_dtr();
|
||||
}
|
||||
|
||||
uint8 USBSerial::getDTR(void) {
|
||||
return usb_cdcacm_get_dtr();
|
||||
}
|
||||
|
@ -202,6 +198,10 @@ uint8 USBSerial::getRTS(void) {
|
|||
return usb_cdcacm_get_rts();
|
||||
}
|
||||
|
||||
USBSerial::operator bool() {
|
||||
return usb_is_connected(USBLIB) && usb_is_configured(USBLIB) && usb_cdcacm_get_dtr();
|
||||
}
|
||||
|
||||
#if BOARD_HAVE_SERIALUSB
|
||||
#ifdef SERIAL_USB
|
||||
USBSerial Serial;
|
||||
|
|
|
@ -49,8 +49,6 @@ public:
|
|||
void begin(unsigned long, uint8_t);
|
||||
void end(void);
|
||||
|
||||
operator bool() { return true; } // Roger Clark. This is needed because in cardinfo.ino it does if (!Serial) . It seems to be a work around for the Leonardo that we needed to implement just to be compliant with the API
|
||||
|
||||
virtual int available(void);// Changed to virtual
|
||||
|
||||
uint32 read(uint8 * buf, uint32 len);
|
||||
|
@ -69,9 +67,21 @@ public:
|
|||
|
||||
uint8 getRTS();
|
||||
uint8 getDTR();
|
||||
uint8 isConnected();
|
||||
uint8 pending();
|
||||
|
||||
/* SukkoPera: This is the Arduino way to check if an USB CDC serial
|
||||
* connection is open.
|
||||
|
||||
* Used for instance in cardinfo.ino.
|
||||
*/
|
||||
operator bool();
|
||||
|
||||
/* Old libmaple way to check for serial connection.
|
||||
*
|
||||
* Deprecated, use the above.
|
||||
*/
|
||||
uint8 isConnected() __attribute__((deprecated("Use !Serial instead"))) { return (bool) *this; }
|
||||
|
||||
protected:
|
||||
static bool _hasBegun;
|
||||
};
|
||||
|
@ -81,4 +91,3 @@ protected:
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void setup() {
|
|||
// Initialize virtual COM over USB on Maple Mini
|
||||
Serial.begin(9600); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -18,7 +18,7 @@ void setup()
|
|||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
Serial.setTimeout(timeoutPeriod); // default is 1 second
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -19,7 +19,7 @@ void setup()
|
|||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
Serial.setTimeout(timeoutPeriod); // default is 1 second
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -38,7 +38,7 @@ void setup(void)
|
|||
pinMode(A_RANDOM_ANALOG_PIN, INPUT_ANALOG);
|
||||
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
@ -48,7 +48,7 @@ void setup(void)
|
|||
setup_temperature_sensor();
|
||||
|
||||
// announce start up
|
||||
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS()))
|
||||
if(Serial)
|
||||
Serial.println("Temp mon startup");
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ void loop(void)
|
|||
t2 = micros();
|
||||
vsense = adc_read(ADC1, 16);
|
||||
t3 = micros();
|
||||
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())) {
|
||||
if(Serial) {
|
||||
sprintf(buf,"%04x %08x %04x %08x" , vsense, t3-t2, alogpin, t2-t1);
|
||||
Serial.println(buf);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void setup()
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -18,7 +18,7 @@ void setup() {
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -18,7 +18,7 @@ void setup() {
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -15,7 +15,7 @@ void setup()
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -17,7 +17,7 @@ void setup() // run once, when the sketch starts
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -16,7 +16,7 @@ void setup() // run once, when the sketch starts
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -13,7 +13,7 @@ void setup() {
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UAR
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
Binary file not shown.
|
@ -34,7 +34,7 @@ void setup() {
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(); // USB does not require BAUD
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
|
@ -19,7 +19,7 @@ void setup() {
|
|||
pinMode(33, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
// wait for serial monitor to be connected.
|
||||
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
||||
while (!Serial)
|
||||
{
|
||||
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
|
||||
delay(100); // fast blink
|
||||
|
|
Loading…
Reference in New Issue