public boolean avrdude(Collection params) throws RunnerException { List commandDownloader = new ArrayList(); commandDownloader.add("avrdude"); // Point avrdude at its config file since it's in a non-standard location. if (Base.isMacOS()) { commandDownloader.add("-C" + "hardware/tools/avr/etc/avrdude.conf"); } else if (Base.isWindows()) { String userdir = System.getProperty("user.dir") + File.separator; commandDownloader.add("-C" + userdir + "hardware/tools/avr/etc/avrdude.conf"); } else { // ???: is it better to have Linux users install avrdude themselves, in // a way that it can find its own configuration file? commandDownloader.add("-C" + "hardware/tools/avrdude.conf"); } if (Preferences.getBoolean("upload.verbose")) { commandDownloader.add("-v"); commandDownloader.add("-v"); commandDownloader.add("-v"); commandDownloader.add("-v"); } else { commandDownloader.add("-q"); commandDownloader.add("-q"); } // XXX: quick hack to chop the "atmega" off of "atmega8" and "atmega168", // then shove an "m" at the beginning. won't work for attiny's, etc. commandDownloader.add( "-pm" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu").substring(6)); commandDownloader.addAll(params); return executeUploadCommand(commandDownloader); }
private Collection getProgrammerCommands(String programmer) { List params = new ArrayList(); params.add("-c" + Preferences.get("programmers." + programmer + ".protocol")); if ("usb".equals(Preferences.get("programmers." + programmer + ".communication"))) { params.add("-Pusb"); } else if ("serial".equals(Preferences.get("programmers." + programmer + ".communication"))) { params.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port")); // XXX: add support for specifying the baud rate for serial programmers. } // XXX: add support for specifying the port address for parallel // programmers, although avrdude has a default that works in most cases. if (Preferences.get("programmers." + programmer + ".force") != null && Preferences.getBoolean("programmers." + programmer + ".force")) params.add("-F"); if (Preferences.get("programmers." + programmer + ".delay") != null) params.add("-i" + Preferences.get("programmers." + programmer + ".delay")); return params; }
private boolean uploadViaBootloader(String buildPath, String className) throws RunnerException { List commandDownloader = new ArrayList(); String protocol = Preferences.get("boards." + Preferences.get("board") + ".upload.protocol"); // avrdude wants "stk500v1" to distinguish it from stk500v2 if (protocol.equals("stk500")) protocol = "stk500v1"; commandDownloader.add("-c" + protocol); commandDownloader.add( "-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port")); commandDownloader.add( "-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed")); commandDownloader.add("-D"); // don't erase commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i"); if (Preferences.get("boards." + Preferences.get("board") + ".upload.disable_flushing") == null || Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.disable_flushing") == false) { flushSerialBuffer(); } return avrdude(commandDownloader); }
public Preferences() { // setup dialog for the prefs //dialog = new JDialog(editor, "Preferences", true); dialog = new JFrame(_("Preferences")); dialog.setResizable(false); Container pain = dialog.getContentPane(); pain.setLayout(null); int top = GUI_BIG; int left = GUI_BIG; int right = 0; JLabel label; JButton button; //, button2; //JComboBox combo; Dimension d, d2; //, d3; int h, vmax; // Sketchbook location: // [...............................] [ Browse ] label = new JLabel(_("Sketchbook location:")); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height; // + GUI_SMALL; sketchbookLocationField = new JTextField(40); pain.add(sketchbookLocationField); d = sketchbookLocationField.getPreferredSize(); button = new JButton(PROMPT_BROWSE); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File dflt = new File(sketchbookLocationField.getText()); File file = Base.selectFolder(_("Select new sketchbook location"), dflt, dialog); if (file != null) { sketchbookLocationField.setText(file.getAbsolutePath()); } } }); pain.add(button); d2 = button.getPreferredSize(); // take max height of all components to vertically align em vmax = Math.max(d.height, d2.height); sketchbookLocationField.setBounds(left, top + (vmax-d.height)/2, d.width, d.height); h = left + d.width + GUI_SMALL; button.setBounds(h, top + (vmax-d2.height)/2, d2.width, d2.height); right = Math.max(right, h + d2.width + GUI_BIG); top += vmax + GUI_BETWEEN; // Preferred language: [ ] (requires restart of Arduino) Container box = Box.createHorizontalBox(); label = new JLabel(_("Editor language: ")); box.add(label); comboLanguage = new JComboBox(languages); comboLanguage.setSelectedIndex((Arrays.asList(languagesISO)).indexOf(Preferences.get("editor.languages.current"))); box.add(comboLanguage); label = new JLabel(_(" (requires restart of Arduino)")); box.add(label); pain.add(box); d = box.getPreferredSize(); box.setForeground(Color.gray); box.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // Editor font size [ ] box = Box.createHorizontalBox(); label = new JLabel(_("Editor font size: ")); box.add(label); fontSizeField = new JTextField(4); box.add(fontSizeField); label = new JLabel(_(" (requires restart of Arduino)")); box.add(label); pain.add(box); d = box.getPreferredSize(); box.setBounds(left, top, d.width, d.height); Font editorFont = Preferences.getFont("editor.font"); fontSizeField.setText(String.valueOf(editorFont.getSize())); top += d.height + GUI_BETWEEN; // Show verbose output during: [ ] compilation [ ] upload box = Box.createHorizontalBox(); label = new JLabel(_("Show verbose output during: ")); box.add(label); verboseCompilationBox = new JCheckBox(_("compilation ")); box.add(verboseCompilationBox); verboseUploadBox = new JCheckBox(_("upload")); box.add(verboseUploadBox); pain.add(box); d = box.getPreferredSize(); box.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; // [ ] Verify code after upload verifyUploadBox = new JCheckBox(_("Verify code after upload")); pain.add(verifyUploadBox); d = verifyUploadBox.getPreferredSize(); verifyUploadBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Use external editor externalEditorBox = new JCheckBox(_("Use external editor")); pain.add(externalEditorBox); d = externalEditorBox.getPreferredSize(); externalEditorBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Check for updates on startup checkUpdatesBox = new JCheckBox(_("Check for updates on startup")); pain.add(checkUpdatesBox); d = checkUpdatesBox.getPreferredSize(); checkUpdatesBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Update sketch files to new extension on save (.pde -> .ino) updateExtensionBox = new JCheckBox(_("Update sketch files to new extension on save (.pde -> .ino)")); pain.add(updateExtensionBox); d = updateExtensionBox.getPreferredSize(); updateExtensionBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; domainPortField= new JTextField(); domainPortField.setColumns(30); Box domainBox = Box.createHorizontalBox(); domainBox.add(new JLabel("Tftp upload Domain:")); domainBox.add(domainPortField); pain.add(domainBox); d = domainBox.getPreferredSize(); domainBox.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; autoResetPortField= new JTextField(); autoResetPortField.setColumns(8); Box resetBox = Box.createHorizontalBox(); resetBox.add(new JLabel("Auto Reset Port:")); resetBox.add(autoResetPortField); pain.add(resetBox); d = resetBox.getPreferredSize(); resetBox.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; tftpPassField = new JTextField(); tftpPassField.setColumns(30); Box tftpBox = Box.createHorizontalBox(); tftpBox.add(new JLabel("Tftp Secret Password:"******"Automatically associate .ino files with Arduino")); pain.add(autoAssociateBox); d = autoAssociateBox.getPreferredSize(); autoAssociateBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; } // More preferences are in the ... label = new JLabel(_("More preferences can be edited directly in the file")); pain.add(label); d = label.getPreferredSize(); label.setForeground(Color.gray); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; // + GUI_SMALL; label = new JLabel(preferencesFile.getAbsolutePath()); final JLabel clickable = label; label.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { Base.openFolder(Base.getSettingsFolder()); } public void mouseEntered(MouseEvent e) { clickable.setForeground(new Color(0, 0, 140)); } public void mouseExited(MouseEvent e) { clickable.setForeground(Color.BLACK); } }); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; label = new JLabel(_("(edit only when Arduino is not running)")); pain.add(label); d = label.getPreferredSize(); label.setForeground(Color.gray); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; // + GUI_SMALL; // [ OK ] [ Cancel ] maybe these should be next to the message? button = new JButton(PROMPT_OK); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyFrame(); disposeFrame(); } }); pain.add(button); d2 = button.getPreferredSize(); BUTTON_HEIGHT = d2.height; h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); h += BUTTON_WIDTH + GUI_SMALL; button = new JButton(PROMPT_CANCEL); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { disposeFrame(); } }); pain.add(button); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); top += BUTTON_HEIGHT + GUI_BETWEEN; // finish up wide = right + GUI_BIG; high = top + GUI_SMALL; // closing the window is same as hitting cancel button dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { disposeFrame(); } }); ActionListener disposer = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { disposeFrame(); } }; Base.registerWindowCloseKeys(dialog.getRootPane(), disposer); Base.setIcon(dialog); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation((screen.width - wide) / 2, (screen.height - high) / 2); dialog.pack(); // get insets Insets insets = dialog.getInsets(); dialog.setSize(wide + insets.left + insets.right, high + insets.top + insets.bottom); // handle window closing commands for ctrl/cmd-W or hitting ESC. pain.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { //System.out.println(e); KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE; if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) || (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) { disposeFrame(); } } }); }