Skip to content

Merge Upload and Upload using programmer options #2073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/cc/arduino/packages/Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected Uploader() {
this.notFoundError = false;
}

public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception;
public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, List<String> warningsAccumulator) throws Exception;

public abstract boolean burnBootloader() throws Exception;

Expand Down
4 changes: 2 additions & 2 deletions app/src/cc/arduino/packages/uploaders/SSHUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public String getAuthorizationKey() {
}

@Override
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws RunnerException {
if (usingProgrammer) {
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, List<String> warningsAccumulator) throws RunnerException {
if (!Preferences.get("programmer").equals("internal")) {
throw new RunnerException(_("Network upload using programmer not supported"));
}

Expand Down
20 changes: 13 additions & 7 deletions app/src/cc/arduino/packages/uploaders/SerialUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@

public class SerialUploader extends Uploader {

public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, List<String> warningsAccumulator) throws Exception {
if (Preferences.get("programmer").equals("internal"))
return uploadUsingBootloader(buildPath, className);
else
return uploadUsingProgrammer(buildPath, className);
}

public boolean uploadUsingBootloader(String buildPath, String className) throws Exception {
// FIXME: Preferences should be reorganized
TargetPlatform targetPlatform = Base.getTargetPlatform();
PreferencesMap prefs = Preferences.getMap();
prefs.putAll(Base.getBoardPreferences());

// if no protocol is specified for this board, assume it lacks a bootloader
if (prefs.get("upload.protocol") == null)
throw new RunnerException(_("Upload using bootloader not supported for this board"));

String tool = prefs.getOrExcept("upload.tool");
if (tool.contains(":")) {
String[] split = tool.split(":", 2);
Expand All @@ -54,12 +66,6 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
}
prefs.putAll(targetPlatform.getTool(tool));

// if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer.
if (usingProgrammer || prefs.get("upload.protocol") == null) {
return uploadUsingProgrammer(buildPath, className);
}

// need to do a little dance for Leonardo and derivatives:
// open then close the port at the magic baudrate (usually 1200 bps) first
// to signal to the sketch that it should reset into bootloader. after doing
Expand Down
32 changes: 18 additions & 14 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1588,28 +1588,32 @@ private void selectBoard(TargetBoard targetBoard) {
rebuildExamplesMenu(Editor.examplesMenu);
}

private void addProgrammerMenuOption(JMenu menu, ButtonGroup group, String id, String name) {
@SuppressWarnings("serial")
AbstractAction action = new AbstractAction(name) {
public void actionPerformed(ActionEvent actionevent) {
Preferences.set("programmer", "" + getValue("id"));
}
};
action.putValue("id", id);
JMenuItem item = new JRadioButtonMenuItem(action);
if (Preferences.get("programmer").equals(id))
item.setSelected(true);
group.add(item);
menu.add(item);
}

public void rebuildProgrammerMenu(JMenu menu) {
menu.removeAll();
ButtonGroup group = new ButtonGroup();
addProgrammerMenuOption(menu, group, "internal", _("Internal (bootloader)"));
menu.addSeparator();
for (TargetPackage targetPackage : packages.values()) {
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
for (String programmer : targetPlatform.getProgrammers().keySet()) {
String id = targetPackage.getId() + ":" + programmer;

@SuppressWarnings("serial")
AbstractAction action = new AbstractAction(targetPlatform
.getProgrammer(programmer).get("name")) {
public void actionPerformed(ActionEvent actionevent) {
Preferences.set("programmer", "" + getValue("id"));
}
};
action.putValue("id", id);
JMenuItem item = new JRadioButtonMenuItem(action);
if (Preferences.get("programmer").equals(id))
item.setSelected(true);
group.add(item);
menu.add(item);
String name = targetPlatform.getProgrammer(programmer).get("name");
addProgrammerMenuOption(menu, group, id, name);
}
}
}
Expand Down
63 changes: 5 additions & 58 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public class Editor extends JFrame implements RunnerListener {
Runnable presentHandler;
Runnable stopHandler;
Runnable exportHandler;
Runnable exportAppHandler;


public Editor(Base ibase, String path, int[] location) throws Exception {
Expand Down Expand Up @@ -558,15 +557,7 @@ public void actionPerformed(ActionEvent e) {
item = newJMenuItem(_("Upload"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(false);
}
});
fileMenu.add(item);

item = newJMenuItemShift(_("Upload Using Programmer"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(true);
handleExport();
}
});
fileMenu.add(item);
Expand Down Expand Up @@ -1410,12 +1401,11 @@ protected void updateRedoState() {

public void setHandlers(Runnable runHandler, Runnable presentHandler,
Runnable stopHandler,
Runnable exportHandler, Runnable exportAppHandler) {
Runnable exportHandler) {
this.runHandler = runHandler;
this.presentHandler = presentHandler;
this.stopHandler = stopHandler;
this.exportHandler = exportHandler;
this.exportAppHandler = exportAppHandler;
}


Expand All @@ -1424,7 +1414,6 @@ public void resetHandlers() {
presentHandler = new DefaultPresentHandler();
stopHandler = new DefaultStopHandler();
exportHandler = new DefaultExportHandler();
exportAppHandler = new DefaultExportAppHandler();
}


Expand Down Expand Up @@ -2373,13 +2362,13 @@ public boolean serialPrompt() {
* Made synchronized to (hopefully) avoid problems of people
* hitting export twice, quickly, and horking things up.
*/
synchronized public void handleExport(final boolean usingProgrammer) {
synchronized public void handleExport() {
//if (!handleExportCheckModified()) return;
toolbar.activate(EditorToolbar.EXPORT);
console.clear();
status.progress(_("Uploading to I/O Board..."));

new Thread(usingProgrammer ? exportAppHandler : exportHandler).start();
new Thread(exportHandler).start();
}

// DAM: in Arduino, this is upload
Expand All @@ -2394,49 +2383,7 @@ public void run() {

uploading = true;

boolean success = sketch.exportApplet(false);
if (success) {
statusNotice(_("Done uploading."));
} else {
// error message will already be visible
}
} catch (SerialNotFoundException e) {
populatePortMenu();
if (serialMenu.getItemCount() == 0) statusError(e);
else if (serialPrompt()) run();
else statusNotice(_("Upload canceled."));
} catch (PreferencesMapException e) {
statusError(I18n.format(
_("Error while uploading: missing '{0}' configuration parameter"),
e.getMessage()));
} catch (RunnerException e) {
//statusError("Error during upload.");
//e.printStackTrace();
status.unprogress();
statusError(e);
} catch (Exception e) {
e.printStackTrace();
}
status.unprogress();
uploading = false;
//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);
}
}

// DAM: in Arduino, this is upload (with verbose output)
class DefaultExportAppHandler implements Runnable {
public void run() {

try {
if (serialMonitor != null) {
serialMonitor.close();
serialMonitor.setVisible(false);
}

uploading = true;

boolean success = sketch.exportApplet(true);
boolean success = sketch.exportApplet();
if (success) {
statusNotice(_("Done uploading."));
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/src/processing/app/EditorToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key

/** Titles for each button when the shift key is pressed. */
static final String titleShift[] = {
_("Verify"), _("Upload Using Programmer"), _("New Editor Window"), _("Open in Another Window"), _("Save"), _("Serial Monitor")
_("Verify"), _("Upload"), _("New Editor Window"), _("Open in Another Window"), _("Save"), _("Serial Monitor")
};

static final int BUTTON_COUNT = title.length;
Expand Down Expand Up @@ -350,7 +350,7 @@ public void mousePressed(MouseEvent e) {
break;

case EXPORT:
editor.handleExport(e.isShiftDown());
editor.handleExport();
break;

case SERIAL:
Expand Down
12 changes: 6 additions & 6 deletions app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -1593,15 +1593,15 @@ public String build(String buildPath, boolean verbose) throws RunnerException {
return null;
}

protected boolean exportApplet(boolean usingProgrammer) throws Exception {
return exportApplet(tempBuildFolder.getAbsolutePath(), usingProgrammer);
protected boolean exportApplet() throws Exception {
return exportApplet(tempBuildFolder.getAbsolutePath());
}


/**
* Handle export to applet.
*/
public boolean exportApplet(String appletPath, boolean usingProgrammer)
public boolean exportApplet(String appletPath)
throws Exception {

prepare();
Expand All @@ -1622,7 +1622,7 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
// }

editor.status.progressNotice(_("Uploading..."));
boolean success = upload(appletPath, foundName, usingProgrammer);
boolean success = upload(appletPath, foundName);
editor.status.progressUpdate(100);
return success;
}
Expand Down Expand Up @@ -1685,7 +1685,7 @@ protected void size(PreferencesMap prefs) throws RunnerException {
System.err.println(_("Low memory available, stability problems may occur."));
}

protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
protected boolean upload(String buildPath, String suggestedClassName) throws Exception {

TargetPlatform target = Base.getTargetPlatform();
String board = Preferences.get("board");
Expand Down Expand Up @@ -1716,7 +1716,7 @@ protected boolean upload(String buildPath, String suggestedClassName, boolean us

List<String> warningsAccumulator = new LinkedList<String>();
try {
success = uploader.uploadUsingPreferences(getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
success = uploader.uploadUsingPreferences(getFolder(), buildPath, suggestedClassName, warningsAccumulator);
} finally {
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
Expand Down
2 changes: 1 addition & 1 deletion build/shared/lib/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ software=ARDUINO
# Warn when data segment uses greater than this percentage
build.warn_data_percentage = 75

programmer = arduino:avrispmkii
programmer = internal

upload.using = bootloader
upload.verify = true
Expand Down
14 changes: 14 additions & 0 deletions build/shared/manpage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ Below, a few of them are documented but a lot more are available.
new temporary build folder is created on every run and deleted
again when the application is closed.

*programmer*::
The programmer to use for programming the board.

{empty}::
The value should be in the form "__package__:__id__", where
__package__ is identifier of the vendor (the first level folders
inside the 'hardware' directory). __id__ is looked up in the
programmers.txt file(s) for that vendor.

{empty}::
The special value "internal" can be used to select the default
upload method for the board (defined by boards.txt), which
usually means through a serial port and bootloader.

EXIT STATUS
-----------
*0*:: Success
Expand Down