Skip to content

Commit fbc5d30

Browse files
committed
for Leonardo don't return from uploading until the bootloader port disconnects and the sketch port reconnects
meant to save users from accidentally opening the bootloader port in Serial Monitor when it is still open immediately after an upload. this is bad for the user because the port dies without notice immediately afterward.
1 parent 79ffd4f commit fbc5d30

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

app/src/processing/app/debug/AvrdudeUploader.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,29 @@ private boolean uploadViaBootloader(String buildPath, String className)
172172
flushSerialBuffer();
173173
}
174174

175-
return avrdude(commandDownloader);
175+
boolean avrdudeResult = avrdude(commandDownloader);
176+
177+
// For Leonardo wait until the bootloader serial port disconnects and the sketch serial
178+
// port reconnects (or timeout after a few seconds if the sketch port never comes back).
179+
// Doing this saves users from accidentally opening Serial Monitor on the soon-to-be-orphaned
180+
// bootloader port.
181+
if (true == avrdudeResult && boardPreferences.get("bootloader.path").equals("caterina")) {
182+
try {
183+
Thread.sleep(500);
184+
} catch (InterruptedException ex) { }
185+
long timeout = System.currentTimeMillis() + 2000;
186+
while (timeout > System.currentTimeMillis()) {
187+
List<String> portList = Serial.list();
188+
if (portList.contains(Preferences.get("serial.port"))) {
189+
break;
190+
}
191+
try {
192+
Thread.sleep(100);
193+
} catch (InterruptedException ex) { }
194+
}
195+
}
196+
197+
return avrdudeResult;
176198
}
177199

178200
public boolean burnBootloader() throws RunnerException {

0 commit comments

Comments
 (0)