Skip to content

Commit c78c1ef

Browse files
committed
Now have uploading working with the Boards menu. Improved serial port error messages.
1 parent 1f35dce commit c78c1ef

File tree

15 files changed

+218
-139
lines changed

15 files changed

+218
-139
lines changed

app/AvrdudeUploader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ public boolean uploadUsingPreferences(String buildPath, String className)
4444
// 0x000000); force it to continue uploading anyway
4545
commandDownloader.add("-F");
4646

47-
String programmer = Preferences.get("upload.programmer");
47+
String protocol = Preferences.get("boards." + Preferences.get("board") + ".upload.protocol");
4848

4949
// avrdude wants "stk500v1" to distinguish it from stk500v2
50-
if (programmer.equals("stk500"))
51-
programmer = "stk500v1";
52-
commandDownloader.add("-c" + programmer);
53-
if (Preferences.get("upload.programmer").equals("dapa")) {
50+
if (protocol.equals("stk500"))
51+
protocol = "stk500v1";
52+
commandDownloader.add("-c" + protocol);
53+
if (protocol.equals("dapa")) {
5454
// avrdude doesn't need to be told the address of the parallel port
5555
//commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
5656
} else {
5757
commandDownloader.add("-P" + Preferences.get("serial.port"));
5858
commandDownloader.add(
59-
"-b" + Preferences.getInteger("serial.download_rate"));
59+
"-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
6060
}
6161
if (Preferences.getBoolean("upload.erase"))
6262
commandDownloader.add("-e");
@@ -151,7 +151,8 @@ else if(Base.isWindows()) {
151151
}
152152
// XXX: quick hack to chop the "atmega" off of "atmega8" and "atmega168",
153153
// then shove an "m" at the beginning. won't work for attiny's, etc.
154-
commandDownloader.add("-pm" + Preferences.get("build.mcu").substring(6));
154+
commandDownloader.add("-pm" +
155+
Preferences.get("boards." + Preferences.get("board") + ".build.mcu").substring(6));
155156
commandDownloader.addAll(params);
156157

157158
return executeUploadCommand(commandDownloader);

app/Compiler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ else if(Base.isLinux()) {
104104
"-Os", // optimize for size
105105
"-I" + target.getPath(),
106106
"-w", // surpress all warnings
107-
"-mmcu=" + Preferences.get("build.mcu"),
108-
"-DF_CPU=" + Preferences.get("build.f_cpu"),
107+
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
108+
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
109109
};
110110

111111
// use lib directories as include paths
@@ -130,8 +130,8 @@ else if(Base.isLinux()) {
130130
"-I" + target.getPath(),
131131
"-w", // surpress all warnings
132132
"-fno-exceptions",
133-
"-mmcu=" + Preferences.get("build.mcu"),
134-
"-DF_CPU=" + Preferences.get("build.f_cpu"),
133+
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
134+
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
135135
};
136136

137137
// use lib directories as include paths
@@ -145,7 +145,7 @@ else if(Base.isLinux()) {
145145
String preCommandLinker[] = new String[] {
146146
avrBasePath + "avr-gcc",
147147
" ",
148-
"-mmcu=" + Preferences.get("build.mcu"),
148+
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
149149
"-o",
150150
" ",
151151
};

app/Editor.java

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -783,24 +783,19 @@ public void run() {
783783
*/
784784
menu.addSeparator();
785785

786-
mcuMenu = new JMenu("Microcontroller (MCU)");
787-
String curr_mcu = Preferences.get("build.mcu");
788-
ButtonGroup mcuGroup = new ButtonGroup();
789-
McuMenuListener mml = new McuMenuListener();
790-
791-
item = new JCheckBoxMenuItem("atmega8", "atmega8".equals(curr_mcu));
792-
item.addActionListener(mml);
793-
mcuGroup.add(item);
794-
mcuMenu.add(item);
795-
796-
item = new JCheckBoxMenuItem("atmega168", "atmega168".equals(curr_mcu));
797-
item.addActionListener(mml);
798-
mcuGroup.add(item);
799-
mcuMenu.add(item);
800-
786+
JMenu boardsMenu = new JMenu("Board");
787+
ButtonGroup boardGroup = new ButtonGroup();
788+
for (Iterator i = Preferences.getSubKeys("boards"); i.hasNext(); ) {
789+
String board = (String) i.next();
790+
Action action = new BoardMenuAction(board);
791+
item = new JRadioButtonMenuItem(action);
792+
if (board.equals(Preferences.get("board")))
793+
item.setSelected(true);
794+
boardGroup.add(item);
795+
boardsMenu.add(item);
796+
}
797+
menu.add(boardsMenu);
801798

802-
menu.add(mcuMenu);
803-
804799
serialMenu = new JMenu("Serial Port");
805800
populateSerialMenu();
806801
menu.add(serialMenu);
@@ -913,7 +908,7 @@ public void actionPerformed(ActionEvent e) {
913908

914909
protected void showBootloaderMenuItemsForCurrentMCU() {
915910
boolean onATmega8 =
916-
Preferences.get("build.mcu").equals("atmega8");
911+
Preferences.get("boards." + Preferences.get("board") + ".build.mcu").equals("atmega8");
917912

918913
burnBootloader8Item.setVisible(onATmega8);
919914
if (burnBootloader8ParallelItem != null)
@@ -926,21 +921,16 @@ protected void showBootloaderMenuItemsForCurrentMCU() {
926921
if (burnBootloader168NGParallelItem != null)
927922
burnBootloader168NGParallelItem.setVisible(!onATmega8);
928923
}
929-
930-
class McuMenuListener implements ActionListener {
931-
McuMenuListener() {}
932924

925+
class BoardMenuAction extends AbstractAction {
926+
private String board;
927+
public BoardMenuAction(String board) {
928+
super(Preferences.get("boards." + board + ".name"));
929+
this.board = board;
930+
}
933931
public void actionPerformed(ActionEvent actionevent) {
934-
for (int i = 0; i < mcuMenu.getItemCount(); i++)
935-
if (mcuMenu.getItem(i) instanceof JCheckBoxMenuItem)
936-
((JCheckBoxMenuItem) mcuMenu.getItem(i)).setState(false);
937-
938-
((JCheckBoxMenuItem) actionevent.getSource()).setState(true);
939-
Preferences.set("build.mcu",
940-
((JCheckBoxMenuItem) actionevent.getSource()).getLabel());
941-
942-
showBootloaderMenuItemsForCurrentMCU();
943-
932+
//System.out.println("Switching to " + board);
933+
Preferences.set("board", board);
944934
try {
945935
LibraryManager libraryManager = new LibraryManager();
946936
libraryManager.rebuildAllBuilt();
@@ -1448,7 +1438,8 @@ public void run() {
14481438
try {
14491439
if (!sketch.handleRun(new Target(
14501440
System.getProperty("user.dir") + File.separator + "hardware" +
1451-
File.separator + "cores", Preferences.get("build.target"))))
1441+
File.separator + "cores",
1442+
Preferences.get("boards." + Preferences.get("board") + ".build.core"))))
14521443
return;
14531444

14541445
//runtime = new Runner(sketch, Editor.this);
@@ -1539,11 +1530,15 @@ public void stop() {
15391530

15401531
public void handleSerial() {
15411532
if (!debugging) {
1542-
console.clear();
1543-
buttons.activate(EditorButtons.SERIAL);
1544-
serialPort = new Serial(true);
1545-
debugging = true;
1546-
status.serial();
1533+
try {
1534+
serialPort = new Serial(true);
1535+
console.clear();
1536+
buttons.activate(EditorButtons.SERIAL);
1537+
debugging = true;
1538+
status.serial();
1539+
} catch(SerialException e) {
1540+
error(e);
1541+
}
15471542
} else {
15481543
doStop();
15491544
}
@@ -2057,7 +2052,8 @@ public void run() {
20572052
//sketch.exportLibrary() : sketch.exportApplet();
20582053
boolean success = sketch.exportApplet(new Target(
20592054
System.getProperty("user.dir") + File.separator + "hardware" +
2060-
File.separator + "cores", Preferences.get("build.target")));
2055+
File.separator + "cores",
2056+
Preferences.get("boards." + Preferences.get("board") + ".build.core")));
20612057
if (success) {
20622058
message("Done uploading.");
20632059
} else {

app/EditorStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ public void actionPerformed(ActionEvent e) {
526526
int rate = Integer.parseInt(rateString);
527527
Preferences.set("serial.debug_rate", rateString);
528528
editor.serialPort.dispose();
529-
editor.serialPort = new Serial(true);
529+
try {
530+
editor.serialPort = new Serial(true);
531+
} catch (SerialException err) {
532+
editor.error(err);
533+
}
530534
}
531535
}
532536
}

app/Library.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ else if(Base.isLinux()) {
335335
"-g",
336336
"-Os",
337337
"-Wall",
338-
"-mmcu=" + Preferences.get("build.mcu"),
339-
"-DF_CPU=" + Preferences.get("build.f_cpu"),
338+
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
339+
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
340340
"-I" + libManager.getTarget().getPath(),
341341
"-I" + getFolder(),
342342
};
@@ -348,8 +348,8 @@ else if(Base.isLinux()) {
348348
"-Os",
349349
"-Wall",
350350
"-fno-exceptions",
351-
"-mmcu=" + Preferences.get("build.mcu"),
352-
"-DF_CPU=" + Preferences.get("build.f_cpu"),
351+
"-mmcu=" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu"),
352+
"-DF_CPU=" + Preferences.get("boards." + Preferences.get("board") + ".build.f_cpu"),
353353
"-I" + libManager.getTarget().getPath(),
354354
"-I" + getFolder(),
355355
};

app/LibraryManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public LibraryManager() throws IOException
4949
"libraries");
5050
target = new Target(
5151
System.getProperty("user.dir") + File.separator + "hardware" +
52-
File.separator + "cores", Preferences.get("build.target"));
52+
File.separator + "cores",
53+
Preferences.get("boards." + Preferences.get("board") + ".build.core"));
5354
refreshLibraries();
5455
}
5556

app/Preferences.java

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,13 @@ public class Preferences {
139139

140140

141141
// data model
142-
143-
static Hashtable table = new Hashtable();;
142+
// we have multiple preference files, one main one and a few subsidiary
143+
// ones with prefixes. the preferences from the main file go in table
144+
// and are saved back to the main file. the preferences from the
145+
// subsidiary files are stored in prefixes (which maps a prefix string to
146+
// a Hashtable mapping unprefixed keys to values) and are not saved.
147+
static Hashtable table = new Hashtable();
148+
static Hashtable prefixes = new Hashtable();
144149
static File preferencesFile;
145150

146151

@@ -203,6 +208,18 @@ static public void init() {
203208
" and restart Arduino.", ex);
204209
}
205210
}
211+
212+
try {
213+
load(new FileInputStream(new File(
214+
System.getProperty("user.dir") +
215+
File.separator + "hardware" +
216+
File.separator + "boards.txt")),
217+
"boards");
218+
} catch (Exception ex) {
219+
Base.showError("Error reading board definitions",
220+
"Error reading the board definitions file. " +
221+
"Please re-download or re-unzip Arduino.\n", ex);
222+
}
206223
}
207224

208225

@@ -521,10 +538,19 @@ public void showFrame(Editor editor) {
521538

522539
// .................................................................
523540

524-
525541
static public void load(InputStream input) throws IOException {
542+
load(input, null);
543+
}
544+
545+
static public void load(InputStream input, String prefix) throws IOException {
526546
BufferedReader reader =
527547
new BufferedReader(new InputStreamReader(input));
548+
Hashtable table = Preferences.table;
549+
550+
if (prefix != null) {
551+
table = new Hashtable();
552+
prefixes.put(prefix, table);
553+
}
528554

529555
//table = new Hashtable();
530556
String line = null;
@@ -633,6 +659,18 @@ static public void save() {
633659
//}
634660

635661
static public String get(String attribute /*, String defaultValue */) {
662+
// if the attribute starts with a prefix used by one of our subsidiary
663+
// preference files, look up the attribute in that file's Hashtable
664+
// (don't override with or fallback to the main file). otherwise,
665+
// look up the attribute in the main file's Hashtable.
666+
Hashtable table = Preferences.table;
667+
if (attribute.indexOf('.') != -1) {
668+
String prefix = attribute.substring(0, attribute.indexOf('.'));
669+
if (prefixes.containsKey(prefix)) {
670+
table = (Hashtable) prefixes.get(prefix);
671+
attribute = attribute.substring(attribute.indexOf('.') + 1);
672+
}
673+
}
636674
return (String) table.get(attribute);
637675
/*
638676
//String value = (properties != null) ?
@@ -643,6 +681,27 @@ static public String get(String attribute /*, String defaultValue */) {
643681
defaultValue : value;
644682
*/
645683
}
684+
685+
/**
686+
* Get the top-level key prefixes defined in the subsidiary file loaded with
687+
* the given prefix. For example, if the file contains:
688+
* foo.count=1
689+
* bar.count=2
690+
* baz.count=3
691+
* this will return { "foo", "bar", "baz" }.
692+
*/
693+
static public Iterator getSubKeys(String prefix) {
694+
if (!prefixes.containsKey(prefix))
695+
return null;
696+
Set subkeys = new HashSet();
697+
for (Enumeration e = ((Hashtable) prefixes.get(prefix)).keys(); e.hasMoreElements(); ) {
698+
String subkey = (String) e.nextElement();
699+
if (subkey.indexOf('.') != -1)
700+
subkey = subkey.substring(0, subkey.indexOf('.'));
701+
subkeys.add(subkey);
702+
}
703+
return subkeys.iterator();
704+
}
646705

647706

648707
static public void set(String attribute, String value) {

0 commit comments

Comments
 (0)