From f14fd94d0eb52e75b3e295e10496b1782a4c8df5 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 12 Aug 2011 16:59:24 -0400 Subject: [PATCH 01/30] Adding SCL, SDA, and LED #defines. --- hardware/arduino/pins/mega/pins_arduino.h | 4 ++++ hardware/arduino/pins/standard/pins_arduino.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/hardware/arduino/pins/mega/pins_arduino.h b/hardware/arduino/pins/mega/pins_arduino.h index e3785e42f..acbd28f8b 100644 --- a/hardware/arduino/pins/mega/pins_arduino.h +++ b/hardware/arduino/pins/mega/pins_arduino.h @@ -32,6 +32,10 @@ const static uint8_t MOSI = 51; const static uint8_t MISO = 50; const static uint8_t SCK = 52; +const static uint8_t SDA = 20; +const static uint8_t SCL = 21; +const static uint8_t LED = 13; + const static uint8_t A0 = 54; const static uint8_t A1 = 55; const static uint8_t A2 = 56; diff --git a/hardware/arduino/pins/standard/pins_arduino.h b/hardware/arduino/pins/standard/pins_arduino.h index 8fabb1781..b42755d04 100644 --- a/hardware/arduino/pins/standard/pins_arduino.h +++ b/hardware/arduino/pins/standard/pins_arduino.h @@ -32,6 +32,10 @@ const static uint8_t MOSI = 11; const static uint8_t MISO = 12; const static uint8_t SCK = 13; +const static uint8_t SDA = 18; +const static uint8_t SCL = 19; +const static uint8_t LED = 13; + const static uint8_t A0 = 14; const static uint8_t A1 = 15; const static uint8_t A2 = 16; From f179794a45c33edcb48c493bc03fb0e39dba11db Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 12 Aug 2011 17:31:22 -0400 Subject: [PATCH 02/30] Adding pin-change interrupt pin mapping macros to pins_arduino.h. http://code.google.com/p/arduino/issues/detail?id=490 --- hardware/arduino/pins/mega/pins_arduino.h | 25 +++++++ hardware/arduino/pins/standard/pins_arduino.h | 5 ++ libraries/SoftwareSerial/SoftwareSerial.cpp | 1 - libraries/SoftwareSerial/icrmacros.h | 69 ------------------- 4 files changed, 30 insertions(+), 70 deletions(-) delete mode 100755 libraries/SoftwareSerial/icrmacros.h diff --git a/hardware/arduino/pins/mega/pins_arduino.h b/hardware/arduino/pins/mega/pins_arduino.h index acbd28f8b..b25f858d8 100644 --- a/hardware/arduino/pins/mega/pins_arduino.h +++ b/hardware/arduino/pins/mega/pins_arduino.h @@ -53,6 +53,31 @@ const static uint8_t A13 = 67; const static uint8_t A14 = 68; const static uint8_t A15 = 69; +// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins) +// Only pins available for RECEIVE (TRANSMIT can be on any pin): +// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me) +// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + +#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \ + (((p) >= 50) && ((p) <= 53)) || \ + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) + +#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ + 0 ) ) + +#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ + ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ + ((uint8_t *)0) ) ) + +#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ + ( ((p) == 50) ? 3 : \ + ( ((p) == 51) ? 2 : \ + ( ((p) == 52) ? 1 : \ + ( ((p) == 53) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ + 0 ) ) ) ) ) ) + #ifdef ARDUINO_MAIN const uint16_t PROGMEM port_to_mode_PGM[] = { diff --git a/hardware/arduino/pins/standard/pins_arduino.h b/hardware/arduino/pins/standard/pins_arduino.h index b42755d04..8e25435ae 100644 --- a/hardware/arduino/pins/standard/pins_arduino.h +++ b/hardware/arduino/pins/standard/pins_arduino.h @@ -45,6 +45,11 @@ const static uint8_t A5 = 19; const static uint8_t A6 = 20; const static uint8_t A7 = 21; +#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) +#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) +#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0)))) +#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14))) + #ifdef ARDUINO_MAIN // On the Arduino board, digital pins are also used diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index b8a1fc46b..b9cb16105 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -42,7 +42,6 @@ http://arduiniana.org. #include #include "Arduino.h" #include "SoftwareSerial.h" -#include "icrmacros.h" // // Lookup table // diff --git a/libraries/SoftwareSerial/icrmacros.h b/libraries/SoftwareSerial/icrmacros.h deleted file mode 100755 index 936eae848..000000000 --- a/libraries/SoftwareSerial/icrmacros.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -icrmacros.h - -A place to put useful ICR (interrupt change register) macros - -If you want to support non-Arduino processors you can extend or replace -this file. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -The latest version of this library can always be found at -http://arduiniana.org. -*/ - -// Abstractions for maximum portability between processors -// These are macros to associate pins to pin change interrupts -#if !defined(digitalPinToPCICR) // Courtesy Paul Stoffregen - -#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) - -#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) -#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) -#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0)))) -#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14))) - -#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -// Specifically for the Arduino Mega 2560 (or 1280 on the original Arduino Mega) -// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins) -// Only pins available for RECEIVE (TRANSMIT can be on any pin): -// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me) -// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 - -#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \ - (((p) >= 50) && ((p) <= 53)) || \ - (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) - -#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ - ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ - 0 ) ) - -#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ - ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ - ((uint8_t *)0) ) ) - -#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ - ( ((p) == 50) ? 3 : \ - ( ((p) == 51) ? 2 : \ - ( ((p) == 52) ? 1 : \ - ( ((p) == 53) ? 0 : \ - ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ - 0 ) ) ) ) ) ) - -#else -#error This processor is not supported by SoftwareSerial -#endif -#endif - From d338f22bde9b83796af4d627d085dfb25a0a405f Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 12 Aug 2011 18:27:00 -0400 Subject: [PATCH 03/30] Adding basic macros for analog + digital pin information. http://code.google.com/p/arduino/issues/detail?id=495 --- hardware/arduino/pins/mega/pins_arduino.h | 5 +++++ hardware/arduino/pins/standard/pins_arduino.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/hardware/arduino/pins/mega/pins_arduino.h b/hardware/arduino/pins/mega/pins_arduino.h index b25f858d8..237173adc 100644 --- a/hardware/arduino/pins/mega/pins_arduino.h +++ b/hardware/arduino/pins/mega/pins_arduino.h @@ -27,6 +27,11 @@ #include +#define NUM_DIGITAL_PINS 70 +#define NUM_ANALOG_INPUTS 16 +#define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1) +#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46)) + const static uint8_t SS = 53; const static uint8_t MOSI = 51; const static uint8_t MISO = 50; diff --git a/hardware/arduino/pins/standard/pins_arduino.h b/hardware/arduino/pins/standard/pins_arduino.h index 8e25435ae..3999d1fcd 100644 --- a/hardware/arduino/pins/standard/pins_arduino.h +++ b/hardware/arduino/pins/standard/pins_arduino.h @@ -27,6 +27,16 @@ #include +#define NUM_DIGITAL_PINS 20 +#define NUM_ANALOG_INPUTS 6 +#define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1) + +#if defined(__AVR_ATmega8__) +#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11) +#else +#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11) +#endif + const static uint8_t SS = 10; const static uint8_t MOSI = 11; const static uint8_t MISO = 12; From 42943b4de3885ce82aaace01cce79bd02b5e1acb Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 16 Aug 2011 19:52:31 +0200 Subject: [PATCH 04/30] Added progressbar (from wiring) --- app/src/processing/app/Editor.java | 10 ++- app/src/processing/app/EditorStatus.java | 78 +++++++++++++++++++++- app/src/processing/app/Sketch.java | 10 ++- app/src/processing/app/debug/Compiler.java | 9 +++ 4 files changed, 102 insertions(+), 5 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 33f1fc855..43f69ecbb 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1841,9 +1841,11 @@ public class Editor extends JFrame implements RunnerListener { String appletClassName = sketch.build(false); statusNotice("Done compiling."); } catch (Exception e) { + status.unprogress(); statusError(e); } + status.unprogress(); toolbar.deactivate(EditorToolbar.RUN); } } @@ -1856,9 +1858,11 @@ public class Editor extends JFrame implements RunnerListener { String appletClassName = sketch.build(true); statusNotice("Done compiling."); } catch (Exception e) { + status.unprogress(); statusError(e); } + status.unprogress(); toolbar.deactivate(EditorToolbar.RUN); } } @@ -2334,7 +2338,7 @@ public class Editor extends JFrame implements RunnerListener { //if (!handleExportCheckModified()) return; toolbar.activate(EditorToolbar.EXPORT); console.clear(); - statusNotice("Uploading to I/O Board..."); + status.progress("Uploading to I/O Board..."); new Thread(usingProgrammer ? exportAppHandler : exportHandler).start(); } @@ -2363,10 +2367,12 @@ public class Editor extends JFrame implements RunnerListener { } catch (RunnerException e) { //statusError("Error during upload."); //e.printStackTrace(); + status.unprogress(); statusError(e); } catch (Exception e) { e.printStackTrace(); } + status.unprogress(); uploading = false; //toolbar.clear(); toolbar.deactivate(EditorToolbar.EXPORT); @@ -2397,10 +2403,12 @@ public class Editor extends JFrame implements RunnerListener { } catch (RunnerException e) { //statusError("Error during upload."); //e.printStackTrace(); + status.unprogress(); statusError(e); } catch (Exception e) { e.printStackTrace(); } + status.unprogress(); uploading = false; //toolbar.clear(); toolbar.deactivate(EditorToolbar.EXPORT); diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index a7035ab7c..a335b9230 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -40,6 +40,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { //static final int PROMPT = 2; //static final int EDIT = 3; static final int EDIT = 2; + static final int PROGRESS = 5; static final int YES = 1; static final int NO = 2; @@ -66,6 +67,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { JButton cancelButton; JButton okButton; JTextField editField; + JProgressBar progressBar; //Thread promptThread; int response; @@ -76,16 +78,22 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { empty(); if (bgcolor == null) { - bgcolor = new Color[3]; //4]; + bgcolor = new Color[6]; bgcolor[0] = Theme.getColor("status.notice.bgcolor"); bgcolor[1] = Theme.getColor("status.error.bgcolor"); bgcolor[2] = Theme.getColor("status.edit.bgcolor"); + bgcolor[3] = null; + bgcolor[4] = null; + bgcolor[5] = Theme.getColor("status.notice.bgcolor"); - fgcolor = new Color[3]; //4]; + fgcolor = new Color[6]; fgcolor[0] = Theme.getColor("status.notice.fgcolor"); fgcolor[1] = Theme.getColor("status.error.fgcolor"); fgcolor[2] = Theme.getColor("status.edit.fgcolor"); - } + fgcolor[3] = null; + fgcolor[4] = null; + fgcolor[5] = Theme.getColor("status.notice.fgcolor"); +} } @@ -163,6 +171,54 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { empty(); } + public void progress(String message) + { + mode = PROGRESS; + this.message = message; + progressBar.setIndeterminate(false); + progressBar.setVisible(true); + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + repaint(); + } + + + public void progressIndeterminate(String message) + { + mode = PROGRESS; + this.message = message; + progressBar.setIndeterminate(true); + progressBar.setValue(50); + progressBar.setVisible(true); + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + repaint(); + } + + + public void progressNotice(String message) { + //mode = NOTICE; + this.message = message; + //update(); + repaint(); + } + + + public void unprogress() + { + if (Preferences.getBoolean("editor.beep.compile")) { + Toolkit.getDefaultToolkit().beep(); + } + progressBar.setVisible(false); + progressBar.setValue(0); + setCursor(null); + //empty(); + } + + + public void progressUpdate(int value) + { + progressBar.setValue(value); + repaint(); + } /* public void update() { @@ -369,6 +425,19 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { }); add(editField); editField.setVisible(false); + + progressBar = new JProgressBar(JScrollBar.HORIZONTAL); + progressBar.setIndeterminate(false); + if (Base.isMacOS()) { + //progressBar.setBackground(bgcolor[PROGRESS]); + //progressBar.putClientProperty("JProgressBar.style", "circular"); + } + progressBar.setValue(0); + progressBar.setBorderPainted(true); + //progressBar.setStringPainted(true); + add(progressBar); + progressBar.setVisible(false); + } } @@ -385,11 +454,13 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { //noButton.setLocation(noLeft, top); cancelButton.setLocation(cancelLeft, top); okButton.setLocation(noLeft, top); + progressBar.setLocation(noLeft, top); //yesButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT); //noButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT); cancelButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT); okButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT); + progressBar.setSize(2*Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT); // edit field height is awkward, and very different between mac and pc, // so use at least the preferred height for now. @@ -398,6 +469,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { int editTop = (1 + sizeH - editHeight) / 2; // add 1 for ceil editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop, editWidth, editHeight); + progressBar.setBounds(noLeft, editTop, editWidth, editHeight); } diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 22e2aa591..93b8e40dc 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1507,6 +1507,7 @@ public class Sketch { throws RunnerException { // run the preprocessor + editor.status.progressUpdate(20); String primaryClassName = preprocess(buildPath); // compile the program. errors will happen as a RunnerException @@ -1552,6 +1553,7 @@ public class Sketch { appletFolder.mkdirs(); // build the sketch + editor.status.progressNotice("Compiling sketch..."); String foundName = build(appletFolder.getPath(), false); // (already reported) error during export, exit this function if (foundName == null) return false; @@ -1565,12 +1567,18 @@ public class Sketch { // return false; // } + editor.status.progressNotice("Uploading..."); upload(appletFolder.getPath(), foundName, usingProgrammer); - + editor.status.progressUpdate(100); return true; } + + public void setCompilingProgress(int percent) { + editor.status.progressUpdate(percent); + } + protected void size(String buildPath, String suggestedClassName) throws RunnerException { long size = 0; diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index bf972b8ea..dd0889859 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -111,6 +111,7 @@ public class Compiler implements MessageConsumer { // 0. include paths for core + all libraries + sketch.setCompilingProgress(20); List includePaths = new ArrayList(); includePaths.add(corePath); if (pinsPath != null) includePaths.add(pinsPath); @@ -120,6 +121,7 @@ public class Compiler implements MessageConsumer { // 1. compile the sketch (already in the buildPath) + sketch.setCompilingProgress(30); objectFiles.addAll( compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(buildPath, "S", false), @@ -129,6 +131,7 @@ public class Compiler implements MessageConsumer { // 2. compile the libraries, outputting .o files to: // + sketch.setCompilingProgress(40); for (File libraryFolder : sketch.getImportedLibraries()) { File outputFolder = new File(buildPath, libraryFolder.getName()); File utilityFolder = new File(libraryFolder, "utility"); @@ -156,6 +159,7 @@ public class Compiler implements MessageConsumer { // 3. compile the core, outputting .o files to and then // collecting them into the core.a library file. + sketch.setCompilingProgress(50); includePaths.clear(); includePaths.add(corePath); // include path for core only if (pinsPath != null) includePaths.add(pinsPath); @@ -180,6 +184,7 @@ public class Compiler implements MessageConsumer { // 4. link it all together into the .elf file + sketch.setCompilingProgress(60); List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", @@ -208,6 +213,7 @@ public class Compiler implements MessageConsumer { List commandObjcopy; // 5. extract EEPROM data (from EEMEM directive) to .eep file. + sketch.setCompilingProgress(70); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.set(3, "-j"); @@ -221,6 +227,7 @@ public class Compiler implements MessageConsumer { execAsynchronously(commandObjcopy); // 6. build the .hex file + sketch.setCompilingProgress(80); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.add(".eeprom"); // remove eeprom data @@ -228,6 +235,8 @@ public class Compiler implements MessageConsumer { commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex"); execAsynchronously(commandObjcopy); + sketch.setCompilingProgress(90); + return true; } From 3fc96366b1b14ebcf91984204f96bbff8bce1046 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 16 Aug 2011 19:57:39 +0200 Subject: [PATCH 05/30] Fixed projects setting to make it compile again inside Eclipse IDE --- .classpath | 10 ++++++---- .settings/org.eclipse.jdt.core.prefs | 17 +++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.classpath b/.classpath index 71e8cc144..5f528e603 100644 --- a/.classpath +++ b/.classpath @@ -2,9 +2,11 @@ - - - - + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ef277e5a2..a4e4441e5 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,15 @@ -#Thu Jan 10 10:50:38 PST 2008 +#Tue Aug 16 19:08:40 CEST 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 From ccb318c2abd193269236141324d04e421a50e44e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 16 Aug 2011 20:38:23 +0200 Subject: [PATCH 06/30] Added Schematic view (from wiring). --- app/src/processing/app/Base.java | 11 + app/src/processing/app/Editor.java | 26 ++- app/src/processing/app/EditorToolbar.java | 45 ++-- app/src/processing/app/Schematics.java | 273 ++++++++++++++++++++++ build/shared/lib/theme/buttons.gif | Bin 3331 -> 3513 bytes 5 files changed, 341 insertions(+), 14 deletions(-) create mode 100644 app/src/processing/app/Schematics.java diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 036cb4f5a..97e9f57e1 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -436,6 +436,17 @@ public class Base { // ................................................................. + /** Command on Mac OS X, Ctrl on Windows and Linux */ + static final int SHORTCUT_KEY_MASK = + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + /** Command-W on Mac OS X, Ctrl-W on Windows and Linux */ + static final KeyStroke WINDOW_CLOSE_KEYSTROKE = + KeyStroke.getKeyStroke('W', SHORTCUT_KEY_MASK); + /** Command-Option on Mac OS X, Ctrl-Alt on Windows and Linux */ + static final int SHORTCUT_ALT_KEY_MASK = ActionEvent.ALT_MASK | + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + + // Because of variations in native windowing systems, no guarantees about // changes to the focused and active Windows can be made. Developers must // never assume that this Window is the focused or active Window until this diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 43f69ecbb..92a516eb6 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -99,6 +99,8 @@ public class Editor extends JFrame implements RunnerListener { static SerialMenuListener serialMenuListener; static SerialMonitor serialMonitor; + Schematics schematics; + EditorHeader header; EditorStatus status; EditorConsole console; @@ -625,6 +627,16 @@ public class Editor extends JFrame implements RunnerListener { // } // }); // sketchMenu.add(item); + + sketchMenu.addSeparator(); + + item = new JMenuItem("Show schematics"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleSchematics(); + } + }); + sketchMenu.add(item); sketchMenu.addSeparator(); @@ -1894,7 +1906,6 @@ public class Editor extends JFrame implements RunnerListener { return sketchWindowLocation; } - /** * Implements Sketch → Stop, or pressing Stop on the toolbar. */ @@ -1911,6 +1922,19 @@ public class Editor extends JFrame implements RunnerListener { } + public void handleSchematics() { // called by menu or buttons + //String s = sketch.getFolder().getAbsolutePath() + File.separator + sketch.getName() + ".png"; + File file = new File(sketch.getFolder(), sketch.getName() + ".png"); + if (file.exists()) { + if (schematics == null) + schematics = new Schematics(file); + schematics.showFrame(this); + } else { + statusNotice("This sketch doesn't include schematics"); + } + } + + /** * Deactivate the Run button. This is called by Runner to notify that the * sketch has stopped running, usually in response to an error (or maybe diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 9d7a5fc13..1f3a68231 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -37,7 +37,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key /** Rollover titles for each button. */ static final String title[] = { - "Verify", "Upload", "New", "Open", "Save", "Serial Monitor" + "Verify", "Upload", "New", "Open", "Save", "Show Schematics", "Serial Monitor" }; /** Titles for each button when the shift key is pressed. */ @@ -56,18 +56,20 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key static final int BUTTON_IMAGE_SIZE = 33; - static final int RUN = 0; - static final int EXPORT = 1; + static final int RUN = 0; + static final int EXPORT = 1; - static final int NEW = 2; - static final int OPEN = 3; - static final int SAVE = 4; + static final int NEW = 2; + static final int OPEN = 3; + static final int SAVE = 4; + static final int SCHEMATICS = 5; - static final int SERIAL = 5; + static final int SERIAL = 6; static final int INACTIVE = 0; static final int ROLLOVER = 1; static final int ACTIVE = 2; + static final int DISABLED = 3; Editor editor; @@ -108,6 +110,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key which[buttonCount++] = NEW; which[buttonCount++] = OPEN; which[buttonCount++] = SAVE; + which[buttonCount++] = SCHEMATICS; which[buttonCount++] = SERIAL; currentRollover = -1; @@ -258,8 +261,9 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key for (int i = 0; i < buttonCount; i++) { if ((y > y1) && (x > x1[i]) && (y < y2) && (x < x2[i])) { - //System.out.println("sel is " + i); - return i; + if (state[i] != DISABLED) { + return i; + } } } return -1; @@ -267,10 +271,12 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key private void setState(int slot, int newState, boolean updateAfter) { - state[slot] = newState; - stateImage[slot] = buttonImages[which[slot]][newState]; - if (updateAfter) { - repaint(); + if (state[slot]!=DISABLED) { + state[slot] = newState; + stateImage[slot] = buttonImages[which[slot]][newState]; + if (updateAfter) { + repaint(); + } } } @@ -338,6 +344,10 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key editor.handleExport(e.isShiftDown()); break; + case SCHEMATICS: + editor.handleSchematics(); + break; + case SERIAL: editor.handleSerial(); break; @@ -371,6 +381,15 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key } + public void disable(int what) { + if (buttonImages != null && which!=null && state!=null && stateImage!=null) { + state[what] = DISABLED; + stateImage[what] = buttonImages[which[what]][INACTIVE]; + repaint(); + } + } + + public Dimension getPreferredSize() { return getMinimumSize(); } diff --git a/app/src/processing/app/Schematics.java b/app/src/processing/app/Schematics.java new file mode 100644 index 000000000..c29d01663 --- /dev/null +++ b/app/src/processing/app/Schematics.java @@ -0,0 +1,273 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Wiring project - http://wiring.org.co + + Copyright (c) 2009-11 Hernando Barragan + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package processing.app; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; + +import javax.swing.*; + +public class Schematics extends JFrame { + private static final long serialVersionUID = 3254345343658939796L; + + // prompt text stuff + Image image; + + int diagramX = 0, diagramY = 0; + + int x1, y1, x2, y2; + + static final String PROMPT_CLOSE = "Close"; + + static final String PROMPT_RESETVIEW = "Reset"; + + /** + * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, + * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. + */ + static public int BUTTON_WIDTH = 80; + + /** + * Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29, presumably + * because it now includes the blue border, where it didn't in Java 1.3. + * Windows XP only wants 23 (not sure what default Linux would be). Because of + * the disparity, on Mac OS X, it will be set inside a static block. + */ + static public int BUTTON_HEIGHT = 24; + + // indents and spacing standards. these probably need to be modified + // per platform as well, since macosx is so huge, windows is smaller, + // and linux is all over the map + + static final int GUI_BIG = 13; + + static final int GUI_BETWEEN = 10; + + static final int GUI_SMALL = 6; + + // gui elements + + int wide, high; + + JLabel label; + + JLabel labelBack; + + JButton resetButton; + + JButton closeButton; + + // the calling editor, so updates can be applied + + Editor editor; + + public Schematics(File path) { + super("Schematics"); + + image = Toolkit.getDefaultToolkit().createImage(path.getAbsolutePath()); + + // dialog = new JFrame("Schematics"); + setResizable(true); + // setBackground(Color.white); + // dialog.setContentPane(new JLabel(new ImageIcon(image))); + + Container pain = getContentPane(); + + pain.setBackground(Color.white); + pain.setLayout(null); + + int top = GUI_BIG; + int left = GUI_BIG; + int right = 0; + + // to override bug on OSX setting the JFrame background color + labelBack = new JLabel(); + + label = new JLabel(new ImageIcon(image)); + // System.out.println(label.getPreferredSize()); + Dimension d = label.getPreferredSize(); + label.addMouseMotionListener(new MouseMotionListener() { + public void mouseDragged(MouseEvent e) { + // Base.openFolder(Base.getSettingsFolder()); + x2 = e.getX(); + y2 = e.getY(); + diagramX += x2 - x1; + diagramY += y2 - y1; + Dimension d = label.getPreferredSize(); + Dimension d1 = getSize(); + diagramX = Math.max(d1.width - (d.width + GUI_BIG), diagramX); + diagramX = Math.min(GUI_BIG, diagramX); + diagramY = Math + .max( + d1.height + - (d.height + GUI_BIG + GUI_BETWEEN + BUTTON_HEIGHT + + GUI_BIG + GUI_BIG), diagramY); + diagramY = Math.min(GUI_BIG, diagramY); + label.setBounds(diagramX, diagramY, d.width, d.height); + // System.out.println("dragging"); + } + + public void mouseMoved(MouseEvent e) { + } + }); + + label.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + x1 = e.getX(); + y1 = e.getY(); + // System.out.println("pressed at "+x1+" "+y1); + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + }); + + label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + pain.add(label); + label.setBounds(left, top, d.width, d.height); + + right = Math.max(right, left + d.width); + top += d.height; // + GUI_SMALL; + + resetButton = new JButton(PROMPT_RESETVIEW); + resetButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + diagramX = GUI_BIG; + diagramY = GUI_BIG; + Dimension d = label.getPreferredSize(); + label.setBounds(diagramX, diagramY, d.width, d.height); + } + }); + + pain.add(resetButton); + BUTTON_HEIGHT = resetButton.getPreferredSize().height; + + int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); + resetButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); + h += BUTTON_WIDTH + GUI_SMALL; + + // h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); + // h += BUTTON_WIDTH + GUI_SMALL; + + closeButton = new JButton(PROMPT_CLOSE); + closeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + disposeFrame(); + } + }); + pain.add(closeButton); + closeButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); + + top += BUTTON_HEIGHT + GUI_BETWEEN; + + // finish up + + wide = right + GUI_BIG; + high = top + GUI_SMALL; + + // closing the window is same as hitting close button + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + disposeFrame(); + } + }); + + ActionListener disposer = new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + disposeFrame(); + } + }; + + Base.registerWindowCloseKeys(getRootPane(), disposer); + if (!Base.isMacOS()) + Base.setIcon(this); + + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + setLocation((screen.width - wide) / 2, (screen.height - high) / 2); + + pack(); // get insets + Insets insets = getInsets(); + setSize(Math.min(screen.width, wide + insets.left + insets.right), Math + .min(screen.height, high + insets.top + insets.bottom)); + + labelBack.setOpaque(true); + labelBack.setBackground(Color.white); + labelBack.setBounds(0, 0, screen.width, screen.height); + pain.add(labelBack); + + getContentPane().setBackground(Color.white); + // handle window closing commands for ctrl/cmd-W or hitting ESC. + addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + Dimension d = getSize(); + int top = d.height - (BUTTON_HEIGHT + GUI_BETWEEN + GUI_BIG + GUI_BIG); + int left = GUI_BIG; + int right = Math.max(0, d.width - (left + GUI_BIG)); + int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); + resetButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); + h += BUTTON_WIDTH + GUI_SMALL; + closeButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); + } + }); + + pain.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + // System.out.println(e); + KeyStroke wc = Base.WINDOW_CLOSE_KEYSTROKE; + if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) + || (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) { + disposeFrame(); + } + } + }); + } + + public Dimension getPreferredSize() { + return new Dimension(wide, high); + } + + // ................................................................. + + /** + * Close the window after an OK or Cancel. + */ + protected void disposeFrame() { + editor.toolbar.deactivate(EditorToolbar.SCHEMATICS); + dispose(); + } + + protected void applyFrame() { + + } + + protected void showFrame(Editor editor) { + this.editor = editor; + setVisible(true); + } + +} diff --git a/build/shared/lib/theme/buttons.gif b/build/shared/lib/theme/buttons.gif index 4de0905d23dec4147b7d56b70b3a91950cd355e9..f0a9c89e0c02936b7640e07d643c3452c90fa3f2 100644 GIT binary patch delta 3061 zcmc(g`9Bj51IM>9n`@hrG33mVv-CwOVPPufZV?UNn7QW2kz;1F4TYj|lhRa_yQS3Z zQFN1Ia}|=K91%8QJ>TblcwVpX`ycqc-k)FIRMZn?X-6jq%fkV)fFQtZqcj^x{`2qh zZ|~#&pZbP?fB4_E0H~-yL+l{AspjoX9kD%C=QmVwJZt+Tt z?phT={vNhQuKZ;A8`6ERO0P%$@9$s#&VA^uEb$%ChIVBHy{-5rrJz6BX8whnsg8^s zZ<7&IjW`leZ`VQEvMT$rVKB+2!~306gvL1f-?Q-~MWv-_dUluE-1uf^*W1M^(kMVObp4K(+SagqhTX1{FGoF*p9N!K2q}y*6`;9M?krv% z;+hb(Z?a@JDxH)WW&m9#G^Uu9qaXv3$AV9I{lnO zjaUf7ZK7(n-X{kb>{oV~N9GATuIF3TwI+{}A{y47_Z>#KvsB^s#;U}RK5d5}yab(!vxv8`KWk+3M zbowO$6YK7p4dNL3m3E(W{#_&HhQSXa9D_m&su zr7V7yCI4j~+mFaH-s6dg_D}3B|J8nY=7E;+&}j^?b@!t6u*<;GGr`itH;S={#>0Y`U1H{LS&~YfvMY}f`k(T%PsPy`9?wA`##d9NN#w5I zB1f(%G5YdBPo`XSt%Ft*BJ)5>fSnK2=Fmt~Cgk3EVw|lqINF$v* zFo_gv09mPnkDwur$h1Eu|MYYqZP3 zyvTEbfQ1RBJ^#~8}b2#Xa6JeMR8EFKnHA z@+LSVpK8!sEeopxX!2LZ-qF4Ry{hcBX#MKl=hCh2CAmcB<`v#n*@x`MU`(wGa^gkP z`2Cf|*w9r{775n{2iaJws)J+}wV5DUJk*hYt7OS==Gbv3EN!l@fM7`0I%0t83;p~n zAG;Q4rWOiF0&##$A=(bI`ogS?l7j242CHX(*m0IGVb+Bl_$rBY5B4mfXzT3Xbn4H| z?WOyrXoF6pfG2)ZSdIhwo206j2LV+epDwP!9%6si#x-j4wwnF0o>%hJp^~Av8C;*w zP}qoTN*F?K>v99rkgOe@8frvU_-JzqUD#54uD;TWmo!x7Q<&$vIFIfB-q(s6s;$@7 zISWrl!(2LVSP?j4m+??E310)6|E9#Q&9H(Mq-Pqb;SRjVZrpc2Vi~joI;}w{rEOTTBUa}a-MzM z+A;$ODAclJOZNb?AJ+x6-iz^j+cjg=*U?lHuFz5|HscVTEz=k%)0j9`Iu+O2lNl1G zg~Hdu*mtkDY5<#D&u{6RV4}1G;X!(nCa?`I(wY?4naG0)nv18T8ySbQCwRt!%BVPv zz1`A|U~&br?L+1x3|1vb@dfYIimC|>Vrk37xl)eN0}P{&25q!o@9CAT%X+{M+*(0u z{+3=YsFdc*>MFkW@{UPveCA87#Wu{IIxplrn-Ugpz9YCai%NL!X3U>%z9;22m(8A@ zwHn?0kocjwLhx?(yDC@es3oNe{9epJg{w)1k=LrQu5)O?W|C`SXSMDQNY7RKQ-Ob6 zjn=h!m*f(S3fOwJtr5|!pnagyA9^1>o{t{G4_c5~(C1{s&Q@L;EO`FcLrDD(zsf4! zQwj5jN-xLi|0LjN4Wlfq5T(sC|lA-pKipX?;Fj9 zlg&m3cxi155AYwyoJs7)2zpw$$rf1l36ZN&5sJ{{#TZ5qV;i*zU2tqd4g?Q*YI7{rdqn7 zEyE7?ftU~XnGuLuKR{NaQq9`c%^_rAx0lNb@kcv&wovsj6YH3fkOC*1(Pusw=k`ehrJ1L1pFlMfE8Em^QBOU{7CL=3WYy{h1 zlKg(TZH@gr)4e@b<8pB@#ClRd7niL|1>Mx;uDg9~QQJ11vxJIER+EoSBH_RLZYIz6 zV0Su?xbys>p~KzbW!H02|H`upVzVQ zb8`W3(RZ_@l;w})X+=2s(12PR$jrtLHhY(F
    _3CT4Vo9m8MdYpiojcXrDMF_)| z6E4XXrO)$Hym*nD=J8RSq$3FN;9lqzjyRi@LY;y9llr|k5ndq?F08~atk|WHOIIwy z2NEKcp{YU^^?Cv#2q3l(6I<+%K8hq-G7xscD6a&XRZ+@ovIXTYT&f$Bh$2v=5<$nH zlF<#2tbAxpuec2^W7{H>(I!?gM1mfmyCaDNK5dajJH)3E5~vFfj3tTG7^?ham}!Wa~tZZiE*JFUs(={gtb hbiy}w)U1%Oz|UP0=KfU7TeZwv!{zOf6GH%w{1=D}RP+D< delta 2877 zcmc(bi9Ztz1IK5^=9(>Mj@d{kk0TX1YBoks(j-R+Id;&ah?yL-%a$TaIdbQTr-zUy zOkpV0(luiW&yQAcvDZgQ=lIxt-YZQnf`iioZ!(jh z`AJwjZZ(mQs8D@<$R&2m^Q@x;ls^`p=+HEA@Q#cM{rFVuw!4GO_wAW17qgw&9G|G2 z?|HkDqgH^ih?7|OaXjhgZU&7QQPC5_@n7Xpco=8 zG}{Fj;6X1}Ua087*ZQmn@uH#Sy`=TwbLUz`ic{JA4ZwlapV;y1%m2Yngx2DB`uy*l z{IOW8jNa_XJ;mQzd335ByL6@FSA(Ze=2wSj0htkij{VC){4FLFFb8H)TS zKEQ2b-%h2yZa~UvG~2mQSD2aHU_f>gzy)oQY%p<2&Vh=V@~BIa@4)U(#J970SLj23 zmPwN}I-#4e1oMD0IZ1zRmO!qaE&h!90jvYsB7t!73IMJ&4O}`F47Y(5E2y4#o>!_* z@OPtKhV(#EmCNxr|5DLc81!`#=tif5;ei0*B-eRtIP;7#0H(rtC8+6OcKWAc#Pe7T z5SC|`EmAxrK58~%(fFKRRsV?gY<;?gOMXpFv3(CaA?xe6u(x~*GD^u`mAx* z+1-jQ$swLvIE_geP|4wd_*zt+oq?&of(bj=KngFbTujeQ+a{nwyp+o3(l z&i%$Px5Xn;=v33v#z#~ej7#AVatECX=j7L&*Ix|)v=7+rsVy%J2eOD(yaTYpo!aENN7FR#cg^Y za~tM8*&*lsG6X^Mor0-5)~8=g0%~-Py>g^?Dv6!(P(LR43FLr;5( zhbU&;yQuyU1e!675yWPIfs1Z-HwNYDR>gCLFfTpcdo0BYLsgXX8@&9qF)OvNo1khw+O!+K~;#eL0T^C)hVBg5VxTb$0k?An_O>q1`L}@GvUA_>gY&YODAww5Vfm~p& zIB88rkA)3<@`vDtX%>8V!?GHHzT^tUff+)k%ML zh&6}(wrZcY3eD_`VDW=Se|<`mbSEMrR+M%7XEeg`2f@H8nIHl=&YLW6NtWZ1NyHeY zb^O=4WO&sLmELHz-Z*n4SeBZq;7AH0kZ5THeJZsio?(l%$=R5F*_D0VnC15%q-8V2GA->WA=G9w?V2Vh#)cE?%b`#?2jMV) G-G2d&RjrW# From fc90fa7d9da449c23b7872f414a28b6f03821a5b Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 16 Aug 2011 17:51:19 -0400 Subject: [PATCH 07/30] Showing progress during compilation as well as upload. --- app/src/processing/app/Editor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 92a516eb6..177fc8527 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1830,7 +1830,7 @@ public class Editor extends JFrame implements RunnerListener { internalCloseRunner(); running = true; toolbar.activate(EditorToolbar.RUN); - statusNotice("Compiling..."); + status.progress("Compiling sketch..."); // do this to advance/clear the terminal window / dos prompt / etc for (int i = 0; i < 10; i++) System.out.println(); From 682b58e5776f7d62513071a1bcafb5e57c329a79 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 17 Aug 2011 13:53:49 -0400 Subject: [PATCH 08/30] Integrating Stream searching & parsing (Michael Margolis) This from Michael's TextFinder library, incorporated into the Stream class: find(), findUntil(), parseInt(), parseFloat(), readChars(), readCharsUntil(), readCharsBetween(), setTimeout(). --- hardware/arduino/cores/arduino/Stream.cpp | 244 ++++++++++++++++++++++ hardware/arduino/cores/arduino/Stream.h | 64 ++++++ 2 files changed, 308 insertions(+) create mode 100644 hardware/arduino/cores/arduino/Stream.cpp diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp new file mode 100644 index 000000000..dea0aff0c --- /dev/null +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -0,0 +1,244 @@ +/* + Stream.cpp - adds parsing methods to Stream class + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Created July 2011 + parsing functions based on TextFinder library by Michael Margolis + */ + +#include "Arduino.h" +#include "Stream.h" + +#define PARSE_TIMEOUT 5 // default number of seconds to wait +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field + +// private method to read stream with timeout +int Stream::timedRead() +{ + //Serial.println(_timeout); + this->_startMillis = millis(); + while(millis() - this->_startMillis < (this->_timeout * 1000L)) + { + if (this->available() > 0) { + return this->read(); + } + } + return -1; // -1 indicates timeout +} + +// returns the next digit in the stream or -1 if timeout +// discards non-numeric characters +int Stream::getNextDigit() +{ + int c; + do{ + c = timedRead(); + if( c < 0) + return c; // timeout + } + while( c != '-' && (c < '0' || c > '9') ) ; + +return c; +} + +// Public Methods +////////////////////////////////////////////////////////////// + +void Stream::setTimeout( long timeout) // sets the maximum number of seconds to wait +{ + this->_timeout = timeout; +} + + // find returns true if the target string is found +bool Stream::find(char *target) +{ + return findUntil(target, NULL); +} + +// reads data from the stream until the target string of given length is found +// returns true if target string is found, false if timed out +bool Stream::find(char *target, size_t length) +{ + return findUntil(target, length, NULL, 0); +} + +// as find but search ends if the terminator string is found +bool Stream::findUntil(char *target, char *terminator) +{ + return findUntil(target, strlen(target), terminator, strlen(terminator)); +} + +// reads data from the stream until the target string of the given length is found +// search terminated if the terminator string is found +// returns true if target string is found, false if terminated or timed out +bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) +{ + size_t index = 0; // maximum target string length is 64k bytes! + size_t termIndex = 0; + int c; + + if( *target == 0) + return true; // return true if target is a null string + while( (c = timedRead()) > 0){ + if( c == target[index]){ + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + if(++index >= targetLen){ // return true if all chars in the target match + return true; + } + } + else{ + index = 0; // reset index if any char does not match + } + if(termLen > 0 && c == terminator[termIndex]){ + if(++termIndex >= termLen) + return false; // return false if terminate string found before target string + } + else + termIndex = 0; + } + return false; +} + + +// returns the first valid (long) integer value from the current position. +// initial characters that are not digits (or the minus sign) are skipped +// function is terminated by the first character that is not a digit. +long Stream::parseInt() +{ + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +} + +// as above but a given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +long Stream::parseInt(char skipChar) +{ + boolean isNegative = false; + long value = 0; + int c; + + c = getNextDigit(); + // ignore non numeric leading characters + if(c < 0) + return 0; // zero returned if timeout + + do{ + if(c == skipChar) + ; // ignore this charactor + else if(c == '-') + isNegative = true; + else if(c >= '0' && c <= '9') // is c a digit? + value = value * 10 + c - '0'; + c = timedRead(); + } + while( (c >= '0' && c <= '9') || c == skipChar ); + + if(isNegative) + value = -value; + return value; +} + + +// as parseInt but returns a floating point value +float Stream::parseFloat() +{ + parseFloat(NO_SKIP_CHAR); +} + +// as above but the given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +float Stream::parseFloat(char skipChar){ + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + float fValue; + char c; + float fraction = 1.0; + + c = getNextDigit(); + // ignore non numeric leading characters + if(c < 0) + return 0; // zero returned if timeout + + do{ + if(c == skipChar) + ; // ignore + else if(c == '-') + isNegative = true; + else if (c == '.') + isFraction = true; + else if(c >= '0' && c <= '9') { // is c a digit? + value = value * 10 + c - '0'; + if(isFraction) + fraction *= 0.1; + } + c = timedRead(); + } + while( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); + + if(isNegative) + value = -value; + if(isFraction) + return value * fraction; + else + return value; +} + +// read characters from stream into buffer +// terminates if length characters have been read, null is detected or timeout (see setTimeout) +// returns the number of characters placed in the buffer (0 means no valid data found) +int Stream::readChars( char *buffer, size_t length) +{ + return readCharsUntil( 0, buffer, length); +} + + +// as readChars with terminator character +// terminates if length characters have been read, timeout, or if the terminator character detected +// returns the number of characters placed in the buffer (0 means no valid data found) + +int Stream::readCharsUntil( char terminator, char *buffer, size_t length) +{ + int index = 0; + *buffer = 0; + while(index < length ){ + int c = timedRead(); + if( c <= 0 ){ + return 0; // timeout returns 0 ! + } + else if( c == terminator){ + buffer[index] = 0; // terminate the string + return index; // data got successfully + } + else{ + buffer[index++] = (char)c; + } + } + buffer[index] = 0; + return index; // here if buffer is full before detecting the terminator +} + + +// read characters found between pre_string and terminator into a buffer +// terminated when the terminator character is matched or the buffer is full +// returns the number of bytes placed in the buffer (0 means no valid data found) +int Stream::readCharsBetween( char *pre_string, char terminator, char *buffer, size_t length) +{ + if( find( pre_string) ){ + return readCharsUntil(terminator, buffer, length); + } + return 0; //failed to find the prestring +} diff --git a/hardware/arduino/cores/arduino/Stream.h b/hardware/arduino/cores/arduino/Stream.h index 93d8275dc..3f763924c 100644 --- a/hardware/arduino/cores/arduino/Stream.h +++ b/hardware/arduino/cores/arduino/Stream.h @@ -15,6 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + parsing functions based on TextFinder library by Michael Margolis */ #ifndef Stream_h @@ -23,13 +25,75 @@ #include #include "Print.h" +// compatability macros for testing +/* +#define getInt() parseInt() +#define getInt(skipChar) parseInt(skipchar) +#define getFloat() parseFloat() +#define getFloat(skipChar) parseFloat(skipChar) +#define getString( pre_string, post_string, buffer, length) +readBytesBetween( pre_string, terminator, buffer, length) +*/ + class Stream : public Print { + private: + long _timeout; // number of seconds to wait for the next char before aborting timed read + long _startMillis; // used for timeout measurement + int timedRead(); // private method to read stream with timeout + int getNextDigit(); // returns the next numeric digit in the stream or -1 if timeout + public: virtual int available() = 0; virtual int read() = 0; virtual int peek() = 0; virtual void flush() = 0; + + Stream() {_timeout=5;} + +// parsing methods + + void setTimeout(long timeout); // sets maximum seconds to wait for stream data, default is 5 seconds + + bool find(char *target); // reads data from the stream until the target string is found + // returns true if target string is found, false if timed out (see setTimeout) + + bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found + // returns true if target string is found, false if timed out + + bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found + + bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found + + + long parseInt(); // returns the first valid (long) integer value from the current position. + // initial characters that are not digits (or the minus sign) are skipped + // integer is terminated by the first character that is not a digit. + + long parseInt(char skipChar); // as above but the given skipChar is ignored + // as above but the given skipChar is ignored + // this allows format characters (typically commas) in values to be ignored + + float parseFloat(); // float version of parseInt + + float parseFloat(char skipChar); // as above but the given skipChar is ignored + + int readChars( char *buffer, size_t length); // read chars from stream into buffer + // terminates if length characters have been read or timeout (see setTimeout) + // returns the number of characters placed in the buffer (0 means no valid data found) + + int readCharsUntil( char terminator, char *buffer, size_t length); // as readChars with terminator character + // terminates if length characters have been read, timeout, or if the terminator character detected + // returns the number of characters placed in the buffer (0 means no valid data found) + + int readCharsBetween( char *pre_string, char terminator, char *buffer, size_t length); + // read characters found between pre_string and terminator into a buffer + // terminated when the terminator character is matched or the buffer is full + // returns the number of bytes placed in the buffer (0 means no valid data found) + + + // Arduino String functions to be added here + }; #endif From cb39ad97399372111ebcb61b10265556d68c071c Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 17 Aug 2011 14:16:47 -0400 Subject: [PATCH 09/30] A few API changes to new Stream parsing functions. Renamed readChars() -> readBytes(), readCharsUntil() -> readBytesUntil(). Changed timeouts to milliseconds from seconds; default from 5 to 1 seconds. Removed readCharsBetween(). --- build/shared/lib/keywords.txt | 7 +++++++ hardware/arduino/cores/arduino/Stream.cpp | 25 +++++++---------------- hardware/arduino/cores/arduino/Stream.h | 16 +++++---------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/build/shared/lib/keywords.txt b/build/shared/lib/keywords.txt index 8859d3b84..730de4e75 100644 --- a/build/shared/lib/keywords.txt +++ b/build/shared/lib/keywords.txt @@ -172,6 +172,13 @@ print KEYWORD2 Serial_Print println KEYWORD2 Serial_Println available KEYWORD2 Serial_Available flush KEYWORD2 Serial_Flush +setTimeout KEYWORD2 +find KEYWORD2 +findUntil KEYWORD2 +parseInt KEYWORD2 +parseFloat KEYWORD2 +readBytes KEYWORD2 +readBytesUntil KEYWORD2 setup KEYWORD3 Setup loop KEYWORD3 Loop diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp index dea0aff0c..bf8304f2d 100644 --- a/hardware/arduino/cores/arduino/Stream.cpp +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -23,7 +23,7 @@ #include "Arduino.h" #include "Stream.h" -#define PARSE_TIMEOUT 5 // default number of seconds to wait +#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait #define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field // private method to read stream with timeout @@ -31,7 +31,7 @@ int Stream::timedRead() { //Serial.println(_timeout); this->_startMillis = millis(); - while(millis() - this->_startMillis < (this->_timeout * 1000L)) + while(millis() - this->_startMillis < this->_timeout) { if (this->available() > 0) { return this->read(); @@ -58,7 +58,7 @@ return c; // Public Methods ////////////////////////////////////////////////////////////// -void Stream::setTimeout( long timeout) // sets the maximum number of seconds to wait +void Stream::setTimeout( long timeout) // sets the maximum number of milliseconds to wait { this->_timeout = timeout; } @@ -200,17 +200,17 @@ float Stream::parseFloat(char skipChar){ // read characters from stream into buffer // terminates if length characters have been read, null is detected or timeout (see setTimeout) // returns the number of characters placed in the buffer (0 means no valid data found) -int Stream::readChars( char *buffer, size_t length) +int Stream::readBytes( char *buffer, size_t length) { - return readCharsUntil( 0, buffer, length); + return readBytesUntil( 0, buffer, length); } -// as readChars with terminator character +// as readBytes with terminator character // terminates if length characters have been read, timeout, or if the terminator character detected // returns the number of characters placed in the buffer (0 means no valid data found) -int Stream::readCharsUntil( char terminator, char *buffer, size_t length) +int Stream::readBytesUntil( char terminator, char *buffer, size_t length) { int index = 0; *buffer = 0; @@ -231,14 +231,3 @@ int Stream::readCharsUntil( char terminator, char *buffer, size_t length) return index; // here if buffer is full before detecting the terminator } - -// read characters found between pre_string and terminator into a buffer -// terminated when the terminator character is matched or the buffer is full -// returns the number of bytes placed in the buffer (0 means no valid data found) -int Stream::readCharsBetween( char *pre_string, char terminator, char *buffer, size_t length) -{ - if( find( pre_string) ){ - return readCharsUntil(terminator, buffer, length); - } - return 0; //failed to find the prestring -} diff --git a/hardware/arduino/cores/arduino/Stream.h b/hardware/arduino/cores/arduino/Stream.h index 3f763924c..1633f15d5 100644 --- a/hardware/arduino/cores/arduino/Stream.h +++ b/hardware/arduino/cores/arduino/Stream.h @@ -38,7 +38,7 @@ readBytesBetween( pre_string, terminator, buffer, length) class Stream : public Print { private: - long _timeout; // number of seconds to wait for the next char before aborting timed read + long _timeout; // number of milliseconds to wait for the next char before aborting timed read long _startMillis; // used for timeout measurement int timedRead(); // private method to read stream with timeout int getNextDigit(); // returns the next numeric digit in the stream or -1 if timeout @@ -49,11 +49,11 @@ class Stream : public Print virtual int peek() = 0; virtual void flush() = 0; - Stream() {_timeout=5;} + Stream() {_timeout=1000;} // parsing methods - void setTimeout(long timeout); // sets maximum seconds to wait for stream data, default is 5 seconds + void setTimeout(long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second bool find(char *target); // reads data from the stream until the target string is found // returns true if target string is found, false if timed out (see setTimeout) @@ -78,20 +78,14 @@ class Stream : public Print float parseFloat(char skipChar); // as above but the given skipChar is ignored - int readChars( char *buffer, size_t length); // read chars from stream into buffer + int readBytes( char *buffer, size_t length); // read chars from stream into buffer // terminates if length characters have been read or timeout (see setTimeout) // returns the number of characters placed in the buffer (0 means no valid data found) - int readCharsUntil( char terminator, char *buffer, size_t length); // as readChars with terminator character + int readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character // terminates if length characters have been read, timeout, or if the terminator character detected // returns the number of characters placed in the buffer (0 means no valid data found) - int readCharsBetween( char *pre_string, char terminator, char *buffer, size_t length); - // read characters found between pre_string and terminator into a buffer - // terminated when the terminator character is matched or the buffer is full - // returns the number of bytes placed in the buffer (0 means no valid data found) - - // Arduino String functions to be added here }; From ac3f093b76e5a5a907dc9b5f9c650e3dfd1a12a0 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 18 Aug 2011 14:54:42 -0400 Subject: [PATCH 10/30] Revert "Added Schematic view (from wiring)." This reverts commit ccb318c2abd193269236141324d04e421a50e44e. --- app/src/processing/app/Base.java | 11 - app/src/processing/app/Editor.java | 26 +-- app/src/processing/app/EditorToolbar.java | 45 ++-- app/src/processing/app/Schematics.java | 273 ---------------------- build/shared/lib/theme/buttons.gif | Bin 3513 -> 3331 bytes 5 files changed, 14 insertions(+), 341 deletions(-) delete mode 100644 app/src/processing/app/Schematics.java diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 97e9f57e1..036cb4f5a 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -436,17 +436,6 @@ public class Base { // ................................................................. - /** Command on Mac OS X, Ctrl on Windows and Linux */ - static final int SHORTCUT_KEY_MASK = - Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - /** Command-W on Mac OS X, Ctrl-W on Windows and Linux */ - static final KeyStroke WINDOW_CLOSE_KEYSTROKE = - KeyStroke.getKeyStroke('W', SHORTCUT_KEY_MASK); - /** Command-Option on Mac OS X, Ctrl-Alt on Windows and Linux */ - static final int SHORTCUT_ALT_KEY_MASK = ActionEvent.ALT_MASK | - Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - - // Because of variations in native windowing systems, no guarantees about // changes to the focused and active Windows can be made. Developers must // never assume that this Window is the focused or active Window until this diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 177fc8527..fa0544a1e 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -99,8 +99,6 @@ public class Editor extends JFrame implements RunnerListener { static SerialMenuListener serialMenuListener; static SerialMonitor serialMonitor; - Schematics schematics; - EditorHeader header; EditorStatus status; EditorConsole console; @@ -627,16 +625,6 @@ public class Editor extends JFrame implements RunnerListener { // } // }); // sketchMenu.add(item); - - sketchMenu.addSeparator(); - - item = new JMenuItem("Show schematics"); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleSchematics(); - } - }); - sketchMenu.add(item); sketchMenu.addSeparator(); @@ -1906,6 +1894,7 @@ public class Editor extends JFrame implements RunnerListener { return sketchWindowLocation; } + /** * Implements Sketch → Stop, or pressing Stop on the toolbar. */ @@ -1922,19 +1911,6 @@ public class Editor extends JFrame implements RunnerListener { } - public void handleSchematics() { // called by menu or buttons - //String s = sketch.getFolder().getAbsolutePath() + File.separator + sketch.getName() + ".png"; - File file = new File(sketch.getFolder(), sketch.getName() + ".png"); - if (file.exists()) { - if (schematics == null) - schematics = new Schematics(file); - schematics.showFrame(this); - } else { - statusNotice("This sketch doesn't include schematics"); - } - } - - /** * Deactivate the Run button. This is called by Runner to notify that the * sketch has stopped running, usually in response to an error (or maybe diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 1f3a68231..9d7a5fc13 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -37,7 +37,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key /** Rollover titles for each button. */ static final String title[] = { - "Verify", "Upload", "New", "Open", "Save", "Show Schematics", "Serial Monitor" + "Verify", "Upload", "New", "Open", "Save", "Serial Monitor" }; /** Titles for each button when the shift key is pressed. */ @@ -56,20 +56,18 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key static final int BUTTON_IMAGE_SIZE = 33; - static final int RUN = 0; - static final int EXPORT = 1; + static final int RUN = 0; + static final int EXPORT = 1; - static final int NEW = 2; - static final int OPEN = 3; - static final int SAVE = 4; - static final int SCHEMATICS = 5; + static final int NEW = 2; + static final int OPEN = 3; + static final int SAVE = 4; - static final int SERIAL = 6; + static final int SERIAL = 5; static final int INACTIVE = 0; static final int ROLLOVER = 1; static final int ACTIVE = 2; - static final int DISABLED = 3; Editor editor; @@ -110,7 +108,6 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key which[buttonCount++] = NEW; which[buttonCount++] = OPEN; which[buttonCount++] = SAVE; - which[buttonCount++] = SCHEMATICS; which[buttonCount++] = SERIAL; currentRollover = -1; @@ -261,9 +258,8 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key for (int i = 0; i < buttonCount; i++) { if ((y > y1) && (x > x1[i]) && (y < y2) && (x < x2[i])) { - if (state[i] != DISABLED) { - return i; - } + //System.out.println("sel is " + i); + return i; } } return -1; @@ -271,12 +267,10 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key private void setState(int slot, int newState, boolean updateAfter) { - if (state[slot]!=DISABLED) { - state[slot] = newState; - stateImage[slot] = buttonImages[which[slot]][newState]; - if (updateAfter) { - repaint(); - } + state[slot] = newState; + stateImage[slot] = buttonImages[which[slot]][newState]; + if (updateAfter) { + repaint(); } } @@ -344,10 +338,6 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key editor.handleExport(e.isShiftDown()); break; - case SCHEMATICS: - editor.handleSchematics(); - break; - case SERIAL: editor.handleSerial(); break; @@ -381,15 +371,6 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key } - public void disable(int what) { - if (buttonImages != null && which!=null && state!=null && stateImage!=null) { - state[what] = DISABLED; - stateImage[what] = buttonImages[which[what]][INACTIVE]; - repaint(); - } - } - - public Dimension getPreferredSize() { return getMinimumSize(); } diff --git a/app/src/processing/app/Schematics.java b/app/src/processing/app/Schematics.java deleted file mode 100644 index c29d01663..000000000 --- a/app/src/processing/app/Schematics.java +++ /dev/null @@ -1,273 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Wiring project - http://wiring.org.co - - Copyright (c) 2009-11 Hernando Barragan - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package processing.app; - -import java.awt.*; -import java.awt.event.*; -import java.io.*; - -import javax.swing.*; - -public class Schematics extends JFrame { - private static final long serialVersionUID = 3254345343658939796L; - - // prompt text stuff - Image image; - - int diagramX = 0, diagramY = 0; - - int x1, y1, x2, y2; - - static final String PROMPT_CLOSE = "Close"; - - static final String PROMPT_RESETVIEW = "Reset"; - - /** - * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, - * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. - */ - static public int BUTTON_WIDTH = 80; - - /** - * Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29, presumably - * because it now includes the blue border, where it didn't in Java 1.3. - * Windows XP only wants 23 (not sure what default Linux would be). Because of - * the disparity, on Mac OS X, it will be set inside a static block. - */ - static public int BUTTON_HEIGHT = 24; - - // indents and spacing standards. these probably need to be modified - // per platform as well, since macosx is so huge, windows is smaller, - // and linux is all over the map - - static final int GUI_BIG = 13; - - static final int GUI_BETWEEN = 10; - - static final int GUI_SMALL = 6; - - // gui elements - - int wide, high; - - JLabel label; - - JLabel labelBack; - - JButton resetButton; - - JButton closeButton; - - // the calling editor, so updates can be applied - - Editor editor; - - public Schematics(File path) { - super("Schematics"); - - image = Toolkit.getDefaultToolkit().createImage(path.getAbsolutePath()); - - // dialog = new JFrame("Schematics"); - setResizable(true); - // setBackground(Color.white); - // dialog.setContentPane(new JLabel(new ImageIcon(image))); - - Container pain = getContentPane(); - - pain.setBackground(Color.white); - pain.setLayout(null); - - int top = GUI_BIG; - int left = GUI_BIG; - int right = 0; - - // to override bug on OSX setting the JFrame background color - labelBack = new JLabel(); - - label = new JLabel(new ImageIcon(image)); - // System.out.println(label.getPreferredSize()); - Dimension d = label.getPreferredSize(); - label.addMouseMotionListener(new MouseMotionListener() { - public void mouseDragged(MouseEvent e) { - // Base.openFolder(Base.getSettingsFolder()); - x2 = e.getX(); - y2 = e.getY(); - diagramX += x2 - x1; - diagramY += y2 - y1; - Dimension d = label.getPreferredSize(); - Dimension d1 = getSize(); - diagramX = Math.max(d1.width - (d.width + GUI_BIG), diagramX); - diagramX = Math.min(GUI_BIG, diagramX); - diagramY = Math - .max( - d1.height - - (d.height + GUI_BIG + GUI_BETWEEN + BUTTON_HEIGHT - + GUI_BIG + GUI_BIG), diagramY); - diagramY = Math.min(GUI_BIG, diagramY); - label.setBounds(diagramX, diagramY, d.width, d.height); - // System.out.println("dragging"); - } - - public void mouseMoved(MouseEvent e) { - } - }); - - label.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - x1 = e.getX(); - y1 = e.getY(); - // System.out.println("pressed at "+x1+" "+y1); - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { - } - }); - - label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - pain.add(label); - label.setBounds(left, top, d.width, d.height); - - right = Math.max(right, left + d.width); - top += d.height; // + GUI_SMALL; - - resetButton = new JButton(PROMPT_RESETVIEW); - resetButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - diagramX = GUI_BIG; - diagramY = GUI_BIG; - Dimension d = label.getPreferredSize(); - label.setBounds(diagramX, diagramY, d.width, d.height); - } - }); - - pain.add(resetButton); - BUTTON_HEIGHT = resetButton.getPreferredSize().height; - - int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); - resetButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); - h += BUTTON_WIDTH + GUI_SMALL; - - // h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); - // h += BUTTON_WIDTH + GUI_SMALL; - - closeButton = new JButton(PROMPT_CLOSE); - closeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - disposeFrame(); - } - }); - pain.add(closeButton); - closeButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); - - top += BUTTON_HEIGHT + GUI_BETWEEN; - - // finish up - - wide = right + GUI_BIG; - high = top + GUI_SMALL; - - // closing the window is same as hitting close button - - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - disposeFrame(); - } - }); - - ActionListener disposer = new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - disposeFrame(); - } - }; - - Base.registerWindowCloseKeys(getRootPane(), disposer); - if (!Base.isMacOS()) - Base.setIcon(this); - - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - setLocation((screen.width - wide) / 2, (screen.height - high) / 2); - - pack(); // get insets - Insets insets = getInsets(); - setSize(Math.min(screen.width, wide + insets.left + insets.right), Math - .min(screen.height, high + insets.top + insets.bottom)); - - labelBack.setOpaque(true); - labelBack.setBackground(Color.white); - labelBack.setBounds(0, 0, screen.width, screen.height); - pain.add(labelBack); - - getContentPane().setBackground(Color.white); - // handle window closing commands for ctrl/cmd-W or hitting ESC. - addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent e) { - Dimension d = getSize(); - int top = d.height - (BUTTON_HEIGHT + GUI_BETWEEN + GUI_BIG + GUI_BIG); - int left = GUI_BIG; - int right = Math.max(0, d.width - (left + GUI_BIG)); - int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); - resetButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); - h += BUTTON_WIDTH + GUI_SMALL; - closeButton.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); - } - }); - - pain.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // System.out.println(e); - KeyStroke wc = Base.WINDOW_CLOSE_KEYSTROKE; - if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) - || (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) { - disposeFrame(); - } - } - }); - } - - public Dimension getPreferredSize() { - return new Dimension(wide, high); - } - - // ................................................................. - - /** - * Close the window after an OK or Cancel. - */ - protected void disposeFrame() { - editor.toolbar.deactivate(EditorToolbar.SCHEMATICS); - dispose(); - } - - protected void applyFrame() { - - } - - protected void showFrame(Editor editor) { - this.editor = editor; - setVisible(true); - } - -} diff --git a/build/shared/lib/theme/buttons.gif b/build/shared/lib/theme/buttons.gif index f0a9c89e0c02936b7640e07d643c3452c90fa3f2..4de0905d23dec4147b7d56b70b3a91950cd355e9 100644 GIT binary patch delta 2877 zcmc(bi9Ztz1IK5^=9(>Mj@d{kk0TX1YBoks(j-R+Id;&ah?yL-%a$TaIdbQTr-zUy zOkpV0(luiW&yQAcvDZgQ=lIxt-YZQnf`iioZ!(jh z`AJwjZZ(mQs8D@<$R&2m^Q@x;ls^`p=+HEA@Q#cM{rFVuw!4GO_wAW17qgw&9G|G2 z?|HkDqgH^ih?7|OaXjhgZU&7QQPC5_@n7Xpco=8 zG}{Fj;6X1}Ua087*ZQmn@uH#Sy`=TwbLUz`ic{JA4ZwlapV;y1%m2Yngx2DB`uy*l z{IOW8jNa_XJ;mQzd335ByL6@FSA(Ze=2wSj0htkij{VC){4FLFFb8H)TS zKEQ2b-%h2yZa~UvG~2mQSD2aHU_f>gzy)oQY%p<2&Vh=V@~BIa@4)U(#J970SLj23 zmPwN}I-#4e1oMD0IZ1zRmO!qaE&h!90jvYsB7t!73IMJ&4O}`F47Y(5E2y4#o>!_* z@OPtKhV(#EmCNxr|5DLc81!`#=tif5;ei0*B-eRtIP;7#0H(rtC8+6OcKWAc#Pe7T z5SC|`EmAxrK58~%(fFKRRsV?gY<;?gOMXpFv3(CaA?xe6u(x~*GD^u`mAx* z+1-jQ$swLvIE_geP|4wd_*zt+oq?&of(bj=KngFbTujeQ+a{nwyp+o3(l z&i%$Px5Xn;=v33v#z#~ej7#AVatECX=j7L&*Ix|)v=7+rsVy%J2eOD(yaTYpo!aENN7FR#cg^Y za~tM8*&*lsG6X^Mor0-5)~8=g0%~-Py>g^?Dv6!(P(LR43FLr;5( zhbU&;yQuyU1e!675yWPIfs1Z-HwNYDR>gCLFfTpcdo0BYLsgXX8@&9qF)OvNo1khw+O!+K~;#eL0T^C)hVBg5VxTb$0k?An_O>q1`L}@GvUA_>gY&YODAww5Vfm~p& zIB88rkA)3<@`vDtX%>8V!?GHHzT^tUff+)k%ML zh&6}(wrZcY3eD_`VDW=Se|<`mbSEMrR+M%7XEeg`2f@H8nIHl=&YLW6NtWZ1NyHeY zb^O=4WO&sLmELHz-Z*n4SeBZq;7AH0kZ5THeJZsio?(l%$=R5F*_D0VnC15%q-8V2GA->WA=G9w?V2Vh#)cE?%b`#?2jMV) G-G2d&RjrW# delta 3061 zcmc(g`9Bj51IM>9n`@hrG33mVv-CwOVPPufZV?UNn7QW2kz;1F4TYj|lhRa_yQS3Z zQFN1Ia}|=K91%8QJ>TblcwVpX`ycqc-k)FIRMZn?X-6jq%fkV)fFQtZqcj^x{`2qh zZ|~#&pZbP?fB4_E0H~-yL+l{AspjoX9kD%C=QmVwJZt+Tt z?phT={vNhQuKZ;A8`6ERO0P%$@9$s#&VA^uEb$%ChIVBHy{-5rrJz6BX8whnsg8^s zZ<7&IjW`leZ`VQEvMT$rVKB+2!~306gvL1f-?Q-~MWv-_dUluE-1uf^*W1M^(kMVObp4K(+SagqhTX1{FGoF*p9N!K2q}y*6`;9M?krv% z;+hb(Z?a@JDxH)WW&m9#G^Uu9qaXv3$AV9I{lnO zjaUf7ZK7(n-X{kb>{oV~N9GATuIF3TwI+{}A{y47_Z>#KvsB^s#;U}RK5d5}yab(!vxv8`KWk+3M zbowO$6YK7p4dNL3m3E(W{#_&HhQSXa9D_m&su zr7V7yCI4j~+mFaH-s6dg_D}3B|J8nY=7E;+&}j^?b@!t6u*<;GGr`itH;S={#>0Y`U1H{LS&~YfvMY}f`k(T%PsPy`9?wA`##d9NN#w5I zB1f(%G5YdBPo`XSt%Ft*BJ)5>fSnK2=Fmt~Cgk3EVw|lqINF$v* zFo_gv09mPnkDwur$h1Eu|MYYqZP3 zyvTEbfQ1RBJ^#~8}b2#Xa6JeMR8EFKnHA z@+LSVpK8!sEeopxX!2LZ-qF4Ry{hcBX#MKl=hCh2CAmcB<`v#n*@x`MU`(wGa^gkP z`2Cf|*w9r{775n{2iaJws)J+}wV5DUJk*hYt7OS==Gbv3EN!l@fM7`0I%0t83;p~n zAG;Q4rWOiF0&##$A=(bI`ogS?l7j242CHX(*m0IGVb+Bl_$rBY5B4mfXzT3Xbn4H| z?WOyrXoF6pfG2)ZSdIhwo206j2LV+epDwP!9%6si#x-j4wwnF0o>%hJp^~Av8C;*w zP}qoTN*F?K>v99rkgOe@8frvU_-JzqUD#54uD;TWmo!x7Q<&$vIFIfB-q(s6s;$@7 zISWrl!(2LVSP?j4m+??E310)6|E9#Q&9H(Mq-Pqb;SRjVZrpc2Vi~joI;}w{rEOTTBUa}a-MzM z+A;$ODAclJOZNb?AJ+x6-iz^j+cjg=*U?lHuFz5|HscVTEz=k%)0j9`Iu+O2lNl1G zg~Hdu*mtkDY5<#D&u{6RV4}1G;X!(nCa?`I(wY?4naG0)nv18T8ySbQCwRt!%BVPv zz1`A|U~&br?L+1x3|1vb@dfYIimC|>Vrk37xl)eN0}P{&25q!o@9CAT%X+{M+*(0u z{+3=YsFdc*>MFkW@{UPveCA87#Wu{IIxplrn-Ugpz9YCai%NL!X3U>%z9;22m(8A@ zwHn?0kocjwLhx?(yDC@es3oNe{9epJg{w)1k=LrQu5)O?W|C`SXSMDQNY7RKQ-Ob6 zjn=h!m*f(S3fOwJtr5|!pnagyA9^1>o{t{G4_c5~(C1{s&Q@L;EO`FcLrDD(zsf4! zQwj5jN-xLi|0LjN4Wlfq5T(sC|lA-pKipX?;Fj9 zlg&m3cxi155AYwyoJs7)2zpw$$rf1l36ZN&5sJ{{#TZ5qV;i*zU2tqd4g?Q*YI7{rdqn7 zEyE7?ftU~XnGuLuKR{NaQq9`c%^_rAx0lNb@kcv&wovsj6YH3fkOC*1(Pusw=k`ehrJ1L1pFlMfE8Em^QBOU{7CL=3WYy{h1 zlKg(TZH@gr)4e@b<8pB@#ClRd7niL|1>Mx;uDg9~QQJ11vxJIER+EoSBH_RLZYIz6 zV0Su?xbys>p~KzbW!H02|H`upVzVQ zb8`W3(RZ_@l;w})X+=2s(12PR$jrtLHhY(F
      _3CT4Vo9m8MdYpiojcXrDMF_)| z6E4XXrO)$Hym*nD=J8RSq$3FN;9lqzjyRi@LY;y9llr|k5ndq?F08~atk|WHOIIwy z2NEKcp{YU^^?Cv#2q3l(6I<+%K8hq-G7xscD6a&XRZ+@ovIXTYT&f$Bh$2v=5<$nH zlF<#2tbAxpuec2^W7{H>(I!?gM1mfmyCaDNK5dajJH)3E5~vFfj3tTG7^?ham}!Wa~tZZiE*JFUs(={gtb hbiy}w)U1%Oz|UP0=KfU7TeZwv!{zOf6GH%w{1=D}RP+D< From 4b0a87b40580c21d4daaf1c0e426985e0c27ac47 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 18 Aug 2011 15:13:47 -0400 Subject: [PATCH 11/30] Stream.readBytesUntil() now writes null terminator within length. --- hardware/arduino/cores/arduino/Stream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp index bf8304f2d..d267bf0cb 100644 --- a/hardware/arduino/cores/arduino/Stream.cpp +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -214,7 +214,7 @@ int Stream::readBytesUntil( char terminator, char *buffer, size_t length) { int index = 0; *buffer = 0; - while(index < length ){ + while(index < length-1 ){ int c = timedRead(); if( c <= 0 ){ return 0; // timeout returns 0 ! From a6c8753a80d6ccf2b168bb8609fbeb0c20a7c3cc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 19 Aug 2011 19:51:02 +0200 Subject: [PATCH 12/30] Schematic URL. Actually tag is "@schematics " that should be put inside code comments. --- app/src/processing/app/Editor.java | 82 +++++++++++++------ .../app/syntax/SyntaxUtilities.java | 70 +++++++++++++++- 2 files changed, 127 insertions(+), 25 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index fa0544a1e..e34bb4a87 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -46,6 +46,7 @@ import gnu.io.*; /** * Main editor panel for the Processing Development Environment. */ +@SuppressWarnings("serial") public class Editor extends JFrame implements RunnerListener { Base base; @@ -113,7 +114,7 @@ public class Editor extends JFrame implements RunnerListener { EditorLineStatus lineStatus; - JEditorPane editorPane; + //JEditorPane editorPane; JEditTextArea textarea; EditorListener listener; @@ -1838,7 +1839,7 @@ public class Editor extends JFrame implements RunnerListener { public void run() { try { sketch.prepare(); - String appletClassName = sketch.build(false); + sketch.build(false); statusNotice("Done compiling."); } catch (Exception e) { status.unprogress(); @@ -1855,7 +1856,7 @@ public class Editor extends JFrame implements RunnerListener { public void run() { try { sketch.prepare(); - String appletClassName = sketch.build(true); + sketch.build(true); statusNotice("Done compiling."); } catch (Exception e) { status.unprogress(); @@ -2628,25 +2629,38 @@ public class Editor extends JFrame implements RunnerListener { * Returns the edit popup menu. */ class TextAreaPopup extends JPopupMenu { - //String currentDir = System.getProperty("user.dir"); - String referenceFile = null; + //private String currentDir = System.getProperty("user.dir"); + private String referenceFile = null; - JMenuItem cutItem; - JMenuItem copyItem; - JMenuItem discourseItem; - JMenuItem referenceItem; + private JMenuItem cutItem; + private JMenuItem copyItem; + private JMenuItem discourseItem; + private JMenuItem referenceItem; + private JMenuItem openURLItem; + private JSeparator openURLItemSeparator; + private String clickedURL; public TextAreaPopup() { - JMenuItem item; - + openURLItem = new JMenuItem("Open URL"); + openURLItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Base.openURL(clickedURL); + } + }); + add(openURLItem); + + openURLItemSeparator = new JSeparator(); + add(openURLItemSeparator); + cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCut(); } }); - this.add(cutItem); + add(cutItem); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @@ -2654,7 +2668,7 @@ public class Editor extends JFrame implements RunnerListener { handleCopy(); } }); - this.add(copyItem); + add(copyItem); discourseItem = new JMenuItem("Copy for Forum"); discourseItem.addActionListener(new ActionListener() { @@ -2662,7 +2676,7 @@ public class Editor extends JFrame implements RunnerListener { handleDiscourseCopy(); } }); - this.add(discourseItem); + add(discourseItem); discourseItem = new JMenuItem("Copy as HTML"); discourseItem.addActionListener(new ActionListener() { @@ -2670,15 +2684,15 @@ public class Editor extends JFrame implements RunnerListener { handleHTMLCopy(); } }); - this.add(discourseItem); + add(discourseItem); - item = new JMenuItem("Paste"); + JMenuItem item = new JMenuItem("Paste"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handlePaste(); } }); - this.add(item); + add(item); item = new JMenuItem("Select All"); item.addActionListener(new ActionListener() { @@ -2686,9 +2700,9 @@ public class Editor extends JFrame implements RunnerListener { handleSelectAll(); } }); - this.add(item); + add(item); - this.addSeparator(); + addSeparator(); item = new JMenuItem("Comment/Uncomment"); item.addActionListener(new ActionListener() { @@ -2696,7 +2710,7 @@ public class Editor extends JFrame implements RunnerListener { handleCommentUncomment(); } }); - this.add(item); + add(item); item = new JMenuItem("Increase Indent"); item.addActionListener(new ActionListener() { @@ -2704,7 +2718,7 @@ public class Editor extends JFrame implements RunnerListener { handleIndentOutdent(true); } }); - this.add(item); + add(item); item = new JMenuItem("Decrease Indent"); item.addActionListener(new ActionListener() { @@ -2712,9 +2726,9 @@ public class Editor extends JFrame implements RunnerListener { handleIndentOutdent(false); } }); - this.add(item); + add(item); - this.addSeparator(); + addSeparator(); referenceItem = new JMenuItem("Find in Reference"); referenceItem.addActionListener(new ActionListener() { @@ -2722,11 +2736,31 @@ public class Editor extends JFrame implements RunnerListener { handleFindReference(); } }); - this.add(referenceItem); + add(referenceItem); } + private boolean clickedURL(String line, int offset) { + String[] parse = SyntaxUtilities.parseCommentUrls(line); + if (parse==null) + return false; + int pos = parse[0].length()+parse[1].length(); + if (offsetpos+2) + return false; + clickedURL = parse[1]; + return true; + } + // if no text is selected, disable copy and cut menu items public void show(Component component, int x, int y) { + int line = textarea.getLineOfOffset(textarea.xyToOffset(x, y)); + if (clickedURL(textarea.getLineText(line), textarea.xToOffset(line, x))) { + openURLItem.setVisible(true); + openURLItemSeparator.setVisible(true); + } else { + openURLItem.setVisible(false); + openURLItemSeparator.setVisible(false); + } + if (textarea.isSelectionActive()) { cutItem.setEnabled(true); copyItem.setEnabled(true); diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index 5225d0b73..9423c3952 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -11,6 +11,8 @@ package processing.app.syntax; import javax.swing.text.*; import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** @@ -148,7 +150,10 @@ public class SyntaxUtilities styles[id].setGraphicsFlags(gfx,defaultFont); line.count = length; - x = Utilities.drawTabbedText(line,x,y,gfx,expander,0); + if (id == Token.COMMENT1 || id == Token.COMMENT2) + x = drawTabbedCommentsText(line, x, y, gfx, expander); + else + x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0); line.offset += length; offset += length; @@ -158,6 +163,69 @@ public class SyntaxUtilities return x; } + /** + * Parse comments and identify "@schematics <something>" pattern. + * + * @param line + * A string to parse + * @return null if the pattern is not found, otherwise an array of + * String is returned: the elements with index 0, 1 and 2 are + * respectively the preamble, the <something> stuff, and + * the remaining part of the string. + */ + public static String[] parseCommentUrls(String line) { + // Try to find pattern + Pattern schematics = Pattern.compile("@schematics\\s+([^\\s]+)"); + Matcher m = schematics.matcher(line.toString()); + if (!m.find()) + return null; + + String res[] = new String[3]; + res[0] = line.substring(0, m.start(1)); + res[1] = line.substring(m.start(1), m.end(1)); + res[2] = line.substring(m.end(1)); + // System.out.println("0 =>"+res[0]+"<\n1 =>"+res[1]+"< \n2 =>"+res[2]+"<"); + return res; + } + + public static Segment stringToSegment(String v) { + return new Segment(v.toCharArray(), 0, v.length()); + } + + private static int drawTabbedCommentsText(Segment line, int x, int y, + Graphics gfx, TabExpander expander) { + + String parse[] = parseCommentUrls(line.toString()); + if (parse == null) + // Revert to plain writing. + return Utilities.drawTabbedText(line, x, y, gfx, expander, 0); + Segment pre = stringToSegment(parse[0]); + Segment tag = stringToSegment(parse[1]); + Segment post = stringToSegment(parse[2]); + + x = Utilities.drawTabbedText(pre, x, y, gfx, expander, 0); + x = Utilities.drawTabbedText(tag, x, y, gfx, expander, 0); + + // Draw arrow. + FontMetrics metrics = gfx.getFontMetrics(); + int h = metrics.getHeight() - 2; + drawArrow(gfx, x, y - h + metrics.getDescent() - 1, h, h); + x = Utilities.drawTabbedText(post, x, y, gfx, expander, 0); + return x; + } + + private static void drawArrow(Graphics gfx, int x, int y, int w, int h) { + int h2 = h / 2; + int h4 = h / 4; + gfx.drawLine(x, y+h2, x+h2, y); + gfx.drawLine(x+h2, y, x+h2, y+h4); + gfx.drawLine(x+h2, y+h4, x+h, y+h4); + gfx.drawLine(x+h, y+h4, x+h, y+h-h4); + gfx.drawLine(x+h, y+h-h4, x+h2, y+h-h4); + gfx.drawLine(x+h2,y+h-h4, x+h2, y+h); + gfx.drawLine(x, y+h2, x+h2, y+h); + } + // private members private SyntaxUtilities() {} } From d60c42e5eddf0e5326f38c870eaa5c61b86f8223 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 19 Aug 2011 22:32:34 +0200 Subject: [PATCH 13/30] Clickable url are now searched with a good regexp and highlighted. --- .../app/syntax/PdeTextAreaDefaults.java | 3 ++ .../app/syntax/SyntaxUtilities.java | 29 ++++++++++++++----- app/src/processing/app/syntax/Token.java | 9 ++++-- build/shared/lib/theme/theme.txt | 3 ++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/syntax/PdeTextAreaDefaults.java b/app/src/processing/app/syntax/PdeTextAreaDefaults.java index b715255be..382c69aaf 100644 --- a/app/src/processing/app/syntax/PdeTextAreaDefaults.java +++ b/app/src/processing/app/syntax/PdeTextAreaDefaults.java @@ -169,6 +169,9 @@ public class PdeTextAreaDefaults extends TextAreaDefaults { // ?? styles[Token.LABEL] = Theme.getStyle("label"); + // http://arduino.cc/ + styles[Token.URL] = Theme.getStyle("url"); + // + - = / styles[Token.OPERATOR] = Theme.getStyle("operator"); diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index 9423c3952..54443c805 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -104,6 +104,7 @@ public class SyntaxUtilities styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true); styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true); styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true); + styles[Token.URL] = new SyntaxStyle(Color.blue,true,false); styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true); return styles; @@ -151,7 +152,7 @@ public class SyntaxUtilities line.count = length; if (id == Token.COMMENT1 || id == Token.COMMENT2) - x = drawTabbedCommentsText(line, x, y, gfx, expander); + x = drawTabbedCommentsText(line, x, y, gfx, expander, styles, styles[id]); else x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0); line.offset += length; @@ -174,9 +175,7 @@ public class SyntaxUtilities * the remaining part of the string. */ public static String[] parseCommentUrls(String line) { - // Try to find pattern - Pattern schematics = Pattern.compile("@schematics\\s+([^\\s]+)"); - Matcher m = schematics.matcher(line.toString()); + Matcher m = urlPattern.matcher(line.toString()); if (!m.find()) return null; @@ -188,12 +187,21 @@ public class SyntaxUtilities return res; } + static private Pattern urlPattern = Pattern.compile( + "((?:https?|ftp)://" + // ( Protocol + "(?:(?:[\\w_\\-]+:)?[\\w_\\-]+@)?" + // Username and password + "(?:[\\w_\\-]+\\.)+[\\w_\\-]+" + // Domain name + "(?::[0-9]{1,5})?" + // Port + "(?:/[\\w_\\-./?%&=+]*)?)" + // Path ) + "(?:\\s|$)"); // whitespace or EOL + public static Segment stringToSegment(String v) { return new Segment(v.toCharArray(), 0, v.length()); } private static int drawTabbedCommentsText(Segment line, int x, int y, - Graphics gfx, TabExpander expander) { + Graphics gfx, TabExpander expander, SyntaxStyle[] styles, + SyntaxStyle commentStyle) { String parse[] = parseCommentUrls(line.toString()); if (parse == null) @@ -203,14 +211,21 @@ public class SyntaxUtilities Segment tag = stringToSegment(parse[1]); Segment post = stringToSegment(parse[2]); - x = Utilities.drawTabbedText(pre, x, y, gfx, expander, 0); + if (pre.length()>0) + x = Utilities.drawTabbedText(pre, x, y, gfx, expander, 0); + + Font f = gfx.getFont(); + styles[Token.URL].setGraphicsFlags(gfx, f); x = Utilities.drawTabbedText(tag, x, y, gfx, expander, 0); // Draw arrow. FontMetrics metrics = gfx.getFontMetrics(); int h = metrics.getHeight() - 2; drawArrow(gfx, x, y - h + metrics.getDescent() - 1, h, h); - x = Utilities.drawTabbedText(post, x, y, gfx, expander, 0); + + commentStyle.setGraphicsFlags(gfx, f); + if (post.length()>0) + x = Utilities.drawTabbedText(post, x, y, gfx, expander, 0); return x; } diff --git a/app/src/processing/app/syntax/Token.java b/app/src/processing/app/syntax/Token.java index a0f73bebf..06dc26323 100644 --- a/app/src/processing/app/syntax/Token.java +++ b/app/src/processing/app/syntax/Token.java @@ -83,17 +83,22 @@ public class Token */ public static final byte OPERATOR = 9; + /** + * URL token id. + */ + public static final byte URL = 10; + /** * Invalid token id. This can be used to mark invalid * or incomplete tokens, so the user can easily spot * syntax errors. */ - public static final byte INVALID = 10; + public static final byte INVALID = 11; /** * The total number of defined token ids. */ - public static final byte ID_COUNT = 11; + public static final byte ID_COUNT = 12; /** * The first id that can be used for internal state diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt index a0889e64a..c488d20ab 100644 --- a/build/shared/lib/theme/theme.txt +++ b/build/shared/lib/theme/theme.txt @@ -83,6 +83,9 @@ editor.literal1.style = #006699,plain # p5 built in variables: e.g. mouseX, width, pixels editor.literal2.style = #006699,plain +# http://arduino.cc/ +editor.url.style = #0000ff,italic + # e.g. + - = / editor.operator.style = #000000,plain From 6886910f3dbea2c0de264c7f4079e562c7685ce6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 22 Aug 2011 18:24:13 +0200 Subject: [PATCH 14/30] Serial button on the right. --- app/src/processing/app/EditorToolbar.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 9d7a5fc13..1d9121498 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -170,6 +170,10 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key x2[i] = x1[i] + BUTTON_WIDTH; offsetX = x2[i]; } + + // Serial button must be on the right + x1[SERIAL] = width - BUTTON_WIDTH - 3; + x2[SERIAL] = width - 3; } Graphics g = offscreen.getGraphics(); g.setColor(bgcolor); //getBackground()); From f233861a4c5b71b65e22151971230b966f9809a7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 23 Aug 2011 19:21:42 +0200 Subject: [PATCH 15/30] URL right-clickable and underlined. --- app/src/processing/app/Editor.java | 5 +-- app/src/processing/app/Preferences.java | 3 +- app/src/processing/app/Theme.java | 3 +- .../processing/app/syntax/SyntaxStyle.java | 34 ++++++++++++++++--- .../app/syntax/SyntaxUtilities.java | 22 ++++++------ build/shared/lib/theme/theme.txt | 2 +- 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index e34bb4a87..0b25324a1 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2743,8 +2743,9 @@ public class Editor extends JFrame implements RunnerListener { String[] parse = SyntaxUtilities.parseCommentUrls(line); if (parse==null) return false; - int pos = parse[0].length()+parse[1].length(); - if (offsetpos+2) + int start = parse[0].length(); + int stop = start + parse[1].length(); + if (offsetstop+2) return false; clickedURL = parse[1]; return true; diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 4dd15c041..315620033 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -772,8 +772,9 @@ public class Preferences { s = st.nextToken(); boolean bold = (s.indexOf("bold") != -1); boolean italic = (s.indexOf("italic") != -1); + boolean underlined = (s.indexOf("underlined") != -1); //System.out.println(what + " = " + str + " " + bold + " " + italic); - return new SyntaxStyle(color, italic, bold); + return new SyntaxStyle(color, italic, bold, underlined); } } diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index 8b68f4f45..373b56835 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -196,7 +196,8 @@ public class Theme { s = st.nextToken(); boolean bold = (s.indexOf("bold") != -1); boolean italic = (s.indexOf("italic") != -1); + boolean underlined = (s.indexOf("underlined") != -1); - return new SyntaxStyle(color, italic, bold); + return new SyntaxStyle(color, italic, bold, underlined); } } \ No newline at end of file diff --git a/app/src/processing/app/syntax/SyntaxStyle.java b/app/src/processing/app/syntax/SyntaxStyle.java index 56323c3cc..ac3dd797d 100644 --- a/app/src/processing/app/syntax/SyntaxStyle.java +++ b/app/src/processing/app/syntax/SyntaxStyle.java @@ -10,6 +10,10 @@ package processing.app.syntax; import java.awt.*; +import java.awt.font.TextAttribute; +import java.util.Hashtable; +import java.util.Map; + import javax.swing.JComponent; @@ -27,11 +31,12 @@ public class SyntaxStyle * @param italic True if the text should be italics * @param bold True if the text should be bold */ - public SyntaxStyle(Color color, boolean italic, boolean bold) + public SyntaxStyle(Color color, boolean italic, boolean bold, boolean underlined) { this.color = color; this.italic = italic; this.bold = bold; + this.underlined = underlined; } /** @@ -47,7 +52,7 @@ public class SyntaxStyle */ public boolean isPlain() { - return !(bold || italic); + return !(bold || italic || underlined); } /** @@ -67,7 +72,14 @@ public class SyntaxStyle } /** - * Returns the specified font, but with the style's bold and + * @return true if underline is enabled for this style. + */ + public boolean isUnderlined() { + return underlined; + } + + /** + * Returns the specified font, but with the style's bold, underline and * italic flags applied. */ public Font getStyledFont(Font font) @@ -78,10 +90,16 @@ public class SyntaxStyle if(font.equals(lastFont)) return lastStyledFont; lastFont = font; + lastStyledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); + if (underlined) { + Map attr = new Hashtable(); + attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + lastStyledFont = lastStyledFont.deriveFont(attr); + } return lastStyledFont; } @@ -100,6 +118,11 @@ public class SyntaxStyle (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); + if (underlined) { + Map attr = new Hashtable(); + attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + lastStyledFont = lastStyledFont.deriveFont(attr); + } //fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont); fontMetrics = comp.getFontMetrics(lastStyledFont); return fontMetrics; @@ -125,13 +148,16 @@ public class SyntaxStyle { return getClass().getName() + "[color=" + color + (italic ? ",italic" : "") + - (bold ? ",bold" : "") + "]"; + (bold ? ",bold" : "") + + (underlined ? ",underlined" : "") + + "]"; } // private members private Color color; private boolean italic; private boolean bold; + private boolean underlined; private Font lastFont; private Font lastStyledFont; private FontMetrics fontMetrics; diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index 54443c805..d4df8da90 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -95,17 +95,17 @@ public class SyntaxUtilities { SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT]; - styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false); - styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false); - styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true); - styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false); - styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false); - styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false); - styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true); - styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true); - styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true); - styles[Token.URL] = new SyntaxStyle(Color.blue,true,false); - styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true); + styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false,false); + styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false,false); + styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true,false); + styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false,false); + styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false,false); + styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false,false); + styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true,false); + styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true,false); + styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true,false); + styles[Token.URL] = new SyntaxStyle(Color.blue,true,false,false); + styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true,false); return styles; } diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt index c488d20ab..d8f5b7aa4 100644 --- a/build/shared/lib/theme/theme.txt +++ b/build/shared/lib/theme/theme.txt @@ -84,7 +84,7 @@ editor.literal1.style = #006699,plain editor.literal2.style = #006699,plain # http://arduino.cc/ -editor.url.style = #0000ff,italic +editor.url.style = #0000ff,underlined # e.g. + - = / editor.operator.style = #000000,plain From 303b2e5103546f34fe956b943d9b753f0979dae2 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 23 Aug 2011 19:29:36 +0200 Subject: [PATCH 16/30] Removed arrow. --- .../processing/app/syntax/SyntaxUtilities.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index d4df8da90..f6aa20e2b 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -218,29 +218,12 @@ public class SyntaxUtilities styles[Token.URL].setGraphicsFlags(gfx, f); x = Utilities.drawTabbedText(tag, x, y, gfx, expander, 0); - // Draw arrow. - FontMetrics metrics = gfx.getFontMetrics(); - int h = metrics.getHeight() - 2; - drawArrow(gfx, x, y - h + metrics.getDescent() - 1, h, h); - commentStyle.setGraphicsFlags(gfx, f); if (post.length()>0) x = Utilities.drawTabbedText(post, x, y, gfx, expander, 0); return x; } - private static void drawArrow(Graphics gfx, int x, int y, int w, int h) { - int h2 = h / 2; - int h4 = h / 4; - gfx.drawLine(x, y+h2, x+h2, y); - gfx.drawLine(x+h2, y, x+h2, y+h4); - gfx.drawLine(x+h2, y+h4, x+h, y+h4); - gfx.drawLine(x+h, y+h4, x+h, y+h-h4); - gfx.drawLine(x+h, y+h-h4, x+h2, y+h-h4); - gfx.drawLine(x+h2,y+h-h4, x+h2, y+h); - gfx.drawLine(x, y+h2, x+h2, y+h); - } - // private members private SyntaxUtilities() {} } From d00f0949ed00d53c885fd04e342b2ce55a6b4d8e Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 23 Aug 2011 17:07:39 -0400 Subject: [PATCH 17/30] Renaming pins/ directory to the more generic variants/ http://code.google.com/p/arduino/issues/detail?id=588 --- app/src/processing/app/debug/Compiler.java | 24 ++++++------- hardware/arduino/boards.txt | 34 +++++++++---------- .../{pins => variants}/mega/pins_arduino.h | 0 .../standard/pins_arduino.h | 0 4 files changed, 29 insertions(+), 29 deletions(-) rename hardware/arduino/{pins => variants}/mega/pins_arduino.h (100%) rename hardware/arduino/{pins => variants}/standard/pins_arduino.h (100%) diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index dd0889859..559df3a61 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -91,19 +91,19 @@ public class Compiler implements MessageConsumer { corePath = coreFolder.getAbsolutePath(); } - String pins = boardPreferences.get("build.pins"); - String pinsPath = null; + String variant = boardPreferences.get("build.variant"); + String variantPath = null; - if (pins != null) { - if (pins.indexOf(':') == -1) { + if (variant != null) { + if (variant.indexOf(':') == -1) { Target t = Base.getTarget(); - File pinsFolder = new File(new File(t.getFolder(), "pins"), pins); - pinsPath = pinsFolder.getAbsolutePath(); + File variantFolder = new File(new File(t.getFolder(), "variants"), variant); + variantPath = variantFolder.getAbsolutePath(); } else { - Target t = Base.targetsTable.get(pins.substring(0, pins.indexOf(':'))); - File pinsFolder = new File(t.getFolder(), "pins"); - pinsFolder = new File(pinsFolder, pins.substring(pins.indexOf(':') + 1)); - pinsPath = pinsFolder.getAbsolutePath(); + Target t = Base.targetsTable.get(variant.substring(0, variant.indexOf(':'))); + File variantFolder = new File(t.getFolder(), "variants"); + variantFolder = new File(variantFolder, variant.substring(variant.indexOf(':') + 1)); + variantPath = variantFolder.getAbsolutePath(); } } @@ -114,7 +114,7 @@ public class Compiler implements MessageConsumer { sketch.setCompilingProgress(20); List includePaths = new ArrayList(); includePaths.add(corePath); - if (pinsPath != null) includePaths.add(pinsPath); + if (variantPath != null) includePaths.add(variantPath); for (File file : sketch.getImportedLibraries()) { includePaths.add(file.getPath()); } @@ -162,7 +162,7 @@ public class Compiler implements MessageConsumer { sketch.setCompilingProgress(50); includePaths.clear(); includePaths.add(corePath); // include path for core only - if (pinsPath != null) includePaths.add(pinsPath); + if (variantPath != null) includePaths.add(variantPath); List coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(corePath, "S", true), diff --git a/hardware/arduino/boards.txt b/hardware/arduino/boards.txt index 88a71433d..8a2af1134 100644 --- a/hardware/arduino/boards.txt +++ b/hardware/arduino/boards.txt @@ -14,7 +14,7 @@ uno.bootloader.lock_bits=0x0F uno.build.mcu=atmega328p uno.build.f_cpu=16000000L uno.build.core=arduino -uno.build.pins=standard +uno.build.variant=standard ############################################################## @@ -35,7 +35,7 @@ atmega328.bootloader.lock_bits=0x0F atmega328.build.mcu=atmega328p atmega328.build.f_cpu=16000000L atmega328.build.core=arduino -atmega328.build.pins=standard +atmega328.build.variant=standard ############################################################## @@ -56,7 +56,7 @@ diecimila.bootloader.lock_bits=0x0F diecimila.build.mcu=atmega168 diecimila.build.f_cpu=16000000L diecimila.build.core=arduino -diecimila.build.pins=standard +diecimila.build.variant=standard ############################################################## @@ -77,7 +77,7 @@ mega2560.bootloader.lock_bits=0x0F mega2560.build.mcu=atmega2560 mega2560.build.f_cpu=16000000L mega2560.build.core=arduino -mega2560.build.pins=mega +mega2560.build.variant=mega ############################################################## @@ -98,7 +98,7 @@ mega.bootloader.lock_bits=0x0F mega.build.mcu=atmega1280 mega.build.f_cpu=16000000L mega.build.core=arduino -mega.build.pins=mega +mega.build.variant=mega ############################################################## @@ -119,7 +119,7 @@ mini.bootloader.lock_bits=0x0F mini.build.mcu=atmega168 mini.build.f_cpu=16000000L mini.build.core=arduino -mini.build.pins=standard +mini.build.variant=standard ############################################################## @@ -140,7 +140,7 @@ fio.bootloader.lock_bits=0x0F fio.build.mcu=atmega328p fio.build.f_cpu=8000000L fio.build.core=arduino -fio.build.pins=standard +fio.build.variant=standard ############################################################## @@ -162,7 +162,7 @@ bt328.bootloader.lock_bits=0x0F bt328.build.mcu=atmega328p bt328.build.f_cpu=16000000L bt328.build.core=arduino -bt328.build.pins=standard +bt328.build.variant=standard ############################################################## @@ -184,7 +184,7 @@ bt.bootloader.lock_bits=0x0F bt.build.mcu=atmega168 bt.build.f_cpu=16000000L bt.build.core=arduino -bt.build.pins=standard +bt.build.variant=standard ############################################################## @@ -205,7 +205,7 @@ lilypad328.bootloader.lock_bits=0x0F lilypad328.build.mcu=atmega328p lilypad328.build.f_cpu=8000000L lilypad328.build.core=arduino -lilypad328.build.pins=standard +lilypad328.build.variant=standard ############################################################## @@ -226,7 +226,7 @@ lilypad.bootloader.lock_bits=0x0F lilypad.build.mcu=atmega168 lilypad.build.f_cpu=8000000L lilypad.build.core=arduino -lilypad.build.pins=standard +lilypad.build.variant=standard ############################################################## @@ -247,7 +247,7 @@ pro5v328.bootloader.lock_bits=0x0F pro5v328.build.mcu=atmega328p pro5v328.build.f_cpu=16000000L pro5v328.build.core=arduino -pro5v328.build.pins=standard +pro5v328.build.variant=standard ############################################################## @@ -268,7 +268,7 @@ pro5v.bootloader.lock_bits=0x0F pro5v.build.mcu=atmega168 pro5v.build.f_cpu=16000000L pro5v.build.core=arduino -pro5v.build.pins=standard +pro5v.build.variant=standard ############################################################## @@ -289,7 +289,7 @@ pro328.bootloader.lock_bits=0x0F pro328.build.mcu=atmega328p pro328.build.f_cpu=8000000L pro328.build.core=arduino -pro328.build.pins=standard +pro328.build.variant=standard ############################################################## @@ -310,7 +310,7 @@ pro.bootloader.lock_bits=0x0F pro.build.mcu=atmega168 pro.build.f_cpu=8000000L pro.build.core=arduino -pro.build.pins=standard +pro.build.variant=standard ############################################################## @@ -331,7 +331,7 @@ atmega168.bootloader.lock_bits=0x0F atmega168.build.mcu=atmega168 atmega168.build.f_cpu=16000000L atmega168.build.core=arduino -atmega168.build.pins=standard +atmega168.build.variant=standard ############################################################## @@ -351,4 +351,4 @@ atmega8.bootloader.lock_bits=0x0F atmega8.build.mcu=atmega8 atmega8.build.f_cpu=16000000L atmega8.build.core=arduino -atmega8.build.pins=standard +atmega8.build.variant=standard diff --git a/hardware/arduino/pins/mega/pins_arduino.h b/hardware/arduino/variants/mega/pins_arduino.h similarity index 100% rename from hardware/arduino/pins/mega/pins_arduino.h rename to hardware/arduino/variants/mega/pins_arduino.h diff --git a/hardware/arduino/pins/standard/pins_arduino.h b/hardware/arduino/variants/standard/pins_arduino.h similarity index 100% rename from hardware/arduino/pins/standard/pins_arduino.h rename to hardware/arduino/variants/standard/pins_arduino.h From b788ad593f289cca83f48f9dddcdd2412a3a7fb7 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 23 Aug 2011 17:29:20 -0400 Subject: [PATCH 18/30] Distinguishing those boards with eight analog inputs (Fio, BT, Nano, Mini). http://code.google.com/p/arduino/issues/detail?id=499 --- hardware/arduino/boards.txt | 54 ++++++++++++++++--- .../variants/eightanaloginputs/pins_arduino.h | 27 ++++++++++ 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 hardware/arduino/variants/eightanaloginputs/pins_arduino.h diff --git a/hardware/arduino/boards.txt b/hardware/arduino/boards.txt index 8a2af1134..7adac6233 100644 --- a/hardware/arduino/boards.txt +++ b/hardware/arduino/boards.txt @@ -18,7 +18,7 @@ uno.build.variant=standard ############################################################## -atmega328.name=Arduino Duemilanove or Nano w/ ATmega328 +atmega328.name=Arduino Duemilanove w/ ATmega328 atmega328.upload.protocol=stk500 atmega328.upload.maximum_size=30720 @@ -39,7 +39,7 @@ atmega328.build.variant=standard ############################################################## -diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 +diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168 diecimila.upload.protocol=stk500 diecimila.upload.maximum_size=14336 @@ -60,6 +60,48 @@ diecimila.build.variant=standard ############################################################## +nano328.name=Arduino Nano w/ ATmega328 + +nano328.upload.protocol=stk500 +nano328.upload.maximum_size=30720 +nano328.upload.speed=57600 + +nano328.bootloader.low_fuses=0xFF +nano328.bootloader.high_fuses=0xDA +nano328.bootloader.extended_fuses=0x05 +nano328.bootloader.path=atmega +nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex +nano328.bootloader.unlock_bits=0x3F +nano328.bootloader.lock_bits=0x0F + +nano328.build.mcu=atmega328p +nano328.build.f_cpu=16000000L +nano328.build.core=arduino +nano328.build.variant=eightanaloginputs + +############################################################## + +nano.name=Arduino Nano w/ ATmega168 + +nano.upload.protocol=stk500 +nano.upload.maximum_size=14336 +nano.upload.speed=19200 + +nano.bootloader.low_fuses=0xff +nano.bootloader.high_fuses=0xdd +nano.bootloader.extended_fuses=0x00 +nano.bootloader.path=atmega +nano.bootloader.file=ATmegaBOOT_168_diecimila.hex +nano.bootloader.unlock_bits=0x3F +nano.bootloader.lock_bits=0x0F + +nano.build.mcu=atmega168 +nano.build.f_cpu=16000000L +nano.build.core=arduino +nano.build.variant=eightanaloginputs + +############################################################## + mega2560.name=Arduino Mega 2560 mega2560.upload.protocol=stk500v2 @@ -119,7 +161,7 @@ mini.bootloader.lock_bits=0x0F mini.build.mcu=atmega168 mini.build.f_cpu=16000000L mini.build.core=arduino -mini.build.variant=standard +mini.build.variant=eightanaloginputs ############################################################## @@ -140,7 +182,7 @@ fio.bootloader.lock_bits=0x0F fio.build.mcu=atmega328p fio.build.f_cpu=8000000L fio.build.core=arduino -fio.build.variant=standard +fio.build.variant=eightanaloginputs ############################################################## @@ -162,7 +204,7 @@ bt328.bootloader.lock_bits=0x0F bt328.build.mcu=atmega328p bt328.build.f_cpu=16000000L bt328.build.core=arduino -bt328.build.variant=standard +bt328.build.variant=eightanaloginputs ############################################################## @@ -184,7 +226,7 @@ bt.bootloader.lock_bits=0x0F bt.build.mcu=atmega168 bt.build.f_cpu=16000000L bt.build.core=arduino -bt.build.variant=standard +bt.build.variant=eightanaloginputs ############################################################## diff --git a/hardware/arduino/variants/eightanaloginputs/pins_arduino.h b/hardware/arduino/variants/eightanaloginputs/pins_arduino.h new file mode 100644 index 000000000..52b37efc4 --- /dev/null +++ b/hardware/arduino/variants/eightanaloginputs/pins_arduino.h @@ -0,0 +1,27 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#include "../standard/pins_arduino.h" +#undef NUM_ANALOG_INPUTS +#define NUM_ANALOG_INPUTS 8 From 8059abe58162faf81cd6d1312915d735116fb844 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 23 Aug 2011 19:12:03 -0400 Subject: [PATCH 19/30] write(), print(), and println() now return number of bytes written. The type is long, and negative values indicate errors. Needs more testing. http://code.google.com/p/arduino/issues/detail?id=551 --- .../arduino/cores/arduino/HardwareSerial.cpp | 5 +- .../arduino/cores/arduino/HardwareSerial.h | 2 +- hardware/arduino/cores/arduino/Print.cpp | 194 +++++++++++------- hardware/arduino/cores/arduino/Print.h | 56 ++--- hardware/arduino/cores/arduino/Printable.h | 2 +- .../ATS_Write_Print/ATS_Write_Print.ino | 61 ++++++ libraries/Ethernet/Client.cpp | 17 +- libraries/Ethernet/Client.h | 6 +- libraries/Ethernet/IPAddress.cpp | 10 +- libraries/Ethernet/IPAddress.h | 2 +- libraries/Ethernet/Server.cpp | 12 +- libraries/Ethernet/Server.h | 6 +- libraries/Ethernet/Udp.cpp | 11 +- libraries/Ethernet/Udp.h | 6 +- libraries/LiquidCrystal/LiquidCrystal.cpp | 3 +- libraries/LiquidCrystal/LiquidCrystal.h | 2 +- libraries/SD/File.cpp | 19 +- libraries/SD/SD.h | 6 +- libraries/SD/utility/SdFat.h | 6 +- libraries/SD/utility/SdFile.cpp | 10 +- libraries/SoftwareSerial/SoftwareSerial.cpp | 6 +- libraries/SoftwareSerial/SoftwareSerial.h | 2 +- libraries/Wire/Wire.cpp | 14 +- libraries/Wire/Wire.h | 6 +- 24 files changed, 290 insertions(+), 174 deletions(-) create mode 100644 libraries/ArduinoTestSuite/examples/ATS_Write_Print/ATS_Write_Print.ino diff --git a/hardware/arduino/cores/arduino/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp index db6b1490b..a200da570 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -352,12 +352,13 @@ void HardwareSerial::flush() ; } -void HardwareSerial::write(uint8_t c) +long HardwareSerial::write(uint8_t c) { int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; // If the output buffer is full, there's nothing for it other than to // wait for the interrupt handler to empty it a bit + // ???: return 0 here instead? while (i == _tx_buffer->tail) ; @@ -365,6 +366,8 @@ void HardwareSerial::write(uint8_t c) _tx_buffer->head = i; sbi(*_ucsrb, _udrie); + + return 1; } // Preinstantiate Objects ////////////////////////////////////////////////////// diff --git a/hardware/arduino/cores/arduino/HardwareSerial.h b/hardware/arduino/cores/arduino/HardwareSerial.h index eefdcbe16..4af8c59d6 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.h +++ b/hardware/arduino/cores/arduino/HardwareSerial.h @@ -55,7 +55,7 @@ class HardwareSerial : public Stream virtual int peek(void); virtual int read(void); virtual void flush(void); - virtual void write(uint8_t); + virtual long write(uint8_t); using Print::write; // pull in write(str) and write(buf, size) from Print }; diff --git a/hardware/arduino/cores/arduino/Print.cpp b/hardware/arduino/cores/arduino/Print.cpp index 06ac52a5e..58b103224 100755 --- a/hardware/arduino/cores/arduino/Print.cpp +++ b/hardware/arduino/cores/arduino/Print.cpp @@ -30,167 +30,196 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -void Print::write(const char *str) +long Print::write(const char *str) { - while (*str) - write(*str++); + long n = 0; + while (*str) { + if (write(*str++) <= 0) break; + n++; + } + return n; } /* default implementation: may be overridden */ -void Print::write(const uint8_t *buffer, size_t size) +long Print::write(const uint8_t *buffer, size_t size) { - while (size--) - write(*buffer++); + long n = 0; + while (size--) { + if (write(*buffer++) <= 0) break; + n++; + } + return n; } -void Print::print(const __FlashStringHelper *ifsh) +long Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; + long n = 0; while (1) { unsigned char c = pgm_read_byte(p++); - if (c == 0) return; - write(c); + if (c == 0) break; + if (write(c) <= 0) break; + n++; } + return n; } -void Print::print(const String &s) +long Print::print(const String &s) { + long n = 0; for (int i = 0; i < s.length(); i++) { - write(s[i]); + if (write(s[i]) < 0) break; + n++; } + return n; } -void Print::print(const char str[]) +long Print::print(const char str[]) { - write(str); + return write(str); } -void Print::print(char c) +long Print::print(char c) { - write(c); + return write(c); } -void Print::print(unsigned char b, int base) +long Print::print(unsigned char b, int base) { - print((unsigned long) b, base); + return print((unsigned long) b, base); } -void Print::print(int n, int base) +long Print::print(int n, int base) { - print((long) n, base); + return print((long) n, base); } -void Print::print(unsigned int n, int base) +long Print::print(unsigned int n, int base) { - print((unsigned long) n, base); + return print((unsigned long) n, base); } -void Print::print(long n, int base) +long Print::print(long n, int base) { if (base == 0) { - write(n); + return write(n); } else if (base == 10) { if (n < 0) { - print('-'); + long t = print('-'); + if (t <= 0) return t; n = -n; + return printNumber(n, 10) + 1; } - printNumber(n, 10); + return printNumber(n, 10); } else { - printNumber(n, base); + return printNumber(n, base); } } -void Print::print(unsigned long n, int base) +long Print::print(unsigned long n, int base) { - if (base == 0) write(n); - else printNumber(n, base); + if (base == 0) return write(n); + else return printNumber(n, base); } -void Print::print(double n, int digits) +long Print::print(double n, int digits) { - printFloat(n, digits); + return printFloat(n, digits); } -void Print::println(const __FlashStringHelper *ifsh) +long Print::println(const __FlashStringHelper *ifsh) { - print(ifsh); - println(); + long n = print(ifsh); + if (n >= 0) n += println(); + return n; } -void Print::print(const Printable& x) +long Print::print(const Printable& x) { - x.printTo(*this); + return x.printTo(*this); } -void Print::println(void) +long Print::println(void) { - print('\r'); - print('\n'); + long t = print('\r'); + if (t <= 0) return t; + if (print('\n') <= 0) return 1; + return 2; } -void Print::println(const String &s) +long Print::println(const String &s) { - print(s); - println(); + long n = print(s); + if (n >= 0) n += println(); + return n; } -void Print::println(const char c[]) +long Print::println(const char c[]) { - print(c); - println(); + long n = print(c); + if (n >= 0) n += println(); + return n; } -void Print::println(char c) +long Print::println(char c) { - print(c); - println(); + long n = print(c); + if (n > 0) n += println(); + return n; } -void Print::println(unsigned char b, int base) +long Print::println(unsigned char b, int base) { - print(b, base); - println(); + long n = print(b, base); + if (n >= 0) n += println(); + return n; } -void Print::println(int n, int base) +long Print::println(int num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(unsigned int n, int base) +long Print::println(unsigned int num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(long n, int base) +long Print::println(long num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(unsigned long n, int base) +long Print::println(unsigned long num, int base) { - print(n, base); - println(); + long n = print(num, base); + if (n >= 0) n += println(); + return n; } -void Print::println(double n, int digits) +long Print::println(double num, int digits) { - print(n, digits); - println(); + long n = print(num, digits); + if (n >= 0) n += println(); + return n; } -void Print::println(const Printable& x) +long Print::println(const Printable& x) { - print(x); - println(); + long n = print(x); + if (n >= 0) n += println(); + return n; } // Private Methods ///////////////////////////////////////////////////////////// -void Print::printNumber(unsigned long n, uint8_t base) { +long Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -206,15 +235,17 @@ void Print::printNumber(unsigned long n, uint8_t base) { *--str = c < 10 ? c + '0' : c + 'A' - 10; } while(n); - write(str); + return write(str); } -void Print::printFloat(double number, uint8_t digits) +long Print::printFloat(double number, uint8_t digits) { + long n = 0, t; + // Handle negative numbers if (number < 0.0) { - print('-'); + if ((n = print('-')) <= 0) return n; number = -number; } @@ -228,18 +259,27 @@ void Print::printFloat(double number, uint8_t digits) // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; - print(int_part); + if ((t = print(int_part)) < 0) return n; + + n += t; // Print the decimal point, but only if there are digits beyond - if (digits > 0) - print("."); + if (digits > 0) { + t = print("."); + if (t <= 0) return n; + n += t; + } // Extract digits from the remainder one at a time while (digits-- > 0) { remainder *= 10.0; int toPrint = int(remainder); - print(toPrint); + t = print(toPrint); + if (t <= 0) return n; + n += t; remainder -= toPrint; } + + return n; } diff --git a/hardware/arduino/cores/arduino/Print.h b/hardware/arduino/cores/arduino/Print.h index bf10b1477..d5b02ff93 100755 --- a/hardware/arduino/cores/arduino/Print.h +++ b/hardware/arduino/cores/arduino/Print.h @@ -34,37 +34,37 @@ class Print { private: - void printNumber(unsigned long, uint8_t); - void printFloat(double, uint8_t); + long printNumber(unsigned long, uint8_t); + long printFloat(double, uint8_t); public: - virtual void write(uint8_t) = 0; - virtual void write(const char *str); - virtual void write(const uint8_t *buffer, size_t size); + virtual long write(uint8_t) = 0; + virtual long write(const char *str); + virtual long write(const uint8_t *buffer, size_t size); - void print(const __FlashStringHelper *); - void print(const String &); - void print(const char[]); - void print(char); - void print(unsigned char, int = DEC); - void print(int, int = DEC); - void print(unsigned int, int = DEC); - void print(long, int = DEC); - void print(unsigned long, int = DEC); - void print(double, int = 2); - void print(const Printable&); + long print(const __FlashStringHelper *); + long print(const String &); + long print(const char[]); + long print(char); + long print(unsigned char, int = DEC); + long print(int, int = DEC); + long print(unsigned int, int = DEC); + long print(long, int = DEC); + long print(unsigned long, int = DEC); + long print(double, int = 2); + long print(const Printable&); - void println(const __FlashStringHelper *); - void println(const String &s); - void println(const char[]); - void println(char); - void println(unsigned char, int = DEC); - void println(int, int = DEC); - void println(unsigned int, int = DEC); - void println(long, int = DEC); - void println(unsigned long, int = DEC); - void println(double, int = 2); - void println(const Printable&); - void println(void); + long println(const __FlashStringHelper *); + long println(const String &s); + long println(const char[]); + long println(char); + long println(unsigned char, int = DEC); + long println(int, int = DEC); + long println(unsigned int, int = DEC); + long println(long, int = DEC); + long println(unsigned long, int = DEC); + long println(double, int = 2); + long println(const Printable&); + long println(void); }; #endif diff --git a/hardware/arduino/cores/arduino/Printable.h b/hardware/arduino/cores/arduino/Printable.h index d332aad1c..6814ee486 100644 --- a/hardware/arduino/cores/arduino/Printable.h +++ b/hardware/arduino/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual void printTo(Print& p) const = 0; + virtual long printTo(Print& p) const = 0; }; #endif diff --git a/libraries/ArduinoTestSuite/examples/ATS_Write_Print/ATS_Write_Print.ino b/libraries/ArduinoTestSuite/examples/ATS_Write_Print/ATS_Write_Print.ino new file mode 100644 index 000000000..d7e47f179 --- /dev/null +++ b/libraries/ArduinoTestSuite/examples/ATS_Write_Print/ATS_Write_Print.ino @@ -0,0 +1,61 @@ +#include + +void Test_Equal(long actual, long expected) +{ + char buf[100]; + boolean b = expected == actual; + ATS_PrintTestStatus("", b); + if (!b) { + Serial.print("expected '"); + Serial.print(expected); + Serial.print("', actual '"); + Serial.print(actual); + Serial.println("'"); + } +} + +void setup() +{ + byte buf[5] = { 65, 66, 67, 0, 69 }; + ATS_begin("Arduino", "Write & Print Return Values Test"); + + Test_Equal(Serial.write('a'), 1); + Test_Equal(Serial.write(byte(0)), 1); + Test_Equal(Serial.write("abc"), 3); + Test_Equal(Serial.write(""), 0); + Test_Equal(Serial.write(buf, 5), 5); + Test_Equal(Serial.print(0), 1); + Test_Equal(Serial.print(""), 0); + Test_Equal(Serial.print("abc"), 3); + Test_Equal(Serial.print(0), 1); + Test_Equal(Serial.print(1), 1); + Test_Equal(Serial.print(11), 2); + Test_Equal(Serial.print(12345), 5); + Test_Equal(Serial.print(-1), 2); + Test_Equal(Serial.print(-123), 4); + Test_Equal(Serial.println(), 2); + Test_Equal(Serial.println(""), 2); + Test_Equal(Serial.println("abc"), 5); + Test_Equal(Serial.println(0), 3); + Test_Equal(Serial.println(1), 3); + Test_Equal(Serial.println(11), 4); + Test_Equal(Serial.println(12345), 7); + Test_Equal(Serial.println(-1), 4); + Test_Equal(Serial.println(-123), 6); + + ATS_end(); +} + +void loop() {} + + + + + + + + + + + + diff --git a/libraries/Ethernet/Client.cpp b/libraries/Ethernet/Client.cpp index f146ac5ed..75cb1f743 100644 --- a/libraries/Ethernet/Client.cpp +++ b/libraries/Ethernet/Client.cpp @@ -70,19 +70,18 @@ int Client::connect(IPAddress ip, uint16_t port) { return 1; } -void Client::write(uint8_t b) { - if (_sock != MAX_SOCK_NUM) - send(_sock, &b, 1); +long Client::write(uint8_t b) { + return write(&b, 1); } -void Client::write(const char *str) { - if (_sock != MAX_SOCK_NUM) - send(_sock, (const uint8_t *)str, strlen(str)); +long Client::write(const char *str) { + return write((const uint8_t *) str, strlen(str)); } -void Client::write(const uint8_t *buf, size_t size) { - if (_sock != MAX_SOCK_NUM) - send(_sock, buf, size); +long Client::write(const uint8_t *buf, size_t size) { + if (_sock == MAX_SOCK_NUM) return -1; + if (!send(_sock, buf, size)) return -2; + return size; } int Client::available() { diff --git a/libraries/Ethernet/Client.h b/libraries/Ethernet/Client.h index 582f4938a..0a95dff96 100644 --- a/libraries/Ethernet/Client.h +++ b/libraries/Ethernet/Client.h @@ -12,9 +12,9 @@ public: uint8_t status(); int connect(IPAddress ip, uint16_t port); int connect(const char *host, uint16_t port); - virtual void write(uint8_t); - virtual void write(const char *str); - virtual void write(const uint8_t *buf, size_t size); + virtual long write(uint8_t); + virtual long write(const char *str); + virtual long write(const uint8_t *buf, size_t size); virtual int available(); virtual int read(); virtual int read(uint8_t *buf, size_t size); diff --git a/libraries/Ethernet/IPAddress.cpp b/libraries/Ethernet/IPAddress.cpp index 77928b5cb..72bb03956 100644 --- a/libraries/Ethernet/IPAddress.cpp +++ b/libraries/Ethernet/IPAddress.cpp @@ -42,13 +42,15 @@ bool IPAddress::operator==(const uint8_t* addr) return memcmp(addr, _address, sizeof(_address)) == 0; } -void IPAddress::printTo(Print& p) const +long IPAddress::printTo(Print& p) const { + long n = 0, t; for (int i =0; i < 3; i++) { - p.print(_address[i], DEC); - p.print('.'); + if ((t = p.print(_address[i], DEC)) > 0) n += t; + if ((t = p.print('.')) > 0) n+= t; } - p.print(_address[3], DEC); + if ((t = p.print(_address[3], DEC)) > 0) n += t; + return n; } diff --git a/libraries/Ethernet/IPAddress.h b/libraries/Ethernet/IPAddress.h index 7dd520351..5d7af6e18 100644 --- a/libraries/Ethernet/IPAddress.h +++ b/libraries/Ethernet/IPAddress.h @@ -60,7 +60,7 @@ public: IPAddress& operator=(const uint8_t *address); IPAddress& operator=(uint32_t address); - virtual void printTo(Print& p) const; + virtual long printTo(Print& p) const; friend class EthernetClass; friend class UDP; diff --git a/libraries/Ethernet/Server.cpp b/libraries/Ethernet/Server.cpp index 4271741b9..9e3347fac 100644 --- a/libraries/Ethernet/Server.cpp +++ b/libraries/Ethernet/Server.cpp @@ -67,18 +67,20 @@ Client Server::available() return Client(MAX_SOCK_NUM); } -void Server::write(uint8_t b) +long Server::write(uint8_t b) { write(&b, 1); } -void Server::write(const char *str) +long Server::write(const char *str) { write((const uint8_t *)str, strlen(str)); } -void Server::write(const uint8_t *buffer, size_t size) +long Server::write(const uint8_t *buffer, size_t size) { + long n = 0; + accept(); for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { @@ -86,7 +88,9 @@ void Server::write(const uint8_t *buffer, size_t size) if (EthernetClass::_server_port[sock] == _port && client.status() == SnSR::ESTABLISHED) { - client.write(buffer, size); + n += client.write(buffer, size); } } + + return n; } diff --git a/libraries/Ethernet/Server.h b/libraries/Ethernet/Server.h index 6aa5d3aaf..60d3f3d75 100644 --- a/libraries/Ethernet/Server.h +++ b/libraries/Ethernet/Server.h @@ -14,9 +14,9 @@ public: Server(uint16_t); Client available(); void begin(); - virtual void write(uint8_t); - virtual void write(const char *str); - virtual void write(const uint8_t *buf, size_t size); + virtual long write(uint8_t); + virtual long write(const char *str); + virtual long write(const uint8_t *buf, size_t size); }; #endif diff --git a/libraries/Ethernet/Udp.cpp b/libraries/Ethernet/Udp.cpp index aed5d983b..5cb2b1eb6 100644 --- a/libraries/Ethernet/Udp.cpp +++ b/libraries/Ethernet/Udp.cpp @@ -102,21 +102,22 @@ int UDP::endPacket() return sendUDP(_sock); } -void UDP::write(uint8_t byte) +long UDP::write(uint8_t byte) { - write(&byte, 1); + return write(&byte, 1); } -void UDP::write(const char *str) +long UDP::write(const char *str) { size_t len = strlen(str); - write((const uint8_t *)str, len); + return write((const uint8_t *)str, len); } -void UDP::write(const uint8_t *buffer, size_t size) +long UDP::write(const uint8_t *buffer, size_t size) { uint16_t bytes_written = bufferData(_sock, _offset, buffer, size); _offset += bytes_written; + return bytes_written; } int UDP::parsePacket() diff --git a/libraries/Ethernet/Udp.h b/libraries/Ethernet/Udp.h index 99df53f15..65cac671a 100644 --- a/libraries/Ethernet/Udp.h +++ b/libraries/Ethernet/Udp.h @@ -67,11 +67,11 @@ public: // Returns 1 if the packet was sent successfully, 0 if there was an error int endPacket(); // Write a single byte into the packet - virtual void write(uint8_t); + virtual long write(uint8_t); // Write a string of characters into the packet - virtual void write(const char *str); + virtual long write(const char *str); // Write size bytes from buffer into the packet - virtual void write(const uint8_t *buffer, size_t size); + virtual long write(const uint8_t *buffer, size_t size); // Start processing the next available incoming packet // Returns the size of the packet in bytes, or 0 if no packets are available diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index 04d0f50e7..53119df85 100644 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -258,8 +258,9 @@ inline void LiquidCrystal::command(uint8_t value) { send(value, LOW); } -inline void LiquidCrystal::write(uint8_t value) { +inline long LiquidCrystal::write(uint8_t value) { send(value, HIGH); + return 1; // assume sucess } /************ low level data pushing commands **********/ diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index f66ec1b4c..2788fe08f 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -79,7 +79,7 @@ public: void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); - virtual void write(uint8_t); + virtual long write(uint8_t); void command(uint8_t); private: void send(uint8_t, uint8_t); diff --git a/libraries/SD/File.cpp b/libraries/SD/File.cpp index 9ef819667..d0d5c00e0 100644 --- a/libraries/SD/File.cpp +++ b/libraries/SD/File.cpp @@ -58,19 +58,20 @@ boolean File::isDirectory(void) { } -void File::write(uint8_t val) { - if (_file) - _file->write(val); +long File::write(uint8_t val) { + return write(&val, 1); } -void File::write(const char *str) { - if (_file) - _file->write(str); +long File::write(const char *str) { + return write((const uint8_t *) str, strlen(str)); } -void File::write(const uint8_t *buf, size_t size) { - if (_file) - _file->write(buf, size); +long File::write(const uint8_t *buf, size_t size) { + long t; + if (!_file) return -1; + t = _file->write(buf, size); + if (t < 0) return t - 1; + return t; } int File::peek() { diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h index 584e2ae9e..ac750f05d 100644 --- a/libraries/SD/SD.h +++ b/libraries/SD/SD.h @@ -32,9 +32,9 @@ public: File(SdFile f, char *name); // wraps an underlying SdFile File(void); // 'empty' constructor ~File(void); // destructor - virtual void write(uint8_t); - virtual void write(const char *str); - virtual void write(const uint8_t *buf, size_t size); + virtual long write(uint8_t); + virtual long write(const char *str); + virtual long write(const uint8_t *buf, size_t size); virtual int read(); virtual int peek(); virtual int available(); diff --git a/libraries/SD/utility/SdFat.h b/libraries/SD/utility/SdFat.h index 048fa711e..f9bd17f99 100644 --- a/libraries/SD/utility/SdFat.h +++ b/libraries/SD/utility/SdFat.h @@ -283,9 +283,9 @@ class SdFile : public Print { } /** \return SdVolume that contains this file. */ SdVolume* volume(void) const {return vol_;} - void write(uint8_t b); - int16_t write(const void* buf, uint16_t nbyte); - void write(const char* str); + long write(uint8_t b); + long write(const void* buf, uint16_t nbyte); + long write(const char* str); void write_P(PGM_P str); void writeln_P(PGM_P str); //------------------------------------------------------------------------------ diff --git a/libraries/SD/utility/SdFile.cpp b/libraries/SD/utility/SdFile.cpp index 40444a721..5e52704ed 100644 --- a/libraries/SD/utility/SdFile.cpp +++ b/libraries/SD/utility/SdFile.cpp @@ -1121,7 +1121,7 @@ uint8_t SdFile::truncate(uint32_t length) { * for a read-only file, device is full, a corrupt file system or an I/O error. * */ -int16_t SdFile::write(const void* buf, uint16_t nbyte) { +long SdFile::write(const void* buf, uint16_t nbyte) { // convert void* to uint8_t* - must be before goto statements const uint8_t* src = reinterpret_cast(buf); @@ -1219,8 +1219,8 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) { * * Use SdFile::writeError to check for errors. */ -void SdFile::write(uint8_t b) { - write(&b, 1); +long SdFile::write(uint8_t b) { + return write(&b, 1); } //------------------------------------------------------------------------------ /** @@ -1228,8 +1228,8 @@ void SdFile::write(uint8_t b) { * * Use SdFile::writeError to check for errors. */ -void SdFile::write(const char* str) { - write(str, strlen(str)); +long SdFile::write(const char* str) { + return write(str, strlen(str)); } //------------------------------------------------------------------------------ /** diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index b9cb16105..61476f373 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -440,10 +440,10 @@ int SoftwareSerial::available() return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; } -void SoftwareSerial::write(uint8_t b) +long SoftwareSerial::write(uint8_t b) { if (_tx_delay == 0) - return; + return -1; uint8_t oldSREG = SREG; cli(); // turn off interrupts for a clean txmit @@ -484,6 +484,8 @@ void SoftwareSerial::write(uint8_t b) SREG = oldSREG; // turn interrupts back on tunedDelay(_tx_delay); + + return 1; } void SoftwareSerial::flush() diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index 2fc998c23..1966f18b4 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -89,7 +89,7 @@ public: bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } int peek(); - virtual void write(uint8_t byte); + virtual long write(uint8_t byte); virtual int read(); virtual int available(); virtual void flush(); diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 5818beef1..941b90385 100755 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -124,13 +124,13 @@ uint8_t TwoWire::endTransmission(void) // must be called in: // slave tx event callback // or after beginTransmission(address) -void TwoWire::write(uint8_t data) +long TwoWire::write(uint8_t data) { if(transmitting){ // in master transmitter mode // don't bother if buffer is full if(txBufferLength >= BUFFER_LENGTH){ - return; + return -1; } // put byte in tx buffer txBuffer[txBufferIndex] = data; @@ -142,31 +142,33 @@ void TwoWire::write(uint8_t data) // reply to master twi_transmit(&data, 1); } + return 1; } // must be called in: // slave tx event callback // or after beginTransmission(address) -void TwoWire::write(const uint8_t *data, size_t quantity) +long TwoWire::write(const uint8_t *data, size_t quantity) { if(transmitting){ // in master transmitter mode for(size_t i = 0; i < quantity; ++i){ - write(data[i]); + if (write(data[i]) < 0) return i; } }else{ // in slave send mode // reply to master twi_transmit(data, quantity); } + return quantity; } // must be called in: // slave tx event callback // or after beginTransmission(address) -void TwoWire::write(const char *data) +long TwoWire::write(const char *data) { - write((uint8_t*)data, strlen(data)); + return write((uint8_t*)data, strlen(data)); } // must be called in: diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index 51df04e97..a76cd8415 100755 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -52,9 +52,9 @@ class TwoWire : public Stream uint8_t endTransmission(void); uint8_t requestFrom(uint8_t, uint8_t); uint8_t requestFrom(int, int); - virtual void write(uint8_t); - virtual void write(const char *); - virtual void write(const uint8_t *, size_t); + virtual long write(uint8_t); + virtual long write(const char *); + virtual long write(const uint8_t *, size_t); virtual int available(void); virtual int read(void); virtual int peek(void); From 88794ec1d6b5374548f251815c8a4fa2d5adec6f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 24 Aug 2011 10:42:58 +0200 Subject: [PATCH 20/30] =?UTF-8?q?Double-click=20now=20opens=20URL=20(right?= =?UTF-8?q?-click=20still=20shows=20"Open=20URL"=20in=20popup=20men=C3=B9)?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/processing/app/Editor.java | 19 +++++-------------- .../processing/app/syntax/JEditTextArea.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 0b25324a1..c3547d87f 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2739,22 +2739,13 @@ public class Editor extends JFrame implements RunnerListener { add(referenceItem); } - private boolean clickedURL(String line, int offset) { - String[] parse = SyntaxUtilities.parseCommentUrls(line); - if (parse==null) - return false; - int start = parse[0].length(); - int stop = start + parse[1].length(); - if (offsetstop+2) - return false; - clickedURL = parse[1]; - return true; - } - // if no text is selected, disable copy and cut menu items public void show(Component component, int x, int y) { - int line = textarea.getLineOfOffset(textarea.xyToOffset(x, y)); - if (clickedURL(textarea.getLineText(line), textarea.xToOffset(line, x))) { + int lineNo = textarea.getLineOfOffset(textarea.xyToOffset(x, y)); + int offset = textarea.xToOffset(lineNo, x); + String line = textarea.getLineText(lineNo); + clickedURL = textarea.checkClickedURL(line, offset); + if (clickedURL != null) { openURLItem.setVisible(true); openURLItemSeparator.setVisible(true); } else { diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index d5c01c48a..9683c43d8 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -2045,6 +2045,17 @@ public class JEditTextArea extends JComponent } } + public String checkClickedURL(String line, int offset) { + String[] parse = SyntaxUtilities.parseCommentUrls(line); + if (parse==null) + return null; + int start = parse[0].length(); + int stop = start + parse[1].length(); + if (offsetstop) + return null; + return parse[1]; + } + class MouseHandler extends MouseAdapter { public void mousePressed(MouseEvent evt) @@ -2111,6 +2122,13 @@ public class JEditTextArea extends JComponent if (getLineLength(line) == 0) return; + // Check for click on urls + String clickedURL = checkClickedURL(getLineText(line), offset); + if (clickedURL != null) { + Base.openURL(clickedURL); + return; + } + try { int bracket = TextUtilities.findMatchingBracket(document, Math.max(0,dot - 1)); From 0fca78cc7e6c85923cc0f9431160fa07dc33fc4a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 24 Aug 2011 11:08:10 +0200 Subject: [PATCH 21/30] Fixed position of the Label of command buttons. --- app/src/processing/app/EditorToolbar.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 1d9121498..6b04aa2d9 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -172,8 +172,8 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key } // Serial button must be on the right - x1[SERIAL] = width - BUTTON_WIDTH - 3; - x2[SERIAL] = width - 3; + x1[SERIAL] = width - BUTTON_WIDTH - 14; + x2[SERIAL] = width - 14; } Graphics g = offscreen.getGraphics(); g.setColor(bgcolor); //getBackground()); @@ -198,9 +198,15 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key g2.drawString(status, statusX, statusY); */ if (currentRollover != -1) { - int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2; + int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2; String status = shiftPressed ? titleShift[currentRollover] : title[currentRollover]; - g.drawString(status, buttonCount * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY); + if (currentRollover != SERIAL) + g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY); + else { + int statusX = x1[SERIAL] - BUTTON_GAP; + statusX -= g.getFontMetrics().stringWidth(status); + g.drawString(status, statusX, statusY); + } } screen.drawImage(offscreen, 0, 0, null); From 71dd5dd534bd98aaffaab19f083cc750058974d6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 24 Aug 2011 16:53:57 +0200 Subject: [PATCH 22/30] Selected board and serial port on status bar. --- app/src/processing/app/Base.java | 8 ++++++++ app/src/processing/app/Editor.java | 8 ++++++++ app/src/processing/app/EditorLineStatus.java | 21 ++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 036cb4f5a..2e3d7b346 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -993,6 +993,13 @@ public class Base { } + public void onBoardOrPortChange() { + for (Editor editor : editors) { + editor.onBoardOrPortChange(); + } + } + + public void rebuildBoardsMenu(JMenu menu) { //System.out.println("rebuilding boards menu"); menu.removeAll(); @@ -1005,6 +1012,7 @@ public class Base { //System.out.println("Switching to " + target + ":" + board); Preferences.set("target", (String) getValue("target")); Preferences.set("board", (String) getValue("board")); + onBoardOrPortChange(); } }; action.putValue("target", target.getName()); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index fa0544a1e..c6f362208 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -907,6 +907,7 @@ public class Editor extends JFrame implements RunnerListener { public void actionPerformed(ActionEvent e) { selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText()); + base.onBoardOrPortChange(); } /* @@ -2623,7 +2624,14 @@ public class Editor extends JFrame implements RunnerListener { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + protected void onBoardOrPortChange() { + Map boardPreferences = Base.getBoardPreferences(); + lineStatus.setBoardName(boardPreferences.get("name")); + lineStatus.setSerialPort(Preferences.get("serial.port")); + lineStatus.repaint(); + } + /** * Returns the edit popup menu. */ diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index f28175ff0..b4c49bdcc 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -25,6 +25,9 @@ package processing.app; import processing.app.syntax.*; import java.awt.*; +import java.awt.geom.Rectangle2D; +import java.util.Map; + import javax.swing.*; @@ -39,10 +42,14 @@ public class EditorLineStatus extends JComponent { Color foreground; Color background; + Color messageForeground; + Font font; int high; String text = ""; + String name = ""; + String serialport = ""; public EditorLineStatus(JEditTextArea textarea) { @@ -87,6 +94,11 @@ public class EditorLineStatus extends JComponent { public void paintComponent(Graphics g) { + if (name=="" && serialport=="") { + Map boardPreferences = Base.getBoardPreferences(); + setBoardName(boardPreferences.get("name")); + setSerialPort(Preferences.get("serial.port")); + } g.setColor(background); Dimension size = getSize(); g.fillRect(0, 0, size.width, size.height); @@ -96,11 +108,20 @@ public class EditorLineStatus extends JComponent { int baseline = (high + g.getFontMetrics().getAscent()) / 2; g.drawString(text, 6, baseline); + g.setColor(messageForeground); + String tmp = "board: " + name + " on " + serialport; + + Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null); + + g.drawString(tmp, size.width - (int) bounds.getWidth() -20 , baseline); + if (Base.isMacOS()) { g.drawImage(resize, size.width - 20, 0, this); } } + public void setBoardName(String name) { this.name = name; } + public void setSerialPort(String serialport) { this.serialport = serialport; } public Dimension getPreferredSize() { return new Dimension(300, high); From d501a9ba0ecae8392e9cbc910a80874b401914a3 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 24 Aug 2011 11:35:12 -0400 Subject: [PATCH 23/30] Single-click to open a URL / link (rather than double-click). --- app/src/processing/app/syntax/JEditTextArea.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index 9683c43d8..3c1548fbd 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -2106,6 +2106,13 @@ public class JEditTextArea extends JComponent private void doSingleClick(MouseEvent evt, int line, int offset, int dot) { + // Check for click on urls + String clickedURL = checkClickedURL(getLineText(line), offset); + if (clickedURL != null) { + Base.openURL(clickedURL); + return; + } + if ((evt.getModifiers() & InputEvent.SHIFT_MASK) != 0) { rectSelect = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; select(getMarkPosition(),dot); @@ -2122,13 +2129,6 @@ public class JEditTextArea extends JComponent if (getLineLength(line) == 0) return; - // Check for click on urls - String clickedURL = checkClickedURL(getLineText(line), offset); - if (clickedURL != null) { - Base.openURL(clickedURL); - return; - } - try { int bracket = TextUtilities.findMatchingBracket(document, Math.max(0,dot - 1)); From 91a94cbe7e2fd458eda176daa00876c970826349 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 24 Aug 2011 11:50:02 -0400 Subject: [PATCH 24/30] Removing "board: " prefix from line status bar. --- app/src/processing/app/EditorLineStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index b4c49bdcc..2fcb8c917 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -109,7 +109,7 @@ public class EditorLineStatus extends JComponent { g.drawString(text, 6, baseline); g.setColor(messageForeground); - String tmp = "board: " + name + " on " + serialport; + String tmp = name + " on " + serialport; Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null); From 0020105283919422c12fa81e279c8758b242f81f Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 24 Aug 2011 11:55:24 -0400 Subject: [PATCH 25/30] Also updating serial port display from "Serial port not found" dialog. --- app/src/processing/app/Editor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 0733530ce..b62fb96c9 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2317,6 +2317,7 @@ public class Editor extends JFrame implements RunnerListener { 0); if (result == null) return false; selectSerialPort(result); + base.onBoardOrPortChange(); return true; } From bd6c90e5b8de7e0d59a95da97d51a30be25e8a4f Mon Sep 17 00:00:00 2001 From: David Mellis Date: Wed, 24 Aug 2011 11:57:58 -0400 Subject: [PATCH 26/30] Setting Arduino icon for serial monitor window. http://code.google.com/p/arduino/issues/detail?id=564 --- app/src/processing/app/Editor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index b62fb96c9..405b16b34 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -196,8 +196,10 @@ public class Editor extends JFrame implements RunnerListener { //PdeKeywords keywords = new PdeKeywords(); //sketchbook = new Sketchbook(this); - if (serialMonitor == null) + if (serialMonitor == null) { serialMonitor = new SerialMonitor(Preferences.get("serial.port")); + serialMonitor.setIconImage(getIconImage()); + } buildMenuBar(); From 3f0b7f21c264e9cfaeef18f5039bb370d0334c54 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 13:34:25 -0400 Subject: [PATCH 27/30] Updating Mac OS X .app version to 1.0-beta2. --- build/macosx/template.app/Contents/Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/macosx/template.app/Contents/Info.plist b/build/macosx/template.app/Contents/Info.plist index 45809f544..2233d7278 100755 --- a/build/macosx/template.app/Contents/Info.plist +++ b/build/macosx/template.app/Contents/Info.plist @@ -7,11 +7,11 @@ CFBundleGetInfoString - 1.0-beta1 + 1.0-beta2 CFBundleVersion 0100 CFBundleShortVersionString - 1.0-beta1 + 1.0-beta2 CFBundleAllowMixedLocalizations From 929597375b5414ecd51e1c73d34cb41f7e2515eb Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 14:20:41 -0400 Subject: [PATCH 28/30] Changing from long to ssize_t (int) for write(), print(), println() return. --- .../arduino/cores/arduino/HardwareSerial.cpp | 2 +- .../arduino/cores/arduino/HardwareSerial.h | 2 +- hardware/arduino/cores/arduino/Print.cpp | 90 +++++++++---------- hardware/arduino/cores/arduino/Print.h | 58 ++++++------ hardware/arduino/cores/arduino/Printable.h | 2 +- libraries/Ethernet/Client.cpp | 6 +- libraries/Ethernet/Client.h | 6 +- libraries/Ethernet/IPAddress.cpp | 4 +- libraries/Ethernet/IPAddress.h | 2 +- libraries/Ethernet/Server.cpp | 8 +- libraries/Ethernet/Server.h | 6 +- libraries/Ethernet/Udp.cpp | 6 +- libraries/Ethernet/Udp.h | 6 +- libraries/LiquidCrystal/LiquidCrystal.cpp | 2 +- libraries/LiquidCrystal/LiquidCrystal.h | 2 +- libraries/SD/File.cpp | 8 +- libraries/SD/SD.h | 6 +- libraries/SD/utility/SdFat.h | 6 +- libraries/SD/utility/SdFile.cpp | 6 +- libraries/SoftwareSerial/SoftwareSerial.cpp | 2 +- libraries/SoftwareSerial/SoftwareSerial.h | 2 +- libraries/Wire/Wire.cpp | 6 +- libraries/Wire/Wire.h | 6 +- 23 files changed, 123 insertions(+), 121 deletions(-) diff --git a/hardware/arduino/cores/arduino/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp index a200da570..641c97343 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -352,7 +352,7 @@ void HardwareSerial::flush() ; } -long HardwareSerial::write(uint8_t c) +ssize_t HardwareSerial::write(uint8_t c) { int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; diff --git a/hardware/arduino/cores/arduino/HardwareSerial.h b/hardware/arduino/cores/arduino/HardwareSerial.h index 4af8c59d6..960d3f51c 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.h +++ b/hardware/arduino/cores/arduino/HardwareSerial.h @@ -55,7 +55,7 @@ class HardwareSerial : public Stream virtual int peek(void); virtual int read(void); virtual void flush(void); - virtual long write(uint8_t); + virtual ssize_t write(uint8_t); using Print::write; // pull in write(str) and write(buf, size) from Print }; diff --git a/hardware/arduino/cores/arduino/Print.cpp b/hardware/arduino/cores/arduino/Print.cpp index 58b103224..192d9a3ff 100755 --- a/hardware/arduino/cores/arduino/Print.cpp +++ b/hardware/arduino/cores/arduino/Print.cpp @@ -30,9 +30,9 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -long Print::write(const char *str) +ssize_t Print::write(const char *str) { - long n = 0; + ssize_t n = 0; while (*str) { if (write(*str++) <= 0) break; n++; @@ -41,9 +41,9 @@ long Print::write(const char *str) } /* default implementation: may be overridden */ -long Print::write(const uint8_t *buffer, size_t size) +ssize_t Print::write(const uint8_t *buffer, size_t size) { - long n = 0; + ssize_t n = 0; while (size--) { if (write(*buffer++) <= 0) break; n++; @@ -51,10 +51,10 @@ long Print::write(const uint8_t *buffer, size_t size) return n; } -long Print::print(const __FlashStringHelper *ifsh) +ssize_t Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; - long n = 0; + ssize_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) break; @@ -64,9 +64,9 @@ long Print::print(const __FlashStringHelper *ifsh) return n; } -long Print::print(const String &s) +ssize_t Print::print(const String &s) { - long n = 0; + ssize_t n = 0; for (int i = 0; i < s.length(); i++) { if (write(s[i]) < 0) break; n++; @@ -74,38 +74,38 @@ long Print::print(const String &s) return n; } -long Print::print(const char str[]) +ssize_t Print::print(const char str[]) { return write(str); } -long Print::print(char c) +ssize_t Print::print(char c) { return write(c); } -long Print::print(unsigned char b, int base) +ssize_t Print::print(unsigned char b, int base) { return print((unsigned long) b, base); } -long Print::print(int n, int base) +ssize_t Print::print(int n, int base) { return print((long) n, base); } -long Print::print(unsigned int n, int base) +ssize_t Print::print(unsigned int n, int base) { return print((unsigned long) n, base); } -long Print::print(long n, int base) +ssize_t Print::print(long n, int base) { if (base == 0) { return write(n); } else if (base == 10) { if (n < 0) { - long t = print('-'); + int t = print('-'); if (t <= 0) return t; n = -n; return printNumber(n, 10) + 1; @@ -116,110 +116,110 @@ long Print::print(long n, int base) } } -long Print::print(unsigned long n, int base) +ssize_t Print::print(unsigned long n, int base) { if (base == 0) return write(n); else return printNumber(n, base); } -long Print::print(double n, int digits) +ssize_t Print::print(double n, int digits) { return printFloat(n, digits); } -long Print::println(const __FlashStringHelper *ifsh) +ssize_t Print::println(const __FlashStringHelper *ifsh) { - long n = print(ifsh); + ssize_t n = print(ifsh); if (n >= 0) n += println(); return n; } -long Print::print(const Printable& x) +ssize_t Print::print(const Printable& x) { return x.printTo(*this); } -long Print::println(void) +ssize_t Print::println(void) { - long t = print('\r'); + ssize_t t = print('\r'); if (t <= 0) return t; if (print('\n') <= 0) return 1; return 2; } -long Print::println(const String &s) +ssize_t Print::println(const String &s) { - long n = print(s); + ssize_t n = print(s); if (n >= 0) n += println(); return n; } -long Print::println(const char c[]) +ssize_t Print::println(const char c[]) { - long n = print(c); + ssize_t n = print(c); if (n >= 0) n += println(); return n; } -long Print::println(char c) +ssize_t Print::println(char c) { - long n = print(c); + ssize_t n = print(c); if (n > 0) n += println(); return n; } -long Print::println(unsigned char b, int base) +ssize_t Print::println(unsigned char b, int base) { - long n = print(b, base); + ssize_t n = print(b, base); if (n >= 0) n += println(); return n; } -long Print::println(int num, int base) +ssize_t Print::println(int num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(unsigned int num, int base) +ssize_t Print::println(unsigned int num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(long num, int base) +ssize_t Print::println(long num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(unsigned long num, int base) +ssize_t Print::println(unsigned long num, int base) { - long n = print(num, base); + ssize_t n = print(num, base); if (n >= 0) n += println(); return n; } -long Print::println(double num, int digits) +ssize_t Print::println(double num, int digits) { - long n = print(num, digits); + ssize_t n = print(num, digits); if (n >= 0) n += println(); return n; } -long Print::println(const Printable& x) +ssize_t Print::println(const Printable& x) { - long n = print(x); + ssize_t n = print(x); if (n >= 0) n += println(); return n; } // Private Methods ///////////////////////////////////////////////////////////// -long Print::printNumber(unsigned long n, uint8_t base) { +ssize_t Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -238,9 +238,9 @@ long Print::printNumber(unsigned long n, uint8_t base) { return write(str); } -long Print::printFloat(double number, uint8_t digits) +ssize_t Print::printFloat(double number, uint8_t digits) { - long n = 0, t; + ssize_t n = 0, t; // Handle negative numbers if (number < 0.0) diff --git a/hardware/arduino/cores/arduino/Print.h b/hardware/arduino/cores/arduino/Print.h index d5b02ff93..3f303f3d0 100755 --- a/hardware/arduino/cores/arduino/Print.h +++ b/hardware/arduino/cores/arduino/Print.h @@ -23,6 +23,8 @@ #include #include // for size_t +typedef int ssize_t; + #include "WString.h" #include "Printable.h" @@ -34,37 +36,37 @@ class Print { private: - long printNumber(unsigned long, uint8_t); - long printFloat(double, uint8_t); + ssize_t printNumber(unsigned long, uint8_t); + ssize_t printFloat(double, uint8_t); public: - virtual long write(uint8_t) = 0; - virtual long write(const char *str); - virtual long write(const uint8_t *buffer, size_t size); + virtual ssize_t write(uint8_t) = 0; + virtual ssize_t write(const char *str); + virtual ssize_t write(const uint8_t *buffer, size_t size); - long print(const __FlashStringHelper *); - long print(const String &); - long print(const char[]); - long print(char); - long print(unsigned char, int = DEC); - long print(int, int = DEC); - long print(unsigned int, int = DEC); - long print(long, int = DEC); - long print(unsigned long, int = DEC); - long print(double, int = 2); - long print(const Printable&); + ssize_t print(const __FlashStringHelper *); + ssize_t print(const String &); + ssize_t print(const char[]); + ssize_t print(char); + ssize_t print(unsigned char, int = DEC); + ssize_t print(int, int = DEC); + ssize_t print(unsigned int, int = DEC); + ssize_t print(long, int = DEC); + ssize_t print(unsigned long, int = DEC); + ssize_t print(double, int = 2); + ssize_t print(const Printable&); - long println(const __FlashStringHelper *); - long println(const String &s); - long println(const char[]); - long println(char); - long println(unsigned char, int = DEC); - long println(int, int = DEC); - long println(unsigned int, int = DEC); - long println(long, int = DEC); - long println(unsigned long, int = DEC); - long println(double, int = 2); - long println(const Printable&); - long println(void); + ssize_t println(const __FlashStringHelper *); + ssize_t println(const String &s); + ssize_t println(const char[]); + ssize_t println(char); + ssize_t println(unsigned char, int = DEC); + ssize_t println(int, int = DEC); + ssize_t println(unsigned int, int = DEC); + ssize_t println(long, int = DEC); + ssize_t println(unsigned long, int = DEC); + ssize_t println(double, int = 2); + ssize_t println(const Printable&); + ssize_t println(void); }; #endif diff --git a/hardware/arduino/cores/arduino/Printable.h b/hardware/arduino/cores/arduino/Printable.h index 6814ee486..9065904bc 100644 --- a/hardware/arduino/cores/arduino/Printable.h +++ b/hardware/arduino/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual long printTo(Print& p) const = 0; + virtual ssize_t printTo(Print& p) const = 0; }; #endif diff --git a/libraries/Ethernet/Client.cpp b/libraries/Ethernet/Client.cpp index 75cb1f743..a448addec 100644 --- a/libraries/Ethernet/Client.cpp +++ b/libraries/Ethernet/Client.cpp @@ -70,15 +70,15 @@ int Client::connect(IPAddress ip, uint16_t port) { return 1; } -long Client::write(uint8_t b) { +ssize_t Client::write(uint8_t b) { return write(&b, 1); } -long Client::write(const char *str) { +ssize_t Client::write(const char *str) { return write((const uint8_t *) str, strlen(str)); } -long Client::write(const uint8_t *buf, size_t size) { +ssize_t Client::write(const uint8_t *buf, size_t size) { if (_sock == MAX_SOCK_NUM) return -1; if (!send(_sock, buf, size)) return -2; return size; diff --git a/libraries/Ethernet/Client.h b/libraries/Ethernet/Client.h index 0a95dff96..2b1165b3a 100644 --- a/libraries/Ethernet/Client.h +++ b/libraries/Ethernet/Client.h @@ -12,9 +12,9 @@ public: uint8_t status(); int connect(IPAddress ip, uint16_t port); int connect(const char *host, uint16_t port); - virtual long write(uint8_t); - virtual long write(const char *str); - virtual long write(const uint8_t *buf, size_t size); + virtual ssize_t write(uint8_t); + virtual ssize_t write(const char *str); + virtual ssize_t write(const uint8_t *buf, size_t size); virtual int available(); virtual int read(); virtual int read(uint8_t *buf, size_t size); diff --git a/libraries/Ethernet/IPAddress.cpp b/libraries/Ethernet/IPAddress.cpp index 72bb03956..31b7769bb 100644 --- a/libraries/Ethernet/IPAddress.cpp +++ b/libraries/Ethernet/IPAddress.cpp @@ -42,9 +42,9 @@ bool IPAddress::operator==(const uint8_t* addr) return memcmp(addr, _address, sizeof(_address)) == 0; } -long IPAddress::printTo(Print& p) const +ssize_t IPAddress::printTo(Print& p) const { - long n = 0, t; + ssize_t n = 0, t; for (int i =0; i < 3; i++) { if ((t = p.print(_address[i], DEC)) > 0) n += t; diff --git a/libraries/Ethernet/IPAddress.h b/libraries/Ethernet/IPAddress.h index 5d7af6e18..473e1c4c7 100644 --- a/libraries/Ethernet/IPAddress.h +++ b/libraries/Ethernet/IPAddress.h @@ -60,7 +60,7 @@ public: IPAddress& operator=(const uint8_t *address); IPAddress& operator=(uint32_t address); - virtual long printTo(Print& p) const; + virtual ssize_t printTo(Print& p) const; friend class EthernetClass; friend class UDP; diff --git a/libraries/Ethernet/Server.cpp b/libraries/Ethernet/Server.cpp index 9e3347fac..9eb5609be 100644 --- a/libraries/Ethernet/Server.cpp +++ b/libraries/Ethernet/Server.cpp @@ -67,19 +67,19 @@ Client Server::available() return Client(MAX_SOCK_NUM); } -long Server::write(uint8_t b) +ssize_t Server::write(uint8_t b) { write(&b, 1); } -long Server::write(const char *str) +ssize_t Server::write(const char *str) { write((const uint8_t *)str, strlen(str)); } -long Server::write(const uint8_t *buffer, size_t size) +ssize_t Server::write(const uint8_t *buffer, size_t size) { - long n = 0; + ssize_t n = 0; accept(); diff --git a/libraries/Ethernet/Server.h b/libraries/Ethernet/Server.h index 60d3f3d75..289a3fe7b 100644 --- a/libraries/Ethernet/Server.h +++ b/libraries/Ethernet/Server.h @@ -14,9 +14,9 @@ public: Server(uint16_t); Client available(); void begin(); - virtual long write(uint8_t); - virtual long write(const char *str); - virtual long write(const uint8_t *buf, size_t size); + virtual ssize_t write(uint8_t); + virtual ssize_t write(const char *str); + virtual ssize_t write(const uint8_t *buf, size_t size); }; #endif diff --git a/libraries/Ethernet/Udp.cpp b/libraries/Ethernet/Udp.cpp index 5cb2b1eb6..6f94c8675 100644 --- a/libraries/Ethernet/Udp.cpp +++ b/libraries/Ethernet/Udp.cpp @@ -102,18 +102,18 @@ int UDP::endPacket() return sendUDP(_sock); } -long UDP::write(uint8_t byte) +ssize_t UDP::write(uint8_t byte) { return write(&byte, 1); } -long UDP::write(const char *str) +ssize_t UDP::write(const char *str) { size_t len = strlen(str); return write((const uint8_t *)str, len); } -long UDP::write(const uint8_t *buffer, size_t size) +ssize_t UDP::write(const uint8_t *buffer, size_t size) { uint16_t bytes_written = bufferData(_sock, _offset, buffer, size); _offset += bytes_written; diff --git a/libraries/Ethernet/Udp.h b/libraries/Ethernet/Udp.h index 65cac671a..b4b715abe 100644 --- a/libraries/Ethernet/Udp.h +++ b/libraries/Ethernet/Udp.h @@ -67,11 +67,11 @@ public: // Returns 1 if the packet was sent successfully, 0 if there was an error int endPacket(); // Write a single byte into the packet - virtual long write(uint8_t); + virtual ssize_t write(uint8_t); // Write a string of characters into the packet - virtual long write(const char *str); + virtual ssize_t write(const char *str); // Write size bytes from buffer into the packet - virtual long write(const uint8_t *buffer, size_t size); + virtual ssize_t write(const uint8_t *buffer, size_t size); // Start processing the next available incoming packet // Returns the size of the packet in bytes, or 0 if no packets are available diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index 53119df85..67f4694f1 100644 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -258,7 +258,7 @@ inline void LiquidCrystal::command(uint8_t value) { send(value, LOW); } -inline long LiquidCrystal::write(uint8_t value) { +inline ssize_t LiquidCrystal::write(uint8_t value) { send(value, HIGH); return 1; // assume sucess } diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index 2788fe08f..449142409 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -79,7 +79,7 @@ public: void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); - virtual long write(uint8_t); + virtual ssize_t write(uint8_t); void command(uint8_t); private: void send(uint8_t, uint8_t); diff --git a/libraries/SD/File.cpp b/libraries/SD/File.cpp index d0d5c00e0..4c8ada3c2 100644 --- a/libraries/SD/File.cpp +++ b/libraries/SD/File.cpp @@ -58,16 +58,16 @@ boolean File::isDirectory(void) { } -long File::write(uint8_t val) { +ssize_t File::write(uint8_t val) { return write(&val, 1); } -long File::write(const char *str) { +ssize_t File::write(const char *str) { return write((const uint8_t *) str, strlen(str)); } -long File::write(const uint8_t *buf, size_t size) { - long t; +ssize_t File::write(const uint8_t *buf, size_t size) { + ssize_t t; if (!_file) return -1; t = _file->write(buf, size); if (t < 0) return t - 1; diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h index ac750f05d..6039936d8 100644 --- a/libraries/SD/SD.h +++ b/libraries/SD/SD.h @@ -32,9 +32,9 @@ public: File(SdFile f, char *name); // wraps an underlying SdFile File(void); // 'empty' constructor ~File(void); // destructor - virtual long write(uint8_t); - virtual long write(const char *str); - virtual long write(const uint8_t *buf, size_t size); + virtual ssize_t write(uint8_t); + virtual ssize_t write(const char *str); + virtual ssize_t write(const uint8_t *buf, size_t size); virtual int read(); virtual int peek(); virtual int available(); diff --git a/libraries/SD/utility/SdFat.h b/libraries/SD/utility/SdFat.h index f9bd17f99..0c14f3d59 100644 --- a/libraries/SD/utility/SdFat.h +++ b/libraries/SD/utility/SdFat.h @@ -283,9 +283,9 @@ class SdFile : public Print { } /** \return SdVolume that contains this file. */ SdVolume* volume(void) const {return vol_;} - long write(uint8_t b); - long write(const void* buf, uint16_t nbyte); - long write(const char* str); + ssize_t write(uint8_t b); + ssize_t write(const void* buf, uint16_t nbyte); + ssize_t write(const char* str); void write_P(PGM_P str); void writeln_P(PGM_P str); //------------------------------------------------------------------------------ diff --git a/libraries/SD/utility/SdFile.cpp b/libraries/SD/utility/SdFile.cpp index 5e52704ed..f44ab6734 100644 --- a/libraries/SD/utility/SdFile.cpp +++ b/libraries/SD/utility/SdFile.cpp @@ -1121,7 +1121,7 @@ uint8_t SdFile::truncate(uint32_t length) { * for a read-only file, device is full, a corrupt file system or an I/O error. * */ -long SdFile::write(const void* buf, uint16_t nbyte) { +ssize_t SdFile::write(const void* buf, uint16_t nbyte) { // convert void* to uint8_t* - must be before goto statements const uint8_t* src = reinterpret_cast(buf); @@ -1219,7 +1219,7 @@ long SdFile::write(const void* buf, uint16_t nbyte) { * * Use SdFile::writeError to check for errors. */ -long SdFile::write(uint8_t b) { +ssize_t SdFile::write(uint8_t b) { return write(&b, 1); } //------------------------------------------------------------------------------ @@ -1228,7 +1228,7 @@ long SdFile::write(uint8_t b) { * * Use SdFile::writeError to check for errors. */ -long SdFile::write(const char* str) { +ssize_t SdFile::write(const char* str) { return write(str, strlen(str)); } //------------------------------------------------------------------------------ diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 61476f373..40f14c28a 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -440,7 +440,7 @@ int SoftwareSerial::available() return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; } -long SoftwareSerial::write(uint8_t b) +ssize_t SoftwareSerial::write(uint8_t b) { if (_tx_delay == 0) return -1; diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index 1966f18b4..59fc6206c 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -89,7 +89,7 @@ public: bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } int peek(); - virtual long write(uint8_t byte); + virtual ssize_t write(uint8_t byte); virtual int read(); virtual int available(); virtual void flush(); diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 941b90385..2b853b2de 100755 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -124,7 +124,7 @@ uint8_t TwoWire::endTransmission(void) // must be called in: // slave tx event callback // or after beginTransmission(address) -long TwoWire::write(uint8_t data) +ssize_t TwoWire::write(uint8_t data) { if(transmitting){ // in master transmitter mode @@ -148,7 +148,7 @@ long TwoWire::write(uint8_t data) // must be called in: // slave tx event callback // or after beginTransmission(address) -long TwoWire::write(const uint8_t *data, size_t quantity) +ssize_t TwoWire::write(const uint8_t *data, size_t quantity) { if(transmitting){ // in master transmitter mode @@ -166,7 +166,7 @@ long TwoWire::write(const uint8_t *data, size_t quantity) // must be called in: // slave tx event callback // or after beginTransmission(address) -long TwoWire::write(const char *data) +ssize_t TwoWire::write(const char *data) { return write((uint8_t*)data, strlen(data)); } diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index a76cd8415..b81cf8cc5 100755 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -52,9 +52,9 @@ class TwoWire : public Stream uint8_t endTransmission(void); uint8_t requestFrom(uint8_t, uint8_t); uint8_t requestFrom(int, int); - virtual long write(uint8_t); - virtual long write(const char *); - virtual long write(const uint8_t *, size_t); + virtual ssize_t write(uint8_t); + virtual ssize_t write(const char *); + virtual ssize_t write(const uint8_t *, size_t); virtual int available(void); virtual int read(void); virtual int peek(void); From b73cf39d9480f44cf55333bd0b544c9cb26330d6 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 26 Aug 2011 16:08:14 -0400 Subject: [PATCH 29/30] Moving write errors out of return value into separate API methods. write(), print(), println() now return size_t (and don't use negative values to signal errors). Print adds writeError() for checking for write errors, clearWriteError() to reset the flag to false, and a protected setWriteError() for signalling errors. http://code.google.com/p/arduino/issues/detail?id=598 --- .../arduino/cores/arduino/HardwareSerial.cpp | 2 +- .../arduino/cores/arduino/HardwareSerial.h | 2 +- hardware/arduino/cores/arduino/Print.cpp | 150 ++++++++---------- hardware/arduino/cores/arduino/Print.h | 66 ++++---- hardware/arduino/cores/arduino/Printable.h | 2 +- libraries/Ethernet/Client.cpp | 16 +- libraries/Ethernet/Client.h | 6 +- libraries/Ethernet/IPAddress.cpp | 10 +- libraries/Ethernet/IPAddress.h | 2 +- libraries/Ethernet/Server.cpp | 8 +- libraries/Ethernet/Server.h | 6 +- libraries/Ethernet/Udp.cpp | 6 +- libraries/Ethernet/Udp.h | 6 +- libraries/LiquidCrystal/LiquidCrystal.cpp | 2 +- libraries/LiquidCrystal/LiquidCrystal.h | 2 +- libraries/SD/File.cpp | 19 ++- libraries/SD/SD.h | 6 +- libraries/SD/utility/SdFat.h | 8 +- libraries/SD/utility/SdFile.cpp | 11 +- libraries/SoftwareSerial/SoftwareSerial.cpp | 8 +- libraries/SoftwareSerial/SoftwareSerial.h | 2 +- libraries/Wire/Wire.cpp | 11 +- libraries/Wire/Wire.h | 6 +- 23 files changed, 184 insertions(+), 173 deletions(-) diff --git a/hardware/arduino/cores/arduino/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp index 641c97343..d6be2181c 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -352,7 +352,7 @@ void HardwareSerial::flush() ; } -ssize_t HardwareSerial::write(uint8_t c) +size_t HardwareSerial::write(uint8_t c) { int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; diff --git a/hardware/arduino/cores/arduino/HardwareSerial.h b/hardware/arduino/cores/arduino/HardwareSerial.h index 960d3f51c..1895f08f6 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.h +++ b/hardware/arduino/cores/arduino/HardwareSerial.h @@ -55,7 +55,7 @@ class HardwareSerial : public Stream virtual int peek(void); virtual int read(void); virtual void flush(void); - virtual ssize_t write(uint8_t); + virtual size_t write(uint8_t); using Print::write; // pull in write(str) and write(buf, size) from Print }; diff --git a/hardware/arduino/cores/arduino/Print.cpp b/hardware/arduino/cores/arduino/Print.cpp index 192d9a3ff..8190d4fb4 100755 --- a/hardware/arduino/cores/arduino/Print.cpp +++ b/hardware/arduino/cores/arduino/Print.cpp @@ -30,85 +30,80 @@ // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -ssize_t Print::write(const char *str) +size_t Print::write(const char *str) { - ssize_t n = 0; + size_t n = 0; while (*str) { - if (write(*str++) <= 0) break; - n++; + n += write(*str++); } return n; } /* default implementation: may be overridden */ -ssize_t Print::write(const uint8_t *buffer, size_t size) +size_t Print::write(const uint8_t *buffer, size_t size) { - ssize_t n = 0; + size_t n = 0; while (size--) { - if (write(*buffer++) <= 0) break; - n++; + n += write(*buffer++); } return n; } -ssize_t Print::print(const __FlashStringHelper *ifsh) +size_t Print::print(const __FlashStringHelper *ifsh) { const prog_char *p = (const prog_char *)ifsh; - ssize_t n = 0; + size_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) break; - if (write(c) <= 0) break; - n++; + n += write(c); } return n; } -ssize_t Print::print(const String &s) +size_t Print::print(const String &s) { - ssize_t n = 0; + size_t n = 0; for (int i = 0; i < s.length(); i++) { - if (write(s[i]) < 0) break; - n++; + n += write(s[i]); } return n; } -ssize_t Print::print(const char str[]) +size_t Print::print(const char str[]) { return write(str); } -ssize_t Print::print(char c) +size_t Print::print(char c) { return write(c); } -ssize_t Print::print(unsigned char b, int base) +size_t Print::print(unsigned char b, int base) { return print((unsigned long) b, base); } -ssize_t Print::print(int n, int base) +size_t Print::print(int n, int base) { return print((long) n, base); } -ssize_t Print::print(unsigned int n, int base) +size_t Print::print(unsigned int n, int base) { return print((unsigned long) n, base); } -ssize_t Print::print(long n, int base) +size_t Print::print(long n, int base) { if (base == 0) { return write(n); } else if (base == 10) { if (n < 0) { int t = print('-'); - if (t <= 0) return t; n = -n; - return printNumber(n, 10) + 1; + return printNumber(n, 10) + t; } return printNumber(n, 10); } else { @@ -116,110 +111,109 @@ ssize_t Print::print(long n, int base) } } -ssize_t Print::print(unsigned long n, int base) +size_t Print::print(unsigned long n, int base) { if (base == 0) return write(n); else return printNumber(n, base); } -ssize_t Print::print(double n, int digits) +size_t Print::print(double n, int digits) { return printFloat(n, digits); } -ssize_t Print::println(const __FlashStringHelper *ifsh) +size_t Print::println(const __FlashStringHelper *ifsh) { - ssize_t n = print(ifsh); - if (n >= 0) n += println(); + size_t n = print(ifsh); + n += println(); return n; } -ssize_t Print::print(const Printable& x) +size_t Print::print(const Printable& x) { return x.printTo(*this); } -ssize_t Print::println(void) +size_t Print::println(void) { - ssize_t t = print('\r'); - if (t <= 0) return t; - if (print('\n') <= 0) return 1; - return 2; -} - -ssize_t Print::println(const String &s) -{ - ssize_t n = print(s); - if (n >= 0) n += println(); + size_t n = print('\r'); + n += print('\n'); return n; } -ssize_t Print::println(const char c[]) +size_t Print::println(const String &s) { - ssize_t n = print(c); - if (n >= 0) n += println(); + size_t n = print(s); + n += println(); return n; } -ssize_t Print::println(char c) +size_t Print::println(const char c[]) { - ssize_t n = print(c); - if (n > 0) n += println(); + size_t n = print(c); + n += println(); return n; } -ssize_t Print::println(unsigned char b, int base) +size_t Print::println(char c) { - ssize_t n = print(b, base); - if (n >= 0) n += println(); + size_t n = print(c); + n += println(); return n; } -ssize_t Print::println(int num, int base) +size_t Print::println(unsigned char b, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(b, base); + n += println(); return n; } -ssize_t Print::println(unsigned int num, int base) +size_t Print::println(int num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(long num, int base) +size_t Print::println(unsigned int num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(unsigned long num, int base) +size_t Print::println(long num, int base) { - ssize_t n = print(num, base); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(double num, int digits) +size_t Print::println(unsigned long num, int base) { - ssize_t n = print(num, digits); - if (n >= 0) n += println(); + size_t n = print(num, base); + n += println(); return n; } -ssize_t Print::println(const Printable& x) +size_t Print::println(double num, int digits) { - ssize_t n = print(x); - if (n >= 0) n += println(); + size_t n = print(num, digits); + n += println(); + return n; +} + +size_t Print::println(const Printable& x) +{ + size_t n = print(x); + n += println(); return n; } // Private Methods ///////////////////////////////////////////////////////////// -ssize_t Print::printNumber(unsigned long n, uint8_t base) { +size_t Print::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; @@ -238,14 +232,14 @@ ssize_t Print::printNumber(unsigned long n, uint8_t base) { return write(str); } -ssize_t Print::printFloat(double number, uint8_t digits) +size_t Print::printFloat(double number, uint8_t digits) { - ssize_t n = 0, t; + size_t n = 0; // Handle negative numbers if (number < 0.0) { - if ((n = print('-')) <= 0) return n; + n += print('-'); number = -number; } @@ -259,15 +253,11 @@ ssize_t Print::printFloat(double number, uint8_t digits) // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; - if ((t = print(int_part)) < 0) return n; - - n += t; + n += print(int_part); // Print the decimal point, but only if there are digits beyond if (digits > 0) { - t = print("."); - if (t <= 0) return n; - n += t; + n += print("."); } // Extract digits from the remainder one at a time @@ -275,9 +265,7 @@ ssize_t Print::printFloat(double number, uint8_t digits) { remainder *= 10.0; int toPrint = int(remainder); - t = print(toPrint); - if (t <= 0) return n; - n += t; + n += print(toPrint); remainder -= toPrint; } diff --git a/hardware/arduino/cores/arduino/Print.h b/hardware/arduino/cores/arduino/Print.h index 3f303f3d0..fce302e72 100755 --- a/hardware/arduino/cores/arduino/Print.h +++ b/hardware/arduino/cores/arduino/Print.h @@ -23,8 +23,6 @@ #include #include // for size_t -typedef int ssize_t; - #include "WString.h" #include "Printable.h" @@ -36,37 +34,45 @@ typedef int ssize_t; class Print { private: - ssize_t printNumber(unsigned long, uint8_t); - ssize_t printFloat(double, uint8_t); + int write_error; + size_t printNumber(unsigned long, uint8_t); + size_t printFloat(double, uint8_t); + protected: + void setWriteError(int err = 1) { write_error = err; } public: - virtual ssize_t write(uint8_t) = 0; - virtual ssize_t write(const char *str); - virtual ssize_t write(const uint8_t *buffer, size_t size); + Print() : write_error(0) {} + + int writeError() { return write_error; } + void clearWriteError() { setWriteError(0); } + + virtual size_t write(uint8_t) = 0; + virtual size_t write(const char *str); + virtual size_t write(const uint8_t *buffer, size_t size); - ssize_t print(const __FlashStringHelper *); - ssize_t print(const String &); - ssize_t print(const char[]); - ssize_t print(char); - ssize_t print(unsigned char, int = DEC); - ssize_t print(int, int = DEC); - ssize_t print(unsigned int, int = DEC); - ssize_t print(long, int = DEC); - ssize_t print(unsigned long, int = DEC); - ssize_t print(double, int = 2); - ssize_t print(const Printable&); + size_t print(const __FlashStringHelper *); + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(double, int = 2); + size_t print(const Printable&); - ssize_t println(const __FlashStringHelper *); - ssize_t println(const String &s); - ssize_t println(const char[]); - ssize_t println(char); - ssize_t println(unsigned char, int = DEC); - ssize_t println(int, int = DEC); - ssize_t println(unsigned int, int = DEC); - ssize_t println(long, int = DEC); - ssize_t println(unsigned long, int = DEC); - ssize_t println(double, int = 2); - ssize_t println(const Printable&); - ssize_t println(void); + size_t println(const __FlashStringHelper *); + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(double, int = 2); + size_t println(const Printable&); + size_t println(void); }; #endif diff --git a/hardware/arduino/cores/arduino/Printable.h b/hardware/arduino/cores/arduino/Printable.h index 9065904bc..e22e87ea2 100644 --- a/hardware/arduino/cores/arduino/Printable.h +++ b/hardware/arduino/cores/arduino/Printable.h @@ -30,7 +30,7 @@ class Print; class Printable { public: - virtual ssize_t printTo(Print& p) const = 0; + virtual size_t printTo(Print& p) const = 0; }; #endif diff --git a/libraries/Ethernet/Client.cpp b/libraries/Ethernet/Client.cpp index a448addec..3c1c2503b 100644 --- a/libraries/Ethernet/Client.cpp +++ b/libraries/Ethernet/Client.cpp @@ -70,17 +70,23 @@ int Client::connect(IPAddress ip, uint16_t port) { return 1; } -ssize_t Client::write(uint8_t b) { +size_t Client::write(uint8_t b) { return write(&b, 1); } -ssize_t Client::write(const char *str) { +size_t Client::write(const char *str) { return write((const uint8_t *) str, strlen(str)); } -ssize_t Client::write(const uint8_t *buf, size_t size) { - if (_sock == MAX_SOCK_NUM) return -1; - if (!send(_sock, buf, size)) return -2; +size_t Client::write(const uint8_t *buf, size_t size) { + if (_sock == MAX_SOCK_NUM) { + setWriteError(); + return 0; + } + if (!send(_sock, buf, size)) { + setWriteError(); + return 0; + } return size; } diff --git a/libraries/Ethernet/Client.h b/libraries/Ethernet/Client.h index 2b1165b3a..a8dd6fa42 100644 --- a/libraries/Ethernet/Client.h +++ b/libraries/Ethernet/Client.h @@ -12,9 +12,9 @@ public: uint8_t status(); int connect(IPAddress ip, uint16_t port); int connect(const char *host, uint16_t port); - virtual ssize_t write(uint8_t); - virtual ssize_t write(const char *str); - virtual ssize_t write(const uint8_t *buf, size_t size); + virtual size_t write(uint8_t); + virtual size_t write(const char *str); + virtual size_t write(const uint8_t *buf, size_t size); virtual int available(); virtual int read(); virtual int read(uint8_t *buf, size_t size); diff --git a/libraries/Ethernet/IPAddress.cpp b/libraries/Ethernet/IPAddress.cpp index 31b7769bb..fe3deb77a 100644 --- a/libraries/Ethernet/IPAddress.cpp +++ b/libraries/Ethernet/IPAddress.cpp @@ -42,15 +42,15 @@ bool IPAddress::operator==(const uint8_t* addr) return memcmp(addr, _address, sizeof(_address)) == 0; } -ssize_t IPAddress::printTo(Print& p) const +size_t IPAddress::printTo(Print& p) const { - ssize_t n = 0, t; + size_t n = 0; for (int i =0; i < 3; i++) { - if ((t = p.print(_address[i], DEC)) > 0) n += t; - if ((t = p.print('.')) > 0) n+= t; + n += p.print(_address[i], DEC); + n += p.print('.'); } - if ((t = p.print(_address[3], DEC)) > 0) n += t; + n += p.print(_address[3], DEC); return n; } diff --git a/libraries/Ethernet/IPAddress.h b/libraries/Ethernet/IPAddress.h index 473e1c4c7..2585aec0e 100644 --- a/libraries/Ethernet/IPAddress.h +++ b/libraries/Ethernet/IPAddress.h @@ -60,7 +60,7 @@ public: IPAddress& operator=(const uint8_t *address); IPAddress& operator=(uint32_t address); - virtual ssize_t printTo(Print& p) const; + virtual size_t printTo(Print& p) const; friend class EthernetClass; friend class UDP; diff --git a/libraries/Ethernet/Server.cpp b/libraries/Ethernet/Server.cpp index 9eb5609be..1ac75d507 100644 --- a/libraries/Ethernet/Server.cpp +++ b/libraries/Ethernet/Server.cpp @@ -67,19 +67,19 @@ Client Server::available() return Client(MAX_SOCK_NUM); } -ssize_t Server::write(uint8_t b) +size_t Server::write(uint8_t b) { write(&b, 1); } -ssize_t Server::write(const char *str) +size_t Server::write(const char *str) { write((const uint8_t *)str, strlen(str)); } -ssize_t Server::write(const uint8_t *buffer, size_t size) +size_t Server::write(const uint8_t *buffer, size_t size) { - ssize_t n = 0; + size_t n = 0; accept(); diff --git a/libraries/Ethernet/Server.h b/libraries/Ethernet/Server.h index 289a3fe7b..fa4a56d88 100644 --- a/libraries/Ethernet/Server.h +++ b/libraries/Ethernet/Server.h @@ -14,9 +14,9 @@ public: Server(uint16_t); Client available(); void begin(); - virtual ssize_t write(uint8_t); - virtual ssize_t write(const char *str); - virtual ssize_t write(const uint8_t *buf, size_t size); + virtual size_t write(uint8_t); + virtual size_t write(const char *str); + virtual size_t write(const uint8_t *buf, size_t size); }; #endif diff --git a/libraries/Ethernet/Udp.cpp b/libraries/Ethernet/Udp.cpp index 6f94c8675..a1244ffb9 100644 --- a/libraries/Ethernet/Udp.cpp +++ b/libraries/Ethernet/Udp.cpp @@ -102,18 +102,18 @@ int UDP::endPacket() return sendUDP(_sock); } -ssize_t UDP::write(uint8_t byte) +size_t UDP::write(uint8_t byte) { return write(&byte, 1); } -ssize_t UDP::write(const char *str) +size_t UDP::write(const char *str) { size_t len = strlen(str); return write((const uint8_t *)str, len); } -ssize_t UDP::write(const uint8_t *buffer, size_t size) +size_t UDP::write(const uint8_t *buffer, size_t size) { uint16_t bytes_written = bufferData(_sock, _offset, buffer, size); _offset += bytes_written; diff --git a/libraries/Ethernet/Udp.h b/libraries/Ethernet/Udp.h index b4b715abe..59238c1ae 100644 --- a/libraries/Ethernet/Udp.h +++ b/libraries/Ethernet/Udp.h @@ -67,11 +67,11 @@ public: // Returns 1 if the packet was sent successfully, 0 if there was an error int endPacket(); // Write a single byte into the packet - virtual ssize_t write(uint8_t); + virtual size_t write(uint8_t); // Write a string of characters into the packet - virtual ssize_t write(const char *str); + virtual size_t write(const char *str); // Write size bytes from buffer into the packet - virtual ssize_t write(const uint8_t *buffer, size_t size); + virtual size_t write(const uint8_t *buffer, size_t size); // Start processing the next available incoming packet // Returns the size of the packet in bytes, or 0 if no packets are available diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index 67f4694f1..81a3b7f64 100644 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -258,7 +258,7 @@ inline void LiquidCrystal::command(uint8_t value) { send(value, LOW); } -inline ssize_t LiquidCrystal::write(uint8_t value) { +inline size_t LiquidCrystal::write(uint8_t value) { send(value, HIGH); return 1; // assume sucess } diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index 449142409..f4352f341 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -79,7 +79,7 @@ public: void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); - virtual ssize_t write(uint8_t); + virtual size_t write(uint8_t); void command(uint8_t); private: void send(uint8_t, uint8_t); diff --git a/libraries/SD/File.cpp b/libraries/SD/File.cpp index 4c8ada3c2..ffd09471f 100644 --- a/libraries/SD/File.cpp +++ b/libraries/SD/File.cpp @@ -58,19 +58,26 @@ boolean File::isDirectory(void) { } -ssize_t File::write(uint8_t val) { +size_t File::write(uint8_t val) { return write(&val, 1); } -ssize_t File::write(const char *str) { +size_t File::write(const char *str) { return write((const uint8_t *) str, strlen(str)); } -ssize_t File::write(const uint8_t *buf, size_t size) { - ssize_t t; - if (!_file) return -1; +size_t File::write(const uint8_t *buf, size_t size) { + size_t t; + if (!_file) { + setWriteError(); + return 0; + } + _file->clearWriteError(); t = _file->write(buf, size); - if (t < 0) return t - 1; + if (_file->writeError()) { + setWriteError(); + return 0; + } return t; } diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h index 6039936d8..cd123edc6 100644 --- a/libraries/SD/SD.h +++ b/libraries/SD/SD.h @@ -32,9 +32,9 @@ public: File(SdFile f, char *name); // wraps an underlying SdFile File(void); // 'empty' constructor ~File(void); // destructor - virtual ssize_t write(uint8_t); - virtual ssize_t write(const char *str); - virtual ssize_t write(const uint8_t *buf, size_t size); + virtual size_t write(uint8_t); + virtual size_t write(const char *str); + virtual size_t write(const uint8_t *buf, size_t size); virtual int read(); virtual int peek(); virtual int available(); diff --git a/libraries/SD/utility/SdFat.h b/libraries/SD/utility/SdFat.h index 0c14f3d59..344326f98 100644 --- a/libraries/SD/utility/SdFat.h +++ b/libraries/SD/utility/SdFat.h @@ -141,7 +141,7 @@ class SdFile : public Print { * Set writeError to false before calling print() and/or write() and check * for true after calls to print() and/or write(). */ - bool writeError; + //bool writeError; /** * Cancel unbuffered reads for this file. * See setUnbufferedRead() @@ -283,9 +283,9 @@ class SdFile : public Print { } /** \return SdVolume that contains this file. */ SdVolume* volume(void) const {return vol_;} - ssize_t write(uint8_t b); - ssize_t write(const void* buf, uint16_t nbyte); - ssize_t write(const char* str); + size_t write(uint8_t b); + size_t write(const void* buf, uint16_t nbyte); + size_t write(const char* str); void write_P(PGM_P str); void writeln_P(PGM_P str); //------------------------------------------------------------------------------ diff --git a/libraries/SD/utility/SdFile.cpp b/libraries/SD/utility/SdFile.cpp index f44ab6734..47974e206 100644 --- a/libraries/SD/utility/SdFile.cpp +++ b/libraries/SD/utility/SdFile.cpp @@ -1121,7 +1121,7 @@ uint8_t SdFile::truncate(uint32_t length) { * for a read-only file, device is full, a corrupt file system or an I/O error. * */ -ssize_t SdFile::write(const void* buf, uint16_t nbyte) { +size_t SdFile::write(const void* buf, uint16_t nbyte) { // convert void* to uint8_t* - must be before goto statements const uint8_t* src = reinterpret_cast(buf); @@ -1210,8 +1210,9 @@ ssize_t SdFile::write(const void* buf, uint16_t nbyte) { writeErrorReturn: // return for write error - writeError = true; - return -1; + //writeError = true; + setWriteError(); + return 0; } //------------------------------------------------------------------------------ /** @@ -1219,7 +1220,7 @@ ssize_t SdFile::write(const void* buf, uint16_t nbyte) { * * Use SdFile::writeError to check for errors. */ -ssize_t SdFile::write(uint8_t b) { +size_t SdFile::write(uint8_t b) { return write(&b, 1); } //------------------------------------------------------------------------------ @@ -1228,7 +1229,7 @@ ssize_t SdFile::write(uint8_t b) { * * Use SdFile::writeError to check for errors. */ -ssize_t SdFile::write(const char* str) { +size_t SdFile::write(const char* str) { return write(str, strlen(str)); } //------------------------------------------------------------------------------ diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 40f14c28a..c15bdda0d 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -440,10 +440,12 @@ int SoftwareSerial::available() return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF; } -ssize_t SoftwareSerial::write(uint8_t b) +size_t SoftwareSerial::write(uint8_t b) { - if (_tx_delay == 0) - return -1; + if (_tx_delay == 0) { + setWriteError(); + return 0; + } uint8_t oldSREG = SREG; cli(); // turn off interrupts for a clean txmit diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index 59fc6206c..67f76cfdc 100755 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -89,7 +89,7 @@ public: bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } int peek(); - virtual ssize_t write(uint8_t byte); + virtual size_t write(uint8_t byte); virtual int read(); virtual int available(); virtual void flush(); diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 2b853b2de..211d9c7ef 100755 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -124,13 +124,14 @@ uint8_t TwoWire::endTransmission(void) // must be called in: // slave tx event callback // or after beginTransmission(address) -ssize_t TwoWire::write(uint8_t data) +size_t TwoWire::write(uint8_t data) { if(transmitting){ // in master transmitter mode // don't bother if buffer is full if(txBufferLength >= BUFFER_LENGTH){ - return -1; + setWriteError(); + return 0; } // put byte in tx buffer txBuffer[txBufferIndex] = data; @@ -148,12 +149,12 @@ ssize_t TwoWire::write(uint8_t data) // must be called in: // slave tx event callback // or after beginTransmission(address) -ssize_t TwoWire::write(const uint8_t *data, size_t quantity) +size_t TwoWire::write(const uint8_t *data, size_t quantity) { if(transmitting){ // in master transmitter mode for(size_t i = 0; i < quantity; ++i){ - if (write(data[i]) < 0) return i; + write(data[i]); } }else{ // in slave send mode @@ -166,7 +167,7 @@ ssize_t TwoWire::write(const uint8_t *data, size_t quantity) // must be called in: // slave tx event callback // or after beginTransmission(address) -ssize_t TwoWire::write(const char *data) +size_t TwoWire::write(const char *data) { return write((uint8_t*)data, strlen(data)); } diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index b81cf8cc5..7f6ea67ad 100755 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -52,9 +52,9 @@ class TwoWire : public Stream uint8_t endTransmission(void); uint8_t requestFrom(uint8_t, uint8_t); uint8_t requestFrom(int, int); - virtual ssize_t write(uint8_t); - virtual ssize_t write(const char *); - virtual ssize_t write(const uint8_t *, size_t); + virtual size_t write(uint8_t); + virtual size_t write(const char *); + virtual size_t write(const uint8_t *, size_t); virtual int available(void); virtual int read(void); virtual int peek(void); From 4553cee4430393e5fa7e80b4bc79b164fe393138 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 27 Aug 2011 00:00:10 +0200 Subject: [PATCH 30/30] Fixes to compile under Java 1.5 (on my Linux machine). --- app/src/processing/app/Editor.java | 1 - app/src/processing/app/syntax/SyntaxUtilities.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 405b16b34..dd6ad5614 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2655,7 +2655,6 @@ public class Editor extends JFrame implements RunnerListener { public TextAreaPopup() { openURLItem = new JMenuItem("Open URL"); openURLItem.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { Base.openURL(clickedURL); } diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index f6aa20e2b..1e3c6c900 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -211,7 +211,7 @@ public class SyntaxUtilities Segment tag = stringToSegment(parse[1]); Segment post = stringToSegment(parse[2]); - if (pre.length()>0) + if (pre.count>0) x = Utilities.drawTabbedText(pre, x, y, gfx, expander, 0); Font f = gfx.getFont(); @@ -219,7 +219,7 @@ public class SyntaxUtilities x = Utilities.drawTabbedText(tag, x, y, gfx, expander, 0); commentStyle.setGraphicsFlags(gfx, f); - if (post.length()>0) + if (post.count>0) x = Utilities.drawTabbedText(post, x, y, gfx, expander, 0); return x; }