1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-19 08:52:15 +01:00

Refactor port selection after 1200bps touch upload

New behaviour:
if upload failed or we are uploading through a "Programming" port (that does not disappear), leave the user selected port selected.
if upload succeded and we are using 1200bps touch, wait for the first port that reappears, and if nothing reappears after the timeout select the bootloader port.

Fixes #https://github.com/arduino/Arduino/issues/3495
This commit is contained in:
Martino Facchin 2018-11-21 17:43:20 +01:00 committed by Cristian Maglie
parent 4d26ec85e6
commit ffba05fd31

View File

@ -199,9 +199,6 @@ public class SerialUploader extends Uploader {
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false); BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
} }
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
String finalUploadPort = null; String finalUploadPort = null;
if (uploadResult && doTouch) { if (uploadResult && doTouch) {
try { try {
@ -210,34 +207,32 @@ public class SerialUploader extends Uploader {
// sketch serial port reconnects (or timeout after a few seconds if the // sketch serial port reconnects (or timeout after a few seconds if the
// sketch port never comes back). Doing this saves users from accidentally // sketch port never comes back). Doing this saves users from accidentally
// opening Serial Monitor on the soon-to-be-orphaned bootloader port. // opening Serial Monitor on the soon-to-be-orphaned bootloader port.
Thread.sleep(1000);
long started = System.currentTimeMillis(); // Reuse waitForUploadPort for this task, but this time we are simply waiting
while (System.currentTimeMillis() - started < 2000) { // for one port to reappear. If no port reappears before the timeout, actualUploadPort is selected
List<String> portList = Serial.list(); finalUploadPort = waitForUploadPort(actualUploadPort, Serial.list(), false);
if (portList.contains(userSelectedUploadPort)) {
finalUploadPort = userSelectedUploadPort;
break;
}
Thread.sleep(250);
}
} }
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
// noop // noop
} }
} }
if (finalUploadPort == null) {
finalUploadPort = actualUploadPort;
}
if (finalUploadPort == null) { if (finalUploadPort == null) {
finalUploadPort = userSelectedUploadPort; finalUploadPort = userSelectedUploadPort;
} }
BaseNoGui.selectSerialPort(finalUploadPort); BaseNoGui.selectSerialPort(finalUploadPort);
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
return uploadResult; return uploadResult;
} }
private String waitForUploadPort(String uploadPort, List<String> before) throws InterruptedException, RunnerException { private String waitForUploadPort(String uploadPort, List<String> before) throws InterruptedException, RunnerException {
return waitForUploadPort(uploadPort, before, verbose);
}
private String waitForUploadPort(String uploadPort, List<String> before, boolean verbose) throws InterruptedException, RunnerException {
// Wait for a port to appear on the list // Wait for a port to appear on the list
int elapsed = 0; int elapsed = 0;
while (elapsed < 10000) { while (elapsed < 10000) {