From 1c247cd33e18e1d4fdcafe99397e238d834f2b85 Mon Sep 17 00:00:00 2001 From: Kirill Krinkin Date: Wed, 8 Jul 2015 12:00:42 +0300 Subject: [PATCH 1/7] Fixed C2000 path --- app/src/processing/app/Base.java | 15 ++++++++-- app/src/processing/app/debug/Compiler.java | 34 +++++++++++++++++----- app/src/processing/app/debug/Target.java | 8 ++++- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 217900484dd..46fa13f08bb 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1100,6 +1100,10 @@ public void actionPerformed(ActionEvent actionevent) { //System.out.println("Switching to " + target + ":" + board); String n = (String)getValue("target"); String o = Preferences.get("target"); + + System.out.println("o="+o); + System.out.println("n="+n); + if(!n.equals(o)) { String targetLibDir = new String(""); if(n.equals("msp430")) @@ -1711,9 +1715,14 @@ static public String getLM4FBasePath() { //TODO: check tools path static public String getC2000BasePath() { - String path = getHardwarePath() + File.separator + "tools" + - File.separator + "c2000" + File.separator + "bin" + File.separator; - + //String path = getHardwarePath() + File.separator + "tools" + + // File.separator + "c2000" + File.separator + "bin" + File.separator; + +String path = getHardwarePath() + File.separator + + "c2000" + File.separator + "bin" + File.separator; + + System.out.println("getC2000BasePath:"+path); + if(!(new File(path)).exists()){ return ""; // use msp430-gcc and mspdebug in PATH instead of platform version } diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 4d166df05b2..b5919f6a340 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -70,6 +70,7 @@ public boolean compile(Sketch sketch, this.verbose = verbose; this.sketchIsCompiled = false; + // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); @@ -77,7 +78,12 @@ public boolean compile(Sketch sketch, Map boardPreferences = Base.getBoardPreferences(); String core = boardPreferences.get("build.core"); String arch = Base.getArch(); - if (core == null) { + + System.out.println("sk="+sketch+", buildpath="+buildPath+", primaryClassName="+primaryClassName+ + ", verbose="+verbose+", basePath="+basePath+", arch="+arch); + + + if (core == null) { RunnerException re = new RunnerException(_("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace(); throw re; @@ -163,14 +169,18 @@ public boolean compile(Sketch sketch, String rtsLibPath = null; if (arch == "c2000") { - Target t = Base.getTarget(); + Target t = Base.getTarget(); + System.out.println("\ntarget="+t.toString()); + //Target t = Base.getC2000BasePath(); File rtsIncFolder; File rtsLibFolder; - rtsIncFolder = new File(new File(new File(t.getFolder(), "..//tools"), "c2000"), "include"); - rtsLibFolder = new File(new File(new File(t.getFolder(), "..//tools"), "c2000"), "lib"); + rtsIncFolder = new File(t.getFolder(), "//include"); + rtsLibFolder = new File(t.getFolder(), "//lib"); rtsIncPath = rtsIncFolder.getAbsolutePath(); rtsLibPath = rtsLibFolder.getAbsolutePath(); + + System.out.println("inc=" + rtsIncPath + ", lib=" + rtsLibPath + ", corepath=" + corePath); } List objectFiles = new ArrayList(); @@ -320,6 +330,7 @@ else if( boardPreferences.get("build.mcu").equals("TMS320F28069")) for(File file : coreObjectFiles) { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); + System.out.println("linker="+commandAR); execAsynchronouslyShell(commandAR); } } @@ -475,6 +486,7 @@ else if( boardPreferences.get("build.mcu").equals("TMS320F28069")) } if(arch == "c2000") { + System.out.println("linker=" + baseCommandLinker); execAsynchronouslyShell(baseCommandLinker); } else @@ -566,9 +578,11 @@ private List compileFiles(String basePath, List objectPaths = new ArrayList(); if(Base.getArch() == "c2000") { - - - for (File file : sSources) { + System.out.println("basePath="+basePath+", buildPath="+buildPath); + + + for (File file : sSources) { + System.out.println("sSources"); String objectPath = buildPath + File.separator + file.getName() + ".o"; objectPaths.add(new File(objectPath)); execAsynchronouslyShell(getCommandCompilerS(basePath, includePaths, @@ -578,6 +592,8 @@ private List compileFiles(String basePath, } for (File file : cSources) { + System.out.println("cSources"); + String objectPath = buildPath + File.separator + file.getName() + ".o"; String dependPath = buildPath + File.separator + file.getName() + ".d"; File objectFile = new File(objectPath); @@ -591,6 +607,8 @@ private List compileFiles(String basePath, } for (File file : cppSources) { + System.out.println("cppSources"); + String objectPath = buildPath + File.separator + file.getName() + ".o"; String dependPath = buildPath + File.separator + file.getName() + ".d"; File objectFile = new File(objectPath); @@ -873,7 +891,7 @@ private void execAsynchronouslyShell(List commandList) throws RunnerException { command_line += str+" "; } - process = Runtime.getRuntime().exec(new String[]{"bash","-c",command_line}); + process = Runtime.getRuntime().exec(new String[]{"bash","-c",command_line},new String[]{"PATH=/ws/devel/Energia/hardware/c2000/bin"}); System.out.println(command_line); } else diff --git a/app/src/processing/app/debug/Target.java b/app/src/processing/app/debug/Target.java index 1aa2f81bef2..579a51a6fdb 100644 --- a/app/src/processing/app/debug/Target.java +++ b/app/src/processing/app/debug/Target.java @@ -60,6 +60,8 @@ public Target(String name, File folder) { System.err.println("Error loading boards from " + boardsFile + ": " + e); } + + File programmersFile = new File(folder, "programmers.txt"); try { if (programmersFile.exists()) { @@ -79,7 +81,11 @@ public Target(String name, File folder) { programmersFile + ": " + e); } } - + + public String toString() { + return "Target: {name="+getName()+", folder="+getFolder().toString()+"}"; + } + public String getName() { return name; } public File getFolder() { return folder; } public Map> getBoards() { From b0ff2800eb72c3f834d7e4abd55554e88c508b50 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 9 Oct 2015 19:08:18 +0300 Subject: [PATCH 2/7] Add widget --- app/src/processing/app/Base.java | 84 +++++++++-------- app/src/processing/app/Editor.java | 140 ++++++++++++++--------------- 2 files changed, 119 insertions(+), 105 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 46fa13f08bb..d82855861e4 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1090,48 +1090,62 @@ public void onArchChanged() { public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); - menu.removeAll(); + menu.removeAll(); + + /* + Here is my work! + */ + + JMenu boardsWidget = new JMenu("BoardsWidget"); + boardsWidget.add(new JMenuItem("Empty 1")); + boardsWidget.add(new JMenuItem("Empty 2")); + menu.add(boardsWidget); + + /* + end! + */ ButtonGroup group = new ButtonGroup(); + for (Target target : targetsTable.values()) { for (String board : target.getBoards().keySet()) { - AbstractAction action = - new AbstractAction(target.getBoards().get(board).get("name")) { - public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + target + ":" + board); - String n = (String)getValue("target"); - String o = Preferences.get("target"); - - System.out.println("o="+o); - System.out.println("n="+n); - - if(!n.equals(o)) { - String targetLibDir = new String(""); - if(n.equals("msp430")) - targetLibDir = "hardware/msp430/"; - else if(n.equals("lm4f")) - targetLibDir = "hardware/lm4f/"; - else if(n.equals("c2000")) - targetLibDir = "hardware/c2000/"; - else if(n.equals("cc3200")) - targetLibDir = "hardware/cc3200/"; - else if(n.equals("msp432")) - targetLibDir = "hardware/msp432/"; - else if(n.equals("cc3200emt")) - targetLibDir = "hardware/cc3200emt/"; - librariesFolder = getContentFile(targetLibDir + "libraries"); - onArchChanged(); - } - Preferences.set("target", (String) getValue("target")); - Preferences.set("board", (String) getValue("board")); - onBoardOrPortChange(); - Sketch.buildSettingChanged(); - } - }; + AbstractAction action = + new AbstractAction(target.getBoards().get(board).get("name")) { + public void actionPerformed(ActionEvent actionevent) { + //System.out.println("Switching to " + target + ":" + board); + String n = (String) getValue("target"); + String o = Preferences.get("target"); + + System.out.println("o=" + o); + System.out.println("n=" + n); + + if (!n.equals(o)) { + String targetLibDir = new String(""); + if (n.equals("msp430")) + targetLibDir = "hardware/msp430/"; + else if (n.equals("lm4f")) + targetLibDir = "hardware/lm4f/"; + else if (n.equals("c2000")) + targetLibDir = "hardware/c2000/"; + else if (n.equals("cc3200")) + targetLibDir = "hardware/cc3200/"; + else if (n.equals("msp432")) + targetLibDir = "hardware/msp432/"; + else if (n.equals("cc3200emt")) + targetLibDir = "hardware/cc3200emt/"; + librariesFolder = getContentFile(targetLibDir + "libraries"); + onArchChanged(); + } + Preferences.set("target", (String) getValue("target")); + Preferences.set("board", (String) getValue("board")); + onBoardOrPortChange(); + Sketch.buildSettingChanged(); + } + }; action.putValue("target", target.getName()); action.putValue("board", board); JMenuItem item = new JRadioButtonMenuItem(action); if (target.getName().equals(Preferences.get("target")) && - board.equals(Preferences.get("board"))) { + board.equals(Preferences.get("board"))) { item.setSelected(true); } group.add(item); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 5f60e7c5d5b..ab02eacb095 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -100,7 +100,7 @@ public class Editor extends JFrame implements RunnerListener { static SerialMenuListener serialMenuListener; static SerialMonitor serialMonitor; - + EditorHeader header; EditorStatus status; EditorConsole console; @@ -116,7 +116,7 @@ public class Editor extends JFrame implements RunnerListener { EditorLineStatus lineStatus; //JEditorPane editorPane; - + JEditTextArea textarea; EditorListener listener; @@ -202,7 +202,7 @@ public void windowDeactivated(WindowEvent e) { serialMonitor = new SerialMonitor(Preferences.get("serial.port")); serialMonitor.setIconImage(getIconImage()); } - + buildMenuBar(); // For rev 0120, placing things inside a JPanel @@ -547,7 +547,7 @@ public void actionPerformed(ActionEvent e) { } }); fileMenu.add(item); - + item = newJMenuItem(_("Upload and then Open Serial Monitor"), 'M'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -556,7 +556,7 @@ public void actionPerformed(ActionEvent e) { }); fileMenu.add(item); - if(!Preferences.get("target").equals("msp430") + if(!Preferences.get("target").equals("msp430") || !Preferences.get("target").equals("lm4f")) { item = newJMenuItemShift(_("Upload Using Programmer"), 'U'); item.addActionListener(new ActionListener() { @@ -610,7 +610,7 @@ public void actionPerformed(ActionEvent e) { } return fileMenu; } - + private void rebuildExamplesMenu(){ base.rebuildExamplesMenu(examplesMenu); @@ -631,8 +631,8 @@ private void rebuildExamplesMenu(){ } MenuScroller.setScrollerFor(examplesMenu,-1,-1,upper>0?upper+1:0,lower); } - - + + protected JMenu buildSketchMenu() { JMenuItem item; sketchMenu = new JMenu(_("Sketch")); @@ -663,9 +663,9 @@ public void actionPerformed(ActionEvent e) { } }); sketchMenu.add(item); - - - + + + item = newJMenuItemAlt(_("Show Compilation Folder"), 'R'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -722,9 +722,9 @@ public void actionPerformed(ActionEvent e) { MenuScroller.setScrollerFor(importMenu,-1,-1,n+1,0); } sketchMenu.add(importMenu); - + // This is the library manager, since is not OS agnostic, for now it is disabled - /*if(Base.isWindows()) + /*if(Base.isWindows()) { item = new JMenuItem(_("Manage Libraries...")); item.addActionListener(new ActionListener() { @@ -770,7 +770,7 @@ protected JMenu buildToolsMenu() { JMenuItem item; addInternalTools(menu); - + item = newJMenuItemShift(_("Serial Monitor"), 'M'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -778,25 +778,25 @@ public void actionPerformed(ActionEvent e) { } }); menu.add(item); - + addTools(menu, Base.getToolsFolder()); File sketchbookTools = new File(Base.getSketchbookFolder(), "tools"); addTools(menu, sketchbookTools); menu.addSeparator(); - + numTools = menu.getItemCount(); - + // XXX: DAM: these should probably be implemented using the Tools plugin // API, if possible (i.e. if it supports custom actions, etc.) - + if (boardsMenu == null) { - boardsMenu = new JMenu(_("Board")); - MenuScroller.setScrollerFor(boardsMenu); - base.rebuildBoardsMenu(boardsMenu); + boardsMenu = new JMenu(_("Board")); + MenuScroller.setScrollerFor(boardsMenu); + base.rebuildBoardsMenu(boardsMenu); } menu.add(boardsMenu); - + if (serialMenuListener == null) serialMenuListener = new SerialMenuListener(); if (serialMenu == null) @@ -819,7 +819,7 @@ public void actionPerformed(ActionEvent e) { }); menu.add(item); } -*/ +*/ item = new JMenuItem(_("Update programmer")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1040,7 +1040,7 @@ public void actionPerformed(ActionEvent e) { } */ } - + protected void selectSerialPort(String name) { if(serialMenu == null) { System.out.println(_("serialMenu is null")); @@ -1074,9 +1074,9 @@ protected void populateSerialMenu() { // getting list of ports JMenuItem rbMenuItem; - + //System.out.println("Clearing serial port menu."); - + serialMenu.removeAll(); boolean empty = true; @@ -1095,7 +1095,7 @@ protected void populateSerialMenu() { if(curr_port.indexOf("tty.uart") == -1 && curr_port.indexOf("tty.usbmodem") == -1 && curr_port.indexOf("tty.usbserial") == -1 - && curr_port.indexOf("cu.usbserial") == -1) continue; + && curr_port.indexOf("cu.usbserial") == -1) continue; } rbMenuItem = new JCheckBoxMenuItem(curr_port, curr_port.equals(Preferences.get("serial.port"))); @@ -1117,7 +1117,7 @@ protected void populateSerialMenu() { System.out.println(_("error retrieving port list")); exception.printStackTrace(); } - + if (serialMenu.getItemCount() == 0) { serialMenu.setEnabled(false); } @@ -1212,7 +1212,7 @@ public void actionPerformed(ActionEvent e) { }); menu.add(item); menu.addSeparator(); - + item = new JMenuItem(_("Frequently Asked Questions")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1549,7 +1549,7 @@ protected void updateRedoState() { public void setHandlers(Runnable runHandler, Runnable presentHandler, Runnable stopHandler, - Runnable exportHandler, + Runnable exportHandler, Runnable exportAppHandler, Runnable doFetUpdateHandler) { this.doFetUpdateHandler = doFetUpdateHandler; @@ -1979,11 +1979,11 @@ protected void handleFindReference() { } else { String referenceFile = PdeKeywords.getReference(text); - if (referenceFile == null) + if (referenceFile == null) { statusNotice(I18n.format(_("No reference available for \"{0}\""), text)); - } - else + } + else { Base.showReference(I18n.format(_("{0}.html"), referenceFile)); } @@ -2238,7 +2238,7 @@ protected boolean handleOpenInternal(String path) { File altPdeFile = new File(parent, pdeName); String inoName = parentName + ".ino"; File altInoFile = new File(parent, pdeName); - + if (pdeName.equals(fileName) || inoName.equals(fileName)) { // no beef with this guy @@ -2443,8 +2443,8 @@ public boolean handleSaveAs() { return true; } - - + + public boolean serialPrompt() { int count = serialMenu.getItemCount(); Object[] names = new Object[count]; @@ -2487,26 +2487,26 @@ public boolean serialPrompt() { * Made synchronized to (hopefully) avoid problems of people * hitting export twice, quickly, and horking things up. */ - + synchronized public void handleExport(final boolean usingProgrammer, final boolean showSerialMonitor) { //if (!handleExportCheckModified()) return; toolbar.activate(EditorToolbar.EXPORT); console.clear(); status.progress(_("Uploading to I/O Board...")); - + if(!usingProgrammer) exportHandler = new DefaultExportHandler(showSerialMonitor); - + new Thread(usingProgrammer ? exportAppHandler : exportHandler).start(); } // DAM: in Arduino, this is upload class DefaultExportHandler implements Runnable { - DefaultExportHandler(Boolean openSerial) { + DefaultExportHandler(Boolean openSerial) { serialMonitor.isOpenPending = openSerial; // Open serial monitor when ending } - DefaultExportHandler() { + DefaultExportHandler() { if(serialMonitor != null) serialMonitor.isOpenPending = false; // Do not serial monitor when ending, as default } @@ -2515,9 +2515,9 @@ public void run() { try { serialMonitor.closeSerialPort(); serialMonitor.setVisible(false); - + uploading = true; - + boolean success = sketch.exportApplet(false); if (success) { statusNotice(_("Done uploading.")); @@ -2557,9 +2557,9 @@ public void run() { try { serialMonitor.closeSerialPort(); serialMonitor.setVisible(false); - + uploading = true; - + boolean success = sketch.exportApplet(true); if (success) { statusNotice(_("Done uploading.")); @@ -2624,7 +2624,7 @@ protected boolean handleExportCheckModified() { public void handleSerial() { if (uploading) { - serialMonitor.isOpenPending = true; // Open serial when ending + serialMonitor.isOpenPending = true; // Open serial when ending return; } try { @@ -2840,7 +2840,7 @@ protected void onArchChanged() { base.rebuildImportMenu(importMenu); base.rebuildExamplesMenu(examplesMenu); } - + protected void onBoardOrPortChange() { Map boardPreferences = Base.getBoardPreferences(); lineStatus.setBoardName(boardPreferences.get("name")); @@ -2848,7 +2848,7 @@ protected void onBoardOrPortChange() { lineStatus.repaint(); } - + /** * Returns the edit popup menu. */ @@ -2873,10 +2873,10 @@ public void actionPerformed(ActionEvent e) { } }); add(openURLItem); - + openURLItemSeparator = new JSeparator(); add(openURLItemSeparator); - + cutItem = new JMenuItem(_("Cut")); cutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -2976,27 +2976,27 @@ public void show(Component component, int x, int y) { openURLItem.setVisible(false); openURLItemSeparator.setVisible(false); } - + if (textarea.isSelectionActive()) { // move caret if is not inside selection int selStart = textarea.getSelectionStart(); - + if(!(selStartoffset2)) textarea.setCaretPosition(offset2); } else { textarea.setCaretPosition(offset2); } - + // Reference referenceFile = searchReference(textarea); referenceItem.setEnabled(referenceFile != null); - + super.show(component, x, y); } } - // Search a JEditTextArea for a selected reference, returning the reference is valid, or null + // Search a JEditTextArea for a selected reference, returning the reference is valid, or null public String searchReference(JEditTextArea jtext) { return searchReference(jtext, false); @@ -3014,16 +3014,16 @@ public String searchReference(JEditTextArea jtext, boolean returnSelection) { sel = jtext.getSelectedText(); } - + if(ref == null) { // Nothing is selected so we will try to find a valid keyword from caret position int start = Math.max(0,jtext.getCaretPosition()-1); sel = findKeyword(t,start, start); } - + sel = sel.trim(); - + if(returnSelection) return sel; else @@ -3031,21 +3031,21 @@ public String searchReference(JEditTextArea jtext, boolean returnSelection) if(sel.length()>0) ref = PdeKeywords.getReference(sel); } - } + } return returnSelection ? "": ref; } - + // Returns true if character is valid for a reference keyword private boolean isValid(char c) { return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; } - + // Recursively finds a valid keyword private String findKeyword(String text, int start, int end) { int l = text.length(); - + if(l>0) { boolean validStart = true, validEnd = true; @@ -3054,24 +3054,24 @@ private String findKeyword(String text, int start, int end) if(isValid(text.charAt(start))) { start--; - validStart = false; - } + validStart = false; + } } - + if(end0) return text.substring(nstart,nend); } @@ -3080,7 +3080,7 @@ private String findKeyword(String text, int start, int end) return findKeyword(text,start,end); // Keep looking } } - + return ""; } } From e751aaee2c3af1176681b5e36bf97ecab9e9deba Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 20 Oct 2015 22:45:22 +0300 Subject: [PATCH 3/7] Changed if's to cicle of board names --- app/build.xml | 1 + app/src/processing/app/Base.java | 335 ++++++++++++----------- app/src/processing/app/debug/Target.java | 2 +- 3 files changed, 181 insertions(+), 157 deletions(-) diff --git a/app/build.xml b/app/build.xml index 06cc52fd7a1..c076790a9b7 100644 --- a/app/build.xml +++ b/app/build.xml @@ -53,4 +53,5 @@ + diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d82855861e4..df3d09daea7 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -63,8 +63,8 @@ public class Base { platformIndices.put("macosx", PConstants.MACOSX); platformIndices.put("linux", PConstants.LINUX); } - - static Map archMap = new HashMap(); + + static Map archMap = new HashMap(); static { archMap.put("arduino", "avr"); archMap.put("msp430", "msp430"); @@ -94,7 +94,7 @@ public class Base { static private File hardwareFolder; static HashSet libraries; - + // maps imported packages to their library folder static HashMap importToLibraryTable; @@ -102,7 +102,7 @@ public class Base { // (both those in the p5/libs folder and those with lib subfolders // found in the sketchbook) static public String librariesClassPath; - + static public HashMap targetsTable; // Location for untitled items @@ -248,90 +248,103 @@ static protected void initRequirements() { public Base(String[] args) { - platform.init(this); + platform.init(this); + + // Get paths for the libraries and examples in the Processing folder + //String workingDirectory = System.getProperty("user.dir"); + examplesFolder = getContentFile("examples"); + + String targetLibDir = new String(""); + String boardNameString = Preferences.get("target"); + for (String boardName : boardsStirngNames) { + if (boardNameString.equals(boardName)) { + targetLibDir = "hardware/" + boardName + "/"; + } + } + + /* + String targetLibDir = new String(""); - // Get paths for the libraries and examples in the Processing folder - //String workingDirectory = System.getProperty("user.dir"); - examplesFolder = getContentFile("examples"); - String targetLibDir = new String(""); - if(Preferences.get("target").equals("msp430")) + if(Preferences.get("target").equals("msp430")) targetLibDir = "hardware/msp430/"; else if (Preferences.get("target").equals("lm4f")) targetLibDir = "hardware/lm4f/"; - else if (Preferences.get("target").equals("c2000")) + else if (Preferences.get("target").equals("c2000")) targetLibDir = "hardware/c2000/"; - else if (Preferences.get("target").equals("cc3200")) + else if (Preferences.get("target").equals("cc3200")) targetLibDir = "hardware/cc3200/"; - else if (Preferences.get("target").equals("cc3200emt")) + else if (Preferences.get("target").equals("cc3200emt")) targetLibDir = "hardware/cc3200emt/"; - else if (Preferences.get("target").equals("msp432")) + else if (Preferences.get("target").equals("msp432")) targetLibDir = "hardware/msp432/"; - librariesFolder = getContentFile(targetLibDir + "libraries"); - toolsFolder = getContentFile("tools"); - - // Get the sketchbook path, and make sure it's set properly - String sketchbookPath = Preferences.get("sketchbook.path"); - - // If a value is at least set, first check to see if the folder exists. - // If it doesn't, warn the user that the sketchbook folder is being reset. - if (sketchbookPath != null) { - File skechbookFolder = new File(sketchbookPath); - if (!skechbookFolder.exists()) { - Base.showWarning(_("Sketchbook folder disappeared"), - _("The sketchbook folder no longer exists.\n" + - "Energia will switch to the default sketchbook\n" + - "location, and create a new sketchbook folder if\n" + - "necessary. Energia will then stop talking about\n" + - "himself in the third person."), null); - sketchbookPath = null; - } - } + */ - // If no path is set, get the default sketchbook folder for this platform - if (sketchbookPath == null) { - File defaultFolder = getDefaultSketchbookFolder(); - Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath()); - if (!defaultFolder.exists()) { - defaultFolder.mkdirs(); + librariesFolder = getContentFile(targetLibDir + "libraries"); + toolsFolder = getContentFile("tools"); + + // Get the sketchbook path, and make sure it's set properly + String sketchbookPath = Preferences.get("sketchbook.path"); + + // If a value is at least set, first check to see if the folder exists. + // If it doesn't, warn the user that the sketchbook folder is being reset. + if (sketchbookPath != null) { + File skechbookFolder = new File(sketchbookPath); + if (!skechbookFolder.exists()) { + Base.showWarning(_("Sketchbook folder disappeared"), + _("The sketchbook folder no longer exists.\n" + + "Energia will switch to the default sketchbook\n" + + "location, and create a new sketchbook folder if\n" + + "necessary. Energia will then stop talking about\n" + + "himself in the third person."), null); + sketchbookPath = null; + } } - } - - targetsTable = new HashMap(); - loadHardware(getHardwareFolder()); - loadHardware(getSketchbookHardwareFolder()); - - // Check if there were previously opened sketches to be restored - boolean opened = restoreSketches(); - - // Check if any files were passed in on the command line - for (int i = 0; i < args.length; i++) { - String path = args[i]; - // Fix a problem with systems that use a non-ASCII languages. Paths are - // being passed in with 8.3 syntax, which makes the sketch loader code - // unhappy, since the sketch folder naming doesn't match up correctly. - // http://dev.processing.org/bugs/show_bug.cgi?id=1089 - if (isWindows()) { - try { - File file = new File(args[i]); - path = file.getCanonicalPath(); - } catch (IOException e) { - e.printStackTrace(); - } + + // If no path is set, get the default sketchbook folder for this platform + if (sketchbookPath == null) { + File defaultFolder = getDefaultSketchbookFolder(); + Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath()); + if (!defaultFolder.exists()) { + defaultFolder.mkdirs(); + } } - if (handleOpen(path) != null) { - opened = true; + + targetsTable = new HashMap(); + loadHardware(getHardwareFolder()); + loadHardware(getSketchbookHardwareFolder()); + + // Check if there were previously opened sketches to be restored + boolean opened = restoreSketches(); + + // Check if any files were passed in on the command line + for (int i = 0; i < args.length; i++) { + String path = args[i]; + // Fix a problem with systems that use a non-ASCII languages. Paths are + // being passed in with 8.3 syntax, which makes the sketch loader code + // unhappy, since the sketch folder naming doesn't match up correctly. + // http://dev.processing.org/bugs/show_bug.cgi?id=1089 + if (isWindows()) { + try { + File file = new File(args[i]); + path = file.getCanonicalPath(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (handleOpen(path) != null) { + opened = true; + } } - } - // Create a new empty window (will be replaced with any files to be opened) - if (!opened) { - handleNew(); - } + // Create a new empty window (will be replaced with any files to be opened) + if (!opened) { + handleNew(); + } - // check for updates - if (Preferences.getBoolean("update.check")) { - new UpdateCheck(this); - } + // check for updates + if (Preferences.getBoolean("update.check")) { + new UpdateCheck(this); + } } @@ -603,14 +616,14 @@ private void findInsertPoint(Editor editor) { // Find the start point String t = editor.getText(); - + try { Pattern regex = Pattern.compile("void\\s+setup\\s*\\(\\s*\\)"); Matcher regexMatcher = regex.matcher(t); - while (regexMatcher.find()) + while (regexMatcher.find()) { int totalLeftBracketsOpened = 0; - + for(int i = regexMatcher.end(); i regexMatcher.end();j--) { int c = t.charAt(j); - + if(c!=10 && c!=13) { editor.setSelection(++j,j); @@ -637,7 +650,7 @@ private void findInsertPoint(Editor editor) } } break; - } + } } catch (PatternSyntaxException ex) { // Syntax error in the regular expression } @@ -1000,7 +1013,7 @@ public void actionPerformed(ActionEvent e) { temp = new JMenu("Contributed Libraries"); found = addSketches(temp, getSketchbookLibrariesFolder(), true); if (found) {menu.add(temp); n++;}; - + temp = new JMenu("Libraries"); addSketches(temp, librariesFolder, true); menu.add(temp); @@ -1008,7 +1021,7 @@ public void actionPerformed(ActionEvent e) { } catch (IOException e) { e.printStackTrace(); } - + return n; } @@ -1073,73 +1086,84 @@ public void rebuildExamplesMenu(JMenu menu) { e.printStackTrace(); } } - - + + public void onBoardOrPortChange() { for (Editor editor : editors) { editor.onBoardOrPortChange(); - } + } } - + public void onArchChanged() { for (Editor editor : editors) { editor.onArchChanged(); - } + } } - + static private ArrayList boardsStirngNames = new ArrayList(); + static{ + boardsStirngNames.add("msp430"); + boardsStirngNames.add("lm4f"); + boardsStirngNames.add("c2000"); + boardsStirngNames.add("cc3200"); + boardsStirngNames.add("msp432"); + boardsStirngNames.add("cc3200emt"); + boardsStirngNames.add("msp432"); + } + + public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); menu.removeAll(); - /* - Here is my work! - */ - JMenu boardsWidget = new JMenu("BoardsWidget"); boardsWidget.add(new JMenuItem("Empty 1")); boardsWidget.add(new JMenuItem("Empty 2")); menu.add(boardsWidget); - /* - end! - */ ButtonGroup group = new ButtonGroup(); for (Target target : targetsTable.values()) { for (String board : target.getBoards().keySet()) { - AbstractAction action = + AbstractAction action = new AbstractAction(target.getBoards().get(board).get("name")) { - public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + target + ":" + board); - String n = (String) getValue("target"); - String o = Preferences.get("target"); - - System.out.println("o=" + o); - System.out.println("n=" + n); - - if (!n.equals(o)) { - String targetLibDir = new String(""); - if (n.equals("msp430")) - targetLibDir = "hardware/msp430/"; - else if (n.equals("lm4f")) - targetLibDir = "hardware/lm4f/"; - else if (n.equals("c2000")) - targetLibDir = "hardware/c2000/"; - else if (n.equals("cc3200")) - targetLibDir = "hardware/cc3200/"; - else if (n.equals("msp432")) - targetLibDir = "hardware/msp432/"; - else if (n.equals("cc3200emt")) - targetLibDir = "hardware/cc3200emt/"; - librariesFolder = getContentFile(targetLibDir + "libraries"); - onArchChanged(); + public void actionPerformed(ActionEvent actionevent) { + //System.out.println("Switching to " + target + ":" + board); + String n = (String) getValue("target"); + String o = Preferences.get("target"); + + System.out.println("o=" + o); + System.out.println("n=" + n); + + if (!n.equals(o)) { + String targetLibDir = new String(""); + for (String boardName : boardsStirngNames){ + if (n.equals(boardName)){ + targetLibDir = "hardware/" + boardName + "/"; + } + } + /* + if (n.equals("msp430")) + targetLibDir = "hardware/msp430/"; + else if (n.equals("lm4f")) + targetLibDir = "hardware/lm4f/"; + else if (n.equals("c2000")) + targetLibDir = "hardware/c2000/"; + else if (n.equals("cc3200")) + targetLibDir = "hardware/cc3200/"; + else if (n.equals("msp432")) + targetLibDir = "hardware/msp432/"; + else if (n.equals("cc3200emt")) + targetLibDir = "hardware/cc3200emt/"; + */ + librariesFolder = getContentFile(targetLibDir + "libraries"); + onArchChanged(); + } + Preferences.set("target", (String) getValue("target")); + Preferences.set("board", (String) getValue("board")); + onBoardOrPortChange(); + Sketch.buildSettingChanged(); } - Preferences.set("target", (String) getValue("target")); - Preferences.set("board", (String) getValue("board")); - onBoardOrPortChange(); - Sketch.buildSettingChanged(); - } }; action.putValue("target", target.getName()); action.putValue("board", board); @@ -1153,9 +1177,8 @@ else if (n.equals("cc3200emt")) } } } - -/* + /* public void rebuildProgrammerMenu(JMenu menu) { //System.out.println("rebuilding programmer menu"); menu.removeAll(); @@ -1232,7 +1255,7 @@ public void actionPerformed(ActionEvent e) { boolean skipLibraryFolder = folder.equals((Base.getSketchbookFolder())); for (int i = 0; i < list.length; i++) { - if ((list[i].charAt(0) == '.') || list[i].startsWith("__disabled_") || list[i].equals("CVS") || + if ((list[i].charAt(0) == '.') || list[i].startsWith("__disabled_") || list[i].equals("CVS") || (skipLibraryFolder && list[i].compareToIgnoreCase("libraries")==0)) continue; File subfolder = new File(folder, list[i]); @@ -1373,11 +1396,11 @@ public void actionPerformed(ActionEvent e) { } return ifound; } - - + + protected void loadHardware(File folder) { if (!folder.isDirectory()) return; - + String list[] = folder.list(new FilenameFilter() { public boolean accept(File dir, String name) { // skip .DS_Store files, .svn folders, etc @@ -1392,9 +1415,9 @@ public boolean accept(File dir, String name) { // alphabetize list, since it's not always alpha order // replaced hella slow bubble sort with this feller for 0093 Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); - + for (String target : list) { - + //Check to ensure compiler is installed before displaying C2000 Support if(target.equals("c2000")){ if(Base.getC2000BasePath() != ""){ @@ -1406,7 +1429,7 @@ public boolean accept(File dir, String name) { targetsTable.put(target, new Target(target, subfolder)); } } - + } @@ -1667,12 +1690,12 @@ static public File getHardwareFolder() { // before the other folders / paths get cached). return getContentFile("hardware"); } - - + + static public String getHardwarePath() { return getHardwareFolder().getAbsolutePath(); } - + static public String readFile(String fileName) throws IOException { BufferedReader br = new BufferedReader(new FileReader(fileName)); @@ -1685,13 +1708,13 @@ static public String readFile(String fileName) throws IOException { sb.append("\n"); line = br.readLine(); } - + return sb.toString(); } finally { br.close(); } } - + static public String getArchCorePath() { String arch = getArch(); String path = getHardwarePath() + File.separator + arch + File.separator + @@ -1699,7 +1722,7 @@ static public String getArchCorePath() { return path; } - + static public String getAvrBasePath() { String path = getHardwarePath() + File.separator + "tools" + File.separator + "avr" + File.separator + "bin" + File.separator; @@ -1746,7 +1769,7 @@ static public String getC2000BasePath() { static public String getArch() { return archMap.get(Preferences.get("target")); } - + static public String toShortPath(String longpath) { String shortpath = "", sub = ""; //longpath = longpath.replaceAll("\\s", ""); @@ -1758,15 +1781,15 @@ static public String toShortPath(String longpath) { { int thisFile = 1; sub = temp.substring(0, 6); - + // Find if there are more files File dir = new File(shortpath); - for (File child : dir.listFiles()) + for (File child : dir.listFiles()) { String originalName = child.getName().toUpperCase(); String tempName = originalName.replaceAll("\\s", ""); int l = tempName.length(); - + if(tempName.substring(0, l>6 ? 6:l).compareTo(sub)==0) { if(originalName.compareTo(temp)==0) @@ -1776,20 +1799,20 @@ static public String toShortPath(String longpath) { } } String ext = ""; - + if(temp.indexOf(".")>0) // There is an extension to add { ext = temp.substring(temp.lastIndexOf(".")+1); ext = "." + ext.substring(0,ext.length()>3?3:ext.length()); } - + temp = sub + "~" + thisFile + ext; } shortpath += temp + "\\"; } return shortpath; } - + static public String getBasePath() { if (Base.isLinux()) { if (getArch() == "msp430") { @@ -1824,7 +1847,7 @@ else if (getArch() == "c2000") { + arch + File.separator + "bin" + File.separator; } } - + static public String getCommonBasePath() { return getToolsPath() + File.separator + "common" + File.separator + "bin" + File.separator; @@ -1833,8 +1856,8 @@ static public String getCommonBasePath() { static public Target getTarget() { return Base.targetsTable.get(Preferences.get("target")); } - - + + static public Map getBoardPreferences() { Target target = getTarget(); if (target == null) return new LinkedHashMap(); @@ -1844,7 +1867,7 @@ static public Map getBoardPreferences() { if (map == null) return new LinkedHashMap(); return map; } - + static public File getSketchbookFolder() { return new File(Preferences.get("sketchbook.path")); @@ -1871,8 +1894,8 @@ static public File getSketchbookLibrariesFolder() { static public String getSketchbookLibrariesPath() { return getSketchbookLibrariesFolder().getAbsolutePath(); } - - + + static public File getSketchbookHardwareFolder() { return new File(getSketchbookFolder(), "hardware"); } @@ -2025,7 +2048,7 @@ static public void setIcon(Frame frame) { // don't use the low-res icon on Mac OS X; the window should // already have the right icon from the .app file. if (Base.isMacOS()) return; - + ArrayList images = new ArrayList(); images.add(createImageFromLib("energia_16.png")); images.add(createImageFromLib("energia_24.png")); @@ -2033,7 +2056,7 @@ static public void setIcon(Frame frame) { images.add(createImageFromLib("energia_48.png")); frame.setIconImages(images); } - + static private Image createImageFromLib(String filename) { return Toolkit.getDefaultToolkit().createImage(new File("lib/" + filename).getAbsolutePath()); @@ -2118,7 +2141,7 @@ static public void showTroubleshooting() { static public void showFAQ() { showReference(_("FAQ.html")); } - + // ................................................................. @@ -2352,7 +2375,7 @@ static public File getAppFile() { return new File(path); //return new File(working, name); } - + static public File getContentFile(String name) { String path = System.getProperty("user.dir"); diff --git a/app/src/processing/app/debug/Target.java b/app/src/processing/app/debug/Target.java index 579a51a6fdb..bf6353126e8 100644 --- a/app/src/processing/app/debug/Target.java +++ b/app/src/processing/app/debug/Target.java @@ -35,7 +35,7 @@ public class Target { private File folder; private Map boards; private Map programmers; - + public Target(String name, File folder) { this.name = name; this.folder = folder; From 22b976878387f3113f17468fc1fc2652bb7df444 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 26 Oct 2015 20:02:37 +0300 Subject: [PATCH 4/7] Tolchain manager refactored --- app/src/processing/app/Base.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index df3d09daea7..ecb6881ebce 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1117,8 +1117,8 @@ public void rebuildBoardsMenu(JMenu menu) { menu.removeAll(); JMenu boardsWidget = new JMenu("BoardsWidget"); - boardsWidget.add(new JMenuItem("Empty 1")); - boardsWidget.add(new JMenuItem("Empty 2")); + boardsWidget.add(new JMenuItem("Mark")); + boardsWidget.add(new JMenuItem("Alex")); menu.add(boardsWidget); ButtonGroup group = new ButtonGroup(); From 33ed01a378c4d4572160bdf4f68a681fa5f8f7fa Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 26 Oct 2015 20:14:36 +0300 Subject: [PATCH 5/7] Refactor --- app/src/processing/app/Base.java | 39 ++------------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index ecb6881ebce..48475ed9147 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -262,23 +262,6 @@ public Base(String[] args) { } } - /* - String targetLibDir = new String(""); - - if(Preferences.get("target").equals("msp430")) - targetLibDir = "hardware/msp430/"; - else if (Preferences.get("target").equals("lm4f")) - targetLibDir = "hardware/lm4f/"; - else if (Preferences.get("target").equals("c2000")) - targetLibDir = "hardware/c2000/"; - else if (Preferences.get("target").equals("cc3200")) - targetLibDir = "hardware/cc3200/"; - else if (Preferences.get("target").equals("cc3200emt")) - targetLibDir = "hardware/cc3200emt/"; - else if (Preferences.get("target").equals("msp432")) - targetLibDir = "hardware/msp432/"; - */ - librariesFolder = getContentFile(targetLibDir + "libraries"); toolsFolder = getContentFile("tools"); @@ -1117,8 +1100,8 @@ public void rebuildBoardsMenu(JMenu menu) { menu.removeAll(); JMenu boardsWidget = new JMenu("BoardsWidget"); - boardsWidget.add(new JMenuItem("Mark")); - boardsWidget.add(new JMenuItem("Alex")); + boardsWidget.add(new JMenuItem("Empty1")); + boardsWidget.add(new JMenuItem("Empty2")); menu.add(boardsWidget); ButtonGroup group = new ButtonGroup(); @@ -1128,13 +1111,9 @@ public void rebuildBoardsMenu(JMenu menu) { AbstractAction action = new AbstractAction(target.getBoards().get(board).get("name")) { public void actionPerformed(ActionEvent actionevent) { - //System.out.println("Switching to " + target + ":" + board); String n = (String) getValue("target"); String o = Preferences.get("target"); - System.out.println("o=" + o); - System.out.println("n=" + n); - if (!n.equals(o)) { String targetLibDir = new String(""); for (String boardName : boardsStirngNames){ @@ -1142,20 +1121,6 @@ public void actionPerformed(ActionEvent actionevent) { targetLibDir = "hardware/" + boardName + "/"; } } - /* - if (n.equals("msp430")) - targetLibDir = "hardware/msp430/"; - else if (n.equals("lm4f")) - targetLibDir = "hardware/lm4f/"; - else if (n.equals("c2000")) - targetLibDir = "hardware/c2000/"; - else if (n.equals("cc3200")) - targetLibDir = "hardware/cc3200/"; - else if (n.equals("msp432")) - targetLibDir = "hardware/msp432/"; - else if (n.equals("cc3200emt")) - targetLibDir = "hardware/cc3200emt/"; - */ librariesFolder = getContentFile(targetLibDir + "libraries"); onArchChanged(); } From db2f7762afa92c959ab1f269cefbe55dfbbb15fc Mon Sep 17 00:00:00 2001 From: Alex Davydov Date: Sun, 15 Nov 2015 19:40:01 +0300 Subject: [PATCH 6/7] Empty widget was deleted --- app/src/processing/app/Base.java | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 5c0731f2a5e..84adb3ebe47 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -25,7 +25,6 @@ import java.awt.*; import java.awt.event.*; import java.io.*; -import java.nio.charset.Charset; import java.util.*; import java.util.regex.*; import javax.swing.*; @@ -257,7 +256,7 @@ public Base(String[] args) { String targetLibDir = new String(""); String boardNameString = Preferences.get("target"); - for (String boardName : boardsStirngNames) { + for (String boardName : boardsStingNames) { if (boardNameString.equals(boardName)) { targetLibDir = "hardware/" + boardName + "/"; } @@ -1085,27 +1084,21 @@ public void onArchChanged() { } } - static private ArrayList boardsStirngNames = new ArrayList(); + static private ArrayList boardsStingNames = new ArrayList(); static{ - boardsStirngNames.add("msp430"); - boardsStirngNames.add("lm4f"); - boardsStirngNames.add("c2000"); - boardsStirngNames.add("cc3200"); - boardsStirngNames.add("msp432"); - boardsStirngNames.add("cc3200emt"); - boardsStirngNames.add("msp432"); + boardsStingNames.add("msp430"); + boardsStingNames.add("lm4f"); + boardsStingNames.add("c2000"); + boardsStingNames.add("cc3200"); + boardsStingNames.add("msp432"); + boardsStingNames.add("cc3200emt"); + boardsStingNames.add("msp432"); } public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); menu.removeAll(); - - JMenu boardsWidget = new JMenu("BoardsWidget"); - boardsWidget.add(new JMenuItem("Empty1")); - boardsWidget.add(new JMenuItem("Empty2")); - menu.add(boardsWidget); - ButtonGroup group = new ButtonGroup(); for (Target target : targetsTable.values()) { @@ -1118,7 +1111,7 @@ public void actionPerformed(ActionEvent actionevent) { if (!n.equals(o)) { String targetLibDir = new String(""); - for (String boardName : boardsStirngNames){ + for (String boardName : boardsStingNames){ if (n.equals(boardName)){ targetLibDir = "hardware/" + boardName + "/"; } From 04c2f159f9c71f00d6d6b30a29681f545efed82e Mon Sep 17 00:00:00 2001 From: Alex Davydov Date: Sun, 15 Nov 2015 20:16:43 +0300 Subject: [PATCH 7/7] Moved initialization of boardsStringNames upstairs --- app/src/processing/app/Base.java | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 84adb3ebe47..5dec9d9e9ad 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -118,6 +118,16 @@ public class Base { // ArrayList editors = Collections.synchronizedList(new ArrayList()); Editor activeEditor; + static private ArrayList boardsStingNames = new ArrayList(); + static{ + boardsStingNames.add("msp430"); + boardsStingNames.add("lm4f"); + boardsStingNames.add("c2000"); + boardsStingNames.add("cc3200"); + boardsStingNames.add("msp432"); + boardsStingNames.add("cc3200emt"); + boardsStingNames.add("msp432"); + } static public void main(String args[]) { try { @@ -1083,19 +1093,6 @@ public void onArchChanged() { editor.onArchChanged(); } } - - static private ArrayList boardsStingNames = new ArrayList(); - static{ - boardsStingNames.add("msp430"); - boardsStingNames.add("lm4f"); - boardsStingNames.add("c2000"); - boardsStingNames.add("cc3200"); - boardsStingNames.add("msp432"); - boardsStingNames.add("cc3200emt"); - boardsStingNames.add("msp432"); - } - - public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); menu.removeAll();