Merge branch 'ide-1.5.x' into can

This commit is contained in:
Cristian Maglie 2013-01-27 12:52:06 +01:00
commit 3a3bf643f9
100 changed files with 51309 additions and 25733 deletions

1
.gitignore vendored
View File

@ -13,7 +13,6 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss
hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
hardware/arduino/bootloaders/caterina_LUFA/.dep/
.gitignore
build/windows/work/
build/linux/work/
build/linux/dist/*.tar.gz

View File

@ -76,7 +76,7 @@
<fileset dir="test" includes="**/*.txt" />
</copy>
<junit printsummary="yes" haltonfailure="yes">
<junit printsummary="yes">
<classpath>
<pathelement location="bin"/>
<pathelement location="test-bin"/>

View File

@ -50,9 +50,9 @@ import static processing.app.I18n._;
* files and images, etc) that comes from that.
*/
public class Base {
public static final int REVISION = 151;
public static final int REVISION = 152;
/** This might be replaced by main() if there's a lib/version.txt file. */
static String VERSION_NAME = "0151";
static String VERSION_NAME = "0152";
/** Set true if this a proper release rather than a numbered revision. */
static public boolean RELEASE = false;
@ -111,8 +111,21 @@ public class Base {
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
Editor activeEditor;
static File portableFolder = null;
static final String portableSketchbookFolder = "sketchbook";
static public void main(String args[]) throws Exception {
initPlatform();
// Portable folder
portableFolder = getContentFile("portable");
if (!portableFolder.exists())
portableFolder = null;
// run static initialization that grabs all the prefs
Preferences.init(null);
try {
File versionFile = getContentFile("lib/version.txt");
if (versionFile.exists()) {
@ -151,8 +164,6 @@ public class Base {
}
*/
initPlatform();
// // Set the look and feel before opening the window
// try {
// platform.setLookAndFeel();
@ -172,12 +183,6 @@ public class Base {
// Make sure a full JDK is installed
//initRequirements();
// run static initialization that grabs all the prefs
Preferences.init(null);
// load the I18n module for internationalization
I18n.init(Preferences.get("editor.languages.current"));
// setup the theme coloring fun
Theme.init();
@ -252,14 +257,18 @@ public class Base {
// 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()) {
File sketchbookFolder;
if (portableFolder != null)
sketchbookFolder = new File(portableFolder, sketchbookPath);
else
sketchbookFolder = new File(sketchbookPath);
if (!sketchbookFolder.exists()) {
Base.showWarning(_("Sketchbook folder disappeared"),
_("The sketchbook folder no longer exists.\n" +
"Arduino will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Arduino will then stop talking about\n" +
"himself in the third person."), null);
_("The sketchbook folder no longer exists.\n" +
"Arduino will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Arduino will then stop talking about\n" +
"himself in the third person."), null);
sketchbookPath = null;
}
}
@ -267,7 +276,10 @@ public class Base {
// 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 (portableFolder != null)
Preferences.set("sketchbook.path", portableSketchbookFolder);
else
Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath());
if (!defaultFolder.exists()) {
defaultFolder.mkdirs();
}
@ -281,6 +293,8 @@ public class Base {
boolean opened = false;
boolean doUpload = false;
boolean doVerify = false;
boolean doVerbose = false;
String selectBoard = null;
String selectPort = null;
// Check if any files were passed in on the command line
@ -289,6 +303,14 @@ public class Base {
doUpload = true;
continue;
}
if (args[i].equals("--verify")) {
doVerify = true;
continue;
}
if (args[i].equals("--verbose") || args[i].equals("-v")) {
doVerbose = true;
continue;
}
if (args[i].equals("--board")) {
i++;
if (i < args.length)
@ -319,16 +341,42 @@ public class Base {
}
}
if (doUpload) {
if (!opened)
throw new Exception(_("Can't open source sketch!"));
Thread.sleep(2000);
if (doUpload || doVerify) {
if (!opened) {
System.out.println(_("Can't open source sketch!"));
System.exit(2);
}
// Set verbosity for command line build
Preferences.set("build.verbose", "" + doVerbose);
Preferences.set("upload.verbose", "" + doVerbose);
Editor editor = editors.get(0);
if (selectPort != null)
editor.selectSerialPort(selectPort);
// Wait until editor is initialized
while (!editor.status.isInitialized())
Thread.sleep(10);
// Do board selection if requested
if (selectBoard != null)
selectBoard(selectBoard, editor);
editor.exportHandler.run();
if (doUpload) {
// Build and upload
if (selectPort != null)
editor.selectSerialPort(selectPort);
editor.exportHandler.run();
} else {
// Build only
editor.runHandler.run();
}
// Error during build or upload
int res = editor.status.mode;
if (res == EditorStatus.ERR)
System.exit(1);
// No errors exit gracefully
System.exit(0);
}
@ -389,6 +437,14 @@ public class Base {
int opened = 0;
for (int i = 0; i < count; i++) {
String path = Preferences.get("last.sketch" + i + ".path");
if (portableFolder != null) {
File absolute = new File(portableFolder, path);
try {
path = absolute.getCanonicalPath();
} catch (IOException e) {
// path unchanged.
}
}
int[] location;
if (windowPositionValid) {
String locationStr = Preferences.get("last.sketch" + i + ".location");
@ -427,6 +483,11 @@ public class Base {
!editor.getSketch().isModified()) {
continue;
}
if (portableFolder != null) {
path = FileUtils.relativePath(portableFolder.toString(), path);
if (path == null)
continue;
}
Preferences.set("last.sketch" + index + ".path", path);
int[] location = editor.getPlacement();
@ -445,6 +506,11 @@ public class Base {
String untitledPath = untitledFolder.getAbsolutePath();
if (path.startsWith(untitledPath)) {
path = "";
} else
if (portableFolder != null) {
path = FileUtils.relativePath(portableFolder.toString(), path);
if (path == null)
path = "";
}
Preferences.set("last.sketch" + index + ".path", path);
}
@ -973,6 +1039,8 @@ public class Base {
}
public Map<String, File> getIDELibs() {
if (libraries == null)
return new HashMap<String, File>();
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) {
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
@ -982,6 +1050,8 @@ public class Base {
}
public Map<String, File> getUserLibs() {
if (libraries == null)
return new HashMap<String, File>();
Map<String, File> userLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) {
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
@ -1005,34 +1075,37 @@ public class Base {
importMenu.add(addLibraryMenuItem);
// Split between user supplied libraries and IDE libraries
Map<String, File> ideLibs = getIDELibs();
Map<String, File> userLibs = getUserLibs();
try {
// Find the current target. Get the platform, and then select the
// correct name and core path.
PreferencesMap prefs = getTargetPlatform().getPreferences();
String targetname = prefs.get("name");
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform != null) {
Map<String, File> ideLibs = getIDELibs();
Map<String, File> 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");
if (false) {
// Hack to extract these words by gettext tool.
// These phrases are actually defined in the "platform.txt".
String notused = _("Arduino AVR Boards");
notused = _("Arduino ARM (32-bits) Boards");
}
if (false) {
// Hack to extract these words by gettext tool.
// These phrases are actually defined in the "platform.txt".
String notused = _("Arduino AVR Boards");
notused = _("Arduino ARM (32-bits) Boards");
}
JMenuItem platformItem = new JMenuItem(_(targetname));
platformItem.setEnabled(false);
importMenu.add(platformItem);
if (ideLibs.size()>0) {
importMenu.addSeparator();
addLibraries(importMenu, ideLibs);
JMenuItem platformItem = new JMenuItem(_(targetname));
platformItem.setEnabled(false);
importMenu.add(platformItem);
if (ideLibs.size() > 0) {
importMenu.addSeparator();
addLibraries(importMenu, ideLibs);
}
if (userLibs.size() > 0) {
importMenu.addSeparator();
addLibraries(importMenu, userLibs);
}
} catch (IOException e) {
e.printStackTrace();
}
if (userLibs.size()>0) {
importMenu.addSeparator();
addLibraries(importMenu, userLibs);
}
} catch (IOException e) {
e.printStackTrace();
}
}
@ -1135,11 +1208,15 @@ public class Base {
}
public void onBoardOrPortChange() {
TargetPlatform targetPlatform = getTargetPlatform();
if (targetPlatform == null)
return;
// Calculate paths for libraries and examples
examplesFolder = getContentFile("examples");
toolsFolder = getContentFile("tools");
File platformFolder = getTargetPlatform().getFolder();
File platformFolder = targetPlatform.getFolder();
librariesFolders = new ArrayList<File>();
librariesFolders.add(getContentFile("libraries"));
librariesFolders.add(new File(platformFolder, "libraries"));
@ -1153,9 +1230,14 @@ public class Base {
// Populate importToLibraryTable
importToLibraryTable = new HashMap<String, File>();
for (File subfolder : libraries.values()) {
String packages[] = headerListFromIncludePath(subfolder);
for (String pkg : packages)
importToLibraryTable.put(pkg, subfolder);
try {
String packages[] = headerListFromIncludePath(subfolder);
for (String pkg : packages) {
importToLibraryTable.put(pkg, subfolder);
}
} catch (IOException e) {
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
}
}
// Update editors status bar
@ -1403,6 +1485,9 @@ public class Base {
*/
protected boolean addSketches(JMenu menu, File folder,
final boolean replaceExisting) throws IOException {
if (folder == null)
return false;
// skip .DS_Store files, etc (this shouldn't actually be necessary)
if (!folder.isDirectory()) return false;
@ -1501,8 +1586,13 @@ public class Base {
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
activeEditor.getSketch().importLibrary(e.getActionCommand());
public void actionPerformed(ActionEvent event) {
String jarPath = event.getActionCommand();
try {
activeEditor.getSketch().importLibrary(jarPath);
} catch (IOException e) {
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
}
}
};
@ -1524,8 +1614,12 @@ public class Base {
* the header files in its sub-folders, as those should be included from
* within the header files at the top-level).
*/
static public String[] headerListFromIncludePath(File path) {
return path.list(new OnlyFilesWithExtension(".h"));
static public String[] headerListFromIncludePath(File path) throws IOException {
String[] list = path.list(new OnlyFilesWithExtension(".h"));
if (list == null) {
throw new IOException();
}
return list;
}
protected void loadHardware(File folder) {
@ -1698,6 +1792,9 @@ public class Base {
static public File getSettingsFolder() {
if (portableFolder != null)
return portableFolder;
File settingsFolder = null;
String preferencesPath = Preferences.get("settings.path");
@ -1717,8 +1814,8 @@ public class Base {
if (!settingsFolder.exists()) {
if (!settingsFolder.mkdirs()) {
showError(_("Settings issues"),
_("Arduino cannot run because it could not\n" +
"create a folder to store your settings."), null);
_("Arduino cannot run because it could not\n" +
"create a folder to store your settings."), null);
}
}
return settingsFolder;
@ -1849,7 +1946,10 @@ public class Base {
*/
static public TargetPlatform getTargetPlatform(String packageName,
String platformName) {
return packages.get(packageName).get(platformName);
TargetPackage p = packages.get(packageName);
if (p == null)
return null;
return p.get(platformName);
}
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
@ -1874,7 +1974,19 @@ public class Base {
return boardPreferences;
}
static public File getPortableFolder() {
return portableFolder;
}
static public String getPortableSketchbookFolder() {
return portableSketchbookFolder;
}
static public File getSketchbookFolder() {
if (portableFolder != null)
return new File(portableFolder, Preferences.get("sketchbook.path"));
return new File(Preferences.get("sketchbook.path"));
}
@ -1907,6 +2019,9 @@ public class Base {
protected File getDefaultSketchbookFolder() {
if (portableFolder != null)
return new File(portableFolder, portableSketchbookFolder);
File sketchbookFolder = null;
try {
sketchbookFolder = platform.getDefaultSketchbookFolder();

View File

@ -508,12 +508,14 @@ public class Editor extends JFrame implements RunnerListener {
if (sketchbookMenu == null) {
sketchbookMenu = new JMenu(_("Sketchbook"));
MenuScroller.setScrollerFor(sketchbookMenu);
base.rebuildSketchbookMenu(sketchbookMenu);
}
fileMenu.add(sketchbookMenu);
if (examplesMenu == null) {
examplesMenu = new JMenu(_("Examples"));
MenuScroller.setScrollerFor(examplesMenu);
base.rebuildExamplesMenu(examplesMenu);
}
fileMenu.add(examplesMenu);
@ -727,7 +729,10 @@ public class Editor extends JFrame implements RunnerListener {
protected void addTools(JMenu menu, File sourceFolder) {
HashMap<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
if (sourceFolder == null)
return;
Map<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
File[] folders = sourceFolder.listFiles(new FileFilter() {
public boolean accept(File folder) {
@ -956,6 +961,9 @@ public class Editor extends JFrame implements RunnerListener {
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
onBoardOrPortChange();
//System.out.println("set to " + get("serial.port"));
}

View File

@ -22,6 +22,7 @@
*/
package processing.app;
import processing.app.tools.MenuScroller;
import static processing.app.I18n._;
import java.awt.*;
@ -238,6 +239,7 @@ public class EditorHeader extends JComponent {
} else {
menu = new JMenu();
MenuScroller.setScrollerFor(menu);
popup = menu.getPopupMenu();
add(popup);
popup.setLightWeightPopupEnabled(true);

View File

@ -72,6 +72,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
//Thread promptThread;
int response;
boolean initialized = false;
public EditorStatus(Editor editor) {
this.editor = editor;
@ -237,7 +238,10 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
public void paintComponent(Graphics screen) {
//if (screen == null) return;
if (okButton == null) setup();
if (!initialized) {
setup();
initialized = true;
}
//System.out.println("status.paintComponent");
@ -290,8 +294,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
protected void setup() {
if (okButton == null) {
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
okButton = new JButton(Preferences.PROMPT_OK);
cancelButton = new JButton(I18n.PROMPT_CANCEL);
okButton = new JButton(I18n.PROMPT_OK);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@ -500,4 +504,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
}
}
}
public boolean isInitialized() {
return initialized;
}
}

View File

@ -19,15 +19,29 @@ import java.text.MessageFormat;
public class I18n {
// start using current locale but still allow using the dropdown list later
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
public static Locale locale;
private static ResourceBundle i18n;
// prompt text stuff
static String PROMPT_YES;
static String PROMPT_NO;
static String PROMPT_CANCEL;
static String PROMPT_OK;
static String PROMPT_BROWSE;
static protected void init (String language) {
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
try {
if (language == null || language.trim().length() == 0) locale = Locale.getDefault();
else locale = new Locale(language);
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
if (language != null && language.trim().length() > 0) {
Locale.setDefault(new Locale(language));
}
i18n = ResourceBundle.getBundle("processing.app.Resources", Locale.getDefault());
PROMPT_YES = _("Yes");
PROMPT_NO = _("No");
PROMPT_CANCEL = _("Cancel");
PROMPT_OK = _("OK");
PROMPT_BROWSE = _("Browse");
} catch (java.lang.NullPointerException e) {
}
}

View File

@ -29,6 +29,7 @@ import javax.swing.UIManager;
import com.sun.jna.Library;
import com.sun.jna.Native;
import processing.core.PConstants;
/**
@ -159,6 +160,10 @@ public class Platform {
return clib.unsetenv(variable);
}
public String getName() {
return PConstants.platformNames[PConstants.OTHER];
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

View File

@ -23,16 +23,18 @@
package processing.app;
import processing.app.helpers.FileUtils;
import processing.app.syntax.SyntaxStyle;
import processing.core.PApplet;
import processing.core.PConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import processing.app.helpers.PreferencesMap;
import processing.app.syntax.*;
import processing.core.*;
import static processing.app.I18n._;
@ -71,20 +73,14 @@ public class Preferences {
static final String PREFS_FILE = "preferences.txt";
// prompt text stuff
static final String PROMPT_YES = _("Yes");
static final String PROMPT_NO = _("No");
static final String PROMPT_CANCEL = _("Cancel");
static final String PROMPT_OK = _("OK");
static final String PROMPT_BROWSE = _("Browse");
String[] languages = {
_("System Default"),
"العربية" + " (" + _("Arabic") + ")",
"Aragonés" + " (" + _("Aragonese") + ")",
"български" + " (" + _("Bulgarian") + ")",
"Català" + " (" + _("Catalan") + ")",
"Hrvatski" + " (" + _("Croatian") + ")",
"český" + " (" + _("Czech") + ")",
"简体中文" + " (" + _("Chinese Simplified") + ")",
"繁體中文" + " (" + _("Chinese Traditional") + ")",
"Dansk" + " (" + _("Danish") + ")",
@ -93,7 +89,10 @@ public class Preferences {
"Eesti" + " (" + _("Estonian") + ")",
"Pilipino" + " (" + _("Filipino") + ")",
"Français" + " (" + _("French") + ")",
"Canadienne-français" + " (" + _("Canadian French") + ")",
"Galego" + " (" + _("Galician") + ")",
"საქართველოს" + " (" + _("Georgian") + ")",
"עברית" + " (" + _("Hebrew") + ")",
"Deutsch" + " (" + _("German") + ")",
"ελληνικά" + " (" + _("Greek") + ")",
"Magyar" + " (" + _("Hindi") + ")",
@ -104,8 +103,9 @@ public class Preferences {
"한국어" + " (" + _("Korean") + ")",
"Latviešu" + " (" + _("Latvian") + ")",
"Lietuvių Kalba" + " (" + _("Lithuaninan") + ")",
"मराठी" + " (" + _("Marathi") + ")",
"मराठी" + " (" + _("Marathi") + ")",
"Norsk" + " (" + _("Norwegian") + ")",
"Norsk bokmål" + " (" + _("Norwegian Bokmål") + ")",
"فارسی" + " (" + _("Persian") + ")",
"Język Polski" + " (" + _("Polish") + ")",
"Português" + " (" + _("Portuguese") + " - Brazil)",
@ -113,12 +113,18 @@ public class Preferences {
"Română" + " (" + _("Romanian") + ")",
"Русский" + " (" + _("Russian") + ")",
"Español" + " (" + _("Spanish") + ")",
"தமிழ்" + " (" + _("Tamil") + ")"};
"தமிழ்" + " (" + _("Tamil") + ")",
"Türk" + " (" + _("Turkish") + ")",
"Український" + " (" + _("Ukrainian") + ")"
};
String[] languagesISO = {
"",
"ar",
"an",
"bg",
"ca",
"hr_hr",
"cs_cz",
"zh_cn",
"zh_tw",
"da",
@ -127,7 +133,10 @@ public class Preferences {
"et",
"tl",
"fr",
"fr_ca",
"gl",
"ka_ge",
"he",
"de",
"el",
"hi",
@ -140,6 +149,7 @@ public class Preferences {
"lt",
"mr",
"no_nb",
"nb_no",
"fa",
"pl",
"pt_br",
@ -147,7 +157,10 @@ public class Preferences {
"ro",
"ru",
"es",
"ta"};
"ta",
"tr",
"uk"
};
/**
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
@ -221,14 +234,13 @@ public class Preferences {
}
// set some runtime constants (not saved on preferences file)
table.put("runtime.os", PConstants.platformNames[PApplet.platform]);
File hardwareFolder = Base.getHardwareFolder();
table.put("runtime.hardware.path", hardwareFolder.getAbsolutePath());
table.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
table.put("runtime.ide.version", "" + Base.REVISION);
// check for platform-specific properties in the defaults
String platformExt = "." + PConstants.platformNames[PApplet.platform];
String platformExt = "." + Base.platform.getName();
int platformExtLength = platformExt.length();
Enumeration e = table.keys();
while (e.hasMoreElements()) {
@ -244,9 +256,6 @@ public class Preferences {
// clone the hash table
defaults = (Hashtable) table.clone();
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
// Load a prefs file if specified on the command line
if (commandLinePrefs != null) {
try {
@ -283,7 +292,16 @@ public class Preferences {
), ex);
}
}
}
}
// load the I18n module for internationalization
I18n.init(Preferences.get("editor.languages.current"));
// set some other runtime constants (not saved on preferences file)
table.put("runtime.os", PConstants.platformNames[PApplet.platform]);
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
}
@ -322,14 +340,21 @@ public class Preferences {
pain.add(sketchbookLocationField);
d = sketchbookLocationField.getPreferredSize();
button = new JButton(PROMPT_BROWSE);
button = new JButton(I18n.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);
Base.selectFolder(_("Select new sketchbook location"), dflt, dialog);
if (file != null) {
sketchbookLocationField.setText(file.getAbsolutePath());
String path = file.getAbsolutePath();
if (Base.getPortableFolder() != null) {
path = FileUtils.relativePath(Base.getPortableFolder().toString(), path);
if (path == null) {
path = Base.getPortableSketchbookFolder();
}
}
sketchbookLocationField.setText(path);
}
}
});
@ -442,6 +467,10 @@ public class Preferences {
autoAssociateBox.setBounds(left, top, d.width + 10, d.height);
right = Math.max(right, left + d.width);
top += d.height + GUI_BETWEEN;
// If using portable mode, it's bad manner to change PC setting.
if (Base.getPortableFolder() != null)
autoAssociateBox.setEnabled(false);
}
// More preferences are in the ...
@ -460,7 +489,7 @@ public class Preferences {
public void mousePressed(MouseEvent e) {
Base.openFolder(Base.getSettingsFolder());
}
public void mouseEntered(MouseEvent e) {
clickable.setForeground(new Color(0, 0, 140));
}
@ -486,7 +515,7 @@ public class Preferences {
// [ OK ] [ Cancel ] maybe these should be next to the message?
button = new JButton(PROMPT_OK);
button = new JButton(I18n.PROMPT_OK);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
applyFrame();
@ -501,7 +530,7 @@ public class Preferences {
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
h += BUTTON_WIDTH + GUI_SMALL;
button = new JButton(PROMPT_CANCEL);
button = new JButton(I18n.PROMPT_CANCEL);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
disposeFrame();
@ -594,6 +623,12 @@ public class Preferences {
// if the sketchbook path has changed, rebuild the menus
String oldPath = get("sketchbook.path");
String newPath = sketchbookLocationField.getText();
if (newPath.isEmpty()) {
if (Base.getPortableFolder() == null)
newPath = editor.base.getDefaultSketchbookFolder().toString();
else
newPath = Base.getPortableSketchbookFolder();
}
if (!newPath.equals(oldPath)) {
editor.base.rebuildSketchbookMenus();
set("sketchbook.path", newPath);
@ -682,8 +717,8 @@ public class Preferences {
load(input, table);
}
static public void load(InputStream input, Map table) throws IOException {
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
static public void load(InputStream input, Map table) throws IOException {
String[] lines = loadStrings(input); // Reads as UTF-8
for (String line : lines) {
if ((line.length() == 0) ||
(line.charAt(0) == '#')) continue;
@ -698,6 +733,41 @@ public class Preferences {
}
}
static public String[] loadStrings(InputStream input) {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(input, "UTF-8"));
String lines[] = new String[100];
int lineCount = 0;
String line = null;
while ((line = reader.readLine()) != null) {
if (lineCount == lines.length) {
String temp[] = new String[lineCount << 1];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
}
lines[lineCount++] = line;
}
reader.close();
if (lineCount == lines.length) {
return lines;
}
// resize array to appropriate amount for these lines
String output[] = new String[lineCount];
System.arraycopy(lines, 0, output, 0, lineCount);
return output;
} catch (IOException e) {
e.printStackTrace();
//throw new RuntimeException("Error inside loadStrings()");
}
return null;
}
// .................................................................
@ -712,9 +782,9 @@ public class Preferences {
// Fix for 0163 to properly use Unicode when writing preferences.txt
PrintWriter writer = PApplet.createWriter(preferencesFile);
Enumeration e = table.keys(); //properties.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String[] keys = (String[])table.keySet().toArray(new String[0]);
Arrays.sort(keys);
for (String key: keys) {
if (key.startsWith("runtime."))
continue;
writer.println(key + "=" + ((String) table.get(key)));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -612,7 +612,7 @@ public class Sketch {
} else {
// delete the file
if (!current.deleteFile()) {
if (!current.deleteFile(tempBuildFolder)) {
Base.showMessage(_("Couldn't do it"),
I18n.format(_("Could not delete \"{0}\"."), current.getFileName()));
return;
@ -826,7 +826,7 @@ public class Sketch {
FileDialog.SAVE);
if (isReadOnly() || isUntitled()) {
// default to the sketchbook folder
fd.setDirectory(Preferences.get("sketchbook.path"));
fd.setDirectory(Base.getSketchbookFolder().getAbsolutePath());
} else {
// default to the parent folder of where this was
fd.setDirectory(folder.getParent());
@ -1124,7 +1124,7 @@ public class Sketch {
* Add import statements to the current tab for all of packages inside
* the specified jar file.
*/
public void importLibrary(String jarPath) {
public void importLibrary(String jarPath) throws IOException {
// make sure the user didn't hide the sketch folder
ensureExistence();
@ -1339,7 +1339,6 @@ public class Sketch {
// make sure the user didn't hide the sketch folder
ensureExistence();
String[] codeFolderPackages = null;
classPath = buildPath;
// // figure out the contents of the code folder to see if there
@ -1381,12 +1380,8 @@ public class Sketch {
// Note that the headerOffset isn't applied until compile and run, because
// it only applies to the code after it's been written to the .java file.
int headerOffset = 0;
//PdePreprocessor preprocessor = new PdePreprocessor();
try {
headerOffset = preprocessor.writePrefix(bigCode.toString(),
buildPath,
name,
codeFolderPackages);
headerOffset = preprocessor.writePrefix(bigCode.toString());
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = _("Build folder disappeared or could not be written");
@ -1399,24 +1394,14 @@ public class Sketch {
String primaryClassName = null;
try {
// if (i != 0) preproc will fail if a pde file is not
// java mode, since that's required
String className = preprocessor.write();
if (className == null) {
throw new RunnerException(_("Could not find main class"));
// this situation might be perfectly fine,
// (i.e. if the file is empty)
//System.out.println("No class found in " + code[i].name);
//System.out.println("(any code in that file will be ignored)");
//System.out.println();
// } else {
// code[0].setPreprocName(className + ".java");
}
// Output file
File streamFile = new File(buildPath, name + ".cpp");
FileOutputStream outputStream = new FileOutputStream(streamFile);
preprocessor.write(outputStream);
outputStream.close();
// store this for the compiler and the runtime
primaryClassName = className + ".cpp";
primaryClassName = name + ".cpp";
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
@ -1630,7 +1615,7 @@ public class Sketch {
editor.status.progressUpdate(percent);
}
protected void size(PreferencesMap prefs) throws RunnerException {
long size = 0;
String maxsizeString = prefs.get("upload.maximum_size");
@ -1641,8 +1626,8 @@ public class Sketch {
try {
size = sizer.computeSize();
System.out.println(I18n
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum)"),
size, maxsize));
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}% used"),
size, maxsize, size * 100 / maxsize));
} catch (RunnerException e) {
System.err.println(I18n.format(_("Couldn't determine program size: {0}"),
e.getMessage()));
@ -1668,58 +1653,7 @@ public class Sketch {
return success ? suggestedClassName : null;
}
/**
* Replace all commented portions of a given String as spaces.
* Utility function used here and in the preprocessor.
*/
static public String scrubComments(String what) {
char p[] = what.toCharArray();
int index = 0;
while (index < p.length) {
// for any double slash comments, ignore until the end of the line
if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
while ((index < p.length) &&
(p[index] != '\n')) {
p[index++] = ' ';
}
// check to see if this is the start of a new multiline comment.
// if it is, then make sure it's actually terminated somewhere.
} else if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '*')) {
p[index++] = ' ';
p[index++] = ' ';
boolean endOfRainbow = false;
while (index < p.length - 1) {
if ((p[index] == '*') && (p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
endOfRainbow = true;
break;
} else {
// continue blanking this area
p[index++] = ' ';
}
}
if (!endOfRainbow) {
throw new RuntimeException(_("Missing the */ from the end of a " +
"/* comment */"));
}
} else { // any old character, move along
index++;
}
}
return new String(p);
}
public boolean exportApplicationPrompt() throws IOException, RunnerException {
return false;
}

View File

@ -107,8 +107,21 @@ public class SketchCode {
}
protected boolean deleteFile() {
return file.delete();
protected boolean deleteFile(File tempBuildFolder) {
if (!file.delete()) {
return false;
}
File[] compiledFiles = tempBuildFolder.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().startsWith(getFileName());
}
});
for (File compiledFile : compiledFiles) {
compiledFile.delete();
}
return true;
}

View File

@ -41,7 +41,6 @@ public class TargetPlatform {
private MapWithSubkeys customMenus;
public TargetPlatform(String _name, File _folder) {
System.out.println("TargetPlatform: constructor start, name: " + _name);
name = _name;
folder = _folder;
boards = new HashMap<String, PreferencesMap>();

View File

@ -90,4 +90,68 @@ public class FileUtils {
return tmpFolder;
}
//
// Compute relative path to "target" from a directory "origin".
//
// If "origin" is not absolute, it is relative from the current directory.
// If "target" is not absolute, it is relative from "origin".
//
// by Shigeru KANEMOTO at SWITCHSCIENCE.
//
public static String relativePath(String origin, String target) {
try {
origin = (new File(origin)).getCanonicalPath();
File targetFile = new File(target);
if (targetFile.isAbsolute())
target = targetFile.getCanonicalPath();
else
target = (new File(origin, target)).getCanonicalPath();
} catch (IOException e) {
return null;
}
if (origin.equals(target)) {
// origin and target is identical.
return ".";
}
if (origin.equals(File.separator)) {
// origin is root.
return "." + target;
}
String prefix = "";
String root = File.separator;
if (System.getProperty("os.name").indexOf("Windows") != -1) {
if (origin.startsWith("\\\\") || target.startsWith("\\\\")) {
// Windows UNC path not supported.
return null;
}
char originLetter = origin.charAt(0);
char targetLetter = target.charAt(0);
if (Character.isLetter(originLetter) && Character.isLetter(targetLetter)) {
// Windows only
if (originLetter != targetLetter) {
// Drive letters differ
return null;
}
}
prefix = "" + originLetter + ':';
root = prefix + File.separator;
}
String relative = "";
while (!target.startsWith(origin + File.separator)) {
origin = (new File(origin)).getParent();
if (origin.equals(root))
origin = prefix;
relative += "..";
relative += File.separator;
}
return relative + target.substring(origin.length() + 1);
}
}

View File

@ -27,6 +27,7 @@ import java.io.File;
import javax.swing.UIManager;
import processing.app.Preferences;
import processing.core.PConstants;
/**
@ -52,6 +53,12 @@ public class Platform extends processing.app.Platform {
}
public File getDefaultSketchbookFolder() throws Exception {
File home = new File(System.getProperty("user.home"));
return new File(home, "Arduino");
}
public void openURL(String url) throws Exception {
if (openFolderAvailable()) {
String launcher = Preferences.get("launcher");
@ -112,4 +119,9 @@ public class Platform extends processing.app.Platform {
file.getAbsolutePath());
}
}
@Override
public String getName() {
return PConstants.platformNames[PConstants.LINUX];
}
}

View File

@ -34,6 +34,7 @@ import com.apple.eio.FileManager;
import processing.app.Base;
import processing.core.PApplet;
import processing.core.PConstants;
/**
@ -195,4 +196,10 @@ public class Platform extends processing.app.Platform {
protected String getDocumentsFolder() throws FileNotFoundException {
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
}
@Override
public String getName() {
return PConstants.platformNames[PConstants.MACOSX];
}
}

View File

@ -29,6 +29,7 @@
package processing.app.preproc;
import static processing.app.I18n._;
import processing.app.*;
import processing.core.*;
@ -61,38 +62,22 @@ public class PdePreprocessor {
// than the others, since the imports are auto-generated.
List<String> codeFolderImports;
String indent;
PrintStream stream;
String program;
String buildPath;
// starts as sketch name, ends as main class name
String name;
/**
* Setup a new preprocessor.
*/
public PdePreprocessor() {
int tabSize = Preferences.getInteger("editor.tabs.size");
char[] indentChars = new char[tabSize];
Arrays.fill(indentChars, ' ');
indent = new String(indentChars);
}
/**
* Writes out the head of the c++ code generated for a sketch.
* Called from processing.app.Sketch.
* @param program the concatenated code from all tabs containing pde-files
* @param buildPath the path into which the processed pde-code is to be written
* @param name the name of the sketch
* @param codeFolderPackages unused param (leftover from processing)
*/
public int writePrefix(String program, String buildPath,
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
this.buildPath = buildPath;
this.name = sketchName;
public int writePrefix(String program)
throws FileNotFoundException {
// if the program ends with no CR or LF an OutOfMemoryError will happen.
// not gonna track down the bug now, so here's a hack for it:
// http://dev.processing.org/bugs/show_bug.cgi?id=5
@ -102,7 +87,7 @@ public class PdePreprocessor {
// an OutOfMemoryError or NullPointerException will happen.
// again, not gonna bother tracking this down, but here's a hack.
// http://dev.processing.org/bugs/show_bug.cgi?id=16
Sketch.scrubComments(program);
scrubComments(program);
// If there are errors, an exception is thrown and this fxn exits.
if (Preferences.getBoolean("preproc.substitute_unicode")) {
@ -134,10 +119,6 @@ public class PdePreprocessor {
// do this after the program gets re-combobulated
this.program = program;
// output the code
File streamFile = new File(buildPath, name + ".cpp");
stream = new PrintStream(new FileOutputStream(streamFile));
return headerCount + prototypeCount;
}
@ -181,17 +162,16 @@ public class PdePreprocessor {
}
/**
* preprocesses a pde file and writes out a java file
* @return the classname of the exported Java
* preprocesses a pde file and writes out a cpp file into the specified
* OutputStream
*
* @param output
* @throws Exception
*/
//public String write(String program, String buildPath, String name,
// String extraImports[]) throws java.lang.Exception {
public String write() throws java.lang.Exception {
public void write(OutputStream output) throws Exception {
PrintStream stream = new PrintStream(output);
writeProgram(stream, program, prototypes);
writeFooter(stream);
stream.close();
return name;
}
// Write the pde program to the cpp file
@ -344,4 +324,56 @@ public class PdePreprocessor {
return functionMatches;
}
/**
* Replace all commented portions of a given String as spaces.
* Utility function used here and in the preprocessor.
*/
static public String scrubComments(String what) {
char p[] = what.toCharArray();
int index = 0;
while (index < p.length) {
// for any double slash comments, ignore until the end of the line
if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
while ((index < p.length) &&
(p[index] != '\n')) {
p[index++] = ' ';
}
// check to see if this is the start of a new multiline comment.
// if it is, then make sure it's actually terminated somewhere.
} else if ((p[index] == '/') &&
(index < p.length - 1) &&
(p[index+1] == '*')) {
p[index++] = ' ';
p[index++] = ' ';
boolean endOfRainbow = false;
while (index < p.length - 1) {
if ((p[index] == '*') && (p[index+1] == '/')) {
p[index++] = ' ';
p[index++] = ' ';
endOfRainbow = true;
break;
} else {
// continue blanking this area
p[index++] = ' ';
}
}
if (!endOfRainbow) {
throw new RuntimeException(_("Missing the */ from the end of a " +
"/* comment */"));
}
} else { // any old character, move along
index++;
}
}
return new String(p);
}
}

View File

@ -0,0 +1,633 @@
/**
* @(#)MenuScroller.java 1.5.0 04/02/12
*/
package processing.app.tools;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.MenuSelectionManager;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.*;
/**
* A class that provides scrolling capabilities to a long menu dropdown or
* popup menu. A number of items can optionally be frozen at the top and/or
* bottom of the menu.
* <P>
* <B>Implementation note:</B> The default number of items to display
* at a time is 15, and the default scrolling interval is 125 milliseconds.
* <P>
*
* @version 1.5.0 04/05/12
* @author Darryl
*/
public class MenuScroller {
//private JMenu menu;
private JPopupMenu menu;
private Component[] menuItems;
private MenuScrollItem upItem;
private MenuScrollItem downItem;
private final MenuScrollListener menuListener = new MenuScrollListener();
private int scrollCount;
private int interval;
private int topFixedCount;
private int bottomFixedCount;
private int firstIndex = 0;
private int keepVisibleIndex = -1;
private static int getMaximumItems(JPopupMenu menu) {
JMenuItem test = new JMenuItem("test");
ButtonUI ui = test.getUI();
Dimension d = ui.getPreferredSize(test);
double item_height = d.getHeight();
//System.out.println("JMenuItem Height " + item_height);
JMenuItem up = new JMenuItem(MenuIcon.UP);
ui = up.getUI();
d = ui.getPreferredSize(up);
double icon_height = d.getHeight();
//System.out.println("icon item height " + icon_height);
double menu_border_height = 8.0; // kludge - how to detect this?
double screen_height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight();
//System.out.println("screen height " + screen_height);
int n = (int)((screen_height - icon_height * 2 - menu_border_height) / item_height);
//System.out.println("max items " + n);
return n;
}
/**
* Registers a menu to be scrolled with the default number of items to
* display at a time and the default scrolling interval.
*
* @param menu the menu
* @return the MenuScroller
*/
public static MenuScroller setScrollerFor(JMenu menu) {
return new MenuScroller(menu);
}
/**
* Registers a popup menu to be scrolled with the default number of items to
* display at a time and the default scrolling interval.
*
* @param menu the popup menu
* @return the MenuScroller
*/
public static MenuScroller setScrollerFor(JPopupMenu menu) {
return new MenuScroller(menu);
}
/**
* Registers a menu to be scrolled with the default number of items to
* display at a time and the specified scrolling interval.
*
* @param menu the menu
* @param scrollCount the number of items to display at a time
* @return the MenuScroller
* @throws IllegalArgumentException if scrollCount is 0 or negative
*/
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount) {
return new MenuScroller(menu, scrollCount);
}
/**
* Registers a popup menu to be scrolled with the default number of items to
* display at a time and the specified scrolling interval.
*
* @param menu the popup menu
* @param scrollCount the number of items to display at a time
* @return the MenuScroller
* @throws IllegalArgumentException if scrollCount is 0 or negative
*/
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount) {
return new MenuScroller(menu, scrollCount);
}
/**
* Registers a menu to be scrolled, with the specified number of items to
* display at a time and the specified scrolling interval.
*
* @param menu the menu
* @param scrollCount the number of items to be displayed at a time
* @param interval the scroll interval, in milliseconds
* @return the MenuScroller
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
*/
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval) {
return new MenuScroller(menu, scrollCount, interval);
}
/**
* Registers a popup menu to be scrolled, with the specified number of items to
* display at a time and the specified scrolling interval.
*
* @param menu the popup menu
* @param scrollCount the number of items to be displayed at a time
* @param interval the scroll interval, in milliseconds
* @return the MenuScroller
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
*/
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval) {
return new MenuScroller(menu, scrollCount, interval);
}
/**
* Registers a menu to be scrolled, with the specified number of items
* to display in the scrolling region, the specified scrolling interval,
* and the specified numbers of items fixed at the top and bottom of the
* menu.
*
* @param menu the menu
* @param scrollCount the number of items to display in the scrolling portion
* @param interval the scroll interval, in milliseconds
* @param topFixedCount the number of items to fix at the top. May be 0.
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
* @throws IllegalArgumentException if scrollCount or interval is 0 or
* negative or if topFixedCount or bottomFixedCount is negative
* @return the MenuScroller
*/
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval,
int topFixedCount, int bottomFixedCount) {
return new MenuScroller(menu, scrollCount, interval,
topFixedCount, bottomFixedCount);
}
/**
* Registers a popup menu to be scrolled, with the specified number of items
* to display in the scrolling region, the specified scrolling interval,
* and the specified numbers of items fixed at the top and bottom of the
* popup menu.
*
* @param menu the popup menu
* @param scrollCount the number of items to display in the scrolling portion
* @param interval the scroll interval, in milliseconds
* @param topFixedCount the number of items to fix at the top. May be 0
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
* @throws IllegalArgumentException if scrollCount or interval is 0 or
* negative or if topFixedCount or bottomFixedCount is negative
* @return the MenuScroller
*/
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval,
int topFixedCount, int bottomFixedCount) {
return new MenuScroller(menu, scrollCount, interval,
topFixedCount, bottomFixedCount);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
* default number of items to display at a time, and default scrolling
* interval.
*
* @param menu the menu
*/
public MenuScroller(JMenu menu) {
this(menu, -1);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
* default number of items to display at a time, and default scrolling
* interval.
*
* @param menu the popup menu
*/
public MenuScroller(JPopupMenu menu) {
this(menu, -1);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
* specified number of items to display at a time, and default scrolling
* interval.
*
* @param menu the menu
* @param scrollCount the number of items to display at a time
* @throws IllegalArgumentException if scrollCount is 0 or negative
*/
public MenuScroller(JMenu menu, int scrollCount) {
this(menu, scrollCount, 150);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
* specified number of items to display at a time, and default scrolling
* interval.
*
* @param menu the popup menu
* @param scrollCount the number of items to display at a time
* @throws IllegalArgumentException if scrollCount is 0 or negative
*/
public MenuScroller(JPopupMenu menu, int scrollCount) {
this(menu, scrollCount, 150);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
* specified number of items to display at a time, and specified scrolling
* interval.
*
* @param menu the menu
* @param scrollCount the number of items to display at a time
* @param interval the scroll interval, in milliseconds
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
*/
public MenuScroller(JMenu menu, int scrollCount, int interval) {
this(menu, scrollCount, interval, 0, 0);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
* specified number of items to display at a time, and specified scrolling
* interval.
*
* @param menu the popup menu
* @param scrollCount the number of items to display at a time
* @param interval the scroll interval, in milliseconds
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
*/
public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {
this(menu, scrollCount, interval, 0, 0);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
* specified number of items to display in the scrolling region, the
* specified scrolling interval, and the specified numbers of items fixed at
* the top and bottom of the menu.
*
* @param menu the menu
* @param scrollCount the number of items to display in the scrolling portion
* @param interval the scroll interval, in milliseconds
* @param topFixedCount the number of items to fix at the top. May be 0
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
* @throws IllegalArgumentException if scrollCount or interval is 0 or
* negative or if topFixedCount or bottomFixedCount is negative
*/
public MenuScroller(JMenu menu, int scrollCount, int interval,
int topFixedCount, int bottomFixedCount) {
this(menu.getPopupMenu(), scrollCount, interval, topFixedCount, bottomFixedCount);
}
/**
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
* specified number of items to display in the scrolling region, the
* specified scrolling interval, and the specified numbers of items fixed at
* the top and bottom of the popup menu.
*
* @param menu the popup menu
* @param scrollCount the number of items to display in the scrolling portion
* @param interval the scroll interval, in milliseconds
* @param topFixedCount the number of items to fix at the top. May be 0
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
* @throws IllegalArgumentException if scrollCount or interval is 0 or
* negative or if topFixedCount or bottomFixedCount is negative
*/
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
int topFixedCount, int bottomFixedCount) {
if(scrollCount == -1)
scrollCount = getMaximumItems(menu)-topFixedCount-bottomFixedCount; // Autosize
if(interval == -1)
interval = 150; // Default value
if (scrollCount <= 0 || interval <= 0) {
throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
}
if (topFixedCount < 0 || bottomFixedCount < 0) {
throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
}
upItem = new MenuScrollItem(MenuIcon.UP, -1);
downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
setScrollCount(scrollCount);
setInterval(interval);
setTopFixedCount(topFixedCount);
setBottomFixedCount(bottomFixedCount);
this.menu = menu;
menu.addPopupMenuListener(menuListener);
}
/**
* Returns the scroll interval in milliseconds
*
* @return the scroll interval in milliseconds
*/
public int getInterval() {
return interval;
}
/**
* Sets the scroll interval in milliseconds
*
* @param interval the scroll interval in milliseconds
* @throws IllegalArgumentException if interval is 0 or negative
*/
public void setInterval(int interval) {
if (interval <= 0) {
throw new IllegalArgumentException("interval must be greater than 0");
}
upItem.setInterval(interval);
downItem.setInterval(interval);
this.interval = interval;
}
/**
* Returns the number of items in the scrolling portion of the menu.
*
* @return the number of items to display at a time
*/
public int getscrollCount() {
return scrollCount;
}
/**
* Sets the number of items in the scrolling portion of the menu.
*
* @param scrollCount the number of items to display at a time
* @throws IllegalArgumentException if scrollCount is 0 or negative
*/
public void setScrollCount(int scrollCount) {
if (scrollCount <= 0) {
throw new IllegalArgumentException("scrollCount must be greater than 0");
}
this.scrollCount = scrollCount;
MenuSelectionManager.defaultManager().clearSelectedPath();
}
/**
* Returns the number of items fixed at the top of the menu or popup menu.
*
* @return the number of items
*/
public int getTopFixedCount() {
return topFixedCount;
}
/**
* Sets the number of items to fix at the top of the menu or popup menu.
*
* @param topFixedCount the number of items
*/
public void setTopFixedCount(int topFixedCount) {
if (firstIndex <= topFixedCount) {
firstIndex = topFixedCount;
} else {
firstIndex += (topFixedCount - this.topFixedCount);
}
this.topFixedCount = topFixedCount;
}
/**
* Returns the number of items fixed at the bottom of the menu or popup menu.
*
* @return the number of items
*/
public int getBottomFixedCount() {
return bottomFixedCount;
}
/**
* Sets the number of items to fix at the bottom of the menu or popup menu.
*
* @param bottomFixedCount the number of items
*/
public void setBottomFixedCount(int bottomFixedCount) {
this.bottomFixedCount = bottomFixedCount;
}
/**
* Scrolls the specified item into view each time the menu is opened. Call this method with
* <code>null</code> to restore the default behavior, which is to show the menu as it last
* appeared.
*
* @param item the item to keep visible
* @see #keepVisible(int)
*/
public void keepVisible(JMenuItem item) {
if (item == null) {
keepVisibleIndex = -1;
} else {
int index = menu.getComponentIndex(item);
keepVisibleIndex = index;
}
}
/**
* Scrolls the item at the specified index into view each time the menu is opened. Call this
* method with <code>-1</code> to restore the default behavior, which is to show the menu as
* it last appeared.
*
* @param index the index of the item to keep visible
* @see #keepVisible(javax.swing.JMenuItem)
*/
public void keepVisible(int index) {
keepVisibleIndex = index;
}
/**
* Removes this MenuScroller from the associated menu and restores the
* default behavior of the menu.
*/
public void dispose() {
if (menu != null) {
menu.removePopupMenuListener(menuListener);
menu = null;
}
}
/**
* Ensures that the <code>dispose</code> method of this MenuScroller is
* called when there are no more refrences to it.
*
* @exception Throwable if an error occurs.
* @see MenuScroller#dispose()
*/
@Override
public void finalize() throws Throwable {
dispose();
}
private void refreshMenu() {
if (menuItems != null && menuItems.length > 0) {
firstIndex = Math.max(topFixedCount, firstIndex);
firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
upItem.setEnabled(firstIndex > topFixedCount);
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
menu.removeAll();
for (int i = 0; i < topFixedCount; i++) {
menu.add(menuItems[i]);
}
/*if (topFixedCount > 0) {
menu.addSeparator();
}*/
menu.add(upItem);
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
menu.add(menuItems[i]);
}
menu.add(downItem);
/*if (bottomFixedCount > 0) {
menu.addSeparator();
}*/
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
menu.add(menuItems[i]);
}
JComponent parent = (JComponent) upItem.getParent();
parent.revalidate();
parent.repaint();
}
}
private class MenuScrollListener implements PopupMenuListener {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
setMenuItems();
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
restoreMenuItems();
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
restoreMenuItems();
}
private void setMenuItems() {
menuItems = menu.getComponents();
// Hack for auto detect the topFixed total
/*int topFixedCountPrev = topFixedCount;
for(int i=menuItems.length-1;i>0;i--)
{
if(menuItems[i].getClass().getName().endsWith("Separator"))
{
System.out.println(i);
setTopFixedCount(i+1);
if(topFixedCount!=topFixedCountPrev)
{
scrollCount = getMaximumItems()-topFixedCount;
System.out.println(getMaximumItems()-topFixedCount);
}
break;
}
}*/
if (keepVisibleIndex >= topFixedCount
&& keepVisibleIndex <= menuItems.length - bottomFixedCount
&& (keepVisibleIndex > firstIndex + scrollCount
|| keepVisibleIndex < firstIndex)) {
firstIndex = Math.min(firstIndex, keepVisibleIndex);
firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
}
if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) {
refreshMenu();
}
}
private void restoreMenuItems() {
menu.removeAll();
for (Component component : menuItems) {
menu.add(component);
}
}
}
private class MenuScrollTimer extends Timer {
public MenuScrollTimer(final int increment, int interval) {
super(interval, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firstIndex += increment;
refreshMenu();
}
});
}
}
private class MenuScrollItem extends JMenuItem
implements ChangeListener {
private MenuScrollTimer timer;
public MenuScrollItem(MenuIcon icon, int increment) {
setIcon(icon);
setDisabledIcon(icon);
timer = new MenuScrollTimer(increment, interval);
addChangeListener(this);
}
public void setInterval(int interval) {
timer.setDelay(interval);
}
@Override
public void stateChanged(ChangeEvent e) {
if (isArmed() && !timer.isRunning()) {
timer.start();
}
if (!isArmed() && timer.isRunning()) {
timer.stop();
}
}
}
private static enum MenuIcon implements Icon {
UP(9, 1, 9),
DOWN(1, 9, 1);
final int[] xPoints = {1, 5, 9};
final int[] yPoints;
MenuIcon(int... yPoints) {
this.yPoints = yPoints;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Dimension size = c.getSize();
Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
g2.setColor(Color.GRAY);
g2.drawPolygon(xPoints, yPoints, 3);
if (c.isEnabled()) {
g2.setColor(Color.BLACK);
g2.fillPolygon(xPoints, yPoints, 3);
}
g2.dispose();
}
@Override
public int getIconWidth() {
return 0;
}
@Override
public int getIconHeight() {
return 10;
}
}
}

View File

@ -32,6 +32,7 @@ import processing.app.Base;
import processing.app.Preferences;
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
import processing.core.PApplet;
import processing.core.PConstants;
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
@ -302,4 +303,10 @@ public class Platform extends processing.app.Platform {
//return 0;
return clib._putenv(variable + "=");
}
@Override
public String getName() {
return PConstants.platformNames[PConstants.WINDOWS];
}
}

View File

@ -0,0 +1,81 @@
package processing.app;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class I18NTest {
private Set<String> loadReferenceI18NKeys() throws IOException {
Properties properties = new Properties();
properties.putAll(loadProperties(new File(I18NTest.class.getResource("./Resources_en.properties").getFile())));
Set<String> keys = new HashSet<String>();
for (Object key : properties.keySet()) {
keys.add(key.toString());
}
return keys;
}
private File[] listPropertiesFiles() {
return new File(I18NTest.class.getResource(".").getFile()).listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile() && file.getName().endsWith(".properties");
}
});
}
private Properties loadProperties(File file) throws IOException {
Properties properties = new Properties();
InputStream is = null;
try {
is = new FileInputStream(file);
properties.load(is);
} finally {
if (is != null) {
is.close();
}
}
return properties;
}
@Test
public void ensureEveryTranslationIsComplete() throws Exception {
Set<String> keys = loadReferenceI18NKeys();
Map<String, List<String>> missingTranslationsPerFile = new HashMap<String, List<String>>();
for (File file : listPropertiesFiles()) {
Properties properties = loadProperties(file);
for (String key : keys) {
if (!properties.containsKey(key) || properties.get(key).equals("")) {
addMissingTranslation(missingTranslationsPerFile, file, key);
}
}
}
if (!missingTranslationsPerFile.isEmpty()) {
List<String> filesWithIncompleteTranslations = new LinkedList<String>(missingTranslationsPerFile.keySet());
Collections.sort(filesWithIncompleteTranslations);
System.out.println("Following files have missing translations:" + filesWithIncompleteTranslations);
for (String file : filesWithIncompleteTranslations) {
System.out.println("Following translations in file " + file + " are missing:");
for (String key : missingTranslationsPerFile.get(file)) {
System.out.println("==> '" + key.replaceAll("\n", "\\\\n").replaceAll(" ", "\\\\ ") + "'");
}
System.out.println();
}
}
}
private void addMissingTranslation(Map<String, List<String>> missingTranslationsPerFile, File file, String key) {
if (!missingTranslationsPerFile.containsKey(file.getName())) {
missingTranslationsPerFile.put(file.getName(), new LinkedList<String>());
}
missingTranslationsPerFile.get(file.getName()).add(key);
}
}

View File

@ -110,41 +110,35 @@
<!-- - - - - - - - - -->
<target name="revision-check">
<!-- figure out the revision number -->
<loadfile srcfile="../todo.txt" property="revision">
<loadfile srcfile="shared/revisions.txt" property="revision">
<filterchain>
<headfilter lines="1"/>
<tokenfilter>
<stringtokenizer suppressdelims="true"/>
<!-- grab the thing from the first line that's 4 digits -->
<containsregex pattern="(\d\d\d\d)" />
</tokenfilter>
<ignoreblank />
<headfilter lines="1"/>
<tokenfilter>
<linetokenizer includeDelims="false" />
<!-- grab the thing from the first line that's 4 digits -->
<containsregex pattern="ARDUINO (.*) " />
<replaceregex pattern="ARDUINO ([^ ]*).*" replace="\1" />
</tokenfilter>
<tokenfilter>
<stringtokenizer suppressdelims="true" />
</tokenfilter>
</filterchain>
</loadfile>
<!-- <echo message="revision is ${revision}." /> -->
<echo message="Latest revision detected in shared/revision.txt is: ${revision}" />
<!-- figure out the revision number in base.java -->
<loadfile srcfile="../app/src/processing/app/Base.java"
property="revision.base">
<filterchain>
<tokenfilter>
<linetokenizer />
<containsregex pattern="String VERSION_NAME = "/>
<replaceregex pattern="[^0-9]*" flags="g" replace=""/>
</tokenfilter>
<tokenfilter>
<linetokenizer />
<containsregex pattern="String VERSION_NAME = "/>
<replaceregex pattern="[^0-9]*" flags="g" replace=""/>
</tokenfilter>
</filterchain>
</loadfile>
<!-- <echo message="base revision is ${revision.base}." /> -->
<condition property="revision.correct">
<!-- Using contains because I can't figure out how to get rid of the
LF in revision.base. Please file a bug if you have a fix. -->
<contains string="${revision.base}" substring="${revision}"/>
</condition>
<!-- the revision.base property won't be set
if $revision wasn't found... -->
<fail unless="revision.correct"
message="Fix revision number in Base.java" />
<echo message="Revision in Base.java is: ${revision.base}" />
</target>
<!-- - - - - - - - -->

View File

@ -21,8 +21,6 @@
*/
// set pin numbers for the five buttons:
// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
@ -66,7 +64,7 @@ void loop() {
Mouse.move(40, 0);
break;
case 'm':
// move mouse right
// perform mouse left click
Mouse.click(MOUSE_LEFT);
break;
}

View File

@ -1,23 +1,43 @@
ARDUINO 1.5.2 BETA - 2012.01.23
[ide]
* Scrollable editor tabs (Shigheru KANEMOTO)
* Scrollable menus
* Portable Arduino (Shigeru KANEMOTO)
* Default sketchbook folder for linux is now "Arduino"
* Fixed IDE startup bug "Menu has no enabled items"
* Command line build.
* Fixed some language strings (Shigeru KANEMOTO)
* Fix to boards.txt: added Micro and fixed Lilypad bootloader path
* Removed check for ".h" existence in libraries.
* Deleting tab from IDE does not delete from temporary folder
* Fixed NPE when unknown boards/platforms are selected in preferences
* Extended command line build flags
[arduino core]
* sam: portOutputRegister() is now writeable.
* sam: fixed issue on weak-symbol for some interrupt handlers
* sam: fixed BSoD on some Windows machine (louismdavis)
* sam: added CANRX1/CANTX1 pins 88/89 (same physical pin for 66/53)
* sam: fixed analogWrite when used in very thight write loops (V.Dorrich)
* sam: fixed USBSerial.write() while sending big buffers (Bill Dreschel)
* sam: USBSerial receive buffer size is now 512 (PeterVH)
[libraries]
* sam: Added Servo library
* sam: Added WiFi library
* Fixed USBHost MouseController example
ARDUINO BETA 1.5.1r2 - 2012.11.06
[other]
* Merged all improvements made in Arduino IDE 1.0.3
* Merged all improvements made in Arduino IDE 1.0.4 (not yet released)
ARDUINO 1.5.1r2 BETA - 2012.11.06
* Fixed wrong release file for windows.
ARDUINO BETA 1.5.1 - 2012.11.05
ARDUINO 1.5.1 BETA - 2012.11.05
* Merged changes coming from stable release of Arduino IDE 1.0.2.
@ -42,7 +62,7 @@ ARDUINO BETA 1.5.1 - 2012.11.05
[firmwares]
* Added firmware for atmega16u2 on Due Board.
ARDUINO BETA 1.5 - 2012.10.22
ARDUINO 1.5 BETA - 2012.10.22
* First release for the unified IDE for both AVR 8-bit and ARM 32-bit
(SAM3 CPUs) architectures.
@ -53,6 +73,24 @@ ARDUINO BETA 1.5 - 2012.10.22
* For more info refer to this press release:
http://arduino.cc/blog/2012/10/22/arduino-1-5-support-for-the-due-and-other-processors-easier-library-installation-simplified-board-menu-etc/
ARDUINO 1.0.4 - Not yet released.
[core]
* Fixed malloc bug (Paul Stoffregen)
[libraries]
* Fixed memory leak when calling Ethernet.begin() multiple times.
* Fixed SD example listfiles.ino
* Fixed a lot of Esplora examples
[environment]
* Sort entries in preferences.txt (Shigeru Kanemoto)
* Fixed some wrong translations
* Fixed NPE due to permissions IO error
ARDUINO 1.0.3 - 2012.12.10
[hardware]

View File

@ -0,0 +1,380 @@
/* Copyright (c) 2002, 2004, 2010 Joerg Wunsch
Copyright (c) 2010 Gerben van den Broeke
All rights reserved.
malloc, free, realloc from avr-libc 1.7.0
with minor modifications, by Paul Stoffregen
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <avr/io.h>
#define __MALLOC_MARGIN__ 120
struct __freelist {
size_t sz;
struct __freelist *nx;
};
/*
* Exported interface:
*
* When extending the data segment, the allocator will not try to go
* beyond the current stack limit, decreased by __malloc_margin bytes.
* Thus, all possible stack frames of interrupt routines that could
* interrupt the current function, plus all further nested function
* calls must not require more stack space, or they'll risk to collide
* with the data segment.
*/
#define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
extern char __heap_start;
char *__brkval = &__heap_start; // first location not yet allocated
struct __freelist *__flp; // freelist pointer (head of freelist)
char *__brkval_maximum = 100;
void *
malloc(size_t len)
{
struct __freelist *fp1, *fp2, *sfp1, *sfp2;
char *cp;
size_t s, avail;
/*
* Our minimum chunk size is the size of a pointer (plus the
* size of the "sz" field, but we don't need to account for
* this), otherwise we could not possibly fit a freelist entry
* into the chunk later.
*/
if (len < sizeof(struct __freelist) - sizeof(size_t))
len = sizeof(struct __freelist) - sizeof(size_t);
/*
* First, walk the free list and try finding a chunk that
* would match exactly. If we found one, we are done. While
* walking, note down the smallest chunk we found that would
* still fit the request -- we need it for step 2.
*
*/
for (s = 0, fp1 = __flp, fp2 = 0;
fp1;
fp2 = fp1, fp1 = fp1->nx) {
if (fp1->sz < len)
continue;
if (fp1->sz == len) {
/*
* Found it. Disconnect the chunk from the
* freelist, and return it.
*/
if (fp2)
fp2->nx = fp1->nx;
else
__flp = fp1->nx;
return &(fp1->nx);
}
else {
if (s == 0 || fp1->sz < s) {
/* this is the smallest chunk found so far */
s = fp1->sz;
sfp1 = fp1;
sfp2 = fp2;
}
}
}
/*
* Step 2: If we found a chunk on the freelist that would fit
* (but was too large), look it up again and use it, since it
* is our closest match now. Since the freelist entry needs
* to be split into two entries then, watch out that the
* difference between the requested size and the size of the
* chunk found is large enough for another freelist entry; if
* not, just enlarge the request size to what we have found,
* and use the entire chunk.
*/
if (s) {
if (s - len < sizeof(struct __freelist)) {
/* Disconnect it from freelist and return it. */
if (sfp2)
sfp2->nx = sfp1->nx;
else
__flp = sfp1->nx;
return &(sfp1->nx);
}
/*
* Split them up. Note that we leave the first part
* as the new (smaller) freelist entry, and return the
* upper portion to the caller. This saves us the
* work to fix up the freelist chain; we just need to
* fixup the size of the current entry, and note down
* the size of the new chunk before returning it to
* the caller.
*/
cp = (char *)sfp1;
s -= len;
cp += s;
sfp2 = (struct __freelist *)cp;
sfp2->sz = len;
sfp1->sz = s - sizeof(size_t);
return &(sfp2->nx);
}
/*
* Step 3: If the request could not be satisfied from a
* freelist entry, just prepare a new chunk. This means we
* need to obtain more memory first. The largest address just
* not allocated so far is remembered in the brkval variable.
* Under Unix, the "break value" was the end of the data
* segment as dynamically requested from the operating system.
* Since we don't have an operating system, just make sure
* that we don't collide with the stack.
*/
cp = STACK_POINTER() - __MALLOC_MARGIN__;
if (cp <= __brkval)
/*
* Memory exhausted.
*/
return 0;
avail = cp - __brkval;
/*
* Both tests below are needed to catch the case len >= 0xfffe.
*/
if (avail >= len && avail >= len + sizeof(size_t)) {
fp1 = (struct __freelist *)__brkval;
__brkval += len + sizeof(size_t);
__brkval_maximum = __brkval;
fp1->sz = len;
return &(fp1->nx);
}
/*
* Step 4: There's no help, just fail. :-/
*/
return 0;
}
void
free(void *p)
{
struct __freelist *fp1, *fp2, *fpnew;
char *cp1, *cp2, *cpnew;
/* ISO C says free(NULL) must be a no-op */
if (p == 0)
return;
cpnew = p;
cpnew -= sizeof(size_t);
fpnew = (struct __freelist *)cpnew;
fpnew->nx = 0;
/*
* Trivial case first: if there's no freelist yet, our entry
* will be the only one on it. If this is the last entry, we
* can reduce __brkval instead.
*/
if (__flp == 0) {
if ((char *)p + fpnew->sz == __brkval)
__brkval = cpnew;
else
__flp = fpnew;
return;
}
/*
* Now, find the position where our new entry belongs onto the
* freelist. Try to aggregate the chunk with adjacent chunks
* if possible.
*/
for (fp1 = __flp, fp2 = 0;
fp1;
fp2 = fp1, fp1 = fp1->nx) {
if (fp1 < fpnew)
continue;
cp1 = (char *)fp1;
fpnew->nx = fp1;
if ((char *)&(fpnew->nx) + fpnew->sz == cp1) {
/* upper chunk adjacent, assimilate it */
fpnew->sz += fp1->sz + sizeof(size_t);
fpnew->nx = fp1->nx;
}
if (fp2 == 0) {
/* new head of freelist */
__flp = fpnew;
return;
}
break;
}
/*
* Note that we get here either if we hit the "break" above,
* or if we fell off the end of the loop. The latter means
* we've got a new topmost chunk. Either way, try aggregating
* with the lower chunk if possible.
*/
fp2->nx = fpnew;
cp2 = (char *)&(fp2->nx);
if (cp2 + fp2->sz == cpnew) {
/* lower junk adjacent, merge */
fp2->sz += fpnew->sz + sizeof(size_t);
fp2->nx = fpnew->nx;
}
/*
* If there's a new topmost chunk, lower __brkval instead.
*/
for (fp1 = __flp, fp2 = 0;
fp1->nx != 0;
fp2 = fp1, fp1 = fp1->nx)
/* advance to entry just before end of list */;
cp2 = (char *)&(fp1->nx);
if (cp2 + fp1->sz == __brkval) {
if (fp2 == NULL)
/* Freelist is empty now. */
__flp = NULL;
else
fp2->nx = NULL;
__brkval = cp2 - sizeof(size_t);
}
}
void *
realloc(void *ptr, size_t len)
{
struct __freelist *fp1, *fp2, *fp3, *ofp3;
char *cp, *cp1;
void *memp;
size_t s, incr;
/* Trivial case, required by C standard. */
if (ptr == 0)
return malloc(len);
cp1 = (char *)ptr;
cp1 -= sizeof(size_t);
fp1 = (struct __freelist *)cp1;
cp = (char *)ptr + len; /* new next pointer */
if (cp < cp1)
/* Pointer wrapped across top of RAM, fail. */
return 0;
/*
* See whether we are growing or shrinking. When shrinking,
* we split off a chunk for the released portion, and call
* free() on it. Therefore, we can only shrink if the new
* size is at least sizeof(struct __freelist) smaller than the
* previous size.
*/
if (len <= fp1->sz) {
/* The first test catches a possible unsigned int
* rollover condition. */
if (fp1->sz <= sizeof(struct __freelist) ||
len > fp1->sz - sizeof(struct __freelist))
return ptr;
fp2 = (struct __freelist *)cp;
fp2->sz = fp1->sz - len - sizeof(size_t);
fp1->sz = len;
free(&(fp2->nx));
return ptr;
}
/*
* If we get here, we are growing. First, see whether there
* is space in the free list on top of our current chunk.
*/
incr = len - fp1->sz;
cp = (char *)ptr + fp1->sz;
fp2 = (struct __freelist *)cp;
for (s = 0, ofp3 = 0, fp3 = __flp;
fp3;
ofp3 = fp3, fp3 = fp3->nx) {
if (fp3 == fp2 && fp3->sz + sizeof(size_t) >= incr) {
/* found something that fits */
if (fp3->sz + sizeof(size_t) - incr > sizeof(struct __freelist)) {
/* split off a new freelist entry */
cp = (char *)ptr + len;
fp2 = (struct __freelist *)cp;
fp2->nx = fp3->nx;
fp2->sz = fp3->sz - incr;
fp1->sz = len;
} else {
/* it just fits, so use it entirely */
fp1->sz += fp3->sz + sizeof(size_t);
fp2 = fp3->nx;
}
if (ofp3)
ofp3->nx = fp2;
else
__flp = fp2;
return ptr;
}
/*
* Find the largest chunk on the freelist while
* walking it.
*/
if (fp3->sz > s)
s = fp3->sz;
}
/*
* If we are the topmost chunk in memory, and there was no
* large enough chunk on the freelist that could be re-used
* (by a call to malloc() below), quickly extend the
* allocation area if possible, without need to copy the old
* data.
*/
if (__brkval == (char *)ptr + fp1->sz && len > s) {
cp = (char *)ptr + len;
cp1 = STACK_POINTER() - __MALLOC_MARGIN__;
if (cp < cp1) {
__brkval = cp;
__brkval_maximum = cp;
fp1->sz = len;
return ptr;
}
/* If that failed, we are out of luck. */
return 0;
}
/*
* Call malloc() for a new chunk, then copy over the data, and
* release the old region.
*/
if ((memp = malloc(len)) == 0)
return 0;
memcpy(memp, ptr, fp1->sz);
free(ptr);
return memp;
}

View File

@ -5,10 +5,20 @@ void * operator new(size_t size)
return malloc(size);
}
void * operator new[](size_t size)
{
return malloc(size);
}
void operator delete(void * ptr)
{
free(ptr);
}
}
void operator delete[](void * ptr)
{
free(ptr);
}
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};

View File

@ -8,7 +8,9 @@
#include <stdlib.h>
void * operator new(size_t size);
void operator delete(void * ptr);
void * operator new[](size_t size);
void operator delete(void * ptr);
void operator delete[](void * ptr);
__extension__ typedef int __guard __attribute__((mode (__DI__)));

View File

@ -0,0 +1,38 @@
/*
Esplora Accelerometer
This sketch shows you how to read the values from the accelerometer.
To see it in action, open the serial monitor and tilt the board. You'll see
the accelerometer values for each axis change when you tilt the board
on that axis.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup()
{
Serial.begin(9600); // initialize serial communications with your computer
}
void loop()
{
int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
Serial.print("x: "); // print the label for X
Serial.print(xAxis); // print the value for the X axis
Serial.print("\ty: "); // print a tab character, then the label for Y
Serial.print(yAxis); // print the value for the Y axis
Serial.print("\tz: "); // print a tab character, then the label for Z
Serial.println(zAxis); // print the value for the Z axis
delay(500); // wait half a second (500 milliseconds)
}

View File

@ -0,0 +1,42 @@
/*
Esplora Blink
This sketch blinks the Esplora's RGB LED. It goes through
all three primary colors (red, green, blue), then it
combines them for secondary colors(yellow, cyan, magenta), then
it turns on all the colors for white.
For best results cover the LED with a piece of white paper to see the colors.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup() {
// There's nothing to set up for this sketch
}
void loop() {
Esplora.writeRGB(255,0,0); // make the LED red
delay(1000); // wait 1 second
Esplora.writeRGB(0,255,0); // make the LED green
delay(1000); // wait 1 second
Esplora.writeRGB(0,0,255); // make the LED blue
delay(1000); // wait 1 second
Esplora.writeRGB(255,255,0); // make the LED yellow
delay(1000); // wait 1 second
Esplora.writeRGB(0,255,255); // make the LED cyan
delay(1000); // wait 1 second
Esplora.writeRGB(255,0,255); // make the LED magenta
delay(1000); // wait 1 second
Esplora.writeRGB(255,255,255);// make the LED white
delay(1000); // wait 1 second
}

View File

@ -0,0 +1,50 @@
/*
Esplora Joystick Mouse
This sketch shows you how to read the joystick and use it to control the movement
of the cursor on your computer. You're making your Esplora into a mouse!
WARNING: this sketch will take over your mouse movement. If you lose control
of your mouse do the following:
1) unplug the Esplora.
2) open the EsploraBlink sketch
3) hold the reset button down while plugging your Esplora back in
4) while holding reset, click "Upload"
5) when you see the message "Done compiling", release the reset button.
This will stop your Esplora from controlling your mouse while you upload a sketch
that doesn't take control of the mouse.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup()
{
Serial.begin(9600); // initialize serial communication with your computer
Mouse.begin(); // take control of the mouse
}
void loop()
{
int xValue = Esplora.readJoystickX(); // read the joystick's X position
int yValue = Esplora.readJoystickY(); // read the joystick's Y position
int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
Serial.print("Joystick X: "); // print a label for the X value
Serial.print(xValue); // print the X value
Serial.print("\tY: "); // print a tab character and a label for the Y value
Serial.print(yValue); // print the Y value
Serial.print("\tButton: "); // print a tab character and a label for the button
Serial.print(button); // print the button value
int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
Mouse.move(mouseX, mouseY, 0); // move the mouse
delay(10); // a short delay before moving again
}

View File

@ -6,7 +6,7 @@
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
Modified 24 Nov 2012
Modified 22 Dec 2012
by Tom Igoe
*/
#include <Esplora.h>
@ -24,7 +24,7 @@ void loop() {
// convert the sensor readings to light levels:
byte red = map(xAxis, -512, 512, 0, 255);
byte green = map(xAxis, -512, 512, 0, 255);
byte green = map(yAxis, -512, 512, 0, 255);
byte blue = slider/4;
// print the light levels:

View File

@ -0,0 +1,91 @@
/*
Esplora Led calibration
This sketch shows you how to read and calibrate the light sensor.
Because light levels vary from one location to another, you need to calibrate the
sensor for each location. To do this, you read the sensor for a few seconds,
and save the highest and lowest readings as maximum and minimum.
Then, when you're using the sensor's reading (for example, to set the brightness
of the LED), you map the sensor's reading to a range between the minimum
and the maximum.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
// variables:
int lightMin = 1023; // minimum sensor value
int lightMax = 0; // maximum sensor value
boolean calibrated = false; // whether the sensor's been calibrated yet
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// print an intial message
Serial.println("To calibrate the light sensor, press and hold Switch 1");
}
void loop() {
// if switch 1 is pressed, go to the calibration function again:
if (Esplora.readButton(1) == LOW) {
calibrate();
}
// read the sensor into a variable:
int light = Esplora.readLightSensor();
// map the light level to a brightness level for the LED
// using the calibration min and max:
int brightness = map(light, lightMin, lightMax, 0, 255);
// limit the brightness to a range from 0 to 255:
brightness = constrain(brightness, 0, 255);
// write the brightness to the blue LED.
Esplora.writeBlue(brightness);
// if the calibration's been done, show the sensor and brightness
// levels in the serial monitor:
if (calibrated == true) {
// print the light sensor levels and the LED levels (to see what's going on):
Serial.print("light sensor level: ");
Serial.print(light);
Serial.print(" blue brightness: ");
Serial.println(brightness);
}
// add a delay to keep the LED from flickering:
delay(10);
}
void calibrate() {
// tell the user what do to using the serial monitor:
Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
// calibrate while switch 1 is pressed:
while(Esplora.readButton(1) == LOW) {
// read the sensor value:
int light = Esplora.readLightSensor();
// record the maximum sensor value:
if (light > lightMax) {
lightMax = light;
}
// record the minimum sensor value:
if (light < lightMin) {
lightMin = light;
}
// note that you're calibrated, for future reference:
calibrated = true;
}
}

View File

@ -6,14 +6,15 @@
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
modified 24 Nov 2012
modified 22 Dec 2012
by Tom Igoe
*/
#include <Esplora.h>
// these are the frequencies for the notes from middle C
// to one octave above middle C:
const int note[] = {
262, // C
277, // C#

View File

@ -0,0 +1,41 @@
/*
Esplora Sound Sensor
This sketch shows you how to read the microphone sensor. The microphone
will range from 0 (total silence) to 1023 (really loud).
When you're using the sensor's reading (for example, to set the brightness
of the LED), you map the sensor's reading to a range between the minimum
and the maximum.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}
void loop() {
// read the sensor into a variable:
int loudness = Esplora.readMicrophone();
// map the sound level to a brightness level for the LED:
int brightness = map(loudness, 0, 1023, 0, 255);
// write the brightness to the green LED:
Esplora.writeGreen(brightness);
// print the microphone levels and the LED levels (to see what's going on):
Serial.print("sound level: ");
Serial.print(loudness);
Serial.print(" Green brightness: ");
Serial.println(brightness);
// add a delay to keep the LED from flickering:
delay(10);
}

View File

@ -0,0 +1,37 @@
/*
Esplora Temperature Sensor
This sketch shows you how to read the Esplora's temperature sensor
You can read the temperature sensor in Farhenheit or Celsius.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup()
{
Serial.begin(9600); // initialize serial communications with your computer
}
void loop()
{
// read the temperature sensor in Celsius, then Fahrenheit:
int celsius = Esplora.readTemperature(DEGREES_C);
int fahrenheit = Esplora.readTemperature(DEGREES_F);
// print the results:
Serial.print("Temperature is: ");
Serial.print(celsius);
Serial.print(" degrees Celsius, or ");
Serial.print(fahrenheit);
Serial.println(" degrees Fahrenheit.");
Serial.println(" Fahrenheit = (9/5 * Celsius) + 32");
// wait a second before reading again:
delay(1000);
}

View File

@ -111,6 +111,15 @@ boolean _Esplora::readButton(byte ch) {
return (val > 512) ? HIGH : LOW;
}
boolean _Esplora::readJoystickButton() {
if (readChannel(CH_JOYSTICK_SW) == 1023) {
return HIGH;
} else if (readChannel(CH_JOYSTICK_SW) == 0) {
return LOW;
}
}
void _Esplora::writeRGB(byte r, byte g, byte b) {
writeRed(r);
writeGreen(g);

View File

@ -21,7 +21,7 @@
#ifndef ESPLORA_H_
#define ESPLORA_H_
#include "Arduino.h"
#include <Arduino.h>
/*
* The following constants are used internally by the Esplora
@ -141,6 +141,8 @@ public:
* LOW if the button is pressed, and HIGH otherwise.
*/
boolean readButton(byte channel);
boolean readJoystickButton();
void writeRGB(byte red, byte green, byte blue);
void writeRed(byte red);

View File

@ -0,0 +1,44 @@
/*
Esplora Pong
This sketch connects serially to a Processing sketch to control a Pong game.
It sends the position of the slider and the states of three pushbuttons to the
Processing sketch serially, separated by commas. The Processing sketch uses that
data to control the graphics in the sketch.
The slider sets a paddle's height
Switch 1 is resets the game
Switch 2 resets the ball to the center
Switch 3 reverses the players
You can play this game with one or two Esploras.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
void setup() {
Serial.begin(9600); // initialize serial communication
}
void loop() {
// read the slider and three of the buttons
int slider = Esplora.readSlider();
int resetButton = Esplora.readButton(SWITCH_1);
int serveButton = Esplora.readButton(SWITCH_3);
int switchPlayerButton = Esplora.readButton(SWITCH_4);
Serial.print(slider); // print the slider value
Serial.print(","); // add a comma
Serial.print(resetButton); // print the reset button value
Serial.print(","); // add another comma
Serial.print(serveButton); // print the serve button value
Serial.print(","); // add another comma
Serial.println(switchPlayerButton); // print the last button with a newline
delay(10); // delay before sending the next set
}

View File

@ -0,0 +1,116 @@
/*
Esplora Remote
This sketch allows to test all the Esplora's peripherals.
It is also used with the ProcessingStart sketch (for Processing).
When uploaded, you can open the Serial monitor and write one of
the following commands (without quotes) to get an answer:
"D": prints the current value of all sensors, separated by a comma.
See the dumpInputs() function below to get the meaning of
each value.
"Rxxx"
"Gxxx"
"Bxxx": set the color of the RGB led. For example, write "R255"
to turn on the red to full brightness, "G128" to turn
the green to half brightness, or "G0" to turn off
the green channel.
"Txxxx": play a tone with the buzzer. The number is the
frequency, e.g. "T440" plays the central A note.
Write "T0" to turn off the buzzer.
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
Modified 23 Dec 2012
by Tom Igoe
*/
#include <Esplora.h>
void setup() {
while(!Serial); // needed for Leonardo-based board like Esplora
Serial.begin(9600);
}
void loop() {
if (Serial.available())
parseCommand();
}
/*
* This function reads a character from the serial line and
* decide what to do next. The "what to do" part is given by
* function it calls (e.g. dumpInputs(), setRed() and so on).
*/
void parseCommand() {
char cmd = Serial.read();
switch(cmd) {
case 'D':
dumpInputs();
break;
case 'R':
setRed();
break;
case 'G':
setGreen();
break;
case 'B':
setBlue();
break;
case 'T':
setTone();
break;
}
}
void dumpInputs() {
Serial.print(Esplora.readButton(SWITCH_1));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_2));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_3));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_4));
Serial.print(',');
Serial.print(Esplora.readSlider());
Serial.print(',');
Serial.print(Esplora.readLightSensor());
Serial.print(',');
Serial.print(Esplora.readTemperature(DEGREES_C));
Serial.print(',');
Serial.print(Esplora.readMicrophone());
Serial.print(',');
Serial.print(Esplora.readJoystickSwitch());
Serial.print(',');
Serial.print(Esplora.readJoystickX());
Serial.print(',');
Serial.print(Esplora.readJoystickY());
Serial.print(',');
Serial.print(Esplora.readAccelerometer(X_AXIS));
Serial.print(',');
Serial.print(Esplora.readAccelerometer(Y_AXIS));
Serial.print(',');
Serial.print(Esplora.readAccelerometer(Z_AXIS));
Serial.println();
}
void setRed() {
Esplora.writeRed(Serial.parseInt());
}
void setGreen() {
Esplora.writeGreen(Serial.parseInt());
}
void setBlue() {
Esplora.writeBlue(Serial.parseInt());
}
void setTone() {
Esplora.tone(Serial.parseInt());
}

View File

@ -1,17 +1,16 @@
/*
Esplora Table
Acts like a keyboard that prints some of its sensors'
Acts like a keyboard that prints sensor
data in a table-like text, row by row.
It is a sort of "data-logger".
At startup, it does nothing. It just waits for you to open a
spreadsheet (e.g. Google Drive spreadsheet) so it can put its
data. Then, by pressing Switch 1, it starts printing the table
At startup, it does nothing. It waits for you to open a
spreadsheet (e.g. Google Drive spreadsheet) so it can write
data. By pressing Switch 1, it starts printing the table
headers and the first row of data. It waits a bit, then it
will print another row, and so on.
The amount of time between each row is given by the slider.
The amount of time between each row is determined by the slider.
If put to full left, the sketch will wait 10 seconds; at
full right position, it will wait 5 minutes. An intermediate
position will make the sketch wait for some time in-between.
@ -175,17 +174,12 @@ void logAndPrint() {
}
/**
* Similar to delay(), but allows to do something else
* in the meanwhile. In particular, it calls waitLoop().
* Similar to delay(), but allows the program to do something else
* in the meanwhile. In particular, it calls checkSwitchPress().
* Note 1: it may wait longer than the specified amount, not less;
* Note 2: beware of data synchronization issues, e.g. if the
* whileWaiting() function alters some variables used by the
* activeDelay() function alters some variables used by the
* caller of this function.
*
* I discovered by chance that there's an ongoing discussion about
* adding yield() in the Arduino API:
* http://comments.gmane.org/gmane.comp.hardware.arduino.devel/1381
* The purpose is the same, but for now I'm using this implementation.
*/
void activeDelay(unsigned long amount) {
unsigned long at = millis() + amount;

View File

@ -1,94 +0,0 @@
/*
Esplora Slave
This sketch allows to test all the Esplora's peripherals.
It is also used with the ProcessingStart sketch (for Processing).
When uploaded, you can open the Serial monitor and write one of
the following commands (without quotes) to get an answer:
"D": prints the current value of all sensors, separated by a comma.
See the dumpInputs() function below to get the meaning of
each value.
"Rxxx"
"Gxxx"
"Bxxx": set the color of the RGB led. For example, write "R255"
to turn on the red to full brightness, "G128" to turn
the green to half brightness, or "G0" to turn off
the green channel.
"Txxxx": play a tone with the buzzer. The number is the
frequency, e.g. "T440" plays the central A note.
Write "T0" to turn off the buzzer.
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
*/
#include <Esplora.h>
void setup() {
while(!Serial); // needed for Leonardo-based board like Esplora
Serial.begin(9600);
}
void loop() {
if (Serial.available())
parseCommand();
}
/*
* This function reads a character from the serial line and
* decide what to do next. The "what to do" part is given by
* function it calls (e.g. dumpInputs(), setRed() and so on).
*/
void parseCommand() {
char cmd = Serial.read();
switch(cmd) {
case 'D': dumpInputs(); break;
case 'R': setRed(); break;
case 'G': setGreen(); break;
case 'B': setBlue(); break;
case 'T': setTone(); break;
}
}
void dumpInputs() {
/*
* please note: a single row contains two instructions.
* one is to print the sensor value, the other to print the
* comma symbol.
*/
Serial.print(Esplora.readButton(SWITCH_1)); Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_2)); Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_3)); Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_4)); Serial.print(',');
Serial.print(Esplora.readSlider()); Serial.print(',');
Serial.print(Esplora.readLightSensor()); Serial.print(',');
Serial.print(Esplora.readTemperature(DEGREES_C)); Serial.print(',');
Serial.print(Esplora.readMicrophone()); Serial.print(',');
Serial.print(Esplora.readJoystickSwitch()); Serial.print(',');
Serial.print(Esplora.readJoystickX()); Serial.print(',');
Serial.print(Esplora.readJoystickY()); Serial.print(',');
Serial.print(Esplora.readAccelerometer(X_AXIS)); Serial.print(',');
Serial.print(Esplora.readAccelerometer(Y_AXIS)); Serial.print(',');
Serial.print(Esplora.readAccelerometer(Z_AXIS)); Serial.println();
}
void setRed() {
Esplora.writeRed(Serial.parseInt());
}
void setGreen() {
Esplora.writeGreen(Serial.parseInt());
}
void setBlue() {
Esplora.writeBlue(Serial.parseInt());
}
void setTone() {
Esplora.tone(Serial.parseInt());
}

View File

@ -16,6 +16,7 @@ readLightSensor KEYWORD2
readTemperature KEYWORD2
readMicrophone KEYWORD2
readJoystickSwitch KEYWORD2
readJoystickButton KEYWORD2
readJoystickX KEYWORD2
readJoystickY KEYWORD2
readAccelerometer KEYWORD2

View File

@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){
_dhcpTransactionId = random(1UL, 2000UL);
_dhcpInitialTransactionId = _dhcpTransactionId;
_dhcpUdpSocket.stop();
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
{
// Couldn't get a socket

View File

@ -10,7 +10,8 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
int EthernetClass::begin(uint8_t *mac_address)
{
_dhcp = new DhcpClass();
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;
// Initialise the basic info

View File

@ -63,7 +63,7 @@ void loop() {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

View File

@ -245,7 +245,7 @@ void FirmataClass::processInput(void)
break;
case REPORT_ANALOG:
case REPORT_DIGITAL:
waitForData = 1; // two data bytes needed
waitForData = 1; // one data byte needed
executeMultiByteCommand = command;
break;
case START_SYSEX:

View File

@ -76,7 +76,7 @@ void loop() {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

View File

@ -1,140 +0,0 @@
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2009, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
/*------------------------------------------------------------------------------
* Linker script for running in internal FLASH on the ATSAM3S4
*----------------------------------------------------------------------------*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00040000 /* flash, 256K */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0000c000 /* sram, 48K */
}
/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(0x4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
. = ALIGN(4);
_efixed = .; /* End of text section */
} > rom
/* .ARM.exidx is sorted, so has to go in its own output section. */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > rom
PROVIDE_HIDDEN (__exidx_end = .);
. = ALIGN(4);
_etext = .;
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram
/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram
/* stack section */
.stack (NOLOAD):
{
. = ALIGN(8);
*(.stack .stack.*)
} > ram
. = ALIGN(4);
_end = . ;
}

View File

@ -157,7 +157,7 @@ void Serial_::accept(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
uint32_t c = USBD_Recv(CDC_RX);
uint32_t i = (uint32_t)(buffer->head+1) % SERIAL_BUFFER_SIZE;
uint32_t i = (uint32_t)(buffer->head+1) % CDC_SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
@ -172,7 +172,7 @@ void Serial_::accept(void)
int Serial_::available(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
return (unsigned int)(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % CDC_SERIAL_BUFFER_SIZE;
}
int Serial_::peek(void)
@ -201,7 +201,7 @@ int Serial_::read(void)
else
{
unsigned char c = buffer->buffer[buffer->tail];
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
buffer->tail = (unsigned int)(buffer->tail + 1) % CDC_SERIAL_BUFFER_SIZE;
return c;
}
}

View File

@ -199,6 +199,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
len -= n;
UDD_Send(ep & 0xF, data, n);
data += n;
}
//TXLED1; // light the TX LED
//TxLEDPulse = TX_RX_LED_PULSE_MS;

View File

@ -243,8 +243,8 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
// Write user value
ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_TXRDY) == 0);
dacc_write_conversion_data(DACC_INTERFACE, ulValue);
while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_EOC) == 0);
return;
}
}

View File

@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){
_dhcpTransactionId = random(1UL, 2000UL);
_dhcpInitialTransactionId = _dhcpTransactionId;
_dhcpUdpSocket.stop();
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
{
// Couldn't get a socket

View File

@ -10,7 +10,9 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
int EthernetClass::begin(uint8_t *mac_address)
{
_dhcp = new DhcpClass();
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;
// Initialise the basic info
W5100.init();
@ -59,7 +61,6 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
W5100.init();
W5100.setMACAddress(mac);
W5100.setIPAddress(local_ip._address);
W5100.setGatewayIp(gateway._address);

View File

@ -63,7 +63,7 @@ void loop() {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

View File

@ -63,15 +63,15 @@ void mousePressed() {
// This function intercepts mouse button release
void mouseReleased() {
Serial.print("Released: ");
if (!mouse.getButton(LEFT_BUTTON) && left==true) {
if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
Serial.print("L");
leftButton = false;
}
if (!mouse.getButton(MIDDLE_BUTTON) && middle==true) {
if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
Serial.print("M");
middleButton = false;
}
if (!mouse.getButton(RIGHT_BUTTON) && right==true) {
if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
Serial.print("R");
rightButton = false;
}

View File

@ -76,7 +76,7 @@ void loop() {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

View File

@ -15,16 +15,11 @@ extern "C" {
#define SLAVEREADY 7 // handshake pin
#define WIFILED 9 // led on wifi shield
#define DELAY_100NS do { asm volatile("nop"); }while(0);
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); }while(++ii<X);}
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < X*6); }
#define DELAY_TRANSFER() DELAY_SPI(10)
void SpiDrv::begin()
{
// pinMode(SCK, OUTPUT);
// pinMode(MOSI, OUTPUT);
// pinMode(SS, OUTPUT);
SPI.begin();
pinMode(SLAVESELECT, OUTPUT);
pinMode(SLAVEREADY, INPUT);
@ -69,11 +64,6 @@ void SpiDrv::spiSlaveDeselect()
char SpiDrv::spiTransfer(volatile char data)
{
char result = SPI.transfer(data);
// SPDR = data; // Start the transmission
// while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
// {
// };
// char result = SPDR;
DELAY_TRANSFER();
return result; // return the received byte

View File

@ -77,6 +77,7 @@ void printDirectory(File dir, int numTabs) {
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}

View File

@ -1,5 +1,3 @@
0151 arduino
Fix Linux make.sh, etc. scripts
Test on Linux.