<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,13 +1,10 @@
 class BasicBlink &lt; ArduinoSketch
-  
-
   # hello world (uncomment to run)
   
   output_pin 13, :as =&gt; :led
   
-    def loop
-      blink led, 100 
-      x = 4
-    end
-    
+  def loop
+    blink led, 100 
+    x = 4
+  end
 end</diff>
      <filename>lib/examples/basic_blink.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,24 +1,26 @@
 class ExternalVariableFu &lt; ArduinoSketch
   
-@one = int
-@two = long
-@three = unsigned
-@four = short
-@five = byte
-@six = 1
-@seven = 1.2
-@eight = &quot;0x00&quot;
-@nine = &quot;arduino&quot;
-@ten = true
-@eleven = false
-@twelve = &quot;1, long&quot;
-@thirteen = &quot;1, unsigned&quot;
-@fourteen = &quot;1, byte&quot;
+  @one = int
+  @two = long
+  @three = unsigned
+  @four = short
+  @five = byte
+  @six = 1
+  @seven = 1.2
+  @eight = &quot;0x00&quot;
+  @nine = &quot;arduino&quot;
+  @ten = true
+  @eleven = false
+  @twelve = &quot;1, long&quot;
+  @thirteen = &quot;1, unsigned&quot;
+  @fourteen = &quot;1, byte&quot;
+  @fifteen = HIGH
+  @sixteen = LOW
+  @seventeen = ON 
+  @eighteen = OFF
 
-
-
-     def loop
-      delay @six
-     end
+  def loop
+   delay @six
+  end
      
 end
\ No newline at end of file</diff>
      <filename>lib/examples/external_variable_fu.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,10 +14,7 @@ class ExternalVariables &lt; ArduinoSketch
   @boom = &quot;1, int&quot;
   @rad = &quot;1.00&quot;
   
-  
-  
   def loop
-
 	  delay 1
 	  @foo = 2
     @foo = KOOL</diff>
      <filename>lib/examples/external_variables.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,9 @@ class HelloWorld &lt; ArduinoSketch
   
   output_pin 13, :as =&gt; :led
 
-     def loop
-         blink led, 100
-     end
+  def loop
+    blink led, 100
+  end
 
 end
 </diff>
      <filename>lib/examples/hello_world.rb</filename>
    </modified>
    <modified>
      <diff>@@ -186,11 +186,30 @@ class ArduinoSketch
     @other_setup = [] # specifically, Serial.begin
     @assembler_declarations = []
     @accessors = []
+#    @signatures = [&quot;void blink();&quot;, &quot;int main();&quot;, &quot;void track_total_loop_time(void);&quot;, &quot;unsigned long find_total_loop_time(void);&quot;]
+#    @signatures = [&quot;int main();&quot;, &quot;void track_total_loop_time(void);&quot;, &quot;unsigned long find_total_loop_time(void);&quot;]
     @signatures = [&quot;int main();&quot;]
 
     helper_methods = []
+#    helper_methods &lt;&lt; &quot;void blink(int pin, int ms) {&quot;
+#    helper_methods &lt;&lt; &quot;\tdigitalWrite( pin, HIGH );&quot;
+#    helper_methods &lt;&lt; &quot;\tdelay( ms );&quot;
+#    helper_methods &lt;&lt; &quot;\tdigitalWrite( pin, LOW );&quot;
+#    helper_methods &lt;&lt; &quot;\tdelay( ms );&quot;
+#    helper_methods &lt;&lt; &quot;}&quot;
+#    helper_methods &lt;&lt; &quot;void track_total_loop_time(void)&quot;
+#    helper_methods &lt;&lt; &quot;{&quot;
+#    helper_methods &lt;&lt; &quot;\ttotal_loop_time = millis() - start_loop_time;&quot;
+#    helper_methods &lt;&lt; &quot;\tstart_loop_time = millis();&quot;
+#    helper_methods &lt;&lt; &quot;}&quot;
+#    helper_methods &lt;&lt; &quot;unsigned long find_total_loop_time(void)&quot;
+#    helper_methods &lt;&lt; &quot;{&quot;
+#    helper_methods &lt;&lt; &quot;\nreturn total_loop_time;&quot;
+#    helper_methods &lt;&lt; &quot;}&quot;
     @helper_methods = helper_methods.join( &quot;\n&quot; )
     
+#    @declarations &lt;&lt; &quot;unsigned long start_loop_time = 0;&quot;
+#    @declarations &lt;&lt; &quot;unsigned long total_loop_time = 0;&quot;
   end
   
   # Setup variables outside of the loop. Does some magic based on type of arguments. Subject to renaming. Use with caution.
@@ -548,23 +567,6 @@ class ArduinoSketch
 
   end
   
-  def formatted_print(opts={})
-
-    buffer_size = opts[:buffer_size] ? opts[:buffer_size] : 64
-    
-    if opts[:as]
-      @@sprintf_inc ||= FALSE
-      if @@sprintf_inc == FALSE
-        @@sprintf_inc = TRUE
-        accessor = []
-        accessor &lt;&lt; &quot;\n#undef int\n#include &lt;stdio.h&gt;&quot;
-        accessor &lt;&lt; &quot;#define write_line(...) sprintf(#{opts[:as]},__VA_ARGS__);&quot;
-        @accessors &lt;&lt; accessor.join( &quot;\n&quot; )
-        array(&quot;char #{opts[:as]}[#{buffer_size}]&quot;) 
-      end
-    end
-  end
-  
   # Treat a pair of digital I/O pins as a serial line. See: http://www.arduino.cc/en/Tutorial/SoftwareSerial
   def software_serial(rx, tx, opts={})
     raise ArgumentError, &quot;can only define rx from Fixnum, got #{rx.class}&quot; unless rx.is_a?(Fixnum)
@@ -650,6 +652,34 @@ class ArduinoSketch
   				accessor &lt;&lt; &quot;void print( SWSerLCDpa&amp; s, long i, int b ) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.print( i, b );&quot;
   				accessor &lt;&lt; &quot;}&quot;
+  				# ------------------- print line generics -------------------------------
+	  			accessor &lt;&lt; &quot;void println(SWSerLCDpa&amp; s) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println();&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, uint8_t b ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( b );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, char* str ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( str );&quot;
+ 	 			  accessor &lt;&lt; &quot;}&quot;
+ 	 			  accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, char c ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( c );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, const char c[] ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( c );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, int i ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( i );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, long i ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( i );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, unsigned long i ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( i );&quot;
+  				accessor &lt;&lt; &quot;}&quot;
+  				accessor &lt;&lt; &quot;void println( SWSerLCDpa&amp; s, long i, int b ) {&quot;
+  				accessor &lt;&lt; &quot;\treturn s.println( i, b );&quot;
+ 	 			  accessor &lt;&lt; &quot;}&quot;
           # ------------------ PA-LCD specific functions ---------------------------------
    				accessor &lt;&lt; &quot;void clearscr(SWSerLCDpa&amp; s) {&quot;
  	 			  accessor &lt;&lt; &quot;\treturn s.clearscr();&quot;
@@ -660,9 +690,6 @@ class ArduinoSketch
   				accessor &lt;&lt; &quot;void clearscr(SWSerLCDpa&amp; s, int n) {&quot;
  	 			  accessor &lt;&lt; &quot;\treturn s.clearscr(n);&quot;
   				accessor &lt;&lt; &quot;}&quot;
-  				accessor &lt;&lt; &quot;void clearscr(SWSerLCDpa&amp; s, long n, int b) {&quot;
- 	 			  accessor &lt;&lt; &quot;\treturn s.clearscr(n, b);&quot;
-  				accessor &lt;&lt; &quot;}&quot;
    				accessor &lt;&lt; &quot;void clearline(SWSerLCDpa&amp; s, int line) {&quot;
  	 			  accessor &lt;&lt; &quot;\treturn s.clearline( line );&quot;
   				accessor &lt;&lt; &quot;}&quot;
@@ -672,9 +699,6 @@ class ArduinoSketch
    				accessor &lt;&lt; &quot;void clearline(SWSerLCDpa&amp; s, int line, int n) {&quot;
  	 			  accessor &lt;&lt; &quot;\treturn s.clearline( line, n );&quot;
   				accessor &lt;&lt; &quot;}&quot;
-   				accessor &lt;&lt; &quot;void clearline(SWSerLCDpa&amp; s, int line, long n,  int b) {&quot;
- 	 			  accessor &lt;&lt; &quot;\treturn s.clearline( line, n, b );&quot;
-  				accessor &lt;&lt; &quot;}&quot;
   				accessor &lt;&lt; &quot;void home( SWSerLCDpa&amp; s) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.home();&quot;
   				accessor &lt;&lt; &quot;}&quot;
@@ -684,18 +708,12 @@ class ArduinoSketch
   				accessor &lt;&lt; &quot;void home( SWSerLCDpa&amp; s, int n) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.home( n );&quot;
     			accessor &lt;&lt; &quot;}&quot;
-  				accessor &lt;&lt; &quot;void home( SWSerLCDpa&amp; s, long n, int b) {&quot;
-  				accessor &lt;&lt; &quot;\treturn s.home( n, b );&quot;
-    			accessor &lt;&lt; &quot;}&quot;
   				accessor &lt;&lt; &quot;void setxy( SWSerLCDpa&amp; s, int x, int y) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.setxy( x, y );&quot;
   				accessor &lt;&lt; &quot;}&quot;
   				accessor &lt;&lt; &quot;void setxy( SWSerLCDpa&amp; s, int x, int y, const char *str) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.setxy( x, y, str );&quot;
     			accessor &lt;&lt; &quot;}&quot;
-  				accessor &lt;&lt; &quot;void setxy( SWSerLCDpa&amp; s, int x, int y, long n, int b) {&quot;
-  				accessor &lt;&lt; &quot;\treturn s.setxy( x, y, n, b );&quot;
-    			accessor &lt;&lt; &quot;}&quot;
   				accessor &lt;&lt; &quot;void setxy( SWSerLCDpa&amp; s, int x, int y, int n) {&quot;
   				accessor &lt;&lt; &quot;\treturn s.setxy( x, y, n );&quot;
     			accessor &lt;&lt; &quot;}&quot;
@@ -1359,18 +1377,9 @@ class ArduinoSketch
   end
   
   def self.pre_process(sketch_string) #:nodoc:
-    result = sketch_string 
     # add external vars to each method (needed for better translation, will be removed in make:upload)
-    result.gsub!(/(^\s*def\s.\w*(\(.*\))?)/, '\1' + &quot; \n #{$external_vars.join(&quot;  \n &quot;)}&quot;  )
-    # gather method names
-    sketch_methods = result.scan(/^\s*def\s.\w*/)
-    sketch_methods.each {|m| $sketch_methods &lt;&lt; m.gsub(/\s*def\s*/, &quot;&quot;) }
-    
-    result.gsub!(&quot;HIGH&quot;, &quot;1&quot;)
-    result.gsub!(&quot;LOW&quot;, &quot;0&quot;)
-    result.gsub!(&quot;ON&quot;, &quot;1&quot;)
-    result.gsub!(&quot;OFF&quot;, &quot;0&quot;)
-    result
+    sketch_string.gsub!(/(^\s*def\s.\w*(\(.*\))?)/, '\1' + &quot; \n #{$external_vars.join(&quot;  \n &quot;)}&quot;  )
+    sketch_string
   end
   
   def self.add_to_setup(meth) </diff>
      <filename>lib/rad/arduino_sketch.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,17 +21,27 @@ class SketchCompiler
   end
   
   def parent_dir
-    @path.split(&quot;/&quot;)[0..@path.split(&quot;/&quot;).length-2].join(&quot;/&quot;)
+    self.path.split(&quot;/&quot;)[0..@path.split(&quot;/&quot;).length-2].join(&quot;/&quot;)
   end
   
   def build_dir
-    &quot;#{@target_dir}/#{@name}&quot;
+    &quot;#{self.target_dir}/#{self.name}&quot;
   end
 
   def create_build_dir! optional_path_prefix=nil
-    @target_dir = optional_path_prefix if optional_path_prefix
+    self.target_dir = optional_path_prefix if optional_path_prefix
     mkdir_p build_dir
   end
   
+  def process_constants
+    self.body.gsub!(&quot;HIGH&quot;, &quot;1&quot;)
+    self.body.gsub!(&quot;LOW&quot;, &quot;0&quot;)
+    self.body.gsub!(&quot;ON&quot;, &quot;1&quot;)
+    self.body.gsub!(&quot;OFF&quot;, &quot;0&quot;)
+  end
+  
+  def sketch_methods
+    self.body.scan(/^\s*def\s.\w*/).collect{ |m| m.gsub(/\s*def\s*/, &quot;&quot;) }
+  end
   
 end
\ No newline at end of file</diff>
      <filename>lib/rad/sketch_compiler.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,18 +19,20 @@ namespace :test do
   end
   
   task :compile =&gt; :gather do 
+
     @examples.each {|e| run_tests(e, &quot;compile&quot;)}
-    end
   end
   
   desc &quot;gather all tests&quot;
   task :gather do # =&gt; &quot;make:upload&quot; do
     @examples = []
-    @test_results = []
-    Dir.entries( File.expand_path(&quot;#{RAD_ROOT}/examples/&quot;) ).each do |f|
-      if (f =~ /\.rb$/)
-        @examples &lt;&lt; f.split('.').first
+    if ENV['sketch']
+      @examples &lt;&lt; ENV['sketch']
+    else
+      Dir.entries( File.expand_path(&quot;#{RAD_ROOT}/examples/&quot;) ).each do |f|
+        @examples &lt;&lt; f.split('.').first if (f =~ /\.rb$/)
       end
+    end
   end
 
 end
@@ -49,10 +51,8 @@ namespace :make do
     
   desc &quot;generate a makefile and use it to compile the .cpp&quot;
   task :compile =&gt; [:clean_sketch_dir, &quot;build:sketch&quot;] do # should also depend on &quot;build:sketch&quot;
-    puts; puts
-    puts @compiler.name
-    puts
     Makefile.compose_for_sketch( @compiler.build_dir )
+
     # not allowed? sh %{export PATH=#{Makefile.software_params[:arduino_root]}/tools/avr/bin:$PATH}
     sh %{cd #{@compiler.build_dir}; make depend; make}
   end
@@ -86,7 +86,7 @@ namespace :build do
     c_methods = []
     sketch_signatures = []
     # until we better understand RubyToC let's see what's happening on errors
-    $sketch_methods.each do |meth| 
+    @compiler.sketch_methods.each do |meth|   
       raw_rtc_meth = RADProcessor.translate(constantize(@compiler.klass), meth) 
       puts &quot;Translator Error: #{raw_rtc_meth.inspect}&quot; if raw_rtc_meth[0..8] == &quot;// ERROR:&quot;
       c_methods &lt;&lt; raw_rtc_meth unless meth == &quot;setup&quot;
@@ -137,6 +137,9 @@ namespace :build do
        end
        CODE
     end   
+    
+    @compiler.process_constants
+    
     eval ArduinoSketch.pre_process(@compiler.body)
     @@as.process_external_vars(constantize(@compiler.klass))
     @setup = @@as.compose_setup
@@ -177,18 +180,15 @@ namespace :build do
   desc &quot;setup target directory named after your sketch class&quot;
   task :sketch_dir =&gt; [:file_list] do
     @compiler.create_build_dir!
-    # mkdir_p &quot;#{@test_dir + @sketch_class.split(&quot;.&quot;).first}&quot;
   end
 
   task :file_list do
     # take another look at this, since if the root directory name is changed, everything breaks
     # perhaps we generate a constant when the project is generated an pop it here or in the init file
-    # assume the only .rb file in the sketch dir is the sketch:
     if ENV['sketch']
-
       @compiler = SketchCompiler.new File.expand_path(&quot;#{ENV['sketch']}.rb&quot;)
-
     else
+      # assume the only .rb file in the sketch dir is the sketch:
       @compiler = SketchCompiler.new Dir.glob(&quot;#{File.expand_path(File.dirname(__FILE__))}/../../../*.rb&quot;).first
     end
 </diff>
      <filename>lib/rad/tasks/build_and_make.rake</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,35 @@
 require File.dirname(__FILE__) + '/spec_helper.rb'
 require File.expand_path(File.dirname(__FILE__) + &quot;/../../lib/rad/sketch_compiler.rb&quot;)
 
+context &quot;SketchCompiler#sketch_methods&quot; do
+  before do
+    @as = File.expand_path(File.dirname(__FILE__)) + &quot;/../../lib/examples/i2c_with_clock_chip.rb&quot;
+    @sc = SketchCompiler.new @as
+  end
+  
+  it &quot;should locate all the methods defined in the sketch&quot; do
+    @sc.sketch_methods.should include( &quot;loop&quot;)
+    @sc.sketch_methods.should include( &quot;printlz&quot;)
+    @sc.sketch_methods.should include( &quot;print_hexbyte&quot;)
+    @sc.sketch_methods.should include( &quot;clear_bottom_line&quot;)
+  end
+end
+
+context &quot;SketchCompiler#process_constants&quot; do
+  before do
+    @as = File.expand_path(File.dirname(__FILE__)) + &quot;/../../lib/examples/external_variable_fu.rb&quot;
+    @sc = SketchCompiler.new @as
+  end
+  
+  it &quot;should correctly process constants&quot; do
+    @sc.process_constants
+    @sc.body.should_not match(/HIGH/)
+    @sc.body.should_not match(/LOW/)
+    @sc.body.should_not match(/ON/)
+    @sc.body.should_not match(/OFF/)
+  end
+end
+
 context &quot;SketchCompiler.new&quot; do
   before do
     @as = File.expand_path(File.dirname(__FILE__)) + &quot;/../../lib/examples/add_hysteresis.rb&quot;</diff>
      <filename>spec/models/sketch_compiler_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b0603cd723018b0cff6518cb1168093bacb2300c</id>
    </parent>
  </parents>
  <author>
    <name>Greg Borenstein</name>
    <email>greg@mfdz.com</email>
  </author>
  <url>http://github.com/atduskgreg/rad/commit/b63bccb7cdef9670eb9361f967543891677ea481</url>
  <id>b63bccb7cdef9670eb9361f967543891677ea481</id>
  <committed-date>2008-08-04T02:09:58-07:00</committed-date>
  <authored-date>2008-08-04T02:09:58-07:00</authored-date>
  <message>SketchCompiler does pre-processing for constants and creates the list of methods</message>
  <tree>56d6ccbd2627f4f20588bf31a386b3c6e7f7641f</tree>
  <committer>
    <name>Greg Borenstein</name>
    <email>greg@mfdz.com</email>
  </committer>
</commit>
