From cbfb87222fec84af899c11d2da8195fe92ad098f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giorgiogg=C3=AC?= Date: Tue, 18 Apr 2017 12:24:06 +0200 Subject: [PATCH 1/8] Fix indentation --- STM32F1/cores/maple/usb_serial.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/STM32F1/cores/maple/usb_serial.h b/STM32F1/cores/maple/usb_serial.h index 96bbefc..c2de1c5 100644 --- a/STM32F1/cores/maple/usb_serial.h +++ b/STM32F1/cores/maple/usb_serial.h @@ -44,19 +44,19 @@ public: void begin(void); - // Roger Clark. Added dummy function so that existing Arduino sketches which specify baud rate will compile. - void begin(unsigned long); - void begin(unsigned long, uint8_t); + // Roger Clark. Added dummy function so that existing Arduino sketches which specify baud rate will compile. + void begin(unsigned long); + 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 + 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); - // uint8 read(void); + // uint8 read(void); - // Roger Clark. added functions to support Arduino 1.0 API + // Roger Clark. added functions to support Arduino 1.0 API virtual int peek(void); virtual int read(void); int availableForWrite(void); @@ -74,8 +74,7 @@ public: }; #ifdef SERIAL_USB - extern USBSerial Serial; + extern USBSerial Serial; #endif #endif - From 0be991b434abc14f7ec9c91252977b60350d263c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giorgiogg=C3=AC?= Date: Tue, 18 Apr 2017 12:43:01 +0200 Subject: [PATCH 2/8] Update usb_serial.h --- STM32F1/cores/maple/usb_serial.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/STM32F1/cores/maple/usb_serial.h b/STM32F1/cores/maple/usb_serial.h index c2de1c5..ceb81e1 100644 --- a/STM32F1/cores/maple/usb_serial.h +++ b/STM32F1/cores/maple/usb_serial.h @@ -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,8 +67,20 @@ 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() { return (bool) *this; } }; #ifdef SERIAL_USB From 38525521fd9ea4713970073326c21b8e9c54c09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giorgiogg=C3=AC?= Date: Tue, 18 Apr 2017 12:44:10 +0200 Subject: [PATCH 3/8] Update usb_serial.cpp --- STM32F1/cores/maple/usb_serial.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/STM32F1/cores/maple/usb_serial.cpp b/STM32F1/cores/maple/usb_serial.cpp index 5eaf70e..2f7dadd 100644 --- a/STM32F1/cores/maple/usb_serial.cpp +++ b/STM32F1/cores/maple/usb_serial.cpp @@ -178,10 +178,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(); } @@ -190,6 +186,10 @@ uint8 USBSerial::getRTS(void) { return usb_cdcacm_get_rts(); } +uint8 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; From 81b1b08b95695256f6253bd236c4ee4755eb0089 Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Tue, 18 Apr 2017 23:25:36 +0200 Subject: [PATCH 4/8] Fix return type --- STM32F1/cores/maple/usb_serial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STM32F1/cores/maple/usb_serial.cpp b/STM32F1/cores/maple/usb_serial.cpp index 2f7dadd..85c7024 100644 --- a/STM32F1/cores/maple/usb_serial.cpp +++ b/STM32F1/cores/maple/usb_serial.cpp @@ -186,7 +186,7 @@ uint8 USBSerial::getRTS(void) { return usb_cdcacm_get_rts(); } -uint8 USBSerial::operator bool() { +USBSerial::operator bool() { return usb_is_connected(USBLIB) && usb_is_configured(USBLIB) && usb_cdcacm_get_dtr(); } From 54cd854161ffe5d84cde14a3763b5abe68a30ae7 Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Tue, 9 May 2017 23:16:10 +0200 Subject: [PATCH 5/8] Tag isConnected() with __attribute__(deprecated) --- STM32F1/cores/maple/usb_serial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STM32F1/cores/maple/usb_serial.h b/STM32F1/cores/maple/usb_serial.h index ceb81e1..40745c1 100644 --- a/STM32F1/cores/maple/usb_serial.h +++ b/STM32F1/cores/maple/usb_serial.h @@ -80,7 +80,7 @@ public: * * Deprecated, use the above. */ - uint8 isConnected() { return (bool) *this; } + uint8 isConnected() __attribute__((deprecated("Use !Serial instead"))) { return (bool) *this; } }; #ifdef SERIAL_USB From ad51f6f8f8888f528badcea133953f525fd1116b Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Tue, 9 May 2017 23:16:47 +0200 Subject: [PATCH 6/8] Avoid usage of deprecated function --- STM32F1/cores/maple/usb_serial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STM32F1/cores/maple/usb_serial.cpp b/STM32F1/cores/maple/usb_serial.cpp index 85c7024..57b439f 100644 --- a/STM32F1/cores/maple/usb_serial.cpp +++ b/STM32F1/cores/maple/usb_serial.cpp @@ -107,7 +107,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; } From bf138eb389c50f68de28d708033442f8d4584c2b Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Fri, 9 Jun 2017 22:07:05 +0200 Subject: [PATCH 7/8] Remove isConnected() usage from examples --- .../examples/General/BlinkNcount/BlinkNcount.ino | 2 +- .../examples/General/IntegerInput/IntegerInput.ino | 2 +- .../IntegerInput_FloatOutput/IntegerInput_FloatOutput.ino | 2 +- .../General/InternalTempSensor/InternalTempSensor.ino | 6 +++--- .../A_STM32_Examples/examples/General/PrimeNos/PrimeNos.ino | 2 +- .../examples/General/PrimeNos2/PrimeNos2.ino | 2 +- .../examples/General/PrimeNos3/PrimeNos3.ino | 2 +- .../examples/General/Print_Binary/Print_Binary.ino | 2 +- .../examples/General/Print_Float/Print_Float.ino | 2 +- .../examples/General/Print_HEX/Print_HEX.ino | 2 +- .../examples/General/SerialReadUntil/SerialReadUntil.ino | 2 +- .../examples/General/USB_ASCII/USB_ASCII.ino | 2 +- .../General/strtol_DecEquivalents/strtol_DecEquivalents.ino | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/BlinkNcount/BlinkNcount.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/BlinkNcount/BlinkNcount.ino index 7cabfde..1b1f58a 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/BlinkNcount/BlinkNcount.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/BlinkNcount/BlinkNcount.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput/IntegerInput.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput/IntegerInput.ino index 55a68e8..4a1d16a 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput/IntegerInput.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput/IntegerInput.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput_FloatOutput/IntegerInput_FloatOutput.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput_FloatOutput/IntegerInput_FloatOutput.ino index 6f04840..b82394e 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput_FloatOutput/IntegerInput_FloatOutput.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/IntegerInput_FloatOutput/IntegerInput_FloatOutput.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/InternalTempSensor/InternalTempSensor.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/InternalTempSensor/InternalTempSensor.ino index d6000cd..871ae25 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/InternalTempSensor/InternalTempSensor.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/InternalTempSensor/InternalTempSensor.ino @@ -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); } diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos/PrimeNos.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos/PrimeNos.ino index 09a7a3f..c744219 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos/PrimeNos.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos/PrimeNos.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos2/PrimeNos2.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos2/PrimeNos2.ino index 51fe332..a2fd1c9 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos2/PrimeNos2.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos2/PrimeNos2.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos3/PrimeNos3.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos3/PrimeNos3.ino index eec3dc0..8e8fe88 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos3/PrimeNos3.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/PrimeNos3/PrimeNos3.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Binary/Print_Binary.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Binary/Print_Binary.ino index c9c4b88..7409ba5 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Binary/Print_Binary.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Binary/Print_Binary.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Float/Print_Float.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Float/Print_Float.ino index 289db9e..4351d31 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Float/Print_Float.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_Float/Print_Float.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_HEX/Print_HEX.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_HEX/Print_HEX.ino index cfdb977..2dc41fe 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/Print_HEX/Print_HEX.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/Print_HEX/Print_HEX.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/SerialReadUntil/SerialReadUntil.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/SerialReadUntil/SerialReadUntil.ino index 1e7d400..80d3b3b 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/SerialReadUntil/SerialReadUntil.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/SerialReadUntil/SerialReadUntil.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/USB_ASCII/USB_ASCII.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/USB_ASCII/USB_ASCII.ino index e38b176..a884978 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/USB_ASCII/USB_ASCII.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/USB_ASCII/USB_ASCII.ino @@ -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 diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/strtol_DecEquivalents/strtol_DecEquivalents.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/strtol_DecEquivalents/strtol_DecEquivalents.ino index 7d799af..f759471 100644 --- a/STM32F1/libraries/A_STM32_Examples/examples/General/strtol_DecEquivalents/strtol_DecEquivalents.ino +++ b/STM32F1/libraries/A_STM32_Examples/examples/General/strtol_DecEquivalents/strtol_DecEquivalents.ino @@ -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 From c4643b265ec344365d9d547ac4f8859d2e20083c Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Fri, 9 Jun 2017 22:07:33 +0200 Subject: [PATCH 8/8] Remove isConnected() usage and binary zeros from StringEx_Parsinge xample --- .../StringEx_Parsing/StringEx_Parsing.ino | Bin 3285 -> 3217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/STM32F1/libraries/A_STM32_Examples/examples/General/StringEx_Parsing/StringEx_Parsing.ino b/STM32F1/libraries/A_STM32_Examples/examples/General/StringEx_Parsing/StringEx_Parsing.ino index d98193c351739023a243a659979419438b658719..fd30b4ca30fcbbae814efffd42c6611eba5a2119 100644 GIT binary patch delta 69 zcmV-L0J{Ix8Ic*Vcmb1n0apWBL@blq0d$j30(G;+0yYB%Q)O~#VQjNG24V%1oeTX5 bTrfH?crs&LFq5GS7y$~CuL~6f3MwxOLQEB= delta 157 zcmbOzc~x>l1tX)v