From 3c01c5ff77b4d43b4cf582fcc497a5f32c7bd629 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 2 Mar 2013 13:24:59 +0100 Subject: [PATCH 01/16] A lot of refactoring on Preferences, custom menus and Boards: - Merged MapWithSubkeys into PreferencesMap. - Added TargetBoard class. - Simplified a bit submenu generation. --- app/src/processing/app/Base.java | 132 ++++++++------- app/src/processing/app/debug/TargetBoard.java | 47 ++++++ .../processing/app/debug/TargetPackage.java | 30 ++-- .../processing/app/debug/TargetPlatform.java | 102 ++++++++---- .../app/debug/TargetPlatformException.java | 22 +++ app/src/processing/app/helpers/Maps.java | 15 -- .../app/helpers/PreferencesMap.java | 153 ++++++++++++++++-- .../processing/app/tools/MapWithSubkeys.java | 66 -------- .../app/tools/MapWithSubkeysTest.java | 59 ------- 9 files changed, 366 insertions(+), 260 deletions(-) create mode 100644 app/src/processing/app/debug/TargetBoard.java create mode 100644 app/src/processing/app/debug/TargetPlatformException.java delete mode 100644 app/src/processing/app/helpers/Maps.java delete mode 100644 app/src/processing/app/tools/MapWithSubkeys.java delete mode 100644 app/test/processing/app/tools/MapWithSubkeysTest.java diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index eb4545958..3057a1da9 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -30,16 +30,16 @@ import java.util.List; import javax.swing.*; +import processing.app.debug.TargetBoard; import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatform; +import processing.app.debug.TargetPlatformException; import processing.app.helpers.FileUtils; -import processing.app.helpers.Maps; import processing.app.helpers.PreferencesMap; import processing.app.helpers.filefilters.OnlyDirs; import processing.app.helpers.filefilters.OnlyFilesWithExtension; import processing.app.javax.swing.filechooser.FileNameExtensionFilter;import processing.app.packages.Library; import processing.app.packages.LibraryList; -import processing.app.tools.MapWithSubkeys; import processing.app.tools.ZipDeflater; import processing.core.*; import static processing.app.I18n._; @@ -116,7 +116,6 @@ public class Base { static File portableFolder = null; static final String portableSketchbookFolder = "sketchbook"; - static public void main(String args[]) throws Exception { initPlatform(); @@ -290,6 +289,11 @@ public class Base { packages = new HashMap(); loadHardware(getHardwareFolder()); loadHardware(getSketchbookHardwareFolder()); + if (packages.size() == 0) { + System.out.println(_("No valid configured cores found! Exiting...")); + System.exit(3); + } + // Setup board-dependent variables. onBoardOrPortChange(); @@ -1180,7 +1184,7 @@ public class Base { try { libraries = scanLibraries(librariesFolders); } catch (IOException e) { - showWarning(_("Error"), _("Error reading preferences"), e); + showWarning(_("Error"), _("Error loading libraries"), e); } String currentArch = Base.getTargetPlatform().getName(); libraries = libraries.filterByArchitecture(currentArch); @@ -1224,16 +1228,15 @@ public class Base { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { String platformName = targetPlatform.getName(); - Map boards = targetPlatform.getBoards(); + PreferencesMap customMenus = targetPlatform.getCustomMenus(); if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) { continue; } // Add a title for each group of boards - if (!first) { + if (!first) boardsMenu.add(new JSeparator()); - } first = false; JMenuItem separator = new JMenuItem(_(targetPlatform.getPreferences().get("name"))); @@ -1241,70 +1244,70 @@ public class Base { boardsMenu.add(separator); // For every platform cycle through all boards - for (final String boardID : targetPlatform.getBoards().keySet()) { + for (TargetBoard board : targetPlatform.getBoards().values()) { // Setup a menu item for the current board - String boardName = boards.get(boardID).get("name"); + String boardName = board.getName(); + String boardId = board.getId(); @SuppressWarnings("serial") Action action = new AbstractAction(boardName) { public void actionPerformed(ActionEvent actionevent) { selectBoard((String) getValue("b"), editor); } }; - action.putValue("b", packageName + ":" + platformName + ":" + boardID); + action.putValue("b", packageName + ":" + platformName + ":" + boardId); JRadioButtonMenuItem item = new JRadioButtonMenuItem(action); boardsMenu.add(item); boardsButtonGroup.add(item); - if (selBoard.equals(boardID) && selPackage.equals(packageName) + if (selBoard.equals(boardId) && selPackage.equals(packageName) && selPlatform.equals(platformName)) { menuItemsToClickAfterStartup.add(item); } - if (targetPlatform.getCustomMenus() != null) { - List customMenuIDs = new LinkedList(targetPlatform.getCustomMenus().getKeys()); - for (int i = 0; i < customMenuIDs.size(); i++) { - final String customMenuID = customMenuIDs.get(i); - JMenu menu = makeOrGetBoardMenu(toolsMenu, _(targetPlatform.getCustomMenus().getValueOf(customMenuID))); - MapWithSubkeys customMenu = targetPlatform.getCustomMenus().get(customMenuID); - if (customMenu.getKeys().contains(boardID)) { - MapWithSubkeys boardCustomMenu = customMenu.get(boardID); - final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one - for (final String customMenuOption : boardCustomMenu.getKeys()) { - @SuppressWarnings("serial") - Action subAction = new AbstractAction(_(boardCustomMenu.getValueOf(customMenuOption))) { + int i = 0; + for (final String customMenuId : customMenus.topLevelKeySet()) { + String title = customMenus.get(customMenuId); + JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); + + Map customMenu = customMenus.subTree(customMenuId).firstLevelMap(); + if (customMenu.containsKey(boardId)) { + PreferencesMap boardCustomMenu = customMenu.get(boardId); + final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one + i++; + for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { + @SuppressWarnings("serial") + Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { + public void actionPerformed(ActionEvent e) { + Preferences.set("target_package", (String) getValue("package")); + Preferences.set("target_platform", (String) getValue("platform")); + Preferences.set("board", (String) getValue("board")); + Preferences.set("custom_" + customMenuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); - public void actionPerformed(ActionEvent e) { - Preferences.set("target_package", (String) getValue("package")); - Preferences.set("target_platform", (String) getValue("platform")); - Preferences.set("board", (String) getValue("board")); - Preferences.set("custom_" + customMenuID, boardID + "_" + (String) getValue("custom_menu_option")); + filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); - filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); - - onBoardOrPortChange(); - Sketch.buildSettingChanged(); - rebuildImportMenu(Editor.importMenu, editor); - rebuildExamplesMenu(Editor.examplesMenu); - } - }; - subAction.putValue("board", boardID); - subAction.putValue("custom_menu_option", customMenuOption); - subAction.putValue("package", packageName); - subAction.putValue("platform", platformName); - - if (!buttonGroupsMap.containsKey(customMenuID)) { - buttonGroupsMap.put(customMenuID, new ButtonGroup()); + onBoardOrPortChange(); + Sketch.buildSettingChanged(); + rebuildImportMenu(Editor.importMenu, editor); + rebuildExamplesMenu(Editor.examplesMenu); } + }; + subAction.putValue("board", boardId); + subAction.putValue("custom_menu_option", customMenuOption); + subAction.putValue("package", packageName); + subAction.putValue("platform", platformName); - item = new JRadioButtonMenuItem(subAction); - menu.add(item); - buttonGroupsMap.get(customMenuID).add(item); + if (!buttonGroupsMap.containsKey(customMenuId)) { + buttonGroupsMap.put(customMenuId, new ButtonGroup()); + } - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); - if (selBoard.equals(boardID) && (boardID + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { - menuItemsToClickAfterStartup.add(item); - } + item = new JRadioButtonMenuItem(subAction); + menu.add(item); + buttonGroupsMap.get(customMenuId).add(item); + + String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuId); + if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { + menuItemsToClickAfterStartup.add(item); } } } @@ -1604,7 +1607,13 @@ public class Base { if (target.equals("tools")) continue; File subfolder = new File(folder, target); - packages.put(target, new TargetPackage(target, subfolder)); + + try { + packages.put(target, new TargetPackage(target, subfolder)); + } catch (TargetPlatformException e) { + System.out.println("WARNING: Error loading hardware folder " + target); + System.out.println(" " + e.getMessage()); + } } } @@ -1921,19 +1930,18 @@ public class Base { return getTargetPlatform(pack, Preferences.get("target_platform")); } - static public Map getBoardPreferences() { + static public PreferencesMap getBoardPreferences() { TargetPlatform target = getTargetPlatform(); String board = Preferences.get("board"); - Map boardPreferences = Maps.merge(target.getBoards().get(board), new LinkedHashMap()); - if (target.getCustomMenus() != null) { - for (String customMenuID : target.getCustomMenus().getKeys()) { - MapWithSubkeys boardCustomMenu = target.getCustomMenus().get(customMenuID).get(board); - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); - if (boardCustomMenu != null && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) { - String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1); - Maps.merge(boardCustomMenu.get(menuEntryId).getValues(), boardPreferences); - boardPreferences.put("name", boardPreferences.get("name") + ", " + boardCustomMenu.getValueOf(menuEntryId)); - } + PreferencesMap boardPreferences = new PreferencesMap(target.getBoard(board).getPreferences()); + PreferencesMap customMenus = target.getCustomMenus(); + for (String customMenuID : customMenus.topLevelKeySet()) { + PreferencesMap boardCustomMenu = customMenus.subTree(customMenuID).subTree(board); + String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); + if (boardCustomMenu.size() > 0 && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) { + String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1); + boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId)); + boardPreferences.put("name", boardPreferences.get("name") + ", " + boardCustomMenu.get(menuEntryId)); } } return boardPreferences; diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java new file mode 100644 index 000000000..bb489c13e --- /dev/null +++ b/app/src/processing/app/debug/TargetBoard.java @@ -0,0 +1,47 @@ +package processing.app.debug; + +import processing.app.helpers.PreferencesMap; + +public class TargetBoard { + + String id; + PreferencesMap prefs; + + /** + * Create a TargetBoard based on preferences passed as argument. + * + * @param _prefs + * @return + */ + public TargetBoard(String _id, PreferencesMap _prefs) { + id = _id; + prefs = new PreferencesMap(_prefs); + } + + /** + * Get the name of the board. + * + * @return + */ + public String getName() { + return prefs.get("name"); + } + + /** + * Get the identifier of the board + * + * @return + */ + public String getId() { + return id; + } + + /** + * Get the full preferences map of the board with a given identifier + * + * @return + */ + public PreferencesMap getPreferences() { + return prefs; + } +} diff --git a/app/src/processing/app/debug/TargetPackage.java b/app/src/processing/app/debug/TargetPackage.java index 3d9e8fcd5..6d04082da 100644 --- a/app/src/processing/app/debug/TargetPackage.java +++ b/app/src/processing/app/debug/TargetPackage.java @@ -25,29 +25,31 @@ package processing.app.debug; import java.io.File; import java.util.Collection; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import processing.app.helpers.filefilters.OnlyDirs; public class TargetPackage { - private final String name; + private String name; - Map platforms = new HashMap(); + Map platforms = new LinkedHashMap(); - public TargetPackage(String name, File folder) { - this.name = name; + public TargetPackage(String packageName, File packageFolder) + throws TargetPlatformException { + name = packageName; - String[] platformsList = folder.list(new OnlyDirs()); - if (platformsList != null) { - for (String platformName : platformsList) { - File platformFolder = new File(folder, platformName); - if (platformFolder.exists() && platformFolder.canRead()) { - TargetPlatform platform = new TargetPlatform(platformName, platformFolder); - platforms.put(platformName, platform); - } - } + File[] folders = packageFolder.listFiles(new OnlyDirs()); + if (folders == null) + return; + + for (File folder : folders) { + if (!folder.exists() || !folder.canRead()) + continue; + String arch = folder.getName(); + TargetPlatform platform = new TargetPlatform(arch, folder); + platforms.put(arch, platform); } } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 5ff600adf..e9dd6bb58 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -24,62 +24,90 @@ package processing.app.debug; import static processing.app.I18n._; +import static processing.app.I18n.format; import java.io.File; -import java.util.HashMap; +import java.io.IOException; +import java.util.LinkedHashMap; import java.util.Map; import processing.app.helpers.PreferencesMap; -import processing.app.tools.MapWithSubkeys; public class TargetPlatform { + private String name; private File folder; - private Map boards; - private Map programmers; - private PreferencesMap preferences; - private MapWithSubkeys customMenus; - public TargetPlatform(String _name, File _folder) { + /** + * Contains preferences for every defined board + */ + private Map boards = new LinkedHashMap(); + + /** + * Contains preferences for every defined programmer + */ + private Map programmers = new LinkedHashMap(); + + /** + * Contains preferences for platform + */ + private PreferencesMap preferences = new PreferencesMap(); + + private PreferencesMap customMenus = new PreferencesMap(); + + public TargetPlatform(String _name, File _folder) + throws TargetPlatformException { name = _name; folder = _folder; - boards = new HashMap(); - programmers = new HashMap(); - preferences = new PreferencesMap(); + // If there is no boards.txt, this is not a valid 1.5 hardware folder + File boardsFile = new File(folder, "boards.txt"); + if (!boardsFile.exists() || !boardsFile.canRead()) + throw new TargetPlatformException( + format(_("Could not find boards.txt in {0}. Is it pre-1.5?"), + boardsFile.getAbsolutePath())); + + // Load boards try { - File boardsFile = new File(_folder, "boards.txt"); - if (boardsFile.exists() && boardsFile.canRead()) { - PreferencesMap boardPreferences = new PreferencesMap(); - boardPreferences.load(boardsFile); - boards = boardPreferences.createFirstLevelMap(); - customMenus = MapWithSubkeys.createFrom(boards.get("menu")); - boards.remove("menu"); + PreferencesMap p = new PreferencesMap(boardsFile); + Map boardsPreferences = p.firstLevelMap(); + + // Create custom menus using the key "menu" and its subkeys + if (boardsPreferences.containsKey("menu")) { + customMenus = new PreferencesMap(boardsPreferences.get("menu")); + boardsPreferences.remove("menu"); } - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Error loading boards from boards.txt: " + e); + + // Create boards + for (String id : boardsPreferences.keySet()) { + PreferencesMap preferences = boardsPreferences.get(id); + boards.put(id, new TargetBoard(id, preferences)); + } + } catch (IOException e) { + throw new TargetPlatformException(format(_("Error loading {0}"), + boardsFile.getAbsolutePath()), e); } + File platformsFile = new File(folder, "platform.txt"); try { - File platformsFile = new File(_folder, "platform.txt"); if (platformsFile.exists() && platformsFile.canRead()) { preferences.load(platformsFile); } - } catch (Exception e) { - System.err.println("Error loading platforms from platform.txt: " + e); + } catch (IOException e) { + throw new TargetPlatformException( + format(_("Error loading {0}"), platformsFile.getAbsolutePath()), e); } + File progFile = new File(folder, "programmers.txt"); try { - File programmersFile = new File(_folder, "programmers.txt"); - if (programmersFile.exists() && programmersFile.canRead()) { + if (progFile.exists() && progFile.canRead()) { PreferencesMap prefs = new PreferencesMap(); - prefs.load(programmersFile); - programmers = prefs.createFirstLevelMap(); + prefs.load(progFile); + programmers = prefs.firstLevelMap(); } - } catch (Exception e) { - System.err - .println("Error loading programmers from programmers.txt: " + e); + } catch (IOException e) { + throw new TargetPlatformException(format(_("Error loading {0}"), progFile + .getAbsolutePath()), e); } } @@ -91,11 +119,11 @@ public class TargetPlatform { return folder; } - public Map getBoards() { + public Map getBoards() { return boards; } - public MapWithSubkeys getCustomMenus() { + public PreferencesMap getCustomMenus() { return customMenus; } @@ -106,12 +134,16 @@ public class TargetPlatform { public PreferencesMap getProgrammer(String programmer) { return getProgrammers().get(programmer); } - + public PreferencesMap getTool(String tool) { - return getPreferences().createSubTree("tools").createSubTree(tool); + return getPreferences().subTree("tools").subTree(tool); } - + public PreferencesMap getPreferences() { return preferences; } + + public TargetBoard getBoard(String boardId) { + return boards.get(boardId); + } } diff --git a/app/src/processing/app/debug/TargetPlatformException.java b/app/src/processing/app/debug/TargetPlatformException.java new file mode 100644 index 000000000..edb5366ec --- /dev/null +++ b/app/src/processing/app/debug/TargetPlatformException.java @@ -0,0 +1,22 @@ +package processing.app.debug; + +@SuppressWarnings("serial") +public class TargetPlatformException extends Exception { + + public TargetPlatformException() { + super(); + } + + public TargetPlatformException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public TargetPlatformException(String arg0) { + super(arg0); + } + + public TargetPlatformException(Throwable arg0) { + super(arg0); + } + +} diff --git a/app/src/processing/app/helpers/Maps.java b/app/src/processing/app/helpers/Maps.java deleted file mode 100644 index 439cb6bc5..000000000 --- a/app/src/processing/app/helpers/Maps.java +++ /dev/null @@ -1,15 +0,0 @@ -package processing.app.helpers; - -import java.util.Map; -import java.util.Map.Entry; - -public class Maps { - - public static Map merge(Map input, Map target) { - for (Entry entry : input.entrySet()) { - target.put(entry.getKey(), entry.getValue()); - } - return target; - } - -} diff --git a/app/src/processing/app/helpers/PreferencesMap.java b/app/src/processing/app/helpers/PreferencesMap.java index 52ff7c3f2..23640875e 100644 --- a/app/src/processing/app/helpers/PreferencesMap.java +++ b/app/src/processing/app/helpers/PreferencesMap.java @@ -28,17 +28,43 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import processing.app.Base; import processing.core.PApplet; +@SuppressWarnings("serial") public class PreferencesMap extends LinkedHashMap { public PreferencesMap(Map table) { super(table); } + /** + * Create a PreferencesMap and load the content of the file passed as + * argument. + * + * Is equivalent to: + * + *
+   * PreferencesMap map = new PreferencesMap();
+   * map.load(file);
+   * 
+ * + * @param file + * @throws IOException + */ + public PreferencesMap(File file) throws IOException { + super(); + load(file); + } + public PreferencesMap() { super(); } @@ -75,7 +101,7 @@ public class PreferencesMap extends LinkedHashMap { } // This is needed to avoid ConcurrentAccessExceptions - Set keys = new HashSet(keySet()); + Set keys = new LinkedHashSet(keySet()); // Override keys that have OS specific versions for (String key : keys) { @@ -95,13 +121,109 @@ public class PreferencesMap extends LinkedHashMap { } /** - * Create a new Map where the keys are the first level - * of the current mapping. E.g. the folowing mapping:
+ * Create a new PreferenceMap that contains all the top level pairs of the + * current mapping. E.g. the folowing mapping:
* *
    * Map (
+   *     alpha = Alpha
    *     alpha.some.keys = v1
    *     alpha.other.keys = v2
+   *     beta = Beta
+   *     beta.some.keys = v3
+   *   )
+   * 
+ * + * will generate the following result: + * + *
+   * Map (
+   *     alpha = Alpha
+   *     beta = Beta
+   *   )
+   * 
+ * + * @return + */ + public PreferencesMap topLevelMap() { + PreferencesMap res = new PreferencesMap(); + for (String key : keySet()) { + if (key.contains(".")) + continue; + res.put(key, get(key)); + } + return res; + } + + /** + * Returns the values of all the top level pairs of the current mapping. E.g. + * the folowing mapping:
+ * + *
+   * Map (
+   *     alpha = Alpha
+   *     alpha.some.keys = v1
+   *     alpha.other.keys = v2
+   *     beta = Beta
+   *     beta.some.keys = v3
+   *   )
+   * 
+ * + * will generate the following result: + * + *
+   * Collection (
+   *     Alpha
+   *     Beta
+   *   )
+   * 
+ * + * @return + */ + public Collection topLevelValues() { + return topLevelMap().values(); + } + + /** + * Returns a key set of all the top level pairs of the current mapping. E.g. + * the folowing mapping:
+ * + *
+   * Map (
+   *     alpha = Alpha
+   *     alpha.some.keys = v1
+   *     alpha.other.keys = v2
+   *     beta = Beta
+   *     beta.some.keys = v3
+   *   )
+   * 
+ * + * will generate the following result: + * + *
+   * Set (
+   *     alpha
+   *     beta
+   *   )
+   * 
+ * + * @return + */ + public Set topLevelKeySet() { + return topLevelMap().keySet(); + } + + /** + * Create a new Map where keys are the first level of + * the current mapping. Top level pairs are discarded. E.g. the folowing + * mapping:
+ * + *
+   * Map (
+   *     alpha = Alpha
+   *     alpha.some.keys = v1
+   *     alpha.other.keys = v2
+   *     beta = Beta
    *     beta.some.keys = v3
    *   )
    * 
@@ -120,7 +242,7 @@ public class PreferencesMap extends LinkedHashMap { * * @return */ - public Map createFirstLevelMap() { + public Map firstLevelMap() { Map res = new LinkedHashMap(); for (String key : keySet()) { int dot = key.indexOf('.'); @@ -138,13 +260,15 @@ public class PreferencesMap extends LinkedHashMap { } /** - * Create a new PreferenceMap using a subtree of the current mapping. E.g. - * with the folowing mapping:
+ * Create a new PreferenceMap using a subtree of the current mapping. Top + * level pairs are ignored. E.g. with the following mapping:
* *
    * Map (
+   *     alpha = Alpha
    *     alpha.some.keys = v1
    *     alpha.other.keys = v2
+   *     beta = Beta
    *     beta.some.keys = v3
    *   )
    * 
@@ -161,7 +285,7 @@ public class PreferencesMap extends LinkedHashMap { * @param parent * @return */ - public PreferencesMap createSubTree(String parent) { + public PreferencesMap subTree(String parent) { PreferencesMap res = new PreferencesMap(); parent += "."; int parentLen = parent.length(); @@ -172,5 +296,16 @@ public class PreferencesMap extends LinkedHashMap { return res; } - private static final long serialVersionUID = 2330591567444282843L; + public String toString(String indent) { + String res = indent + "{\n"; + SortedSet treeSet = new TreeSet(keySet()); + for (String k : treeSet) + res += indent + k + " = " + get(k) + "\n"; + return res; + } + + @Override + public String toString() { + return toString(""); + } } diff --git a/app/src/processing/app/tools/MapWithSubkeys.java b/app/src/processing/app/tools/MapWithSubkeys.java deleted file mode 100644 index 1ad5e4b62..000000000 --- a/app/src/processing/app/tools/MapWithSubkeys.java +++ /dev/null @@ -1,66 +0,0 @@ -package processing.app.tools; - -import java.util.*; -import java.util.Map.Entry; - -public class MapWithSubkeys { - - public static MapWithSubkeys createFrom(Map input) { - if (input == null) { - return null; - } - MapWithSubkeys target = new MapWithSubkeys(); - for (Entry entry : input.entrySet()) { - String[] entryParts = entry.getKey().split("\\."); - if (entryParts.length == 1) { - target.put(entryParts[0], entry.getValue()); - } else if (entryParts.length == 3) { - target.get(entryParts[0]).get(entryParts[1]).put(entryParts[2], entry.getValue()); - } else if (entryParts.length > 3) { - StringBuilder sb = new StringBuilder(); - for (int i = 3; i < entryParts.length; i++) { - sb.append(entryParts[i]).append("."); - } - sb.deleteCharAt(sb.length() - 1); - String key = sb.toString(); - target.get(entryParts[0]).get(entryParts[1]).get(entryParts[2]).put(key, entry.getValue()); - } - } - return target; - } - - private final Map values; - private final Map maps; - - public MapWithSubkeys() { - this.values = new LinkedHashMap(); - this.maps = new LinkedHashMap(); - } - - public Collection getKeys() { - return values.keySet(); - } - - public Map getValues() { - return values; - } - - public String getValueOf(String key) { - return values.get(key); - } - - public MapWithSubkeys get(String key) { - if (!maps.containsKey(key)) { - maps.put(key, new MapWithSubkeys()); - } - if (!values.containsKey(key)) { - put(key, null); - } - return maps.get(key); - } - - public void put(String key, String value) { - values.put(key, value); - } - -} diff --git a/app/test/processing/app/tools/MapWithSubkeysTest.java b/app/test/processing/app/tools/MapWithSubkeysTest.java deleted file mode 100644 index a602e08f6..000000000 --- a/app/test/processing/app/tools/MapWithSubkeysTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package processing.app.tools; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; - -public class MapWithSubkeysTest { - - private MapWithSubkeys map; - - @Before - public void setup() throws Exception { - Map input = new HashMap(); - BufferedReader reader = new BufferedReader(new InputStreamReader(MapWithSubkeysTest.class.getResourceAsStream("test_partial_boards.txt"))); - String line = null; - while ((line = reader.readLine()) != null) { - String[] lineParts = line.split("="); - input.put(lineParts[0], lineParts[1]); - } - map = MapWithSubkeys.createFrom(input); - } - - @Test - public void shouldListCustomMenusIDs() { - Collection menusIDs = map.getKeys(); - - assertEquals(2, menusIDs.size()); - assertTrue(menusIDs.contains("cpu")); - assertTrue(menusIDs.contains("speed")); - - assertEquals("Processor", map.getValueOf("cpu")); - - MapWithSubkeys cpu = map.get("cpu"); - - Collection boards = cpu.getKeys(); - assertEquals(1, boards.size()); - assertTrue(boards.contains("nano")); - - Collection cpuNanoProcessors = cpu.get("nano").getKeys(); - assertEquals(2, cpuNanoProcessors.size()); - assertTrue(cpuNanoProcessors.contains("atmega168")); - assertTrue(cpuNanoProcessors.contains("atmega328")); - assertEquals("ATmega168", cpu.get("nano").getValueOf("atmega168")); - assertEquals("ATmega328", cpu.get("nano").getValueOf("atmega328")); - - MapWithSubkeys atmega168Properties = cpu.get("nano").get("atmega168"); - assertEquals(9, atmega168Properties.getKeys().size()); - assertTrue(atmega168Properties.getKeys().contains("bootloader.high_fuses")); - } - -} From eed4a43b547ad04f2c55a9a3a987b75233e6d0cd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 3 Mar 2013 11:15:57 +0100 Subject: [PATCH 02/16] Refactored board specific options into TargetBoard --- app/src/processing/app/Base.java | 45 +++++++++++-------- app/src/processing/app/debug/TargetBoard.java | 20 ++++++++- .../processing/app/debug/TargetPlatform.java | 39 +++++++++++++--- 3 files changed, 76 insertions(+), 28 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 3057a1da9..c1f378db0 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1228,7 +1228,6 @@ public class Base { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { String platformName = targetPlatform.getName(); - PreferencesMap customMenus = targetPlatform.getCustomMenus(); if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) { continue; @@ -1265,14 +1264,17 @@ public class Base { menuItemsToClickAfterStartup.add(item); } + PreferencesMap customMenus = targetPlatform.getCustomMenus(); int i = 0; - for (final String customMenuId : customMenus.topLevelKeySet()) { - String title = customMenus.get(customMenuId); + for (final String menuId : customMenus.keySet()) { + String title = customMenus.get(menuId); JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); - Map customMenu = customMenus.subTree(customMenuId).firstLevelMap(); - if (customMenu.containsKey(boardId)) { - PreferencesMap boardCustomMenu = customMenu.get(boardId); + //Map customMenu = customMenus.subTree(menuId).firstLevelMap(); + if (board.hasMenuOptions(menuId)) { + //if (customMenu.containsKey(boardId)) { + //PreferencesMap boardCustomMenu = customMenu.get(boardId); + PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one i++; for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { @@ -1282,7 +1284,7 @@ public class Base { Preferences.set("target_package", (String) getValue("package")); Preferences.set("target_platform", (String) getValue("platform")); Preferences.set("board", (String) getValue("board")); - Preferences.set("custom_" + customMenuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); + Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); @@ -1297,15 +1299,15 @@ public class Base { subAction.putValue("package", packageName); subAction.putValue("platform", platformName); - if (!buttonGroupsMap.containsKey(customMenuId)) { - buttonGroupsMap.put(customMenuId, new ButtonGroup()); + if (!buttonGroupsMap.containsKey(menuId)) { + buttonGroupsMap.put(menuId, new ButtonGroup()); } item = new JRadioButtonMenuItem(subAction); menu.add(item); - buttonGroupsMap.get(customMenuId).add(item); + buttonGroupsMap.get(menuId).add(item); - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuId); + String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { menuItemsToClickAfterStartup.add(item); } @@ -1932,16 +1934,21 @@ public class Base { static public PreferencesMap getBoardPreferences() { TargetPlatform target = getTargetPlatform(); - String board = Preferences.get("board"); - PreferencesMap boardPreferences = new PreferencesMap(target.getBoard(board).getPreferences()); + String boardId = Preferences.get("board"); + TargetBoard board = target.getBoard(boardId); + PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences()); PreferencesMap customMenus = target.getCustomMenus(); - for (String customMenuID : customMenus.topLevelKeySet()) { - PreferencesMap boardCustomMenu = customMenus.subTree(customMenuID).subTree(board); - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); - if (boardCustomMenu.size() > 0 && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) { - String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1); + for (String menuId : customMenus.keySet()) { + PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); + String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); + if (boardCustomMenu != null && boardCustomMenu.size() > 0 && + selectedCustomMenuEntry != null && + selectedCustomMenuEntry.startsWith(boardId)) { + String menuEntryId = selectedCustomMenuEntry + .substring(selectedCustomMenuEntry.indexOf("_") + 1); boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId)); - boardPreferences.put("name", boardPreferences.get("name") + ", " + boardCustomMenu.get(menuEntryId)); + boardPreferences.put("name", boardPreferences.get("name") + ", " + + boardCustomMenu.get(menuEntryId)); } } return boardPreferences; diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index bb489c13e..2ee0ec71a 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -1,11 +1,15 @@ package processing.app.debug; +import java.util.LinkedHashMap; +import java.util.Map; + import processing.app.helpers.PreferencesMap; public class TargetBoard { - String id; - PreferencesMap prefs; + private String id; + private PreferencesMap prefs; + private Map menuOptions = new LinkedHashMap(); /** * Create a TargetBoard based on preferences passed as argument. @@ -44,4 +48,16 @@ public class TargetBoard { public PreferencesMap getPreferences() { return prefs; } + + public void setMenuOptions(String menuId, PreferencesMap _menuOptions) { + menuOptions.put(menuId, _menuOptions); + } + + public PreferencesMap getMenuOptions(String menuId) { + return menuOptions.get(menuId); + } + + public boolean hasMenuOptions(String menuId) { + return menuOptions.containsKey(menuId); + } } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index e9dd6bb58..297f8c908 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -53,6 +53,9 @@ public class TargetPlatform { */ private PreferencesMap preferences = new PreferencesMap(); + /** + * Contains labels for top level menus + */ private PreferencesMap customMenus = new PreferencesMap(); public TargetPlatform(String _name, File _folder) @@ -69,19 +72,41 @@ public class TargetPlatform { // Load boards try { - PreferencesMap p = new PreferencesMap(boardsFile); - Map boardsPreferences = p.firstLevelMap(); + Map boardsPreferences = new PreferencesMap( + boardsFile).firstLevelMap(); - // Create custom menus using the key "menu" and its subkeys - if (boardsPreferences.containsKey("menu")) { - customMenus = new PreferencesMap(boardsPreferences.get("menu")); - boardsPreferences.remove("menu"); + // Create custom menus for this platform + PreferencesMap menus = boardsPreferences.get("menu"); + boardsPreferences.remove("menu"); + if (menus != null) + customMenus = menus.topLevelMap(); + + // Create maps for every menu option: + // - a Map that pairs a specific menu option (e.g. "cpu") to + // - a Map that pairs a specific board (e.g. "duemilanove") to + // - a PrefenceMap with all the options that overrides default + // configuration values + Map> subMenus = new LinkedHashMap>(); + for (String id : customMenus.keySet()) { + subMenus.put(id, menus.subTree(id).firstLevelMap()); } // Create boards for (String id : boardsPreferences.keySet()) { PreferencesMap preferences = boardsPreferences.get(id); - boards.put(id, new TargetBoard(id, preferences)); + TargetBoard board = new TargetBoard(id, preferences); + + if (menus != null) { + // Build custom menu for the specified board + PreferencesMap boardCustomMenu = new PreferencesMap(); + for (String menuId : customMenus.keySet()) { + // Check if the board has option for this custom menu + if (subMenus.get(menuId).containsKey(id)) + // Add specific custom menu to the board + board.setMenuOptions(menuId, subMenus.get(menuId).get(id)); + } + } + boards.put(id, board); } } catch (IOException e) { throw new TargetPlatformException(format(_("Error loading {0}"), From 51c36c73253fb310828056147c909b62bfc4589b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 3 Mar 2013 11:31:31 +0100 Subject: [PATCH 03/16] Slighty changed custom menu format: simplifies parsing --- app/src/processing/app/debug/TargetBoard.java | 4 + .../processing/app/debug/TargetPlatform.java | 23 +- hardware/arduino/avr/boards.txt | 256 ++++++++++-------- 3 files changed, 141 insertions(+), 142 deletions(-) diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 2ee0ec71a..44b0def01 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -20,6 +20,10 @@ public class TargetBoard { public TargetBoard(String _id, PreferencesMap _prefs) { id = _id; prefs = new PreferencesMap(_prefs); + + PreferencesMap menus = prefs.firstLevelMap().get("menu"); + if (menus != null) + menuOptions = menus.firstLevelMap(); } /** diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 297f8c908..2bca7a460 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -77,35 +77,14 @@ public class TargetPlatform { // Create custom menus for this platform PreferencesMap menus = boardsPreferences.get("menu"); - boardsPreferences.remove("menu"); if (menus != null) customMenus = menus.topLevelMap(); - - // Create maps for every menu option: - // - a Map that pairs a specific menu option (e.g. "cpu") to - // - a Map that pairs a specific board (e.g. "duemilanove") to - // - a PrefenceMap with all the options that overrides default - // configuration values - Map> subMenus = new LinkedHashMap>(); - for (String id : customMenus.keySet()) { - subMenus.put(id, menus.subTree(id).firstLevelMap()); - } + boardsPreferences.remove("menu"); // Create boards for (String id : boardsPreferences.keySet()) { PreferencesMap preferences = boardsPreferences.get(id); TargetBoard board = new TargetBoard(id, preferences); - - if (menus != null) { - // Build custom menu for the specified board - PreferencesMap boardCustomMenu = new PreferencesMap(); - for (String menuId : customMenus.keySet()) { - // Check if the board has option for this custom menu - if (subMenus.get(menuId).containsKey(id)) - // Add specific custom menu to the board - board.setMenuOptions(menuId, subMenus.get(menuId).get(id)); - } - } boards.put(id, board); } } catch (IOException e) { diff --git a/hardware/arduino/avr/boards.txt b/hardware/arduino/avr/boards.txt index f28192094..ee5a19579 100644 --- a/hardware/arduino/avr/boards.txt +++ b/hardware/arduino/avr/boards.txt @@ -42,28 +42,30 @@ atmega328diecimila.build.core=arduino atmega328diecimila.build.variant=standard ## Arduino Duemilanove or Diecimila w/ ATmega328 -menu.cpu.atmega328diecimila.atmega328=ATmega328 +## --------------------------------------------- +atmega328diecimila.menu.cpu.atmega328=ATmega328 -menu.cpu.atmega328diecimila.atmega328.upload.maximum_size=30720 -menu.cpu.atmega328diecimila.atmega328.upload.speed=57600 +atmega328diecimila.menu.cpu.atmega328.upload.maximum_size=30720 +atmega328diecimila.menu.cpu.atmega328.upload.speed=57600 -menu.cpu.atmega328diecimila.atmega328.bootloader.high_fuses=0xDA -menu.cpu.atmega328diecimila.atmega328.bootloader.extended_fuses=0x05 -menu.cpu.atmega328diecimila.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +atmega328diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA +atmega328diecimila.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +atmega328diecimila.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex -menu.cpu.atmega328diecimila.atmega328.build.mcu=atmega328p +atmega328diecimila.menu.cpu.atmega328.build.mcu=atmega328p ## Arduino Duemilanove or Diecimila w/ ATmega168 -menu.cpu.atmega328diecimila.atmega168=ATmega168 +## --------------------------------------------- +atmega328diecimila.menu.cpu.atmega168=ATmega168 -menu.cpu.atmega328diecimila.atmega168.upload.maximum_size=14336 -menu.cpu.atmega328diecimila.atmega168.upload.speed=19200 +atmega328diecimila.menu.cpu.atmega168.upload.maximum_size=14336 +atmega328diecimila.menu.cpu.atmega168.upload.speed=19200 -menu.cpu.atmega328diecimila.atmega168.bootloader.high_fuses=0xdd -menu.cpu.atmega328diecimila.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.atmega328diecimila.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex +atmega328diecimila.menu.cpu.atmega168.bootloader.high_fuses=0xdd +atmega328diecimila.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +atmega328diecimila.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex -menu.cpu.atmega328diecimila.atmega168.build.mcu=atmega168 +atmega328diecimila.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -82,30 +84,32 @@ nano.build.core=arduino nano.build.variant=eightanaloginputs ## Arduino Nano w/ ATmega328 -menu.cpu.nano.atmega328=ATmega328 +## ------------------------- +nano.menu.cpu.atmega328=ATmega328 -menu.cpu.nano.atmega328.upload.maximum_size=30720 -menu.cpu.nano.atmega328.upload.speed=57600 +nano.menu.cpu.atmega328.upload.maximum_size=30720 +nano.menu.cpu.atmega328.upload.speed=57600 -menu.cpu.nano.atmega328.bootloader.low_fuses=0xFF -menu.cpu.nano.atmega328.bootloader.high_fuses=0xDA -menu.cpu.nano.atmega328.bootloader.extended_fuses=0x05 -menu.cpu.nano.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +nano.menu.cpu.atmega328.bootloader.low_fuses=0xFF +nano.menu.cpu.atmega328.bootloader.high_fuses=0xDA +nano.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +nano.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex menu.cpu.nano.atmega328.build.mcu=atmega328p ## Arduino Nano w/ ATmega168 -menu.cpu.nano.atmega168=ATmega168 +## ------------------------- +nano.menu.cpu.atmega168=ATmega168 -menu.cpu.nano.atmega168.upload.maximum_size=14336 -menu.cpu.nano.atmega168.upload.speed=19200 +nano.menu.cpu.atmega168.upload.maximum_size=14336 +nano.menu.cpu.atmega168.upload.speed=19200 -menu.cpu.nano.atmega168.bootloader.low_fuses=0xff -menu.cpu.nano.atmega168.bootloader.high_fuses=0xdd -menu.cpu.nano.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.nano.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex +nano.menu.cpu.atmega168.bootloader.low_fuses=0xff +nano.menu.cpu.atmega168.bootloader.high_fuses=0xdd +nano.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +nano.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex -menu.cpu.nano.atmega168.build.mcu=atmega168 +nano.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -257,28 +261,30 @@ mini.build.core=arduino mini.build.variant=eightanaloginputs ## Arduino Mini w/ ATmega328 -menu.cpu.mini.atmega328=ATmega328 +## ------------------------- +mini.menu.cpu.atmega328=ATmega328 -menu.cpu.mini.atmega328.upload.maximum_size=28672 -menu.cpu.mini.atmega328.upload.speed=115200 +mini.menu.cpu.atmega328.upload.maximum_size=28672 +mini.menu.cpu.atmega328.upload.speed=115200 -menu.cpu.mini.atmega328.bootloader.high_fuses=0xd8 -menu.cpu.mini.atmega328.bootloader.extended_fuses=0x05 -menu.cpu.mini.atmega328.bootloader.file=optiboot/optiboot_atmega328-Mini.hex +mini.menu.cpu.atmega328.bootloader.high_fuses=0xd8 +mini.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +mini.menu.cpu.atmega328.bootloader.file=optiboot/optiboot_atmega328-Mini.hex -menu.cpu.mini.atmega328.build.mcu=atmega328p +mini.menu.cpu.atmega328.build.mcu=atmega328p ## Arduino Mini w/ ATmega168 -menu.cpu.mini.atmega168=ATmega168 +## ------------------------- +mini.menu.cpu.atmega168=ATmega168 -menu.cpu.mini.atmega168.upload.maximum_size=14336 -menu.cpu.mini.atmega168.upload.speed=19200 +mini.menu.cpu.atmega168.upload.maximum_size=14336 +mini.menu.cpu.atmega168.upload.speed=19200 -menu.cpu.mini.atmega168.bootloader.high_fuses=0xdd -menu.cpu.mini.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.mini.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex +mini.menu.cpu.atmega168.bootloader.high_fuses=0xdd +mini.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +mini.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex -menu.cpu.mini.atmega168.build.mcu=atmega168 +mini.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -346,24 +352,26 @@ bt.build.core=arduino bt.build.variant=eightanaloginputs ## Arduino BT w/ ATmega328 -menu.cpu.bt.atmega328=ATmega328 -menu.cpu.bt.atmega328.upload.maximum_size=28672 +## ----------------------- +bt.menu.cpu.atmega328=ATmega328 +bt.menu.cpu.atmega328.upload.maximum_size=28672 -menu.cpu.bt.atmega328.bootloader.high_fuses=0xd8 -menu.cpu.bt.atmega328.bootloader.extended_fuses=0x05 -menu.cpu.bt.atmega328.bootloader.file=bt/ATmegaBOOT_168_atmega328_bt.hex +bt.menu.cpu.atmega328.bootloader.high_fuses=0xd8 +bt.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +bt.menu.cpu.atmega328.bootloader.file=bt/ATmegaBOOT_168_atmega328_bt.hex -menu.cpu.bt.atmega328.build.mcu=atmega328p +bt.menu.cpu.atmega328.build.mcu=atmega328p ## Arduino BT w/ ATmega168 -menu.cpu.bt.atmega168=ATmega168 -menu.cpu.bt.atmega168.upload.maximum_size=14336 +## ----------------------- +bt.menu.cpu.atmega168=ATmega168 +bt.menu.cpu.atmega168.upload.maximum_size=14336 -menu.cpu.bt.atmega168.bootloader.high_fuses=0xdd -menu.cpu.bt.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.bt.atmega168.bootloader.file=bt/ATmegaBOOT_168.hex +bt.menu.cpu.atmega168.bootloader.high_fuses=0xdd +bt.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +bt.menu.cpu.atmega168.bootloader.file=bt/ATmegaBOOT_168.hex -menu.cpu.bt.atmega168.build.mcu=atmega168 +bt.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -411,30 +419,32 @@ lilypad.build.core=arduino lilypad.build.variant=standard ## LilyPad Arduino w/ ATmega328 -menu.cpu.lilypad.atmega328=ATmega328 +## ---------------------------- +lilypad.menu.cpu.atmega328=ATmega328 -menu.cpu.lilypad.atmega328.upload.maximum_size=30720 -menu.cpu.lilypad.atmega328.upload.speed=57600 +lilypad.menu.cpu.atmega328.upload.maximum_size=30720 +lilypad.menu.cpu.atmega328.upload.speed=57600 -menu.cpu.lilypad.atmega328.bootloader.low_fuses=0xFF -menu.cpu.lilypad.atmega328.bootloader.high_fuses=0xDA -menu.cpu.lilypad.atmega328.bootloader.extended_fuses=0x05 -menu.cpu.lilypad.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +lilypad.menu.cpu.atmega328.bootloader.low_fuses=0xFF +lilypad.menu.cpu.atmega328.bootloader.high_fuses=0xDA +lilypad.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +lilypad.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex -menu.cpu.lilypad.atmega328.build.mcu=atmega328p +lilypad.menu.cpu.atmega328.build.mcu=atmega328p ## LilyPad Arduino w/ ATmega168 -menu.cpu.lilypad.atmega168=ATmega168 +## ---------------------------- +lilypad.menu.cpu.atmega168=ATmega168 -menu.cpu.lilypad.atmega168.upload.maximum_size=14336 -menu.cpu.lilypad.atmega168.upload.speed=19200 +lilypad.menu.cpu.atmega168.upload.maximum_size=14336 +lilypad.menu.cpu.atmega168.upload.speed=19200 -menu.cpu.lilypad.atmega168.bootloader.low_fuses=0xe2 -menu.cpu.lilypad.atmega168.bootloader.high_fuses=0xdd -menu.cpu.lilypad.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.lilypad.atmega168.bootloader.file=lilypad/LilyPadBOOT_168.hex +lilypad.menu.cpu.atmega168.bootloader.low_fuses=0xe2 +lilypad.menu.cpu.atmega168.bootloader.high_fuses=0xdd +lilypad.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +lilypad.menu.cpu.atmega168.bootloader.file=lilypad/LilyPadBOOT_168.hex -menu.cpu.lilypad.atmega168.build.mcu=atmega168 +lilypad.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -452,60 +462,64 @@ pro.build.core=arduino pro.build.variant=standard ## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 -menu.cpu.pro.16MHzatmega328=ATmega328 (5V, 16 MHz) +## ------------------------------------------------- +pro.menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz) -menu.cpu.pro.16MHzatmega328.upload.maximum_size=30720 -menu.cpu.pro.16MHzatmega328.upload.speed=57600 +pro.menu.cpu.16MHzatmega328.upload.maximum_size=30720 +pro.menu.cpu.16MHzatmega328.upload.speed=57600 -menu.cpu.pro.16MHzatmega328.bootloader.low_fuses=0xFF -menu.cpu.pro.16MHzatmega328.bootloader.high_fuses=0xDA -menu.cpu.pro.16MHzatmega328.bootloader.extended_fuses=0x05 -menu.cpu.pro.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +pro.menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF +pro.menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA +pro.menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05 +pro.menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex -menu.cpu.pro.16MHzatmega328.build.mcu=atmega328p -menu.cpu.pro.16MHzatmega328.build.f_cpu=16000000L +pro.menu.cpu.16MHzatmega328.build.mcu=atmega328p +pro.menu.cpu.16MHzatmega328.build.f_cpu=16000000L ## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 -menu.cpu.pro.8MHzatmega328=ATmega328 (3.3V, 8 MHz) +## -------------------------------------------------- +pro.menu.cpu.8MHzatmega328=ATmega328 (3.3V, 8 MHz) -menu.cpu.pro.8MHzatmega328.upload.maximum_size=30720 -menu.cpu.pro.8MHzatmega328.upload.speed=57600 +pro.menu.cpu.8MHzatmega328.upload.maximum_size=30720 +pro.menu.cpu.8MHzatmega328.upload.speed=57600 -menu.cpu.pro.8MHzatmega328.bootloader.low_fuses=0xFF -menu.cpu.pro.8MHzatmega328.bootloader.high_fuses=0xDA -menu.cpu.pro.8MHzatmega328.bootloader.extended_fuses=0x05 -menu.cpu.pro.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +pro.menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF +pro.menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA +pro.menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x05 +pro.menu.cpu.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex -menu.cpu.pro.8MHzatmega328.build.mcu=atmega328p -menu.cpu.pro.8MHzatmega328.build.f_cpu=8000000L +pro.menu.cpu.8MHzatmega328.build.mcu=atmega328p +pro.menu.cpu.8MHzatmega328.build.f_cpu=8000000L ## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 -menu.cpu.pro.16MHzatmega168=ATmega168 (5V, 16 MHz) +## ------------------------------------------------- +pro.menu.cpu.16MHzatmega168=ATmega168 (5V, 16 MHz) -menu.cpu.pro.16MHzatmega168.upload.maximum_size=14336 -menu.cpu.pro.16MHzatmega168.upload.speed=19200 +pro.menu.cpu.16MHzatmega168.upload.maximum_size=14336 +pro.menu.cpu.16MHzatmega168.upload.speed=19200 -menu.cpu.pro.16MHzatmega168.bootloader.low_fuses=0xff -menu.cpu.pro.16MHzatmega168.bootloader.high_fuses=0xdd -menu.cpu.pro.16MHzatmega168.bootloader.extended_fuses=0x00 -menu.cpu.pro.16MHzatmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex +pro.menu.cpu.16MHzatmega168.bootloader.low_fuses=0xff +pro.menu.cpu.16MHzatmega168.bootloader.high_fuses=0xdd +pro.menu.cpu.16MHzatmega168.bootloader.extended_fuses=0x00 +pro.menu.cpu.16MHzatmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex -menu.cpu.pro.16MHzatmega168.build.mcu=atmega168 -menu.cpu.pro.16MHzatmega168.build.f_cpu=16000000L +pro.menu.cpu.16MHzatmega168.build.mcu=atmega168 +pro.menu.cpu.16MHzatmega168.build.f_cpu=16000000L ## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 -menu.cpu.pro.8MHzatmega168=ATmega168 (3.3V, 8 MHz) +## -------------------------------------------------- +pro.menu.cpu.8MHzatmega168=ATmega168 (3.3V, 8 MHz) -menu.cpu.pro.8MHzatmega168.upload.maximum_size=14336 -menu.cpu.pro.8MHzatmega168.upload.speed=19200 +pro.menu.cpu.8MHzatmega168.upload.maximum_size=14336 +pro.menu.cpu.8MHzatmega168.upload.speed=19200 -menu.cpu.pro.8MHzatmega168.bootloader.low_fuses=0xc6 -menu.cpu.pro.8MHzatmega168.bootloader.high_fuses=0xdd -menu.cpu.pro.8MHzatmega168.bootloader.extended_fuses=0x00 -menu.cpu.pro.8MHzatmega168.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex +pro.menu.cpu.8MHzatmega168.bootloader.low_fuses=0xc6 +pro.menu.cpu.8MHzatmega168.bootloader.high_fuses=0xdd +pro.menu.cpu.8MHzatmega168.bootloader.extended_fuses=0x00 +pro.menu.cpu.8MHzatmega168.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex -menu.cpu.pro.8MHzatmega168.build.mcu=atmega168 -menu.cpu.pro.8MHzatmega168.build.f_cpu=8000000L +pro.menu.cpu.8MHzatmega168.build.mcu=atmega168 +pro.menu.cpu.8MHzatmega168.build.f_cpu=8000000L ############################################################## @@ -526,24 +540,26 @@ atmegang.build.core=arduino atmegang.build.variant=standard ## Arduino NG or older w/ ATmega168 -menu.cpu.atmegang.atmega168=ATmega168 +## -------------------------------- +atmegang.menu.cpu.atmega168=ATmega168 -menu.cpu.atmegang.atmega168.upload.maximum_size=14336 +atmegang.menu.cpu.atmega168.upload.maximum_size=14336 -menu.cpu.atmegang.atmega168.bootloader.low_fuses=0xff -menu.cpu.atmegang.atmega168.bootloader.high_fuses=0xdd -menu.cpu.atmegang.atmega168.bootloader.extended_fuses=0x00 -menu.cpu.atmegang.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex +atmegang.menu.cpu.atmega168.bootloader.low_fuses=0xff +atmegang.menu.cpu.atmega168.bootloader.high_fuses=0xdd +atmegang.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +atmegang.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex -menu.cpu.atmegang.atmega168.build.mcu=atmega168 +atmegang.menu.cpu.atmega168.build.mcu=atmega168 ## Arduino NG or older w/ ATmega8 -menu.cpu.atmegang.atmega8=ATmega8 +## ------------------------------ +atmegang.menu.cpu.atmega8=ATmega8 -menu.cpu.atmegang.atmega8.upload.maximum_size=7168 +atmegang.menu.cpu.atmega8.upload.maximum_size=7168 -menu.cpu.atmegang.atmega8.bootloader.low_fuses=0xdf -menu.cpu.atmegang.atmega8.bootloader.high_fuses=0xca -menu.cpu.atmegang.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex +atmegang.menu.cpu.atmega8.bootloader.low_fuses=0xdf +atmegang.menu.cpu.atmega8.bootloader.high_fuses=0xca +atmegang.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex -menu.cpu.atmegang.atmega8.build.mcu=atmega8 +atmegang.menu.cpu.atmega8.build.mcu=atmega8 From acc477af05458651259aafba2f05fba6e7c8f5f7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 3 Mar 2013 12:08:16 +0100 Subject: [PATCH 04/16] Other refinement in TargetBoard --- app/src/processing/app/Base.java | 33 ++++------- app/src/processing/app/debug/TargetBoard.java | 55 ++++++++++++++--- .../processing/app/debug/TargetPlatform.java | 5 ++ .../app/helpers/PreferencesMap.java | 59 ------------------- 4 files changed, 64 insertions(+), 88 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c1f378db0..d42ce7854 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1270,14 +1270,11 @@ public class Base { String title = customMenus.get(menuId); JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); - //Map customMenu = customMenus.subTree(menuId).firstLevelMap(); - if (board.hasMenuOptions(menuId)) { - //if (customMenu.containsKey(boardId)) { - //PreferencesMap boardCustomMenu = customMenu.get(boardId); - PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); + if (board.hasMenu(menuId)) { + PreferencesMap boardCustomMenu = board.getMenuLabels(menuId); final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one i++; - for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { + for (String customMenuOption : boardCustomMenu.keySet()) { @SuppressWarnings("serial") Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { public void actionPerformed(ActionEvent e) { @@ -1936,22 +1933,18 @@ public class Base { TargetPlatform target = getTargetPlatform(); String boardId = Preferences.get("board"); TargetBoard board = target.getBoard(boardId); - PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences()); - PreferencesMap customMenus = target.getCustomMenus(); - for (String menuId : customMenus.keySet()) { - PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); - String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); - if (boardCustomMenu != null && boardCustomMenu.size() > 0 && - selectedCustomMenuEntry != null && - selectedCustomMenuEntry.startsWith(boardId)) { - String menuEntryId = selectedCustomMenuEntry - .substring(selectedCustomMenuEntry.indexOf("_") + 1); - boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId)); - boardPreferences.put("name", boardPreferences.get("name") + ", " + - boardCustomMenu.get(menuEntryId)); + PreferencesMap prefs = new PreferencesMap(board.getPreferences()); + for (String menuId : target.getCustomMenusKeys()) { + String entry = Preferences.get("custom_" + menuId); + if (board.hasMenu(menuId) && entry != null && + entry.startsWith(boardId)) { + String selectionId = entry.substring(entry.indexOf("_") + 1); + prefs.putAll(board.getMenuConfiguration(menuId, selectionId)); + prefs.put("name", prefs.get("name") + ", " + + board.getMenuLabel(menuId, selectionId)); } } - return boardPreferences; + return prefs; } static public File getPortableFolder() { diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 44b0def01..958c1f2d5 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -53,15 +53,52 @@ public class TargetBoard { return prefs; } - public void setMenuOptions(String menuId, PreferencesMap _menuOptions) { - menuOptions.put(menuId, _menuOptions); - } - - public PreferencesMap getMenuOptions(String menuId) { - return menuOptions.get(menuId); - } - - public boolean hasMenuOptions(String menuId) { + /** + * Check if the board has a sub menu. + * + * @param menuId + * The menu ID to check + * @return + */ + public boolean hasMenu(String menuId) { return menuOptions.containsKey(menuId); } + + /** + * Returns the options available on a specific menu + * + * @param menuId + * The menu ID + * @return + */ + public PreferencesMap getMenuLabels(String menuId) { + return menuOptions.get(menuId).topLevelMap(); + } + + /** + * Returns the label of the specified option in the specified menu + * + * @param menuId + * The menu ID + * @param selectionId + * The option ID + * @return + */ + public String getMenuLabel(String menuId, String selectionId) { + return getMenuLabels(menuId).get(selectionId); + } + + /** + * Returns the configuration parameters to override (as a PreferenceMap) when + * the specified option in the specified menu is selected + * + * @param menuId + * The menu ID + * @param selectionId + * The option ID + * @return + */ + public PreferencesMap getMenuConfiguration(String menuId, String selectionId) { + return menuOptions.get(menuId).subTree(selectionId); + } } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 2bca7a460..ea72f79fb 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import processing.app.helpers.PreferencesMap; @@ -131,6 +132,10 @@ public class TargetPlatform { return customMenus; } + public Set getCustomMenusKeys() { + return customMenus.keySet(); + } + public Map getProgrammers() { return programmers; } diff --git a/app/src/processing/app/helpers/PreferencesMap.java b/app/src/processing/app/helpers/PreferencesMap.java index 23640875e..e4729c166 100644 --- a/app/src/processing/app/helpers/PreferencesMap.java +++ b/app/src/processing/app/helpers/PreferencesMap.java @@ -28,7 +28,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -155,64 +154,6 @@ public class PreferencesMap extends LinkedHashMap { return res; } - /** - * Returns the values of all the top level pairs of the current mapping. E.g. - * the folowing mapping:
- * - *
-   * Map (
-   *     alpha = Alpha
-   *     alpha.some.keys = v1
-   *     alpha.other.keys = v2
-   *     beta = Beta
-   *     beta.some.keys = v3
-   *   )
-   * 
- * - * will generate the following result: - * - *
-   * Collection (
-   *     Alpha
-   *     Beta
-   *   )
-   * 
- * - * @return - */ - public Collection topLevelValues() { - return topLevelMap().values(); - } - - /** - * Returns a key set of all the top level pairs of the current mapping. E.g. - * the folowing mapping:
- * - *
-   * Map (
-   *     alpha = Alpha
-   *     alpha.some.keys = v1
-   *     alpha.other.keys = v2
-   *     beta = Beta
-   *     beta.some.keys = v3
-   *   )
-   * 
- * - * will generate the following result: - * - *
-   * Set (
-   *     alpha
-   *     beta
-   *   )
-   * 
- * - * @return - */ - public Set topLevelKeySet() { - return topLevelMap().keySet(); - } - /** * Create a new Map where keys are the first level of * the current mapping. Top level pairs are discarded. E.g. the folowing From 9024fe455c86ebd6a3374fa6238ef3b8eca51b9b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 4 Mar 2013 16:56:33 +0100 Subject: [PATCH 05/16] When using cores from other packages also the referenced platforms.txt is imported See #1157 --- app/src/processing/app/Base.java | 282 +++++++++++------- app/src/processing/app/Editor.java | 23 +- app/src/processing/app/EditorToolbar.java | 8 +- app/src/processing/app/debug/Compiler.java | 22 +- app/src/processing/app/debug/TargetBoard.java | 75 ++++- .../processing/app/debug/TargetPackage.java | 27 +- .../processing/app/debug/TargetPlatform.java | 35 ++- .../processing/app/macosx/ThinkDifferent.java | 6 +- 8 files changed, 336 insertions(+), 142 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d42ce7854..37abcd4fd 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -293,6 +293,8 @@ public class Base { System.out.println(_("No valid configured cores found! Exiting...")); System.exit(3); } + for (TargetPackage pack : packages.values()) + pack.resolveReferencedPlatforms(packages); // Setup board-dependent variables. onBoardOrPortChange(); @@ -407,8 +409,9 @@ public class Base { * sketch that was used (if any), and restores other Editor settings. * The complement to "storePreferences", this is called when the * application is first launched. + * @throws Exception */ - protected boolean restoreSketches() { + protected boolean restoreSketches() throws Exception { // figure out window placement Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); @@ -668,8 +671,9 @@ public class Base { /** * Create a new untitled document in a new sketch window. + * @throws Exception */ - public void handleNew() { + public void handleNew() throws Exception { try { String path = createNewUntitled(); if (path != null) { @@ -737,8 +741,9 @@ public class Base { /** * Prompt for a sketch to open, and open it in a new window. + * @throws Exception */ - public void handleOpenPrompt() { + public void handleOpenPrompt() throws Exception { // get the frontmost window frame for placing file dialog FileDialog fd = new FileDialog(activeEditor, _("Open an Arduino sketch..."), @@ -773,13 +778,14 @@ public class Base { * @param path Path to the pde file for the sketch in question * @return the Editor object, so that properties (like 'untitled') * can be set by the caller + * @throws Exception */ - public Editor handleOpen(String path) { + public Editor handleOpen(String path) throws Exception { return handleOpen(path, nextEditorLocation()); } - protected Editor handleOpen(String path, int[] location) { + protected Editor handleOpen(String path, int[] location) throws Exception { // System.err.println("entering handleOpen " + path); File file = new File(path); @@ -1011,7 +1017,11 @@ public class Base { item = Editor.newJMenuItem(_("Open..."), 'O'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - handleOpenPrompt(); + try { + handleOpenPrompt(); + } catch (Exception e1) { + e1.printStackTrace(); + } } }); menu.add(item); @@ -1076,17 +1086,17 @@ public class Base { importMenu.add(addLibraryMenuItem); // Split between user supplied libraries and IDE libraries - TargetPlatform targetPlatform = getTargetPlatform(); - if (targetPlatform != null) { + TargetBoard board = getTargetBoard(); + + if (board != null) { LibraryList ideLibs = getIDELibs(); LibraryList userLibs = getUserLibs(); try { // Find the current target. Get the platform, and then select the // correct name and core path. - PreferencesMap prefs = targetPlatform.getPreferences(); - String targetname = prefs.get("name"); - - JMenuItem platformItem = new JMenuItem(_(targetname)); + PreferencesMap prefs = board.getMergedPlatformPreferences(); + String platformName = prefs.get("name"); + JMenuItem platformItem = new JMenuItem(_(platformName)); platformItem.setEnabled(false); importMenu.add(platformItem); if (ideLibs.size() > 0) { @@ -1186,7 +1196,7 @@ public class Base { } catch (IOException e) { showWarning(_("Error"), _("Error loading libraries"), e); } - String currentArch = Base.getTargetPlatform().getName(); + String currentArch = Base.getTargetPlatform().getId(); libraries = libraries.filterByArchitecture(currentArch); // Populate importToLibraryTable @@ -1208,12 +1218,8 @@ public class Base { editor.onBoardOrPortChange(); } - public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) { - JMenu boardsMenu = makeOrGetBoardMenu(toolsMenu, _("Board")); - - String selPackage = Preferences.get("target_package"); - String selPlatform = Preferences.get("target_platform"); - String selBoard = Preferences.get("board"); + public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception { + JMenu boardsMenu = getBoardCustomMenu(); boolean first = true; @@ -1222,93 +1228,72 @@ public class Base { ButtonGroup boardsButtonGroup = new ButtonGroup(); Map buttonGroupsMap = new HashMap(); + // Generate custom menus for all platforms + for (TargetPackage targetPackage : packages.values()) { + for (TargetPlatform targetPlatform : targetPackage.platforms()) { + PreferencesMap customMenus = targetPlatform.getCustomMenus(); + for (String menuId : customMenus.keySet()) { + String title = customMenus.get(menuId); + makeBoardCustomMenu(toolsMenu, _(title)); + } + } + } + // Cycle through all packages for (TargetPackage targetPackage : packages.values()) { - String packageName = targetPackage.getName(); // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { - String platformName = targetPlatform.getName(); - - if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) { + String platformLabel = targetPlatform.getPreferences().get("name"); + if (platformLabel == null || targetPlatform.getBoards().isEmpty()) { continue; } - // Add a title for each group of boards + // Add a separator from the previous platform if (!first) boardsMenu.add(new JSeparator()); first = false; - JMenuItem separator = new JMenuItem(_(targetPlatform.getPreferences().get("name"))); + // Add a title for each platform + JMenuItem separator = new JMenuItem(_(platformLabel)); separator.setEnabled(false); boardsMenu.add(separator); - // For every platform cycle through all boards + // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { - // Setup a menu item for the current board - String boardName = board.getName(); - String boardId = board.getId(); - @SuppressWarnings("serial") - Action action = new AbstractAction(boardName) { - public void actionPerformed(ActionEvent actionevent) { - selectBoard((String) getValue("b"), editor); - } - }; - action.putValue("b", packageName + ":" + platformName + ":" + boardId); - - JRadioButtonMenuItem item = new JRadioButtonMenuItem(action); + JMenuItem item = createBoardMenusAndCustomMenus( + editor, + menuItemsToClickAfterStartup, + buttonGroupsMap, + board, targetPlatform, targetPackage); boardsMenu.add(item); boardsButtonGroup.add(item); + } + + // Cycle through all boards of referenced platforms + for (TargetPackage pack : packages.values()) { + if (pack == targetPackage) + continue; + for (TargetPlatform platf : pack.getPlatforms().values()) { + if (!platf.getId().equals(targetPlatform.getId())) + continue; + boolean firstRefBoardBlock = true; + for (TargetBoard board : platf.getBoards().values()) { + if (board.getReferencedPackageId() == null) + continue; - if (selBoard.equals(boardId) && selPackage.equals(packageName) - && selPlatform.equals(platformName)) { - menuItemsToClickAfterStartup.add(item); - } + // Add a separator from the previous platform + if (firstRefBoardBlock) + boardsMenu.add(new JSeparator()); + firstRefBoardBlock = false; - PreferencesMap customMenus = targetPlatform.getCustomMenus(); - int i = 0; - for (final String menuId : customMenus.keySet()) { - String title = customMenus.get(menuId); - JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); - - if (board.hasMenu(menuId)) { - PreferencesMap boardCustomMenu = board.getMenuLabels(menuId); - final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one - i++; - for (String customMenuOption : boardCustomMenu.keySet()) { - @SuppressWarnings("serial") - Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { - public void actionPerformed(ActionEvent e) { - Preferences.set("target_package", (String) getValue("package")); - Preferences.set("target_platform", (String) getValue("platform")); - Preferences.set("board", (String) getValue("board")); - Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); - - filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); - - onBoardOrPortChange(); - Sketch.buildSettingChanged(); - rebuildImportMenu(Editor.importMenu, editor); - rebuildExamplesMenu(Editor.examplesMenu); - } - }; - subAction.putValue("board", boardId); - subAction.putValue("custom_menu_option", customMenuOption); - subAction.putValue("package", packageName); - subAction.putValue("platform", platformName); - - if (!buttonGroupsMap.containsKey(menuId)) { - buttonGroupsMap.put(menuId, new ButtonGroup()); - } - - item = new JRadioButtonMenuItem(subAction); - menu.add(item); - buttonGroupsMap.get(menuId).add(item); - - String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); - if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { - menuItemsToClickAfterStartup.add(item); - } - } + JMenuItem item = createBoardMenusAndCustomMenus( + editor, + menuItemsToClickAfterStartup, + buttonGroupsMap, + board, platf, + pack); + boardsMenu.add(item); + boardsButtonGroup.add(item); } } } @@ -1325,6 +1310,87 @@ public class Base { } } + private JRadioButtonMenuItem createBoardMenusAndCustomMenus( + final Editor editor, + List menuItemsToClickAfterStartup, + Map buttonGroupsMap, + TargetBoard board, TargetPlatform targetPlatform, TargetPackage targetPackage) + throws Exception { + String selPackage = Preferences.get("target_package"); + String selPlatform = Preferences.get("target_platform"); + String selBoard = Preferences.get("board"); + + String boardId = board.getId(); + String packageName = targetPackage.getId(); + String platformName = targetPlatform.getId(); + + // Setup a menu item for the current board + @SuppressWarnings("serial") + Action action = new AbstractAction(board.getName()) { + public void actionPerformed(ActionEvent actionevent) { + selectBoard((String) getValue("b"), editor); + } + }; + action.putValue("b", packageName + ":" + platformName + ":" + boardId); + + JRadioButtonMenuItem item = new JRadioButtonMenuItem(action); + + if (selBoard.equals(boardId) && selPackage.equals(packageName) + && selPlatform.equals(platformName)) { + menuItemsToClickAfterStartup.add(item); + } + + int i = 0; + PreferencesMap customMenus = targetPlatform.getCustomMenus(); + for (final String menuId : customMenus.keySet()) { + String title = customMenus.get(menuId); + JMenu menu = getBoardCustomMenu(_(title)); + + if (board.hasMenu(menuId)) { + PreferencesMap boardCustomMenu = board.getMenuLabels(menuId); + final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one + i++; + for (String customMenuOption : boardCustomMenu.keySet()) { + @SuppressWarnings("serial") + Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { + public void actionPerformed(ActionEvent e) { + Preferences.set("target_package", (String) getValue("package")); + Preferences.set("target_platform", (String) getValue("platform")); + Preferences.set("board", (String) getValue("board")); + Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); + + filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); + + onBoardOrPortChange(); + Sketch.buildSettingChanged(); + rebuildImportMenu(Editor.importMenu, editor); + rebuildExamplesMenu(Editor.examplesMenu); + } + }; + subAction.putValue("board", boardId); + subAction.putValue("custom_menu_option", customMenuOption); + subAction.putValue("package", packageName); + subAction.putValue("platform", platformName); + + if (!buttonGroupsMap.containsKey(menuId)) { + buttonGroupsMap.put(menuId, new ButtonGroup()); + } + + JRadioButtonMenuItem subItem = new JRadioButtonMenuItem(subAction); + menu.add(subItem); + buttonGroupsMap.get(menuId).add(subItem); + + String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); + if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { + menuItemsToClickAfterStartup.add(subItem); + } + } + } + } + + return item; + } + private static void filterVisibilityOfSubsequentBoardMenus(String boardID, int fromIndex) { for (int i = fromIndex; i < Editor.boardsMenus.size(); i++) { JMenu menu = Editor.boardsMenus.get(i); @@ -1353,18 +1419,24 @@ public class Base { return false; } - private JMenu makeOrGetBoardMenu(JMenu toolsMenu, String label) { - for (JMenu menu : Editor.boardsMenus) { - if (label.equals(menu.getText())) { - return menu; - } - } + private JMenu makeBoardCustomMenu(JMenu toolsMenu, String label) { JMenu menu = new JMenu(label); Editor.boardsMenus.add(menu); toolsMenu.add(menu); return menu; } + private JMenu getBoardCustomMenu() throws Exception { + return getBoardCustomMenu(_("Board")); + } + + private JMenu getBoardCustomMenu(String label) throws Exception { + for (JMenu menu : Editor.boardsMenus) + if (label.equals(menu.getText())) + return menu; + throw new Exception("Custom menu not found!"); + } + private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) { JMenuItem firstVisible = null; for (int i = 0; i < menu.getItemCount(); i++) { @@ -1418,7 +1490,7 @@ public class Base { for (TargetPackage targetPackage : packages.values()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) { for (String programmer : targetPlatform.getProgrammers().keySet()) { - String id = targetPackage.getName() + ":" + programmer; + String id = targetPackage.getId() + ":" + programmer; @SuppressWarnings("serial") AbstractAction action = new AbstractAction(targetPlatform @@ -1496,7 +1568,11 @@ public class Base { if (replace) { handleOpenReplace(path); } else { - handleOpen(path); + try { + handleOpen(path); + } catch (Exception e1) { + e1.printStackTrace(); + } } } else { showWarning(_("Sketch Does Not Exist"), @@ -1930,16 +2006,15 @@ public class Base { } static public PreferencesMap getBoardPreferences() { - TargetPlatform target = getTargetPlatform(); - String boardId = Preferences.get("board"); - TargetBoard board = target.getBoard(boardId); + TargetBoard board = getTargetBoard(); + PreferencesMap prefs = new PreferencesMap(board.getPreferences()); - for (String menuId : target.getCustomMenusKeys()) { + for (String menuId : board.getMenuIds()) { String entry = Preferences.get("custom_" + menuId); if (board.hasMenu(menuId) && entry != null && - entry.startsWith(boardId)) { + entry.startsWith(board.getId())) { String selectionId = entry.substring(entry.indexOf("_") + 1); - prefs.putAll(board.getMenuConfiguration(menuId, selectionId)); + prefs.putAll(board.getMenuPreferences(menuId, selectionId)); prefs.put("name", prefs.get("name") + ", " + board.getMenuLabel(menuId, selectionId)); } @@ -1947,6 +2022,11 @@ public class Base { return prefs; } + public static TargetBoard getTargetBoard() { + String boardId = Preferences.get("board"); + return getTargetPlatform().getBoard(boardId); + } + static public File getPortableFolder() { return portableFolder; } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 0175da235..621d1bfc9 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -150,7 +150,7 @@ public class Editor extends JFrame implements RunnerListener { Runnable exportAppHandler; - public Editor(Base ibase, String path, int[] location) { + public Editor(Base ibase, String path, int[] location) throws Exception { super("Arduino"); this.base = ibase; @@ -476,7 +476,7 @@ public class Editor extends JFrame implements RunnerListener { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - protected void buildMenuBar() { + protected void buildMenuBar() throws Exception { JMenuBar menubar = new JMenuBar(); menubar.add(buildFileMenu()); menubar.add(buildEditMenu()); @@ -494,7 +494,11 @@ public class Editor extends JFrame implements RunnerListener { item = newJMenuItem(_("New"), 'N'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - base.handleNew(); + try { + base.handleNew(); + } catch (Exception e1) { + e1.printStackTrace(); + } } }); fileMenu.add(item); @@ -502,7 +506,11 @@ public class Editor extends JFrame implements RunnerListener { item = Editor.newJMenuItem(_("Open..."), 'O'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - base.handleOpenPrompt(); + try { + base.handleOpenPrompt(); + } catch (Exception e1) { + e1.printStackTrace(); + } } }); fileMenu.add(item); @@ -662,7 +670,7 @@ public class Editor extends JFrame implements RunnerListener { } - protected JMenu buildToolsMenu() { + protected JMenu buildToolsMenu() throws Exception { toolsMenu = new JMenu(_("Tools")); JMenu menu = toolsMenu; JMenuItem item; @@ -690,6 +698,11 @@ public class Editor extends JFrame implements RunnerListener { if (boardsMenus == null) { boardsMenus = new LinkedList(); + + JMenu boardsMenu = new JMenu(_("Board")); + Editor.boardsMenus.add(boardsMenu); + toolsMenu.add(boardsMenu); + base.rebuildBoardsMenu(toolsMenu, this); //Debug: rebuild imports importMenu.removeAll(); diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index e7b8d3752..afb469a3b 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -335,9 +335,13 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key case NEW: if (shiftPressed) { - editor.base.handleNew(); + try { + editor.base.handleNew(); + } catch (Exception e1) { + e1.printStackTrace(); + } } else { - editor.base.handleNewReplace(); + editor.base.handleNewReplace(); } break; diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 80cbe9ed6..9d3e4992d 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -132,12 +132,13 @@ public class Compiler implements MessageConsumer { throw re; } - TargetPlatform targetPlatform = Base.getTargetPlatform(); + TargetBoard targetBoard = Base.getTargetBoard(); + TargetPlatform targetPlatform = targetBoard.getContainerPlatform(); // Merge all the global preference configuration in order of priority PreferencesMap p = new PreferencesMap(); p.putAll(Preferences.getMap()); - p.putAll(targetPlatform.getPreferences()); + p.putAll(targetBoard.getMergedPlatformPreferences()); p.putAll(Base.getBoardPreferences()); for (String k : p.keySet()) { if (p.get(k) == null) @@ -146,28 +147,23 @@ public class Compiler implements MessageConsumer { p.put("build.path", _buildPath); p.put("build.project_name", _primaryClassName); - targetArch = targetPlatform.getName(); + targetArch = targetPlatform.getId(); p.put("build.arch", targetArch.toUpperCase()); if (!p.containsKey("compiler.path")) p.put("compiler.path", Base.getAvrBasePath()); // Core folder - String core = p.get("build.core"); - TargetPlatform tp; - if (!core.contains(":")) { - tp = targetPlatform; - } else { - String[] split = core.split(":", 2); - tp = Base.getTargetPlatform(split[0], Preferences.get("target_platform")); - core = split[1]; - } + TargetPlatform tp = targetBoard.getReferencedPlatform(); + if (tp == null) + tp = targetBoard.getContainerPlatform(); File coreFolder = new File(tp.getFolder(), "cores"); + String core = p.get("build.core"); coreFolder = new File(coreFolder, core); p.put("build.core.path", coreFolder.getAbsolutePath()); // System Folder - File systemFolder = targetPlatform.getFolder(); + File systemFolder = tp.getFolder(); systemFolder = new File(systemFolder, "system"); p.put("build.system.path", systemFolder.getAbsolutePath()); diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 958c1f2d5..6b791d66b 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -1,7 +1,11 @@ package processing.app.debug; +import static processing.app.I18n._; +import static processing.app.I18n.format; + import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import processing.app.helpers.PreferencesMap; @@ -10,6 +14,11 @@ public class TargetBoard { private String id; private PreferencesMap prefs; private Map menuOptions = new LinkedHashMap(); + private TargetPlatform containerPlatform; + + private String referencedPackageId; + private TargetPlatform referencedPlatform; + private TargetPackage referencedPackage; /** * Create a TargetBoard based on preferences passed as argument. @@ -17,13 +26,23 @@ public class TargetBoard { * @param _prefs * @return */ - public TargetBoard(String _id, PreferencesMap _prefs) { + public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) { + containerPlatform = parent; id = _id; prefs = new PreferencesMap(_prefs); + // Setup sub-menus PreferencesMap menus = prefs.firstLevelMap().get("menu"); if (menus != null) menuOptions = menus.firstLevelMap(); + + // Setup referenced platform + String core = prefs.get("build.core"); + if (core.contains(":")) { + String[] split = core.split(":"); + referencedPackageId = split[0]; + prefs.put("build.core", split[1]); + } } /** @@ -44,6 +63,15 @@ public class TargetBoard { return id; } + /** + * Get the package this board refers to + * + * @return + */ + public String getReferencedPackageId() { + return referencedPackageId; + } + /** * Get the full preferences map of the board with a given identifier * @@ -88,6 +116,10 @@ public class TargetBoard { return getMenuLabels(menuId).get(selectionId); } + public Set getMenuIds() { + return menuOptions.keySet(); + } + /** * Returns the configuration parameters to override (as a PreferenceMap) when * the specified option in the specified menu is selected @@ -98,7 +130,46 @@ public class TargetBoard { * The option ID * @return */ - public PreferencesMap getMenuConfiguration(String menuId, String selectionId) { + public PreferencesMap getMenuPreferences(String menuId, String selectionId) { return menuOptions.get(menuId).subTree(selectionId); } + + public TargetPlatform getContainerPlatform() { + return containerPlatform; + } + + public void resolveReferencedPlatforms(Map packages) + throws Exception { + if (referencedPackageId == null) + return; + + if (!packages.containsKey(referencedPackageId)) + throw new Exception( + format(_("Can't find referenced package ({1}) for board {0}"), id, + referencedPackageId)); + referencedPackage = packages.get(referencedPackageId); + + Map platforms = referencedPackage.getPlatforms(); + + String ourPlatformId = getContainerPlatform().getId(); + if (!platforms.containsKey(ourPlatformId)) + throw new Exception( + format(_("Can't find referenced package ({1}) for board {0}"), id, + referencedPackageId)); + referencedPlatform = platforms.get(ourPlatformId); + } + + public TargetPlatform getReferencedPlatform() { + return referencedPlatform; + } + + public PreferencesMap getMergedPlatformPreferences() { + PreferencesMap res = new PreferencesMap(); + if (referencedPlatform != null) + res.putAll(referencedPlatform.getPreferences()); + if (containerPlatform.getPreferences() != null) + res.putAll(containerPlatform.getPreferences()); + return res; + } + } diff --git a/app/src/processing/app/debug/TargetPackage.java b/app/src/processing/app/debug/TargetPackage.java index 6d04082da..5c0d7bb8a 100644 --- a/app/src/processing/app/debug/TargetPackage.java +++ b/app/src/processing/app/debug/TargetPackage.java @@ -32,23 +32,22 @@ import processing.app.helpers.filefilters.OnlyDirs; public class TargetPackage { - private String name; + private String id; Map platforms = new LinkedHashMap(); - public TargetPackage(String packageName, File packageFolder) - throws TargetPlatformException { - name = packageName; + public TargetPackage(String _id, File _folder) throws TargetPlatformException { + id = _id; - File[] folders = packageFolder.listFiles(new OnlyDirs()); + File[] folders = _folder.listFiles(new OnlyDirs()); if (folders == null) return; - for (File folder : folders) { - if (!folder.exists() || !folder.canRead()) + for (File subFolder : folders) { + if (!subFolder.exists() || !subFolder.canRead()) continue; - String arch = folder.getName(); - TargetPlatform platform = new TargetPlatform(arch, folder); + String arch = subFolder.getName(); + TargetPlatform platform = new TargetPlatform(arch, subFolder, this); platforms.put(arch, platform); } } @@ -65,7 +64,13 @@ public class TargetPackage { return platforms.get(platform); } - public String getName() { - return name; + public void resolveReferencedPlatforms(Map packages) + throws Exception { + for (TargetPlatform platform : getPlatforms().values()) + platform.resolveReferencedPlatforms(packages); + } + + public String getId() { + return id; } } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index ea72f79fb..9caf9cec1 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -36,8 +36,9 @@ import processing.app.helpers.PreferencesMap; public class TargetPlatform { - private String name; + private String id; private File folder; + private TargetPackage containerPackage; /** * Contains preferences for every defined board @@ -59,10 +60,12 @@ public class TargetPlatform { */ private PreferencesMap customMenus = new PreferencesMap(); - public TargetPlatform(String _name, File _folder) + public TargetPlatform(String _name, File _folder, TargetPackage parent) throws TargetPlatformException { - name = _name; + + id = _name; folder = _folder; + containerPackage = parent; // If there is no boards.txt, this is not a valid 1.5 hardware folder File boardsFile = new File(folder, "boards.txt"); @@ -85,7 +88,7 @@ public class TargetPlatform { // Create boards for (String id : boardsPreferences.keySet()) { PreferencesMap preferences = boardsPreferences.get(id); - TargetBoard board = new TargetBoard(id, preferences); + TargetBoard board = new TargetBoard(id, preferences, this); boards.put(id, board); } } catch (IOException e) { @@ -116,8 +119,8 @@ public class TargetPlatform { } } - public String getName() { - return name; + public String getId() { + return id; } public File getFolder() { @@ -132,7 +135,7 @@ public class TargetPlatform { return customMenus; } - public Set getCustomMenusKeys() { + public Set getCustomMenuIds() { return customMenus.keySet(); } @@ -155,4 +158,22 @@ public class TargetPlatform { public TargetBoard getBoard(String boardId) { return boards.get(boardId); } + + public TargetPackage getContainerPackage() { + return containerPackage; + } + + public void resolveReferencedPlatforms(Map packages) + throws Exception { + for (TargetBoard board : getBoards().values()) + board.resolveReferencedPlatforms(packages); + } + + @Override + public String toString() { + String res = "TargetPlatform: name=" + id + " boards={\n"; + for (String boardId : boards.keySet()) + res += " " + boardId + " = " + boards.get(boardId) + "\n"; + return res + "}"; + } } diff --git a/app/src/processing/app/macosx/ThinkDifferent.java b/app/src/processing/app/macosx/ThinkDifferent.java index f0c13cbba..6448b1e9a 100644 --- a/app/src/processing/app/macosx/ThinkDifferent.java +++ b/app/src/processing/app/macosx/ThinkDifferent.java @@ -96,7 +96,11 @@ public class ThinkDifferent implements ApplicationListener { public void handleOpenFile(ApplicationEvent ae) { // System.out.println("got open file event " + ae.getFilename()); String filename = ae.getFilename(); - base.handleOpen(filename); + try { + base.handleOpen(filename); + } catch (Exception e) { + e.printStackTrace(); + } ae.setHandled(true); } From 6bfe877c4562218b142635b525a9792a16ca6848 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 4 Mar 2013 17:29:44 +0100 Subject: [PATCH 06/16] Fixed check for referenced cores. See #1157 --- app/src/processing/app/Base.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 37abcd4fd..a69eb53ae 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1278,9 +1278,10 @@ public class Base { continue; boolean firstRefBoardBlock = true; for (TargetBoard board : platf.getBoards().values()) { - if (board.getReferencedPackageId() == null) + String ref = board.getReferencedPackageId(); + if (ref == null || !ref.equals(targetPackage.getId())) continue; - + // Add a separator from the previous platform if (firstRefBoardBlock) boardsMenu.add(new JSeparator()); From 0947e3d55c5170c69346382320635a53b8e4fe4d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 4 Mar 2013 17:56:51 +0100 Subject: [PATCH 07/16] Unused custom menus are not showed --- app/src/processing/app/Base.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index a69eb53ae..976e4f3ae 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1229,15 +1229,13 @@ public class Base { Map buttonGroupsMap = new HashMap(); // Generate custom menus for all platforms + Set titles = new HashSet(); for (TargetPackage targetPackage : packages.values()) { - for (TargetPlatform targetPlatform : targetPackage.platforms()) { - PreferencesMap customMenus = targetPlatform.getCustomMenus(); - for (String menuId : customMenus.keySet()) { - String title = customMenus.get(menuId); - makeBoardCustomMenu(toolsMenu, _(title)); - } - } + for (TargetPlatform targetPlatform : targetPackage.platforms()) + titles.addAll(targetPlatform.getCustomMenus().values()); } + for (String title : titles) + makeBoardCustomMenu(toolsMenu, _(title)); // Cycle through all packages for (TargetPackage targetPackage : packages.values()) { @@ -1399,9 +1397,9 @@ public class Base { JMenuItem menuItem = menu.getItem(m); menuItem.setVisible(menuItem.getAction().getValue("board").equals(boardID)); } - menu.setEnabled(ifThereAreVisibleItemsOn(menu)); + menu.setVisible(ifThereAreVisibleItemsOn(menu)); - if (menu.isEnabled()) { + if (menu.isVisible()) { JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem(menu); if (!visibleSelectedOrFirstMenuItem.isSelected()) { visibleSelectedOrFirstMenuItem.setSelected(true); From c1c87a16426682ff43f2adb2f2e69a6b935cf92a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 5 Mar 2013 19:53:49 +0100 Subject: [PATCH 08/16] Simplified Boards menu layout. Fixes #1307 --- app/src/processing/app/Base.java | 46 ++++++-------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 976e4f3ae..23a9a02d8 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -38,7 +38,8 @@ import processing.app.helpers.FileUtils; import processing.app.helpers.PreferencesMap; import processing.app.helpers.filefilters.OnlyDirs; import processing.app.helpers.filefilters.OnlyFilesWithExtension; -import processing.app.javax.swing.filechooser.FileNameExtensionFilter;import processing.app.packages.Library; +import processing.app.javax.swing.filechooser.FileNameExtensionFilter; +import processing.app.packages.Library; import processing.app.packages.LibraryList; import processing.app.tools.ZipDeflater; import processing.core.*; @@ -1241,10 +1242,6 @@ public class Base { for (TargetPackage targetPackage : packages.values()) { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { - String platformLabel = targetPlatform.getPreferences().get("name"); - if (platformLabel == null || targetPlatform.getBoards().isEmpty()) { - continue; - } // Add a separator from the previous platform if (!first) @@ -1252,9 +1249,12 @@ public class Base { first = false; // Add a title for each platform - JMenuItem separator = new JMenuItem(_(platformLabel)); - separator.setEnabled(false); - boardsMenu.add(separator); + String platformLabel = targetPlatform.getPreferences().get("name"); + if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) { + JMenuItem menuLabel = new JMenuItem(_(platformLabel)); + menuLabel.setEnabled(false); + boardsMenu.add(menuLabel); + } // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { @@ -1266,36 +1266,6 @@ public class Base { boardsMenu.add(item); boardsButtonGroup.add(item); } - - // Cycle through all boards of referenced platforms - for (TargetPackage pack : packages.values()) { - if (pack == targetPackage) - continue; - for (TargetPlatform platf : pack.getPlatforms().values()) { - if (!platf.getId().equals(targetPlatform.getId())) - continue; - boolean firstRefBoardBlock = true; - for (TargetBoard board : platf.getBoards().values()) { - String ref = board.getReferencedPackageId(); - if (ref == null || !ref.equals(targetPackage.getId())) - continue; - - // Add a separator from the previous platform - if (firstRefBoardBlock) - boardsMenu.add(new JSeparator()); - firstRefBoardBlock = false; - - JMenuItem item = createBoardMenusAndCustomMenus( - editor, - menuItemsToClickAfterStartup, - buttonGroupsMap, - board, platf, - pack); - boardsMenu.add(item); - boardsButtonGroup.add(item); - } - } - } } } From 1d89e86b62dc6c87a686fa3076291cb35dfc3490 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 5 Mar 2013 20:18:46 +0100 Subject: [PATCH 09/16] "build.core" property can now be used inside custom menus. Fixes #1304 --- app/src/processing/app/Base.java | 20 ++++--- app/src/processing/app/debug/Compiler.java | 32 +++++++--- app/src/processing/app/debug/TargetBoard.java | 58 ------------------- .../processing/app/debug/TargetPackage.java | 6 -- .../processing/app/debug/TargetPlatform.java | 6 -- 5 files changed, 35 insertions(+), 87 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 23a9a02d8..c149583a4 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -294,8 +294,6 @@ public class Base { System.out.println(_("No valid configured cores found! Exiting...")); System.exit(3); } - for (TargetPackage pack : packages.values()) - pack.resolveReferencedPlatforms(packages); // Setup board-dependent variables. onBoardOrPortChange(); @@ -1087,19 +1085,23 @@ public class Base { importMenu.add(addLibraryMenuItem); // Split between user supplied libraries and IDE libraries - TargetBoard board = getTargetBoard(); + TargetPlatform targetPlatform = getTargetPlatform(); - if (board != null) { + if (targetPlatform != null) { LibraryList ideLibs = getIDELibs(); LibraryList userLibs = getUserLibs(); try { // Find the current target. Get the platform, and then select the // correct name and core path. - PreferencesMap prefs = board.getMergedPlatformPreferences(); - String platformName = prefs.get("name"); - JMenuItem platformItem = new JMenuItem(_(platformName)); - platformItem.setEnabled(false); - importMenu.add(platformItem); + PreferencesMap prefs = targetPlatform.getPreferences(); + if (prefs != null) { + String platformName = prefs.get("name"); + if (platformName != null) { + JMenuItem platformItem = new JMenuItem(_(platformName)); + platformItem.setEnabled(false); + importMenu.add(platformItem); + } + } if (ideLibs.size() > 0) { importMenu.addSeparator(); addLibraries(importMenu, ideLibs); diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 9d3e4992d..8f1b9a112 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -132,13 +132,30 @@ public class Compiler implements MessageConsumer { throw re; } - TargetBoard targetBoard = Base.getTargetBoard(); - TargetPlatform targetPlatform = targetBoard.getContainerPlatform(); + // Check if the board needs a platform from another package + TargetPlatform targetPlatform = Base.getTargetPlatform(); + TargetPlatform corePlatform = null; + PreferencesMap boardPreferences = Base.getBoardPreferences(); + String core = boardPreferences.get("build.core"); + if (core.contains(":")) { + String[] split = core.split(":"); + core = split[1]; + corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId()); + if (corePlatform == null) { + RunnerException re = new RunnerException(I18n + .format(_("Selected board depends on '{0}' core (not installed)."), + split[0])); + re.hideStackTrace(); + throw re; + } + } // Merge all the global preference configuration in order of priority PreferencesMap p = new PreferencesMap(); p.putAll(Preferences.getMap()); - p.putAll(targetBoard.getMergedPlatformPreferences()); + if (corePlatform != null) + p.putAll(corePlatform.getPreferences()); + p.putAll(targetPlatform.getPreferences()); p.putAll(Base.getBoardPreferences()); for (String k : p.keySet()) { if (p.get(k) == null) @@ -154,12 +171,12 @@ public class Compiler implements MessageConsumer { p.put("compiler.path", Base.getAvrBasePath()); // Core folder - TargetPlatform tp = targetBoard.getReferencedPlatform(); + TargetPlatform tp = corePlatform; if (tp == null) - tp = targetBoard.getContainerPlatform(); + tp = targetPlatform; File coreFolder = new File(tp.getFolder(), "cores"); - String core = p.get("build.core"); coreFolder = new File(coreFolder, core); + p.put("build.core", core); p.put("build.core.path", coreFolder.getAbsolutePath()); // System Folder @@ -175,8 +192,7 @@ public class Compiler implements MessageConsumer { t = targetPlatform; } else { String[] split = variant.split(":", 2); - t = Base - .getTargetPlatform(split[0], Preferences.get("target_platform")); + t = Base.getTargetPlatform(split[0], targetPlatform.getId()); variant = split[1]; } File variantFolder = new File(t.getFolder(), "variants"); diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 6b791d66b..2a5f21dd4 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -1,8 +1,5 @@ package processing.app.debug; -import static processing.app.I18n._; -import static processing.app.I18n.format; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -16,10 +13,6 @@ public class TargetBoard { private Map menuOptions = new LinkedHashMap(); private TargetPlatform containerPlatform; - private String referencedPackageId; - private TargetPlatform referencedPlatform; - private TargetPackage referencedPackage; - /** * Create a TargetBoard based on preferences passed as argument. * @@ -35,14 +28,6 @@ public class TargetBoard { PreferencesMap menus = prefs.firstLevelMap().get("menu"); if (menus != null) menuOptions = menus.firstLevelMap(); - - // Setup referenced platform - String core = prefs.get("build.core"); - if (core.contains(":")) { - String[] split = core.split(":"); - referencedPackageId = split[0]; - prefs.put("build.core", split[1]); - } } /** @@ -63,15 +48,6 @@ public class TargetBoard { return id; } - /** - * Get the package this board refers to - * - * @return - */ - public String getReferencedPackageId() { - return referencedPackageId; - } - /** * Get the full preferences map of the board with a given identifier * @@ -138,38 +114,4 @@ public class TargetBoard { return containerPlatform; } - public void resolveReferencedPlatforms(Map packages) - throws Exception { - if (referencedPackageId == null) - return; - - if (!packages.containsKey(referencedPackageId)) - throw new Exception( - format(_("Can't find referenced package ({1}) for board {0}"), id, - referencedPackageId)); - referencedPackage = packages.get(referencedPackageId); - - Map platforms = referencedPackage.getPlatforms(); - - String ourPlatformId = getContainerPlatform().getId(); - if (!platforms.containsKey(ourPlatformId)) - throw new Exception( - format(_("Can't find referenced package ({1}) for board {0}"), id, - referencedPackageId)); - referencedPlatform = platforms.get(ourPlatformId); - } - - public TargetPlatform getReferencedPlatform() { - return referencedPlatform; - } - - public PreferencesMap getMergedPlatformPreferences() { - PreferencesMap res = new PreferencesMap(); - if (referencedPlatform != null) - res.putAll(referencedPlatform.getPreferences()); - if (containerPlatform.getPreferences() != null) - res.putAll(containerPlatform.getPreferences()); - return res; - } - } diff --git a/app/src/processing/app/debug/TargetPackage.java b/app/src/processing/app/debug/TargetPackage.java index 5c0d7bb8a..020cf89e3 100644 --- a/app/src/processing/app/debug/TargetPackage.java +++ b/app/src/processing/app/debug/TargetPackage.java @@ -64,12 +64,6 @@ public class TargetPackage { return platforms.get(platform); } - public void resolveReferencedPlatforms(Map packages) - throws Exception { - for (TargetPlatform platform : getPlatforms().values()) - platform.resolveReferencedPlatforms(packages); - } - public String getId() { return id; } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 9caf9cec1..2e9b88a39 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -163,12 +163,6 @@ public class TargetPlatform { return containerPackage; } - public void resolveReferencedPlatforms(Map packages) - throws Exception { - for (TargetBoard board : getBoards().values()) - board.resolveReferencedPlatforms(packages); - } - @Override public String toString() { String res = "TargetPlatform: name=" + id + " boards={\n"; From fe44fbf7e3b189234e92a7d07fe98b7704be726a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 5 Mar 2013 21:24:34 +0100 Subject: [PATCH 10/16] Added message for unknown tools. See #1304 --- app/src/processing/app/debug/BasicUploader.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/debug/BasicUploader.java b/app/src/processing/app/debug/BasicUploader.java index 4328cc1a6..6f2b9200d 100644 --- a/app/src/processing/app/debug/BasicUploader.java +++ b/app/src/processing/app/debug/BasicUploader.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.List; import processing.app.Base; +import processing.app.I18n; import processing.app.Preferences; import processing.app.Serial; import processing.app.SerialException; @@ -260,7 +261,13 @@ public class BasicUploader extends Uploader { PreferencesMap prefs = Preferences.getMap(); prefs.putAll(Base.getBoardPreferences()); prefs.putAll(targetPlatform.getProgrammer(programmer)); - prefs.putAll(targetPlatform.getTool(prefs.get("bootloader.tool"))); + + String toolName = prefs.get("bootloader.tool"); + PreferencesMap toolPrefs = targetPlatform.getTool(toolName); + if (toolPrefs.size() == 0) + throw new RunnerException(I18n.format(_("Could not find tool {0}"), + toolName)); + prefs.putAll(toolPrefs); if (verbose) { prefs.put("erase.verbose", prefs.get("erase.params.verbose")); prefs.put("bootloader.verbose", prefs.get("bootloader.params.verbose")); From bed305a55613facf65087e1262cfa0fbe60a8abb Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 6 Mar 2013 12:49:41 +0100 Subject: [PATCH 11/16] Added auto-generation for 'build.board' value in boards.txt. See #1305. --- app/src/processing/app/debug/TargetBoard.java | 15 ++ hardware/arduino/avr/boards.txt | 173 +++++++++--------- hardware/arduino/avr/platform.txt | 4 +- hardware/arduino/sam/boards.txt | 68 +++---- hardware/arduino/sam/platform.txt | 4 +- 5 files changed, 140 insertions(+), 124 deletions(-) diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 2a5f21dd4..721b69613 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -1,5 +1,8 @@ package processing.app.debug; +import static processing.app.I18n._; +import static processing.app.I18n.format; + import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -28,6 +31,18 @@ public class TargetBoard { PreferencesMap menus = prefs.firstLevelMap().get("menu"); if (menus != null) menuOptions = menus.firstLevelMap(); + + // Auto generate build.board if not set + if (!prefs.containsKey("build.board")) { + String board = containerPlatform.getId() + "_" + id; + board = board.toUpperCase(); + prefs.put("build.board", board); + System.out + .println(format( + _("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"), + containerPlatform.getContainerPackage().getId(), + containerPlatform.getId(), id, board)); + } } /** diff --git a/hardware/arduino/avr/boards.txt b/hardware/arduino/avr/boards.txt index ee5a19579..de767f510 100644 --- a/hardware/arduino/avr/boards.txt +++ b/hardware/arduino/avr/boards.txt @@ -20,52 +20,52 @@ uno.bootloader.file=optiboot/optiboot_atmega328.hex uno.build.mcu=atmega328p uno.build.f_cpu=16000000L -uno.build.board=ARDUINO_UNO +uno.build.board=AVR_UNO uno.build.core=arduino uno.build.variant=standard ############################################################## -atmega328diecimila.name=Arduino Duemilanove or Diecimila +duemilanove.name=Arduino Duemilanove or Diecimila -atmega328diecimila.upload.tool=avrdude -atmega328diecimila.upload.protocol=arduino +duemilanove.upload.tool=avrdude +duemilanove.upload.protocol=arduino -atmega328diecimila.bootloader.tool=avrdude -atmega328diecimila.bootloader.low_fuses=0xFF -atmega328diecimila.bootloader.unlock_bits=0x3F -atmega328diecimila.bootloader.lock_bits=0x0F +duemilanove.bootloader.tool=avrdude +duemilanove.bootloader.low_fuses=0xFF +duemilanove.bootloader.unlock_bits=0x3F +duemilanove.bootloader.lock_bits=0x0F -atmega328diecimila.build.f_cpu=16000000L -atmega328diecimila.build.board=ARDUINO_DUEMILANOVE -atmega328diecimila.build.core=arduino -atmega328diecimila.build.variant=standard +duemilanove.build.f_cpu=16000000L +duemilanove.build.board=AVR_DUEMILANOVE +duemilanove.build.core=arduino +duemilanove.build.variant=standard ## Arduino Duemilanove or Diecimila w/ ATmega328 ## --------------------------------------------- -atmega328diecimila.menu.cpu.atmega328=ATmega328 +duemilanove.menu.cpu.atmega328=ATmega328 -atmega328diecimila.menu.cpu.atmega328.upload.maximum_size=30720 -atmega328diecimila.menu.cpu.atmega328.upload.speed=57600 +duemilanove.menu.cpu.atmega328.upload.maximum_size=30720 +duemilanove.menu.cpu.atmega328.upload.speed=57600 -atmega328diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA -atmega328diecimila.menu.cpu.atmega328.bootloader.extended_fuses=0x05 -atmega328diecimila.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +duemilanove.menu.cpu.atmega328.bootloader.high_fuses=0xDA +duemilanove.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +duemilanove.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex -atmega328diecimila.menu.cpu.atmega328.build.mcu=atmega328p +duemilanove.menu.cpu.atmega328.build.mcu=atmega328p ## Arduino Duemilanove or Diecimila w/ ATmega168 ## --------------------------------------------- -atmega328diecimila.menu.cpu.atmega168=ATmega168 +duemilanove.menu.cpu.atmega168=ATmega168 -atmega328diecimila.menu.cpu.atmega168.upload.maximum_size=14336 -atmega328diecimila.menu.cpu.atmega168.upload.speed=19200 +duemilanove.menu.cpu.atmega168.upload.maximum_size=14336 +duemilanove.menu.cpu.atmega168.upload.speed=19200 -atmega328diecimila.menu.cpu.atmega168.bootloader.high_fuses=0xdd -atmega328diecimila.menu.cpu.atmega168.bootloader.extended_fuses=0x00 -atmega328diecimila.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex +duemilanove.menu.cpu.atmega168.bootloader.high_fuses=0xdd +duemilanove.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +duemilanove.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex -atmega328diecimila.menu.cpu.atmega168.build.mcu=atmega168 +duemilanove.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -79,7 +79,7 @@ nano.bootloader.unlock_bits=0x3F nano.bootloader.lock_bits=0x0F nano.build.f_cpu=16000000L -nano.build.board=ARDUINO_NANO +nano.build.board=AVR_NANO nano.build.core=arduino nano.build.variant=eightanaloginputs @@ -131,7 +131,7 @@ mega2560.bootloader.lock_bits=0x0F mega2560.build.mcu=atmega2560 mega2560.build.f_cpu=16000000L -mega2560.build.board=ARDUINO_MEGA2560 +mega2560.build.board=AVR_MEGA2560 mega2560.build.core=arduino mega2560.build.variant=mega @@ -155,7 +155,7 @@ mega.bootloader.lock_bits=0x0F mega.build.mcu=atmega1280 mega.build.f_cpu=16000000L -mega.build.board=ARDUINO_MEGA +mega.build.board=AVR_MEGA mega.build.core=arduino mega.build.variant=mega @@ -182,7 +182,7 @@ leonardo.build.mcu=atmega32u4 leonardo.build.f_cpu=16000000L leonardo.build.vid=0x2341 leonardo.build.pid=0x8036 -leonardo.build.board=ARDUINO_LEONARDO +leonardo.build.board=AVR_LEONARDO leonardo.build.core=arduino leonardo.build.variant=leonardo leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} @@ -210,7 +210,7 @@ micro.build.mcu=atmega32u4 micro.build.f_cpu=16000000L micro.build.vid=0x2341 micro.build.pid=0x8037 -micro.build.board=ARDUINO_MICRO +micro.build.board=AVR_MICRO micro.build.core=arduino micro.build.variant=micro micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} @@ -238,7 +238,7 @@ esplora.build.mcu=atmega32u4 esplora.build.f_cpu=16000000L esplora.build.vid=0x2341 esplora.build.pid=0x803c -esplora.build.board=ARDUINO_ESPLORA +esplora.build.board=AVR_ESPLORA esplora.build.core=arduino esplora.build.variant=leonardo esplora.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} @@ -256,7 +256,7 @@ mini.bootloader.unlock_bits=0x3F mini.bootloader.lock_bits=0x0F mini.build.f_cpu=16000000L -mini.build.board=ARDUINO_MINI +mini.build.board=AVR_MINI mini.build.core=arduino mini.build.variant=eightanaloginputs @@ -306,7 +306,7 @@ ethernet.bootloader.lock_bits=0x0F ethernet.build.variant=standard ethernet.build.mcu=atmega328p ethernet.build.f_cpu=16000000L -ethernet.build.board=ARDUINO_ETHERNET +ethernet.build.board=AVR_ETHERNET ethernet.build.core=arduino ############################################################## @@ -328,7 +328,7 @@ fio.bootloader.lock_bits=0x0F fio.build.mcu=atmega328p fio.build.f_cpu=8000000L -fio.build.board=ARDUINO_FIO +fio.build.board=AVR_FIO fio.build.core=arduino fio.build.variant=eightanaloginputs @@ -347,7 +347,7 @@ bt.bootloader.unlock_bits=0x3F bt.bootloader.lock_bits=0x0F bt.build.f_cpu=16000000L -bt.build.board=ARDUINO_BT +bt.build.board=AVR_BT bt.build.core=arduino bt.build.variant=eightanaloginputs @@ -375,32 +375,32 @@ bt.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## -LilyPadUSB.name=LilyPad Arduino USB +lilypad_usb.name=LilyPad Arduino USB -LilyPadUSB.upload.tool=avrdude -LilyPadUSB.upload.protocol=avr109 -LilyPadUSB.upload.maximum_size=28672 -LilyPadUSB.upload.speed=57600 -LilyPadUSB.upload.disable_flushing=true -LilyPadUSB.upload.use_1200bps_touch=true -LilyPadUSB.upload.wait_for_upload_port=true +lilypad_usb.upload.tool=avrdude +lilypad_usb.upload.protocol=avr109 +lilypad_usb.upload.maximum_size=28672 +lilypad_usb.upload.speed=57600 +lilypad_usb.upload.disable_flushing=true +lilypad_usb.upload.use_1200bps_touch=true +lilypad_usb.upload.wait_for_upload_port=true -LilyPadUSB.bootloader.tool=avrdude -LilyPadUSB.bootloader.low_fuses=0xff -LilyPadUSB.bootloader.high_fuses=0xd8 -LilyPadUSB.bootloader.extended_fuses=0xce -LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex -LilyPadUSB.bootloader.unlock_bits=0x3F -LilyPadUSB.bootloader.lock_bits=0x2F +lilypad_usb.bootloader.tool=avrdude +lilypad_usb.bootloader.low_fuses=0xff +lilypad_usb.bootloader.high_fuses=0xd8 +lilypad_usb.bootloader.extended_fuses=0xce +lilypad_usb.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex +lilypad_usb.bootloader.unlock_bits=0x3F +lilypad_usb.bootloader.lock_bits=0x2F -LilyPadUSB.build.mcu=atmega32u4 -LilyPadUSB.build.f_cpu=8000000L -LilyPadUSB.build.vid=0x1B4F -LilyPadUSB.build.pid=0x9208 -LilyPadUSB.build.board=ARDUINO_LILYPAD_USB -LilyPadUSB.build.core=arduino -LilyPadUSB.build.variant=leonardo -LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} +lilypad_usb.build.mcu=atmega32u4 +lilypad_usb.build.f_cpu=8000000L +lilypad_usb.build.vid=0x1B4F +lilypad_usb.build.pid=0x9208 +lilypad_usb.build.board=AVR_LILYPAD_USB +lilypad_usb.build.core=arduino +lilypad_usb.build.variant=leonardo +lilypad_usb.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} ############################################################## @@ -414,7 +414,7 @@ lilypad.bootloader.unlock_bits=0x3F lilypad.bootloader.lock_bits=0x0F lilypad.build.f_cpu=8000000L -lilypad.build.board=ARDUINO_LILYPAD +lilypad.build.board=AVR_LILYPAD lilypad.build.core=arduino lilypad.build.variant=standard @@ -457,7 +457,7 @@ pro.bootloader.tool=avrdude pro.bootloader.unlock_bits=0x3F pro.bootloader.lock_bits=0x0F -pro.build.board=ARDUINO_PRO +pro.build.board=AVR_PRO pro.build.core=arduino pro.build.variant=standard @@ -523,43 +523,44 @@ pro.menu.cpu.8MHzatmega168.build.f_cpu=8000000L ############################################################## -atmegang.name=Arduino NG or older +ng.name=Arduino NG or older -atmegang.upload.tool=avrdude -atmegang.upload.protocol=arduino -atmegang.upload.speed=19200 +ng.upload.tool=avrdude +ng.upload.protocol=arduino +ng.upload.speed=19200 -atmegang.bootloader.tool=avrdude -atmegang.bootloader.unlock_bits=0x3F -atmegang.bootloader.lock_bits=0x0F +ng.bootloader.tool=avrdude +ng.bootloader.unlock_bits=0x3F +ng.bootloader.lock_bits=0x0F -atmegang.build.mcu=atmegang -atmegang.build.f_cpu=16000000L -atmegang.build.board=ARDUINO_NG -atmegang.build.core=arduino -atmegang.build.variant=standard +ng.build.mcu=atmegang +ng.build.f_cpu=16000000L +ng.build.board=AVR_NG +ng.build.core=arduino +ng.build.variant=standard ## Arduino NG or older w/ ATmega168 ## -------------------------------- -atmegang.menu.cpu.atmega168=ATmega168 +ng.menu.cpu.atmega168=ATmega168 -atmegang.menu.cpu.atmega168.upload.maximum_size=14336 +ng.menu.cpu.atmega168.upload.maximum_size=14336 -atmegang.menu.cpu.atmega168.bootloader.low_fuses=0xff -atmegang.menu.cpu.atmega168.bootloader.high_fuses=0xdd -atmegang.menu.cpu.atmega168.bootloader.extended_fuses=0x00 -atmegang.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex +ng.menu.cpu.atmega168.bootloader.low_fuses=0xff +ng.menu.cpu.atmega168.bootloader.high_fuses=0xdd +ng.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +ng.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex -atmegang.menu.cpu.atmega168.build.mcu=atmega168 +ng.menu.cpu.atmega168.build.mcu=atmega168 ## Arduino NG or older w/ ATmega8 ## ------------------------------ -atmegang.menu.cpu.atmega8=ATmega8 +ng.menu.cpu.atmega8=ATmega8 -atmegang.menu.cpu.atmega8.upload.maximum_size=7168 +ng.menu.cpu.atmega8.upload.maximum_size=7168 -atmegang.menu.cpu.atmega8.bootloader.low_fuses=0xdf -atmegang.menu.cpu.atmega8.bootloader.high_fuses=0xca -atmegang.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex +ng.menu.cpu.atmega8.bootloader.low_fuses=0xdf +ng.menu.cpu.atmega8.bootloader.high_fuses=0xca +ng.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex + +ng.menu.cpu.atmega8.build.mcu=atmega8 -atmegang.menu.cpu.atmega8.build.mcu=atmega8 diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index a6cd314c1..53c31620c 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -27,10 +27,10 @@ build.extra_flags= # -------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -D{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -D{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Create archives recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" diff --git a/hardware/arduino/sam/boards.txt b/hardware/arduino/sam/boards.txt index d3629e596..437941d70 100644 --- a/hardware/arduino/sam/boards.txt +++ b/hardware/arduino/sam/boards.txt @@ -1,37 +1,37 @@ -arduino_due_x_dbg.name=Arduino Due (Programming Port) -arduino_due_x_dbg.upload.tool=bossac -arduino_due_x_dbg.upload.protocol=sam-ba -arduino_due_x_dbg.upload.maximum_size=524288 -arduino_due_x_dbg.upload.use_1200bps_touch=true -arduino_due_x_dbg.upload.wait_for_upload_port=false -arduino_due_x_dbg.upload.native_usb=false -arduino_due_x_dbg.build.mcu=cortex-m3 -arduino_due_x_dbg.build.f_cpu=84000000L -arduino_due_x_dbg.build.board=ARDUINO_DUE -arduino_due_x_dbg.build.core=arduino -arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON -arduino_due_x_dbg.build.ldscript=linker_scripts/gcc/flash.ld -arduino_due_x_dbg.build.variant=arduino_due_x -arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a -arduino_due_x_dbg.build.vid=0x2341 -arduino_due_x_dbg.build.pid=0x003e +due_prgport.name=Arduino Due (Programming Port) +due_prgport.upload.tool=bossac +due_prgport.upload.protocol=sam-ba +due_prgport.upload.maximum_size=524288 +due_prgport.upload.use_1200bps_touch=true +due_prgport.upload.wait_for_upload_port=false +due_prgport.upload.native_usb=false +due_prgport.build.mcu=cortex-m3 +due_prgport.build.f_cpu=84000000L +due_prgport.build.board=SAM_DUE +due_prgport.build.core=arduino +due_prgport.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON +due_prgport.build.ldscript=linker_scripts/gcc/flash.ld +due_prgport.build.variant=arduino_due_x +due_prgport.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a +due_prgport.build.vid=0x2341 +due_prgport.build.pid=0x003e -arduino_due_x.name=Arduino Due (Native USB Port) -arduino_due_x.upload.tool=bossac -arduino_due_x.upload.protocol=sam-ba -arduino_due_x.upload.maximum_size=524288 -arduino_due_x.upload.use_1200bps_touch=true -arduino_due_x.upload.wait_for_upload_port=true -arduino_due_x.upload.native_usb=true -arduino_due_x.build.mcu=cortex-m3 -arduino_due_x.build.f_cpu=84000000L -arduino_due_x.build.board=ARDUINO_DUE -arduino_due_x.build.core=arduino -arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON -arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld -arduino_due_x.build.variant=arduino_due_x -arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a -arduino_due_x.build.vid=0x2341 -arduino_due_x.build.pid=0x003e +due.name=Arduino Due (Native USB Port) +due.upload.tool=bossac +due.upload.protocol=sam-ba +due.upload.maximum_size=524288 +due.upload.use_1200bps_touch=true +due.upload.wait_for_upload_port=true +due.upload.native_usb=true +due.build.mcu=cortex-m3 +due.build.f_cpu=84000000L +due.build.board=SAM_DUE +due.build.core=arduino +due.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON +due.build.ldscript=linker_scripts/gcc/flash.ld +due.build.variant=arduino_due_x +due.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a +due.build.vid=0x2341 +due.build.pid=0x003e diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index 3594610ea..f64309a23 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -30,10 +30,10 @@ compiler.libsam.c.flags="-I{build.system.path}/libsam" "-I{build.system.path}/CM # --------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -D{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -D{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" ## Create archives recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" From 8ef2fe3fafb6d29a91866bddb4377ceffc65ca94 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 11 Mar 2013 19:08:02 +0100 Subject: [PATCH 12/16] The "tool" for burning bootloader is now correctly selected from board preferences. --- .../processing/app/debug/BasicUploader.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/debug/BasicUploader.java b/app/src/processing/app/debug/BasicUploader.java index 6f2b9200d..685165c48 100644 --- a/app/src/processing/app/debug/BasicUploader.java +++ b/app/src/processing/app/debug/BasicUploader.java @@ -250,18 +250,27 @@ public class BasicUploader extends Uploader { } public boolean burnBootloader() throws RunnerException { - String programmer = Preferences.get("programmer"); TargetPlatform targetPlatform = Base.getTargetPlatform(); + + // Find preferences for the selected programmer + PreferencesMap programmerPrefs; + String programmer = Preferences.get("programmer"); if (programmer.contains(":")) { String[] split = programmer.split(":", 2); - targetPlatform = Base.getCurrentTargetPlatformFromPackage(split[0]); + TargetPlatform platform = Base + .getCurrentTargetPlatformFromPackage(split[0]); programmer = split[1]; + programmerPrefs = platform.getProgrammer(programmer); + } else { + programmerPrefs = targetPlatform.getProgrammer(programmer); } + // Build configuration for the current programmer PreferencesMap prefs = Preferences.getMap(); prefs.putAll(Base.getBoardPreferences()); - prefs.putAll(targetPlatform.getProgrammer(programmer)); + prefs.putAll(programmerPrefs); + // Add configuration for bootloader tool String toolName = prefs.get("bootloader.tool"); PreferencesMap toolPrefs = targetPlatform.getTool(toolName); if (toolPrefs.size() == 0) @@ -277,12 +286,6 @@ public class BasicUploader extends Uploader { } try { - // if (prefs.get("program.disable_flushing") == null - // || prefs.get("program.disable_flushing").toLowerCase().equals("false")) - // { - // flushSerialBuffer(); - // } - String pattern = prefs.get("erase.pattern"); String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true); if (!executeUploadCommand(cmd)) From a6bf2bb5677b3fa4da22c3d38fd8c7c0029541b1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 11 Mar 2013 19:59:15 +0100 Subject: [PATCH 13/16] Another update on the way burnBootloader builds its configuration. See #1038 #1176 --- .../processing/app/debug/BasicUploader.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/debug/BasicUploader.java b/app/src/processing/app/debug/BasicUploader.java index 685165c48..1909c464a 100644 --- a/app/src/processing/app/debug/BasicUploader.java +++ b/app/src/processing/app/debug/BasicUploader.java @@ -270,12 +270,25 @@ public class BasicUploader extends Uploader { prefs.putAll(Base.getBoardPreferences()); prefs.putAll(programmerPrefs); - // Add configuration for bootloader tool - String toolName = prefs.get("bootloader.tool"); - PreferencesMap toolPrefs = targetPlatform.getTool(toolName); + // Create configuration for bootloader tool + PreferencesMap toolPrefs = new PreferencesMap(); + String tool = prefs.get("bootloader.tool"); + if (tool.contains(":")) { + String[] split = tool.split(":", 2); + TargetPlatform platform = Base.getCurrentTargetPlatformFromPackage(split[0]); + tool = split[1]; + toolPrefs.putAll(platform.getTool(tool)); + if (toolPrefs.size() == 0) + throw new RunnerException( + I18n.format(_("Could not find tool {0} from package {1}"), tool, + split[0])); + } + toolPrefs.putAll(targetPlatform.getTool(tool)); if (toolPrefs.size() == 0) throw new RunnerException(I18n.format(_("Could not find tool {0}"), - toolName)); + tool)); + + // Merge tool with global configuration prefs.putAll(toolPrefs); if (verbose) { prefs.put("erase.verbose", prefs.get("erase.params.verbose")); From cad69358b4625e7a612f8ea26e3fba633c6f0157 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 18 Mar 2013 13:14:30 +0100 Subject: [PATCH 14/16] Changed the way ARDUINO is defined inside platform.txt --- hardware/arduino/avr/platform.txt | 4 ++-- hardware/arduino/sam/platform.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index 53c31620c..f2f80f11b 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -27,10 +27,10 @@ build.extra_flags= # -------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Create archives recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index f64309a23..8d07879ef 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -30,10 +30,10 @@ compiler.libsam.c.flags="-I{build.system.path}/libsam" "-I{build.system.path}/CM # --------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" ## Create archives recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" From f772be90325ebbbd7e6a9a38a413bfa43d39d19f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 21 Mar 2013 09:20:29 +0100 Subject: [PATCH 15/16] Added version field to platform.txt --- hardware/arduino/avr/platform.txt | 12 ++++++++++-- hardware/arduino/sam/platform.txt | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index f2f80f11b..5fc26822f 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -1,8 +1,16 @@ +# Arduino AVR Core and platform. +# ------------------------------ + +# For more info: +# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification + +name=Arduino AVR Boards +version=1.5.3 + # AVR compile variables # --------------------- -name=Arduino AVR Boards # Default "compiler.path" is correct, change only if you want to overidde the initial value #compiler.path={ide.path}/tools/avr/bin/.. compiler.c.cmd=avr-gcc @@ -50,7 +58,7 @@ recipe.size.regex=Total\s+([0-9]+).* # AVR Uploader/Programmers tools -# ------------------- +# ------------------------------ tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index 8d07879ef..2aa8c0ab3 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -1,8 +1,15 @@ -# SAM3 compile variables -# --------------------- +# Arduino SAM Core and platform. +# +# For more info: +# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification name=Arduino ARM (32-bits) Boards +version=1.5.3 + +# SAM3 compile variables +# ---------------------- + compiler.path={runtime.ide.path}/hardware/tools/g++_arm_none_eabi/bin/ compiler.c.cmd=arm-none-eabi-gcc compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf From f1221c8ebfcf52736692d0a696ef6aeef50845f5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 17 Apr 2013 17:45:57 +0200 Subject: [PATCH 16/16] Reverted to old board ids --- hardware/arduino/avr/boards.txt | 146 ++++++++++++++++---------------- hardware/arduino/sam/boards.txt | 68 +++++++-------- 2 files changed, 107 insertions(+), 107 deletions(-) diff --git a/hardware/arduino/avr/boards.txt b/hardware/arduino/avr/boards.txt index de767f510..6627cfa1a 100644 --- a/hardware/arduino/avr/boards.txt +++ b/hardware/arduino/avr/boards.txt @@ -26,46 +26,46 @@ uno.build.variant=standard ############################################################## -duemilanove.name=Arduino Duemilanove or Diecimila +atmega328diecimila.name=Arduino Duemilanove or Diecimila -duemilanove.upload.tool=avrdude -duemilanove.upload.protocol=arduino +atmega328diecimila.upload.tool=avrdude +atmega328diecimila.upload.protocol=arduino -duemilanove.bootloader.tool=avrdude -duemilanove.bootloader.low_fuses=0xFF -duemilanove.bootloader.unlock_bits=0x3F -duemilanove.bootloader.lock_bits=0x0F +atmega328diecimila.bootloader.tool=avrdude +atmega328diecimila.bootloader.low_fuses=0xFF +atmega328diecimila.bootloader.unlock_bits=0x3F +atmega328diecimila.bootloader.lock_bits=0x0F -duemilanove.build.f_cpu=16000000L -duemilanove.build.board=AVR_DUEMILANOVE -duemilanove.build.core=arduino -duemilanove.build.variant=standard +atmega328diecimila.build.f_cpu=16000000L +atmega328diecimila.build.board=AVR_DUEMILANOVE +atmega328diecimila.build.core=arduino +atmega328diecimila.build.variant=standard ## Arduino Duemilanove or Diecimila w/ ATmega328 ## --------------------------------------------- -duemilanove.menu.cpu.atmega328=ATmega328 +atmega328diecimila.menu.cpu.atmega328=ATmega328 -duemilanove.menu.cpu.atmega328.upload.maximum_size=30720 -duemilanove.menu.cpu.atmega328.upload.speed=57600 +atmega328diecimila.menu.cpu.atmega328.upload.maximum_size=30720 +atmega328diecimila.menu.cpu.atmega328.upload.speed=57600 -duemilanove.menu.cpu.atmega328.bootloader.high_fuses=0xDA -duemilanove.menu.cpu.atmega328.bootloader.extended_fuses=0x05 -duemilanove.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +atmega328diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA +atmega328diecimila.menu.cpu.atmega328.bootloader.extended_fuses=0x05 +atmega328diecimila.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex -duemilanove.menu.cpu.atmega328.build.mcu=atmega328p +atmega328diecimila.menu.cpu.atmega328.build.mcu=atmega328p ## Arduino Duemilanove or Diecimila w/ ATmega168 ## --------------------------------------------- -duemilanove.menu.cpu.atmega168=ATmega168 +atmega328diecimila.menu.cpu.atmega168=ATmega168 -duemilanove.menu.cpu.atmega168.upload.maximum_size=14336 -duemilanove.menu.cpu.atmega168.upload.speed=19200 +atmega328diecimila.menu.cpu.atmega168.upload.maximum_size=14336 +atmega328diecimila.menu.cpu.atmega168.upload.speed=19200 -duemilanove.menu.cpu.atmega168.bootloader.high_fuses=0xdd -duemilanove.menu.cpu.atmega168.bootloader.extended_fuses=0x00 -duemilanove.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex +atmega328diecimila.menu.cpu.atmega168.bootloader.high_fuses=0xdd +atmega328diecimila.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +atmega328diecimila.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex -duemilanove.menu.cpu.atmega168.build.mcu=atmega168 +atmega328diecimila.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## @@ -375,32 +375,32 @@ bt.menu.cpu.atmega168.build.mcu=atmega168 ############################################################## -lilypad_usb.name=LilyPad Arduino USB +LilyPadUSB.name=LilyPad Arduino USB -lilypad_usb.upload.tool=avrdude -lilypad_usb.upload.protocol=avr109 -lilypad_usb.upload.maximum_size=28672 -lilypad_usb.upload.speed=57600 -lilypad_usb.upload.disable_flushing=true -lilypad_usb.upload.use_1200bps_touch=true -lilypad_usb.upload.wait_for_upload_port=true +LilyPadUSB.upload.tool=avrdude +LilyPadUSB.upload.protocol=avr109 +LilyPadUSB.upload.maximum_size=28672 +LilyPadUSB.upload.speed=57600 +LilyPadUSB.upload.disable_flushing=true +LilyPadUSB.upload.use_1200bps_touch=true +LilyPadUSB.upload.wait_for_upload_port=true -lilypad_usb.bootloader.tool=avrdude -lilypad_usb.bootloader.low_fuses=0xff -lilypad_usb.bootloader.high_fuses=0xd8 -lilypad_usb.bootloader.extended_fuses=0xce -lilypad_usb.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex -lilypad_usb.bootloader.unlock_bits=0x3F -lilypad_usb.bootloader.lock_bits=0x2F +LilyPadUSB.bootloader.tool=avrdude +LilyPadUSB.bootloader.low_fuses=0xff +LilyPadUSB.bootloader.high_fuses=0xd8 +LilyPadUSB.bootloader.extended_fuses=0xce +LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex +LilyPadUSB.bootloader.unlock_bits=0x3F +LilyPadUSB.bootloader.lock_bits=0x2F -lilypad_usb.build.mcu=atmega32u4 -lilypad_usb.build.f_cpu=8000000L -lilypad_usb.build.vid=0x1B4F -lilypad_usb.build.pid=0x9208 -lilypad_usb.build.board=AVR_LILYPAD_USB -lilypad_usb.build.core=arduino -lilypad_usb.build.variant=leonardo -lilypad_usb.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} +LilyPadUSB.build.mcu=atmega32u4 +LilyPadUSB.build.f_cpu=8000000L +LilyPadUSB.build.vid=0x1B4F +LilyPadUSB.build.pid=0x9208 +LilyPadUSB.build.board=AVR_LILYPAD_USB +LilyPadUSB.build.core=arduino +LilyPadUSB.build.variant=leonardo +LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} ############################################################## @@ -523,44 +523,44 @@ pro.menu.cpu.8MHzatmega168.build.f_cpu=8000000L ############################################################## -ng.name=Arduino NG or older +atmegang.name=Arduino NG or older -ng.upload.tool=avrdude -ng.upload.protocol=arduino -ng.upload.speed=19200 +atmegang.upload.tool=avrdude +atmegang.upload.protocol=arduino +atmegang.upload.speed=19200 -ng.bootloader.tool=avrdude -ng.bootloader.unlock_bits=0x3F -ng.bootloader.lock_bits=0x0F +atmegang.bootloader.tool=avrdude +atmegang.bootloader.unlock_bits=0x3F +atmegang.bootloader.lock_bits=0x0F -ng.build.mcu=atmegang -ng.build.f_cpu=16000000L -ng.build.board=AVR_NG -ng.build.core=arduino -ng.build.variant=standard +atmegang.build.mcu=atmegang +atmegang.build.f_cpu=16000000L +atmegang.build.board=AVR_NG +atmegang.build.core=arduino +atmegang.build.variant=standard ## Arduino NG or older w/ ATmega168 ## -------------------------------- -ng.menu.cpu.atmega168=ATmega168 +atmegang.menu.cpu.atmega168=ATmega168 -ng.menu.cpu.atmega168.upload.maximum_size=14336 +atmegang.menu.cpu.atmega168.upload.maximum_size=14336 -ng.menu.cpu.atmega168.bootloader.low_fuses=0xff -ng.menu.cpu.atmega168.bootloader.high_fuses=0xdd -ng.menu.cpu.atmega168.bootloader.extended_fuses=0x00 -ng.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex +atmegang.menu.cpu.atmega168.bootloader.low_fuses=0xff +atmegang.menu.cpu.atmega168.bootloader.high_fuses=0xdd +atmegang.menu.cpu.atmega168.bootloader.extended_fuses=0x00 +atmegang.menu.cpu.atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex -ng.menu.cpu.atmega168.build.mcu=atmega168 +atmegang.menu.cpu.atmega168.build.mcu=atmega168 ## Arduino NG or older w/ ATmega8 ## ------------------------------ -ng.menu.cpu.atmega8=ATmega8 +atmegang.menu.cpu.atmega8=ATmega8 -ng.menu.cpu.atmega8.upload.maximum_size=7168 +atmegang.menu.cpu.atmega8.upload.maximum_size=7168 -ng.menu.cpu.atmega8.bootloader.low_fuses=0xdf -ng.menu.cpu.atmega8.bootloader.high_fuses=0xca -ng.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex +atmegang.menu.cpu.atmega8.bootloader.low_fuses=0xdf +atmegang.menu.cpu.atmega8.bootloader.high_fuses=0xca +atmegang.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex -ng.menu.cpu.atmega8.build.mcu=atmega8 +atmegang.menu.cpu.atmega8.build.mcu=atmega8 diff --git a/hardware/arduino/sam/boards.txt b/hardware/arduino/sam/boards.txt index 437941d70..c61b01fac 100644 --- a/hardware/arduino/sam/boards.txt +++ b/hardware/arduino/sam/boards.txt @@ -1,37 +1,37 @@ -due_prgport.name=Arduino Due (Programming Port) -due_prgport.upload.tool=bossac -due_prgport.upload.protocol=sam-ba -due_prgport.upload.maximum_size=524288 -due_prgport.upload.use_1200bps_touch=true -due_prgport.upload.wait_for_upload_port=false -due_prgport.upload.native_usb=false -due_prgport.build.mcu=cortex-m3 -due_prgport.build.f_cpu=84000000L -due_prgport.build.board=SAM_DUE -due_prgport.build.core=arduino -due_prgport.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON -due_prgport.build.ldscript=linker_scripts/gcc/flash.ld -due_prgport.build.variant=arduino_due_x -due_prgport.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a -due_prgport.build.vid=0x2341 -due_prgport.build.pid=0x003e +arduino_due_x_dbg.name=Arduino Due (Programming Port) +arduino_due_x_dbg.upload.tool=bossac +arduino_due_x_dbg.upload.protocol=sam-ba +arduino_due_x_dbg.upload.maximum_size=524288 +arduino_due_x_dbg.upload.use_1200bps_touch=true +arduino_due_x_dbg.upload.wait_for_upload_port=false +arduino_due_x_dbg.upload.native_usb=false +arduino_due_x_dbg.build.mcu=cortex-m3 +arduino_due_x_dbg.build.f_cpu=84000000L +arduino_due_x_dbg.build.board=SAM_DUE +arduino_due_x_dbg.build.core=arduino +arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON +arduino_due_x_dbg.build.ldscript=linker_scripts/gcc/flash.ld +arduino_due_x_dbg.build.variant=arduino_due_x +arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a +arduino_due_x_dbg.build.vid=0x2341 +arduino_due_x_dbg.build.pid=0x003e -due.name=Arduino Due (Native USB Port) -due.upload.tool=bossac -due.upload.protocol=sam-ba -due.upload.maximum_size=524288 -due.upload.use_1200bps_touch=true -due.upload.wait_for_upload_port=true -due.upload.native_usb=true -due.build.mcu=cortex-m3 -due.build.f_cpu=84000000L -due.build.board=SAM_DUE -due.build.core=arduino -due.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON -due.build.ldscript=linker_scripts/gcc/flash.ld -due.build.variant=arduino_due_x -due.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a -due.build.vid=0x2341 -due.build.pid=0x003e +arduino_due_x.name=Arduino Due (Native USB Port) +arduino_due_x.upload.tool=bossac +arduino_due_x.upload.protocol=sam-ba +arduino_due_x.upload.maximum_size=524288 +arduino_due_x.upload.use_1200bps_touch=true +arduino_due_x.upload.wait_for_upload_port=true +arduino_due_x.upload.native_usb=true +arduino_due_x.build.mcu=cortex-m3 +arduino_due_x.build.f_cpu=84000000L +arduino_due_x.build.board=SAM_DUE +arduino_due_x.build.core=arduino +arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON +arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld +arduino_due_x.build.variant=arduino_due_x +arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a +arduino_due_x.build.vid=0x2341 +arduino_due_x.build.pid=0x003e