mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
parent
c24b3f6489
commit
8ab419fd13
@ -23,6 +23,7 @@
|
|||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
import processing.app.debug.*;
|
import processing.app.debug.*;
|
||||||
|
import processing.app.helpers.PreferencesMapException;
|
||||||
import processing.app.syntax.*;
|
import processing.app.syntax.*;
|
||||||
import processing.app.tools.*;
|
import processing.app.tools.*;
|
||||||
import processing.core.*;
|
import processing.core.*;
|
||||||
@ -2543,9 +2544,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
statusError(_("Error while burning bootloader."));
|
statusError(_("Error while burning bootloader."));
|
||||||
// error message will already be visible
|
// error message will already be visible
|
||||||
}
|
}
|
||||||
} catch (RunnerException e) {
|
} catch (PreferencesMapException e) {
|
||||||
statusError(_("Error while burning bootloader."));
|
statusError(I18n.format(
|
||||||
e.printStackTrace();
|
_("Error while burning bootloader: missing '{0}' configuration parameter"),
|
||||||
|
e.getMessage()));
|
||||||
//statusError(e);
|
//statusError(e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
statusError(_("Error while burning bootloader."));
|
statusError(_("Error while burning bootloader."));
|
||||||
|
@ -1581,7 +1581,7 @@ public class Sketch {
|
|||||||
* Handle export to applet.
|
* Handle export to applet.
|
||||||
*/
|
*/
|
||||||
public boolean exportApplet(String appletPath, boolean usingProgrammer)
|
public boolean exportApplet(String appletPath, boolean usingProgrammer)
|
||||||
throws RunnerException, IOException, SerialException {
|
throws Exception {
|
||||||
|
|
||||||
prepare();
|
prepare();
|
||||||
|
|
||||||
@ -1660,7 +1660,7 @@ public class Sketch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer)
|
protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer)
|
||||||
throws RunnerException, SerialException {
|
throws Exception {
|
||||||
|
|
||||||
Uploader uploader;
|
Uploader uploader;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ import processing.app.Preferences;
|
|||||||
import processing.app.Serial;
|
import processing.app.Serial;
|
||||||
import processing.app.SerialException;
|
import processing.app.SerialException;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
import processing.app.helpers.PreferencesMapException;
|
||||||
import processing.app.helpers.StringReplacer;
|
import processing.app.helpers.StringReplacer;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import static processing.app.I18n._;
|
||||||
@ -45,7 +46,7 @@ public class BasicUploader extends Uploader {
|
|||||||
|
|
||||||
public boolean uploadUsingPreferences(String buildPath, String className,
|
public boolean uploadUsingPreferences(String buildPath, String className,
|
||||||
boolean usingProgrammer)
|
boolean usingProgrammer)
|
||||||
throws RunnerException, SerialException {
|
throws Exception {
|
||||||
// FIXME: Preferences should be reorganized
|
// FIXME: Preferences should be reorganized
|
||||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||||
PreferencesMap prefs = Preferences.getMap();
|
PreferencesMap prefs = Preferences.getMap();
|
||||||
@ -71,7 +72,7 @@ public class BasicUploader extends Uploader {
|
|||||||
boolean waitForUploadPort = (t != null) && t.equals("true");
|
boolean waitForUploadPort = (t != null) && t.equals("true");
|
||||||
|
|
||||||
if (doTouch) {
|
if (doTouch) {
|
||||||
String uploadPort = prefs.get("serial.port");
|
String uploadPort = prefs.getOrExcept("serial.port");
|
||||||
try {
|
try {
|
||||||
// Toggle 1200 bps on selected serial port to force board reset.
|
// Toggle 1200 bps on selected serial port to force board reset.
|
||||||
List<String> before = Serial.list();
|
List<String> before = Serial.list();
|
||||||
@ -109,9 +110,9 @@ public class BasicUploader extends Uploader {
|
|||||||
prefs.put("build.path", buildPath);
|
prefs.put("build.path", buildPath);
|
||||||
prefs.put("build.project_name", className);
|
prefs.put("build.project_name", className);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
prefs.put("upload.verbose", prefs.get("upload.params.verbose"));
|
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
|
||||||
else
|
else
|
||||||
prefs.put("upload.verbose", prefs.get("upload.params.quiet"));
|
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
|
||||||
|
|
||||||
boolean uploadResult;
|
boolean uploadResult;
|
||||||
try {
|
try {
|
||||||
@ -120,7 +121,7 @@ public class BasicUploader extends Uploader {
|
|||||||
// flushSerialBuffer();
|
// flushSerialBuffer();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String pattern = prefs.get("upload.pattern");
|
String pattern = prefs.getOrExcept("upload.pattern");
|
||||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||||
uploadResult = executeUploadCommand(cmd);
|
uploadResult = executeUploadCommand(cmd);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -211,7 +212,7 @@ public class BasicUploader extends Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean uploadUsingProgrammer(String buildPath, String className)
|
public boolean uploadUsingProgrammer(String buildPath, String className)
|
||||||
throws RunnerException {
|
throws Exception {
|
||||||
|
|
||||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||||
String programmer = Preferences.get("programmer");
|
String programmer = Preferences.get("programmer");
|
||||||
@ -224,15 +225,15 @@ public class BasicUploader extends Uploader {
|
|||||||
PreferencesMap prefs = Preferences.getMap();
|
PreferencesMap prefs = Preferences.getMap();
|
||||||
prefs.putAll(Base.getBoardPreferences());
|
prefs.putAll(Base.getBoardPreferences());
|
||||||
prefs.putAll(targetPlatform.getProgrammer(programmer));
|
prefs.putAll(targetPlatform.getProgrammer(programmer));
|
||||||
prefs.putAll(targetPlatform.getTool(prefs.get("program.tool")));
|
prefs.putAll(targetPlatform.getTool(prefs.getOrExcept("program.tool")));
|
||||||
|
|
||||||
prefs.put("build.path", buildPath);
|
prefs.put("build.path", buildPath);
|
||||||
prefs.put("build.project_name", className);
|
prefs.put("build.project_name", className);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
prefs.put("program.verbose", prefs.get("program.params.verbose"));
|
prefs.put("program.verbose", prefs.getOrExcept("program.params.verbose"));
|
||||||
else
|
else
|
||||||
prefs.put("program.verbose", prefs.get("program.params.quiet"));
|
prefs.put("program.verbose", prefs.getOrExcept("program.params.quiet"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// if (prefs.get("program.disable_flushing") == null
|
// if (prefs.get("program.disable_flushing") == null
|
||||||
@ -241,7 +242,7 @@ public class BasicUploader extends Uploader {
|
|||||||
// flushSerialBuffer();
|
// flushSerialBuffer();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String pattern = prefs.get("program.pattern");
|
String pattern = prefs.getOrExcept("program.pattern");
|
||||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||||
return executeUploadCommand(cmd);
|
return executeUploadCommand(cmd);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -249,7 +250,7 @@ public class BasicUploader extends Uploader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean burnBootloader() throws RunnerException {
|
public boolean burnBootloader() throws RunnerException, PreferencesMapException {
|
||||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||||
|
|
||||||
// Find preferences for the selected programmer
|
// Find preferences for the selected programmer
|
||||||
@ -272,7 +273,7 @@ public class BasicUploader extends Uploader {
|
|||||||
|
|
||||||
// Create configuration for bootloader tool
|
// Create configuration for bootloader tool
|
||||||
PreferencesMap toolPrefs = new PreferencesMap();
|
PreferencesMap toolPrefs = new PreferencesMap();
|
||||||
String tool = prefs.get("bootloader.tool");
|
String tool = prefs.getOrExcept("bootloader.tool");
|
||||||
if (tool.contains(":")) {
|
if (tool.contains(":")) {
|
||||||
String[] split = tool.split(":", 2);
|
String[] split = tool.split(":", 2);
|
||||||
TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
@ -291,20 +292,20 @@ public class BasicUploader extends Uploader {
|
|||||||
// Merge tool with global configuration
|
// Merge tool with global configuration
|
||||||
prefs.putAll(toolPrefs);
|
prefs.putAll(toolPrefs);
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
prefs.put("erase.verbose", prefs.get("erase.params.verbose"));
|
prefs.put("erase.verbose", prefs.getOrExcept("erase.params.verbose"));
|
||||||
prefs.put("bootloader.verbose", prefs.get("bootloader.params.verbose"));
|
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.verbose"));
|
||||||
} else {
|
} else {
|
||||||
prefs.put("erase.verbose", prefs.get("erase.params.quiet"));
|
prefs.put("erase.verbose", prefs.getOrExcept("erase.params.quiet"));
|
||||||
prefs.put("bootloader.verbose", prefs.get("bootloader.params.quiet"));
|
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet"));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String pattern = prefs.get("erase.pattern");
|
String pattern = prefs.getOrExcept("erase.pattern");
|
||||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||||
if (!executeUploadCommand(cmd))
|
if (!executeUploadCommand(cmd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
pattern = prefs.get("bootloader.pattern");
|
pattern = prefs.getOrExcept("bootloader.pattern");
|
||||||
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||||
return executeUploadCommand(cmd);
|
return executeUploadCommand(cmd);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -35,7 +35,6 @@ import java.util.Collection;
|
|||||||
import processing.app.I18n;
|
import processing.app.I18n;
|
||||||
import processing.app.Preferences;
|
import processing.app.Preferences;
|
||||||
import processing.app.Serial;
|
import processing.app.Serial;
|
||||||
import processing.app.SerialException;
|
|
||||||
import processing.app.SerialNotFoundException;
|
import processing.app.SerialNotFoundException;
|
||||||
|
|
||||||
public abstract class Uploader implements MessageConsumer {
|
public abstract class Uploader implements MessageConsumer {
|
||||||
@ -52,11 +51,11 @@ public abstract class Uploader implements MessageConsumer {
|
|||||||
boolean verbose;
|
boolean verbose;
|
||||||
|
|
||||||
public abstract boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
|
public abstract boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
|
||||||
throws RunnerException, SerialException;
|
throws Exception;
|
||||||
|
|
||||||
public abstract boolean burnBootloader() throws RunnerException;
|
public abstract boolean burnBootloader() throws Exception;
|
||||||
|
|
||||||
protected void flushSerialBuffer() throws RunnerException, SerialException {
|
protected void flushSerialBuffer() throws Exception {
|
||||||
// Cleanup the serial buffer
|
// Cleanup the serial buffer
|
||||||
try {
|
try {
|
||||||
Serial serialPort = new Serial();
|
Serial serialPort = new Serial();
|
||||||
@ -87,14 +86,14 @@ public abstract class Uploader implements MessageConsumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean executeUploadCommand(Collection<String> commandDownloader)
|
protected boolean executeUploadCommand(Collection<String> commandDownloader)
|
||||||
throws RunnerException {
|
throws Exception {
|
||||||
String[] commandArray = new String[commandDownloader.size()];
|
String[] commandArray = new String[commandDownloader.size()];
|
||||||
commandDownloader.toArray(commandArray);
|
commandDownloader.toArray(commandArray);
|
||||||
return executeUploadCommand(commandArray);
|
return executeUploadCommand(commandArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean executeUploadCommand(String commandArray[])
|
protected boolean executeUploadCommand(String commandArray[])
|
||||||
throws RunnerException
|
throws Exception
|
||||||
{
|
{
|
||||||
firstErrorFound = false; // haven't found any errors yet
|
firstErrorFound = false; // haven't found any errors yet
|
||||||
secondErrorFound = false;
|
secondErrorFound = false;
|
||||||
|
@ -245,6 +245,22 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value to which the specified key is mapped, or throws a
|
||||||
|
* PreferencesMapException if not found
|
||||||
|
*
|
||||||
|
* @param k
|
||||||
|
* the key whose associated value is to be returned
|
||||||
|
* @return the value to which the specified key is mapped
|
||||||
|
* @throws PreferencesMapException
|
||||||
|
*/
|
||||||
|
public String getOrExcept(String k) throws PreferencesMapException {
|
||||||
|
String r = get(k);
|
||||||
|
if (r == null)
|
||||||
|
throw new PreferencesMapException(k);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toString("");
|
return toString("");
|
||||||
|
10
app/src/processing/app/helpers/PreferencesMapException.java
Normal file
10
app/src/processing/app/helpers/PreferencesMapException.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package processing.app.helpers;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class PreferencesMapException extends Exception {
|
||||||
|
|
||||||
|
public PreferencesMapException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user