diff --git a/app/AvrdudeUploader.java b/app/AvrdudeUploader.java index 5bc920304..e93843266 100755 --- a/app/AvrdudeUploader.java +++ b/app/AvrdudeUploader.java @@ -85,6 +85,10 @@ public class AvrdudeUploader extends Uploader { // XXX: add support for specifying the port address for parallel // programmers, although avrdude has a default that works in most cases. + if (Preferences.get("programmers." + programmer + ".force") != null && + Preferences.getBoolean("programmers." + programmer + ".force")) + params.add("-F"); + if (Preferences.get("programmers." + programmer + ".delay") != null) params.add("-i" + Preferences.get("programmers." + programmer + ".delay")); diff --git a/app/preproc/PdePreprocessor.java b/app/preproc/PdePreprocessor.java index 95cdefe47..40bd31330 100755 --- a/app/preproc/PdePreprocessor.java +++ b/app/preproc/PdePreprocessor.java @@ -83,6 +83,41 @@ public class PdePreprocessor { */ //public static TokenStreamCopyingHiddenTokenFilter filter; + /** + * Returns the index of the first character that's not whitespace, a comment + * or a pre-processor directive. + */ + public int firstStatement(String in) { + PatternMatcherInput input = new PatternMatcherInput(in); + PatternCompiler compiler = new Perl5Compiler(); + PatternMatcher matcher = new Perl5Matcher(); + Pattern pattern = null; + + try { + pattern = compiler.compile( + // XXX: doesn't properly handle special single-quoted characters + // whitespace + "\\s+" + "|" + + // multi-line comment + "(/\\*(?:.|\\n)*?\\*/)" + "|" + + // single-line comment + "(//.*?$)" + "|" + + // pre-processor directive + "(#(?:\\\\\\n|.)*)", + Perl5Compiler.MULTILINE_MASK); + } catch (MalformedPatternException e) { + throw new RuntimeException("Internal error in firstStatement()", e); + } + + int i = 0; + while (matcher.matchesPrefix(input, pattern)) { + i = matcher.getMatch().endOffset(0); + input.setCurrentOffset(i); + } + + return i; + } + /** * Strips comments, pre-processor directives, single- and double-quoted * strings from a string. @@ -272,9 +307,9 @@ public class PdePreprocessor { File streamFile = new File(buildPath, name + ".cpp"); PrintStream stream = new PrintStream(new FileOutputStream(streamFile)); - writeHeader(stream, name, prototypes); + writeHeader(stream); //added to write the pde code to the cpp file - writeProgram(stream, name, program); + writeProgram(stream, program, prototypes); writeFooter(stream, target); stream.close(); @@ -282,8 +317,17 @@ public class PdePreprocessor { } // Write the pde program to the cpp file - void writeProgram(PrintStream out, String className, String program) { - out.print(program); + void writeProgram(PrintStream out, String program, List prototypes) { + int prototypeInsertionPoint = firstStatement(program); + + out.print(program.substring(0, prototypeInsertionPoint)); + + // print user defined prototypes + for (int i = 0; i < prototypes.size(); i++) { + out.print(prototypes.get(i) + "\n"); + } + + out.print(program.substring(prototypeInsertionPoint)); } @@ -291,24 +335,10 @@ public class PdePreprocessor { * Write any required header material (eg imports, class decl stuff) * * @param out PrintStream to write it to. - * @param exporting Is this being exported from PDE? - * @param name Name of the class being created. */ - void writeHeader(PrintStream out, String className, List prototypes) + void writeHeader(PrintStream out) throws IOException { - out.print("#include \"WProgram.h\"\n"); - - // print user defined prototypes - for (int i = 0; i < prototypes.size(); i++) { - out.print(prototypes.get(i) + "\n"); - } - -// // emit emports that are needed for classes from the code folder -// if (extraImports != null) { -// for (int i = 0; i < extraImports.length; i++) { -// out.print("#include \"" + extraImports[i] + "\"\n"); -// } -// } + out.print("#include \"WProgram.h\"\n"); } /** diff --git a/build/macosx/Arduino.xcodeproj/project.pbxproj b/build/macosx/Arduino.xcodeproj/project.pbxproj index 734dd64b1..79578de93 100644 --- a/build/macosx/Arduino.xcodeproj/project.pbxproj +++ b/build/macosx/Arduino.xcodeproj/project.pbxproj @@ -151,6 +151,7 @@ $JAVAROOT/registry.jar $JAVAROOT/RXTXcomm.jar $JAVAROOT/quaqua.jar + /System/Library/Java JVMVersion 1.4+ diff --git a/hardware/programmers.txt b/hardware/programmers.txt index a235d0033..c3e4d9b66 100644 --- a/hardware/programmers.txt +++ b/hardware/programmers.txt @@ -11,4 +11,5 @@ usbtinyisp.protocol=usbtiny parallel.name=Parallel Programmer parallel.protocol=dapa -parallel.delay=800 \ No newline at end of file +parallel.force=true +# parallel.delay=200 diff --git a/readme.txt b/readme.txt index c3e3f690f..290edee1b 100644 --- a/readme.txt +++ b/readme.txt @@ -54,6 +54,9 @@ UPDATES * Added interrupts() and noInterrupts() functions. * Added degrees() and radians() functions. * Support for uploading sketch using a programmer (upload.using preference). +* Improved detection of functions that need prototyping. +* Placing function prototypes after #include's and #define's. +* No longer moving #include statements to the top of the sketch. * Including a working version of the Firmata firmware. * New script for downloading the reference from Tom Pollard. Thanks Tom! * Miscellaneous Mac OS X and other patches from Wim Lewis. Thanks Wim! diff --git a/todo.txt b/todo.txt index 2d8748c08..0a1008ad0 100644 --- a/todo.txt +++ b/todo.txt @@ -3,16 +3,16 @@ 0011 Improve preprocessing of sketches: - - Don't move #include statements. - - Insert prototypes as a better spot in the code (after pre-processor directives). - Better determine which header files are included (not commented out). - Remember the original locations of function prototypes to highlight the correct line on error. + - [done] Insert prototypes at a better spot in the code (after pre-processor directives). + - [done] Don't move #include statements. - [done] Better determine which functions need prototypes Update version of the FTDI drivers. Floating point support in the map() function. -Modify parallel port programmer burning (add -F, lower or remove delay). Incorporate ladyada's new SoftwareSerial library. Add timeout parameter to pulseIn(). +[done] Modify parallel port programmer burning (add -F, lower or remove delay). [done] Allow uploading using a hardware programmer. [done] Add analogReference() function. [done] Add miscellaneous #defines (interrupts(), int(), etc.) @@ -28,6 +28,8 @@ Add pulseOut(), etc. functions from Wiring. Add String library. Create Encoder library (but don't include in the distribution). Create Ping library (but don't include in the distribution). +Add highByte(), lowByte(), and word(high, low) functions. +Add bitRead() and bitWrite() functions. Include Arduino as AVR-ISP sketch in hardware/firmwares. COMPUTER