Skip to content

Refactor port selection after 1200bps touch upload #8218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
}

BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);

String finalUploadPort = null;
if (uploadResult && doTouch) {
try {
Expand All @@ -210,34 +207,32 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
// sketch serial port reconnects (or timeout after a few seconds if the
// sketch port never comes back). Doing this saves users from accidentally
// opening Serial Monitor on the soon-to-be-orphaned bootloader port.
Thread.sleep(1000);
long started = System.currentTimeMillis();
while (System.currentTimeMillis() - started < 2000) {
List<String> portList = Serial.list();
if (portList.contains(userSelectedUploadPort)) {
finalUploadPort = userSelectedUploadPort;
break;
}
Thread.sleep(250);
}

// Reuse waitForUploadPort for this task, but this time we are simply waiting
// for one port to reappear. If no port reappears before the timeout, actualUploadPort is selected
finalUploadPort = waitForUploadPort(actualUploadPort, Serial.list(), false);
}
} catch (InterruptedException ex) {
// noop
}
}

if (finalUploadPort == null) {
finalUploadPort = actualUploadPort;
}
if (finalUploadPort == null) {
finalUploadPort = userSelectedUploadPort;
}
BaseNoGui.selectSerialPort(finalUploadPort);

BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);

return uploadResult;
}

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
int elapsed = 0;
while (elapsed < 10000) {
Expand Down