Skip to content

Commit 443d0e1

Browse files
committed

18 files changed

+802
-508
lines changed

app/src/processing/app/Base.java

+187-128
Large diffs are not rendered by default.

app/src/processing/app/Editor.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class Editor extends JFrame implements RunnerListener {
150150
Runnable exportAppHandler;
151151

152152

153-
public Editor(Base ibase, String path, int[] location) {
153+
public Editor(Base ibase, String path, int[] location) throws Exception {
154154
super("Arduino");
155155
this.base = ibase;
156156

@@ -476,7 +476,7 @@ protected void applyPreferences() {
476476
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
477477

478478

479-
protected void buildMenuBar() {
479+
protected void buildMenuBar() throws Exception {
480480
JMenuBar menubar = new JMenuBar();
481481
menubar.add(buildFileMenu());
482482
menubar.add(buildEditMenu());
@@ -494,15 +494,23 @@ protected JMenu buildFileMenu() {
494494
item = newJMenuItem(_("New"), 'N');
495495
item.addActionListener(new ActionListener() {
496496
public void actionPerformed(ActionEvent e) {
497-
base.handleNew();
497+
try {
498+
base.handleNew();
499+
} catch (Exception e1) {
500+
e1.printStackTrace();
501+
}
498502
}
499503
});
500504
fileMenu.add(item);
501505

502506
item = Editor.newJMenuItem(_("Open..."), 'O');
503507
item.addActionListener(new ActionListener() {
504508
public void actionPerformed(ActionEvent e) {
505-
base.handleOpenPrompt();
509+
try {
510+
base.handleOpenPrompt();
511+
} catch (Exception e1) {
512+
e1.printStackTrace();
513+
}
506514
}
507515
});
508516
fileMenu.add(item);
@@ -662,7 +670,7 @@ public void actionPerformed(ActionEvent e) {
662670
}
663671

664672

665-
protected JMenu buildToolsMenu() {
673+
protected JMenu buildToolsMenu() throws Exception {
666674
toolsMenu = new JMenu(_("Tools"));
667675
JMenu menu = toolsMenu;
668676
JMenuItem item;
@@ -690,6 +698,11 @@ public void actionPerformed(ActionEvent e) {
690698

691699
if (boardsMenus == null) {
692700
boardsMenus = new LinkedList<JMenu>();
701+
702+
JMenu boardsMenu = new JMenu(_("Board"));
703+
Editor.boardsMenus.add(boardsMenu);
704+
toolsMenu.add(boardsMenu);
705+
693706
base.rebuildBoardsMenu(toolsMenu, this);
694707
//Debug: rebuild imports
695708
importMenu.removeAll();

app/src/processing/app/EditorToolbar.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,13 @@ public void mousePressed(MouseEvent e) {
335335

336336
case NEW:
337337
if (shiftPressed) {
338-
editor.base.handleNew();
338+
try {
339+
editor.base.handleNew();
340+
} catch (Exception e1) {
341+
e1.printStackTrace();
342+
}
339343
} else {
340-
editor.base.handleNewReplace();
344+
editor.base.handleNewReplace();
341345
}
342346
break;
343347

app/src/processing/app/debug/BasicUploader.java

+33-10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333

3434
import processing.app.Base;
35+
import processing.app.I18n;
3536
import processing.app.Preferences;
3637
import processing.app.Serial;
3738
import processing.app.SerialException;
@@ -249,18 +250,46 @@ public boolean uploadUsingProgrammer(String buildPath, String className)
249250
}
250251

251252
public boolean burnBootloader() throws RunnerException {
252-
String programmer = Preferences.get("programmer");
253253
TargetPlatform targetPlatform = Base.getTargetPlatform();
254+
255+
// Find preferences for the selected programmer
256+
PreferencesMap programmerPrefs;
257+
String programmer = Preferences.get("programmer");
254258
if (programmer.contains(":")) {
255259
String[] split = programmer.split(":", 2);
256-
targetPlatform = Base.getCurrentTargetPlatformFromPackage(split[0]);
260+
TargetPlatform platform = Base
261+
.getCurrentTargetPlatformFromPackage(split[0]);
257262
programmer = split[1];
263+
programmerPrefs = platform.getProgrammer(programmer);
264+
} else {
265+
programmerPrefs = targetPlatform.getProgrammer(programmer);
258266
}
259267

268+
// Build configuration for the current programmer
260269
PreferencesMap prefs = Preferences.getMap();
261270
prefs.putAll(Base.getBoardPreferences());
262-
prefs.putAll(targetPlatform.getProgrammer(programmer));
263-
prefs.putAll(targetPlatform.getTool(prefs.get("bootloader.tool")));
271+
prefs.putAll(programmerPrefs);
272+
273+
// Create configuration for bootloader tool
274+
PreferencesMap toolPrefs = new PreferencesMap();
275+
String tool = prefs.get("bootloader.tool");
276+
if (tool.contains(":")) {
277+
String[] split = tool.split(":", 2);
278+
TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]);
279+
tool = split[1];
280+
toolPrefs.putAll(platform.getTool(tool));
281+
if (toolPrefs.size() == 0)
282+
throw new RunnerException(
283+
I18n.format(_("Could not find tool {0} from package {1}"), tool,
284+
split[0]));
285+
}
286+
toolPrefs.putAll(targetPlatform.getTool(tool));
287+
if (toolPrefs.size() == 0)
288+
throw new RunnerException(I18n.format(_("Could not find tool {0}"),
289+
tool));
290+
291+
// Merge tool with global configuration
292+
prefs.putAll(toolPrefs);
264293
if (verbose) {
265294
prefs.put("erase.verbose", prefs.get("erase.params.verbose"));
266295
prefs.put("bootloader.verbose", prefs.get("bootloader.params.verbose"));
@@ -270,12 +299,6 @@ public boolean burnBootloader() throws RunnerException {
270299
}
271300

272301
try {
273-
// if (prefs.get("program.disable_flushing") == null
274-
// || prefs.get("program.disable_flushing").toLowerCase().equals("false"))
275-
// {
276-
// flushSerialBuffer();
277-
// }
278-
279302
String pattern = prefs.get("erase.pattern");
280303
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
281304
if (!executeUploadCommand(cmd))

app/src/processing/app/debug/Compiler.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,29 @@ private PreferencesMap createBuildPreferences(String _buildPath,
132132
throw re;
133133
}
134134

135+
// Check if the board needs a platform from another package
135136
TargetPlatform targetPlatform = Base.getTargetPlatform();
137+
TargetPlatform corePlatform = null;
138+
PreferencesMap boardPreferences = Base.getBoardPreferences();
139+
String core = boardPreferences.get("build.core");
140+
if (core.contains(":")) {
141+
String[] split = core.split(":");
142+
core = split[1];
143+
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
144+
if (corePlatform == null) {
145+
RunnerException re = new RunnerException(I18n
146+
.format(_("Selected board depends on '{0}' core (not installed)."),
147+
split[0]));
148+
re.hideStackTrace();
149+
throw re;
150+
}
151+
}
136152

137153
// Merge all the global preference configuration in order of priority
138154
PreferencesMap p = new PreferencesMap();
139155
p.putAll(Preferences.getMap());
156+
if (corePlatform != null)
157+
p.putAll(corePlatform.getPreferences());
140158
p.putAll(targetPlatform.getPreferences());
141159
p.putAll(Base.getBoardPreferences());
142160
for (String k : p.keySet()) {
@@ -146,28 +164,23 @@ private PreferencesMap createBuildPreferences(String _buildPath,
146164

147165
p.put("build.path", _buildPath);
148166
p.put("build.project_name", _primaryClassName);
149-
targetArch = targetPlatform.getName();
167+
targetArch = targetPlatform.getId();
150168
p.put("build.arch", targetArch.toUpperCase());
151169

152170
if (!p.containsKey("compiler.path"))
153171
p.put("compiler.path", Base.getAvrBasePath());
154172

155173
// Core folder
156-
String core = p.get("build.core");
157-
TargetPlatform tp;
158-
if (!core.contains(":")) {
174+
TargetPlatform tp = corePlatform;
175+
if (tp == null)
159176
tp = targetPlatform;
160-
} else {
161-
String[] split = core.split(":", 2);
162-
tp = Base.getTargetPlatform(split[0], Preferences.get("target_platform"));
163-
core = split[1];
164-
}
165177
File coreFolder = new File(tp.getFolder(), "cores");
166178
coreFolder = new File(coreFolder, core);
179+
p.put("build.core", core);
167180
p.put("build.core.path", coreFolder.getAbsolutePath());
168181

169182
// System Folder
170-
File systemFolder = targetPlatform.getFolder();
183+
File systemFolder = tp.getFolder();
171184
systemFolder = new File(systemFolder, "system");
172185
p.put("build.system.path", systemFolder.getAbsolutePath());
173186

@@ -179,8 +192,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
179192
t = targetPlatform;
180193
} else {
181194
String[] split = variant.split(":", 2);
182-
t = Base
183-
.getTargetPlatform(split[0], Preferences.get("target_platform"));
195+
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
184196
variant = split[1];
185197
}
186198
File variantFolder = new File(t.getFolder(), "variants");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package processing.app.debug;
2+
3+
import static processing.app.I18n._;
4+
import static processing.app.I18n.format;
5+
6+
import java.util.LinkedHashMap;
7+
import java.util.Map;
8+
import java.util.Set;
9+
10+
import processing.app.helpers.PreferencesMap;
11+
12+
public class TargetBoard {
13+
14+
private String id;
15+
private PreferencesMap prefs;
16+
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
17+
private TargetPlatform containerPlatform;
18+
19+
/**
20+
* Create a TargetBoard based on preferences passed as argument.
21+
*
22+
* @param _prefs
23+
* @return
24+
*/
25+
public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
26+
containerPlatform = parent;
27+
id = _id;
28+
prefs = new PreferencesMap(_prefs);
29+
30+
// Setup sub-menus
31+
PreferencesMap menus = prefs.firstLevelMap().get("menu");
32+
if (menus != null)
33+
menuOptions = menus.firstLevelMap();
34+
35+
// Auto generate build.board if not set
36+
if (!prefs.containsKey("build.board")) {
37+
String board = containerPlatform.getId() + "_" + id;
38+
board = board.toUpperCase();
39+
prefs.put("build.board", board);
40+
System.out
41+
.println(format(
42+
_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
43+
containerPlatform.getContainerPackage().getId(),
44+
containerPlatform.getId(), id, board));
45+
}
46+
}
47+
48+
/**
49+
* Get the name of the board.
50+
*
51+
* @return
52+
*/
53+
public String getName() {
54+
return prefs.get("name");
55+
}
56+
57+
/**
58+
* Get the identifier of the board
59+
*
60+
* @return
61+
*/
62+
public String getId() {
63+
return id;
64+
}
65+
66+
/**
67+
* Get the full preferences map of the board with a given identifier
68+
*
69+
* @return
70+
*/
71+
public PreferencesMap getPreferences() {
72+
return prefs;
73+
}
74+
75+
/**
76+
* Check if the board has a sub menu.
77+
*
78+
* @param menuId
79+
* The menu ID to check
80+
* @return
81+
*/
82+
public boolean hasMenu(String menuId) {
83+
return menuOptions.containsKey(menuId);
84+
}
85+
86+
/**
87+
* Returns the options available on a specific menu
88+
*
89+
* @param menuId
90+
* The menu ID
91+
* @return
92+
*/
93+
public PreferencesMap getMenuLabels(String menuId) {
94+
return menuOptions.get(menuId).topLevelMap();
95+
}
96+
97+
/**
98+
* Returns the label of the specified option in the specified menu
99+
*
100+
* @param menuId
101+
* The menu ID
102+
* @param selectionId
103+
* The option ID
104+
* @return
105+
*/
106+
public String getMenuLabel(String menuId, String selectionId) {
107+
return getMenuLabels(menuId).get(selectionId);
108+
}
109+
110+
public Set<String> getMenuIds() {
111+
return menuOptions.keySet();
112+
}
113+
114+
/**
115+
* Returns the configuration parameters to override (as a PreferenceMap) when
116+
* the specified option in the specified menu is selected
117+
*
118+
* @param menuId
119+
* The menu ID
120+
* @param selectionId
121+
* The option ID
122+
* @return
123+
*/
124+
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
125+
return menuOptions.get(menuId).subTree(selectionId);
126+
}
127+
128+
public TargetPlatform getContainerPlatform() {
129+
return containerPlatform;
130+
}
131+
132+
}

0 commit comments

Comments
 (0)