Skip to content

Commit e2b9920

Browse files
committed
Tweaks to post-upload touch for Leonardo upload.
Added a delay to avoid exceptions when touching the serial port. Only printing the debug message in verbose mode.
1 parent 5fa8cd4 commit e2b9920

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private boolean uploadViaBootloader(String buildPath, String className)
138138
// come back, so use a longer time out before assuming that the selected
139139
// port is the bootloader (not the sketch).
140140
if (((!Base.isWindows() && elapsed >= 500) || elapsed >= 5000) && now.contains(uploadPort)) {
141-
if (verbose || Preferences.getBoolean("upload.verbose"))
141+
if (verbose || Preferences.getBoolean("upload.verbose"))
142142
System.out.println("Uploading using selected port: " + uploadPort);
143143
caterinaUploadPort = uploadPort;
144144
break;
@@ -174,29 +174,33 @@ private boolean uploadViaBootloader(String buildPath, String className)
174174

175175
boolean avrdudeResult = avrdude(commandDownloader);
176176

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.
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.
181181
if (true == avrdudeResult && boardPreferences.get("bootloader.path") != null && 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-
uploadPort = Preferences.get("serial.port");
189-
if (portList.contains(uploadPort)) {
190-
// Remove the magic baud rate (1200bps) to avoid future unwanted board resets
191-
int serialRate = Preferences.getInteger("serial.debug_rate");
192-
System.out.println("Set baud rate to " + serialRate);
193-
Serial.touchPort(uploadPort, serialRate);
194-
break;
195-
}
196-
try {
197-
Thread.sleep(100);
198-
} catch (InterruptedException ex) { }
199-
}
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+
uploadPort = Preferences.get("serial.port");
189+
if (portList.contains(uploadPort)) {
190+
try {
191+
Thread.sleep(100); // delay to avoid port in use and invalid parameters errors
192+
} catch (InterruptedException ex) { }
193+
// Remove the magic baud rate (1200bps) to avoid future unwanted board resets
194+
int serialRate = Preferences.getInteger("serial.debug_rate");
195+
if (verbose || Preferences.getBoolean("upload.verbose"))
196+
System.out.println("Setting baud rate to " + serialRate + " on " + uploadPort);
197+
Serial.touchPort(uploadPort, serialRate);
198+
break;
199+
}
200+
try {
201+
Thread.sleep(100);
202+
} catch (InterruptedException ex) { }
203+
}
200204
}
201205

202206
return avrdudeResult;

0 commit comments

Comments
 (0)