diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 628056d52..58bee2355 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -85,7 +85,7 @@ public class Base { // found in the sketchbook) static public String librariesClassPath; - static HashMap platformsTable; + static public HashMap platformsTable; // Location for untitled items static File untitledFolder; @@ -248,7 +248,7 @@ public class Base { // Get paths for the libraries and examples in the Processing folder //String workingDirectory = System.getProperty("user.dir"); examplesFolder = getContentFile("examples"); - librariesFolder = new File(getContentFile("hardware"), "libraries"); + librariesFolder = getContentFile("libraries"); toolsFolder = getContentFile("tools"); // Get the sketchbook path, and make sure it's set properly @@ -278,6 +278,7 @@ public class Base { } } + platformsTable = new HashMap(); loadHardware(getHardwareFolder()); loadHardware(getSketchbookHardwareFolder()); @@ -994,25 +995,39 @@ public class Base { public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); - try { - menu.removeAll(); - ButtonGroup group = new ButtonGroup(); - for (String board : Preferences.getSubKeys("boards")) { - JMenu item = - new JRadioButtonMenuItem( - new AbstractAction(Preferences.get("boards", "board", "name")) { - { putValue("board", board); } - public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + board); - Preferences.set("board", getValue("board")); - } - })); - if (board.equals(Preferences.get("board"))) item.setSelected(true); - group.add(item); - menu.add(item); - } - } catch (IOException e) { - e.printStackTrace(); + menu.removeAll(); + ButtonGroup group = new ButtonGroup(); + for (String board : Preferences.getSubKeys("boards")) { + AbstractAction action = + new AbstractAction(Preferences.get("boards." + board + ".name")) { + public void actionPerformed(ActionEvent actionevent) { + //System.out.println("Switching to " + board); + Preferences.set("board", (String) getValue("board")); + } + }; + action.putValue("board", board); + JMenuItem item = new JRadioButtonMenuItem(action); + if (board.equals(Preferences.get("board"))) item.setSelected(true); + group.add(item); + menu.add(item); + } + } + + + public void rebuildBurnBootloaderMenu(JMenu menu) { + //System.out.println("rebuilding burn bootloader menu"); + menu.removeAll(); + for (String programmer : Preferences.getSubKeys("programmers")) { + AbstractAction action = + new AbstractAction( + "w/ " + Preferences.get("programmers." + programmer + ".name")) { + public void actionPerformed(ActionEvent actionevent) { + activeEditor.handleBurnBootloader((String) getValue("programmer")); + } + }; + action.putValue("programmer", programmer); + JMenuItem item = new JMenuItem(action); + menu.add(item); } } @@ -1195,8 +1210,8 @@ public class Base { } - protected boolean loadHardware(File folder) { - if (!folder.isDirectory()) return false; + protected void loadHardware(File folder) { + if (!folder.isDirectory()) return; String list[] = folder.list(new FilenameFilter() { public boolean accept(File dir, String name) { @@ -1207,7 +1222,7 @@ public class Base { } }); // if a bad folder or something like that, this might come back null - if (list == null) return false; + if (list == null) return; // alphabetize list, since it's not always alpha order // replaced hella slow bubble sort with this feller for 0093 @@ -1217,13 +1232,23 @@ public class Base { File subfolder = new File(folder, platform); File boardsFile = new File(subfolder, "boards.txt"); - if (boardsFile.exists()) { - Preferences.load(new FileInputStream(boardsFile), "boards"); + try { + if (boardsFile.exists()) { + Preferences.load(new FileInputStream(boardsFile), "boards"); + } + } catch (Exception e) { + System.err.println("Error loading boards from " + + boardsFile + ": " + e); } - + File programmersFile = new File(subfolder, "programmers.txt"); - if (programmersFile.exists()) { - Preferences.load(new FileInputStream(programmersFile), "programmers"); + try { + if (programmersFile.exists()) { + Preferences.load(new FileInputStream(programmersFile), "programmers"); + } + } catch (Exception e) { + System.err.println("Error loading programmers from " + + programmersFile + ": " + e); } platformsTable.put(platform, subfolder); @@ -1513,6 +1538,11 @@ public class Base { static public String getSketchbookLibrariesPath() { return getSketchbookLibrariesFolder().getAbsolutePath(); } + + + static public File getSketchbookHardwareFolder() { + return new File(getSketchbookFolder(), "hardware"); + } protected File getDefaultSketchbookFolder() { diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index baff66111..355dca9d4 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -706,16 +706,7 @@ public class Editor extends JFrame implements RunnerListener { if (boardsMenu == null) { boardsMenu = new JMenu("Board"); - ButtonGroup boardGroup = new ButtonGroup(); - for (Iterator i = Preferences.getSubKeys("boards"); i.hasNext(); ) { - String board = (String) i.next(); - Action action = new BoardMenuAction(board); - item = new JRadioButtonMenuItem(action); - if (board.equals(Preferences.get("board"))) - item.setSelected(true); - boardGroup.add(item); - boardsMenu.add(item); - } + base.rebuildBoardsMenu(boardsMenu); } menu.add(boardsMenu); @@ -727,14 +718,9 @@ public class Editor extends JFrame implements RunnerListener { menu.add(serialMenu); menu.addSeparator(); - + JMenu bootloaderMenu = new JMenu("Burn Bootloader"); - for (Iterator i = Preferences.getSubKeys("programmers"); i.hasNext(); ) { - String programmer = (String) i.next(); - Action action = new BootloaderMenuAction(programmer); - item = new JMenuItem(action); - bootloaderMenu.add(item); - } + base.rebuildBurnBootloaderMenu(bootloaderMenu); menu.add(bootloaderMenu); menu.addMenuListener(new MenuListener() { @@ -964,30 +950,6 @@ public class Editor extends JFrame implements RunnerListener { } - class BoardMenuAction extends AbstractAction { - private String board; - public BoardMenuAction(String board) { - super(Preferences.get("boards." + board + ".name")); - this.board = board; - } - public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + board); - Preferences.set("board", board); - } - } - - class BootloaderMenuAction extends AbstractAction { - private String programmer; - public BootloaderMenuAction(String programmer) { - super("w/ " + Preferences.get("programmers." + programmer + ".name")); - this.programmer = programmer; - } - public void actionPerformed(ActionEvent actionevent) { - handleBurnBootloader(programmer); - } - } - - protected void populateSerialMenu() { // getting list of ports diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index cb1ba9975..003804f0a 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -647,7 +647,7 @@ public class Preferences { * baz.count=3 * this will return { "foo", "bar", "baz" }. */ - static public Iterator getSubKeys(String prefix) { + static public Set getSubKeys(String prefix) { if (!prefixes.containsKey(prefix)) return null; Set subkeys = new LinkedHashSet(); @@ -657,7 +657,7 @@ public class Preferences { subkey = subkey.substring(0, subkey.indexOf('.')); subkeys.add(subkey); } - return subkeys.iterator(); + return subkeys; } diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index bd69c9575..0a099405e 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -71,23 +71,25 @@ public class Compiler implements MessageConsumer { MessageStream pms = new MessageStream(this); String avrBasePath = Base.getAvrBasePath(); - String corePath = Preferences.get("boards", "board", "build.core"); + String platform = Preferences.get("boards", "board", "build.core"); + File platformFile = Base.platformsTable.get(platform); + String corePath = new File(platformFile, "core").getAbsolutePath(); List objectFiles = new ArrayList(); List includePaths = new ArrayList(); - includePaths.add(target.getPath()); + includePaths.add(corePath); String runtimeLibraryName = buildPath + File.separator + "core.a"; - // 1. compile the target (core), outputting .o files to and - // then collecting them into the core.a library file. + // 1. compile the core, outputting .o files to and then + // collecting them into the core.a library file. - List targetObjectFiles = + List coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths, - findFilesInPath(target.getPath(), "S", true), - findFilesInPath(target.getPath(), "c", true), - findFilesInPath(target.getPath(), "cpp", true)); + findFilesInPath(corePath, "S", true), + findFilesInPath(corePath, "c", true), + findFilesInPath(corePath, "cpp", true)); List baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-ar", @@ -95,7 +97,7 @@ public class Compiler implements MessageConsumer { runtimeLibraryName })); - for(File file : targetObjectFiles) { + for(File file : coreObjectFiles) { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index c2e38cd50..b00b7cb03 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -30,7 +30,6 @@ package processing.app.preproc; import processing.app.*; -import processing.app.debug.Target; import processing.core.*; import java.io.*; @@ -50,7 +49,6 @@ public class PdePreprocessor { // we always write one header: WProgram.h public int headerCount = 1; - Target target; List prototypes; @@ -82,12 +80,10 @@ public class PdePreprocessor { public PdePreprocessor() { } public int writePrefix(String program, String buildPath, - String name, String codeFolderPackages[], - Target target) + String name, String codeFolderPackages[]) throws FileNotFoundException { this.buildPath = buildPath; this.name = name; - this.target = target; int tabSize = Preferences.getInteger("editor.tabs.size"); char[] indentChars = new char[tabSize]; @@ -196,7 +192,7 @@ public class PdePreprocessor { // String extraImports[]) throws java.lang.Exception { public String write() throws java.lang.Exception { writeProgram(stream, program, prototypes); - writeFooter(stream, target); + writeFooter(stream); stream.close(); return name; @@ -223,23 +219,7 @@ public class PdePreprocessor { * * @param out PrintStream to write it to. */ - protected void writeFooter(PrintStream out, Target target) throws java.lang.Exception { - // Open the file main.cxx and copy its entire contents to the bottom of the - // generated sketch .cpp file... - - String mainFileName = target.getPath() + File.separator + "main.cxx"; - FileReader reader = null; - reader = new FileReader(mainFileName); - - LineNumberReader mainfile = new LineNumberReader(reader); - - String line; - while ((line = mainfile.readLine()) != null) { - out.print(line + "\n"); - } - - mainfile.close(); - } + protected void writeFooter(PrintStream out) throws java.lang.Exception {} public ArrayList getExtraImports() { diff --git a/build/macosx/make.sh b/build/macosx/make.sh index 6b247d839..12601e0b5 100755 --- a/build/macosx/make.sh +++ b/build/macosx/make.sh @@ -36,7 +36,7 @@ else chmod +x work/Arduino.app/Contents/MacOS/JavaApplicationStub cp -rX ../shared/lib "$RESOURCES/" - cp -rX ../shared/libraries "$RESOURCES/" + cp -rX ../../libraries "$RESOURCES/" cp -rX ../shared/tools "$RESOURCES/" cp -rX ../../hardware "$RESOURCES/" @@ -126,4 +126,4 @@ cd ../.. echo -echo Done. \ No newline at end of file +echo Done. diff --git a/hardware/arduino/core/main.cxx b/hardware/arduino/core/main.cpp similarity index 78% rename from hardware/arduino/core/main.cxx rename to hardware/arduino/core/main.cpp index 52351e4c9..cc6e81d90 100755 --- a/hardware/arduino/core/main.cxx +++ b/hardware/arduino/core/main.cpp @@ -1,3 +1,5 @@ +#include + int main(void) { init();