Skip to content

Commit ffba05f

Browse files
facchinmcmaglie
authored andcommitted
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 ##3495
1 parent 4d26ec8 commit ffba05f

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
199199
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
200200
}
201201

202-
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
203-
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
204-
205202
String finalUploadPort = null;
206203
if (uploadResult && doTouch) {
207204
try {
@@ -210,34 +207,32 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
210207
// sketch serial port reconnects (or timeout after a few seconds if the
211208
// sketch port never comes back). Doing this saves users from accidentally
212209
// opening Serial Monitor on the soon-to-be-orphaned bootloader port.
213-
Thread.sleep(1000);
214-
long started = System.currentTimeMillis();
215-
while (System.currentTimeMillis() - started < 2000) {
216-
List<String> portList = Serial.list();
217-
if (portList.contains(userSelectedUploadPort)) {
218-
finalUploadPort = userSelectedUploadPort;
219-
break;
220-
}
221-
Thread.sleep(250);
222-
}
210+
211+
// Reuse waitForUploadPort for this task, but this time we are simply waiting
212+
// for one port to reappear. If no port reappears before the timeout, actualUploadPort is selected
213+
finalUploadPort = waitForUploadPort(actualUploadPort, Serial.list(), false);
223214
}
224215
} catch (InterruptedException ex) {
225216
// noop
226217
}
227218
}
228219

229-
if (finalUploadPort == null) {
230-
finalUploadPort = actualUploadPort;
231-
}
232220
if (finalUploadPort == null) {
233221
finalUploadPort = userSelectedUploadPort;
234222
}
235223
BaseNoGui.selectSerialPort(finalUploadPort);
236224

225+
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false);
226+
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
227+
237228
return uploadResult;
238229
}
239230

240231
private String waitForUploadPort(String uploadPort, List<String> before) throws InterruptedException, RunnerException {
232+
return waitForUploadPort(uploadPort, before, verbose);
233+
}
234+
235+
private String waitForUploadPort(String uploadPort, List<String> before, boolean verbose) throws InterruptedException, RunnerException {
241236
// Wait for a port to appear on the list
242237
int elapsed = 0;
243238
while (elapsed < 10000) {

0 commit comments

Comments
 (0)