1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

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.
This commit is contained in:
Zach Eveland 2012-04-07 22:47:07 -04:00
parent 79ffd4fa1b
commit fbc5d30ad7

View File

@ -172,7 +172,29 @@ public class AvrdudeUploader extends Uploader {
flushSerialBuffer(); flushSerialBuffer();
} }
return avrdude(commandDownloader); boolean avrdudeResult = avrdude(commandDownloader);
// For Leonardo wait until the bootloader serial port disconnects and the 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.
if (true == avrdudeResult && boardPreferences.get("bootloader.path").equals("caterina")) {
try {
Thread.sleep(500);
} catch (InterruptedException ex) { }
long timeout = System.currentTimeMillis() + 2000;
while (timeout > System.currentTimeMillis()) {
List<String> portList = Serial.list();
if (portList.contains(Preferences.get("serial.port"))) {
break;
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) { }
}
}
return avrdudeResult;
} }
public boolean burnBootloader() throws RunnerException { public boolean burnBootloader() throws RunnerException {