1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Third-party cores seems to sort of work now, but burning bootloaders is probably broken.

Need to decide on the format for the boards.txt file.
This commit is contained in:
David A. Mellis 2009-11-07 18:56:45 +00:00
parent 3075c8e4fd
commit e5b5f25476
7 changed files with 82 additions and 106 deletions

View File

@ -85,7 +85,7 @@ public class Base {
// found in the sketchbook)
static public String librariesClassPath;
static HashMap<String, File> platformsTable;
static public HashMap<String, File> platformsTable;
// Location for untitled items
static File untitledFolder;
@ -248,7 +248,7 @@ public class Base {
// Get paths for the libraries and examples in the Processing folder
//String workingDirectory = System.getProperty("user.dir");
examplesFolder = getContentFile("examples");
librariesFolder = new File(getContentFile("hardware"), "libraries");
librariesFolder = getContentFile("libraries");
toolsFolder = getContentFile("tools");
// Get the sketchbook path, and make sure it's set properly
@ -278,6 +278,7 @@ public class Base {
}
}
platformsTable = new HashMap<String, File>();
loadHardware(getHardwareFolder());
loadHardware(getSketchbookHardwareFolder());
@ -994,25 +995,39 @@ public class Base {
public void rebuildBoardsMenu(JMenu menu) {
//System.out.println("rebuilding boards menu");
try {
menu.removeAll();
ButtonGroup group = new ButtonGroup();
for (String board : Preferences.getSubKeys("boards")) {
JMenu item =
new JRadioButtonMenuItem(
new AbstractAction(Preferences.get("boards", "board", "name")) {
{ putValue("board", board); }
public void actionPerformed(ActionEvent actionevent) {
//System.out.println("Switching to " + board);
Preferences.set("board", getValue("board"));
}
}));
if (board.equals(Preferences.get("board"))) item.setSelected(true);
group.add(item);
menu.add(item);
}
} catch (IOException e) {
e.printStackTrace();
menu.removeAll();
ButtonGroup group = new ButtonGroup();
for (String board : Preferences.getSubKeys("boards")) {
AbstractAction action =
new AbstractAction(Preferences.get("boards." + board + ".name")) {
public void actionPerformed(ActionEvent actionevent) {
//System.out.println("Switching to " + board);
Preferences.set("board", (String) getValue("board"));
}
};
action.putValue("board", board);
JMenuItem item = new JRadioButtonMenuItem(action);
if (board.equals(Preferences.get("board"))) item.setSelected(true);
group.add(item);
menu.add(item);
}
}
public void rebuildBurnBootloaderMenu(JMenu menu) {
//System.out.println("rebuilding burn bootloader menu");
menu.removeAll();
for (String programmer : Preferences.getSubKeys("programmers")) {
AbstractAction action =
new AbstractAction(
"w/ " + Preferences.get("programmers." + programmer + ".name")) {
public void actionPerformed(ActionEvent actionevent) {
activeEditor.handleBurnBootloader((String) getValue("programmer"));
}
};
action.putValue("programmer", programmer);
JMenuItem item = new JMenuItem(action);
menu.add(item);
}
}
@ -1195,8 +1210,8 @@ public class Base {
}
protected boolean loadHardware(File folder) {
if (!folder.isDirectory()) return false;
protected void loadHardware(File folder) {
if (!folder.isDirectory()) return;
String list[] = folder.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
@ -1207,7 +1222,7 @@ public class Base {
}
});
// if a bad folder or something like that, this might come back null
if (list == null) return false;
if (list == null) return;
// alphabetize list, since it's not always alpha order
// replaced hella slow bubble sort with this feller for 0093
@ -1217,13 +1232,23 @@ public class Base {
File subfolder = new File(folder, platform);
File boardsFile = new File(subfolder, "boards.txt");
if (boardsFile.exists()) {
Preferences.load(new FileInputStream(boardsFile), "boards");
try {
if (boardsFile.exists()) {
Preferences.load(new FileInputStream(boardsFile), "boards");
}
} catch (Exception e) {
System.err.println("Error loading boards from " +
boardsFile + ": " + e);
}
File programmersFile = new File(subfolder, "programmers.txt");
if (programmersFile.exists()) {
Preferences.load(new FileInputStream(programmersFile), "programmers");
try {
if (programmersFile.exists()) {
Preferences.load(new FileInputStream(programmersFile), "programmers");
}
} catch (Exception e) {
System.err.println("Error loading programmers from " +
programmersFile + ": " + e);
}
platformsTable.put(platform, subfolder);
@ -1513,6 +1538,11 @@ public class Base {
static public String getSketchbookLibrariesPath() {
return getSketchbookLibrariesFolder().getAbsolutePath();
}
static public File getSketchbookHardwareFolder() {
return new File(getSketchbookFolder(), "hardware");
}
protected File getDefaultSketchbookFolder() {

View File

@ -706,16 +706,7 @@ public class Editor extends JFrame implements RunnerListener {
if (boardsMenu == null) {
boardsMenu = new JMenu("Board");
ButtonGroup boardGroup = new ButtonGroup();
for (Iterator i = Preferences.getSubKeys("boards"); i.hasNext(); ) {
String board = (String) i.next();
Action action = new BoardMenuAction(board);
item = new JRadioButtonMenuItem(action);
if (board.equals(Preferences.get("board")))
item.setSelected(true);
boardGroup.add(item);
boardsMenu.add(item);
}
base.rebuildBoardsMenu(boardsMenu);
}
menu.add(boardsMenu);
@ -727,14 +718,9 @@ public class Editor extends JFrame implements RunnerListener {
menu.add(serialMenu);
menu.addSeparator();
JMenu bootloaderMenu = new JMenu("Burn Bootloader");
for (Iterator i = Preferences.getSubKeys("programmers"); i.hasNext(); ) {
String programmer = (String) i.next();
Action action = new BootloaderMenuAction(programmer);
item = new JMenuItem(action);
bootloaderMenu.add(item);
}
base.rebuildBurnBootloaderMenu(bootloaderMenu);
menu.add(bootloaderMenu);
menu.addMenuListener(new MenuListener() {
@ -964,30 +950,6 @@ public class Editor extends JFrame implements RunnerListener {
}
class BoardMenuAction extends AbstractAction {
private String board;
public BoardMenuAction(String board) {
super(Preferences.get("boards." + board + ".name"));
this.board = board;
}
public void actionPerformed(ActionEvent actionevent) {
//System.out.println("Switching to " + board);
Preferences.set("board", board);
}
}
class BootloaderMenuAction extends AbstractAction {
private String programmer;
public BootloaderMenuAction(String programmer) {
super("w/ " + Preferences.get("programmers." + programmer + ".name"));
this.programmer = programmer;
}
public void actionPerformed(ActionEvent actionevent) {
handleBurnBootloader(programmer);
}
}
protected void populateSerialMenu() {
// getting list of ports

View File

@ -647,7 +647,7 @@ public class Preferences {
* baz.count=3
* this will return { "foo", "bar", "baz" }.
*/
static public Iterator getSubKeys(String prefix) {
static public Set<String> getSubKeys(String prefix) {
if (!prefixes.containsKey(prefix))
return null;
Set subkeys = new LinkedHashSet();
@ -657,7 +657,7 @@ public class Preferences {
subkey = subkey.substring(0, subkey.indexOf('.'));
subkeys.add(subkey);
}
return subkeys.iterator();
return subkeys;
}

View File

@ -71,23 +71,25 @@ public class Compiler implements MessageConsumer {
MessageStream pms = new MessageStream(this);
String avrBasePath = Base.getAvrBasePath();
String corePath = Preferences.get("boards", "board", "build.core");
String platform = Preferences.get("boards", "board", "build.core");
File platformFile = Base.platformsTable.get(platform);
String corePath = new File(platformFile, "core").getAbsolutePath();
List<File> objectFiles = new ArrayList<File>();
List includePaths = new ArrayList();
includePaths.add(target.getPath());
includePaths.add(corePath);
String runtimeLibraryName = buildPath + File.separator + "core.a";
// 1. compile the target (core), outputting .o files to <buildPath> and
// then collecting them into the core.a library file.
// 1. compile the core, outputting .o files to <buildPath> and then
// collecting them into the core.a library file.
List<File> targetObjectFiles =
List<File> coreObjectFiles =
compileFiles(avrBasePath, buildPath, includePaths,
findFilesInPath(target.getPath(), "S", true),
findFilesInPath(target.getPath(), "c", true),
findFilesInPath(target.getPath(), "cpp", true));
findFilesInPath(corePath, "S", true),
findFilesInPath(corePath, "c", true),
findFilesInPath(corePath, "cpp", true));
List baseCommandAR = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-ar",
@ -95,7 +97,7 @@ public class Compiler implements MessageConsumer {
runtimeLibraryName
}));
for(File file : targetObjectFiles) {
for(File file : coreObjectFiles) {
List commandAR = new ArrayList(baseCommandAR);
commandAR.add(file.getAbsolutePath());
execAsynchronously(commandAR);

View File

@ -30,7 +30,6 @@
package processing.app.preproc;
import processing.app.*;
import processing.app.debug.Target;
import processing.core.*;
import java.io.*;
@ -50,7 +49,6 @@ public class PdePreprocessor {
// we always write one header: WProgram.h
public int headerCount = 1;
Target target;
List prototypes;
@ -82,12 +80,10 @@ public class PdePreprocessor {
public PdePreprocessor() { }
public int writePrefix(String program, String buildPath,
String name, String codeFolderPackages[],
Target target)
String name, String codeFolderPackages[])
throws FileNotFoundException {
this.buildPath = buildPath;
this.name = name;
this.target = target;
int tabSize = Preferences.getInteger("editor.tabs.size");
char[] indentChars = new char[tabSize];
@ -196,7 +192,7 @@ public class PdePreprocessor {
// String extraImports[]) throws java.lang.Exception {
public String write() throws java.lang.Exception {
writeProgram(stream, program, prototypes);
writeFooter(stream, target);
writeFooter(stream);
stream.close();
return name;
@ -223,23 +219,7 @@ public class PdePreprocessor {
*
* @param out PrintStream to write it to.
*/
protected void writeFooter(PrintStream out, Target target) throws java.lang.Exception {
// Open the file main.cxx and copy its entire contents to the bottom of the
// generated sketch .cpp file...
String mainFileName = target.getPath() + File.separator + "main.cxx";
FileReader reader = null;
reader = new FileReader(mainFileName);
LineNumberReader mainfile = new LineNumberReader(reader);
String line;
while ((line = mainfile.readLine()) != null) {
out.print(line + "\n");
}
mainfile.close();
}
protected void writeFooter(PrintStream out) throws java.lang.Exception {}
public ArrayList<String> getExtraImports() {

View File

@ -36,7 +36,7 @@ else
chmod +x work/Arduino.app/Contents/MacOS/JavaApplicationStub
cp -rX ../shared/lib "$RESOURCES/"
cp -rX ../shared/libraries "$RESOURCES/"
cp -rX ../../libraries "$RESOURCES/"
cp -rX ../shared/tools "$RESOURCES/"
cp -rX ../../hardware "$RESOURCES/"
@ -126,4 +126,4 @@ cd ../..
echo
echo Done.
echo Done.

View File

@ -1,3 +1,5 @@
#include <WProgram.h>
int main(void)
{
init();