madrona-rad 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.2.4 2008-07-12
2
+ * 1ish large update:
3
+ - added incredibly primitive tests
4
+ - added 11 sketch examples which are compiled or compiled/uploaded
5
+ - use rake test:compile or rake test:upload
6
+ - can also use the following to run an example (make:compile also works)
7
+ - make:upload sketch=examples/hello_servos
8
+
1
9
  == 0.2.3 2008-07-10
2
10
  * Manyish updates:
3
11
  - updated servo library to support position parameter
data/Manifest.txt CHANGED
@@ -4,6 +4,17 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  bin/rad
7
+ lib/examples/add_hysteresis.rb
8
+ lib/examples/first_sound.rb
9
+ lib/examples/frequency_generator.rb
10
+ lib/examples/hello_servos.rb
11
+ lib/examples/hello_world.rb
12
+ lib/examples/orig_servo_throttle.rb
13
+ lib/examples/servo_buttons.rb
14
+ lib/examples/servo_throttle.rb
15
+ lib/examples/sparkfun_lcd.rb
16
+ lib/examples/times_method.rb
17
+ lib/examples/toggle.rb
7
18
  lib/libraries/FrequencyTimer2/keywords.txt
8
19
  lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
9
20
  lib/libraries/FrequencyTimer2/FrequencyTimer2.h
@@ -14,6 +25,7 @@ lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp
14
25
  lib/libraries/SWSerLCDpa/SWSerLCDpa.h
15
26
  lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp
16
27
  lib/libraries/SWSerLCDsf/SWSerLCDsf.h
28
+ lib/plugins/blink_m.rb
17
29
  lib/plugins/debounce.rb
18
30
  lib/plugins/debug_output_to_lcd.rb
19
31
  lib/plugins/input_output_state.rb
data/bin/rad CHANGED
@@ -120,6 +120,16 @@ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDsf/.", "#{ske
120
120
  puts "Installed SWSerLCDsf into #{sketch_name}/vendor/libraries"
121
121
  puts
122
122
 
123
+ # Build examples -- used for basic testing
124
+
125
+ FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
126
+ puts "Successfully created your examples directory."
127
+
128
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/examples/.", "#{sketch_name}/examples"
129
+ puts "Installed examples into #{sketch_name}/examples"
130
+ puts
131
+
132
+
123
133
  # Build vendor/plugins:
124
134
 
125
135
  FileUtils.mkdir_p "#{sketch_name}/vendor/plugins"
@@ -129,6 +139,11 @@ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/plugins/.", "#{sketch_name}/ven
129
139
  puts "Installed Default plugins into #{sketch_name}/vendor/plugins"
130
140
  puts
131
141
 
142
+ # Add an default sketch directory # needed to run test:compile
143
+
144
+ FileUtils.mkdir_p "#{sketch_name}/#{sketch_name}"
145
+ puts "Successfully created your default sketch directory."
146
+
132
147
  # Build sketch files, etc.:
133
148
 
134
149
  FileUtils.touch "#{sketch_name}/#{sketch_name}.rb"
@@ -0,0 +1,13 @@
1
+ class AddHysteresis < ArduinoSketch
2
+
3
+ input_pin 3, :as => :sensor
4
+ output_pin 13, :as => :led
5
+
6
+
7
+ def loop
8
+ reading = add_hysteresis sensor, 8
9
+ blink led, 100 if reading > 100
10
+ blink led, 1000 if reading <= 100
11
+ end
12
+
13
+ end
@@ -0,0 +1,23 @@
1
+ class FirstSound < ArduinoSketch
2
+
3
+
4
+
5
+ output_pin 11, :as => :myTone, :device => :freq_out, :frequency => 100 # frequency required
6
+
7
+ def loop
8
+ myTone.disable
9
+ 1.upto(400) { |x| tone_out x } # run up the scale to 4000 Hz in 10 Hz steps
10
+ 399.downto(1) { |x| tone_out x } # come back down in 10 Hz steps
11
+ delay 2000
12
+ end
13
+
14
+ def tone_out(n)
15
+ myTone.set_frequency 10*n
16
+ myTone.enable
17
+ delay 80
18
+ myTone.disable
19
+ delay 10
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,30 @@
1
+ class FrequencyGenerator < ArduinoSketch
2
+
3
+ # need explaination
4
+
5
+ output_pin 11, :as => :myTone, :device => :freq_out, :frequency => 100
6
+
7
+ def loop
8
+ uh_oh 4
9
+ end
10
+
11
+ def uh_oh(n)
12
+
13
+
14
+ n.times do
15
+ myTone.enable
16
+ myTone.set_frequency 1800
17
+ delay 500
18
+ myTone.disable
19
+ delay 100
20
+ myTone.enable
21
+ myTone.set_frequency 1800
22
+ delay 800
23
+ myTone.enable
24
+ end
25
+ # hack to help translator guess that n is an int
26
+ f = n + 0
27
+ end
28
+
29
+
30
+ end
@@ -0,0 +1,88 @@
1
+ class HelloServos < ArduinoSketch
2
+
3
+ output_pin 2, :as => :servo_1, :max => 2400, :min => 800
4
+ output_pin 3, :as => :servo_2, :max => 2400, :min => 800
5
+ output_pin 4, :as => :servo_3, :max => 2400, :min => 800
6
+
7
+
8
+ # time to go old school
9
+ def loop
10
+ song_sheet_two
11
+ end
12
+
13
+ def song_sheet_two
14
+ e
15
+ d
16
+ e
17
+ d
18
+ c
19
+ d
20
+ d
21
+ c
22
+ b
23
+ c
24
+ b
25
+ a
26
+ e
27
+ a
28
+ e
29
+ a
30
+ e
31
+ a
32
+ b
33
+ c
34
+ b
35
+ c
36
+ d
37
+ d
38
+ c
39
+ d
40
+ e
41
+ d
42
+ e
43
+ end
44
+
45
+ def a
46
+ pulse_servo servo_1, 1450
47
+ delay 100
48
+ home servo_1
49
+ delay 20
50
+ end
51
+
52
+ def b
53
+ pulse_servo servo_1, 1350
54
+ delay 100
55
+ home servo_1
56
+ delay 20
57
+ end
58
+
59
+ def c
60
+ pulse_servo servo_2, 1450
61
+ delay 100
62
+ home servo_2
63
+ delay 20
64
+ end
65
+
66
+ def d
67
+ pulse_servo servo_2, 1350
68
+ delay 100
69
+ home servo_2
70
+ delay 20
71
+ end
72
+
73
+ def e
74
+ pulse_servo servo_3, 1500
75
+ delay 100
76
+ home servo_3
77
+ delay 20
78
+ end
79
+
80
+
81
+ # center servos
82
+
83
+ def home(s)
84
+ pulse_servo s, 1400
85
+ f = s + 0
86
+ end
87
+
88
+ end
@@ -0,0 +1,11 @@
1
+ class HelloWorld < ArduinoSketch
2
+
3
+ output_pin 13, :as => :led
4
+
5
+ def loop
6
+ blink led, 100
7
+ end
8
+
9
+ end
10
+
11
+
@@ -0,0 +1,39 @@
1
+ class OrigServoThrottle < ArduinoSketch
2
+
3
+ # old school servo control
4
+ # uses pulsewidth for positioning
5
+ # potentiometer to control servo
6
+ # with a bit of hysteresis
7
+ # use analog pin for sensor
8
+ # need to format the output of sensor_position and sensor_amount
9
+ # probably going away soon
10
+
11
+
12
+ external_vars :sensor_position => "int, 0", :servo_amount => "int, 0", :pw => "int, 0", :time_check => "unsigned long, 0"
13
+
14
+ output_pin 5, :as => :my_lcd, :device => :sf_lcd
15
+ input_pin 1, :as => :sensor
16
+ output_pin 2, :as => :my_servo, :min => 700, :max => 2200 #, :refresh => 60
17
+
18
+
19
+ def loop
20
+ #delay 9 # comment out if using servo status, since it will add enough delay
21
+ sensor_position = analogRead(sensor)
22
+ servo_amount = (add_hysteresis(sensor_position, 10)*2 + 500)
23
+ move_servo my_servo, servo_amount
24
+ servo_status
25
+
26
+ end
27
+
28
+ def servo_status
29
+
30
+ my_lcd.home # line 0, col 0
31
+ my_lcd.print "Read Send"
32
+ my_lcd.setxy 0,1 # line 1, col 0
33
+ my_lcd.print sensor_position # need method of blanking out previous reading
34
+ my_lcd.setxy 6,1
35
+ my_lcd.print servo_amount
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,23 @@
1
+ class ServoButtons < ArduinoSketch
2
+
3
+ # original syntax
4
+ input_pin 6, :as => :button_one, :latch => :off
5
+ # preferred syntax
6
+ input_pin 7, :as => :button_two, :device => :button
7
+ input_pin 8, :as => :button_three, :device => :button
8
+ output_pin 13, :as => :led
9
+ output_pin 2, :as => :my_servo, :device => :servo
10
+
11
+
12
+ def loop
13
+ check_buttons
14
+ servo_refresh
15
+ end
16
+
17
+ def check_buttons
18
+ read_and_toggle button_one, led
19
+ my_servo.position 180 if read_input button_two
20
+ my_servo.position 60 if read_input button_three
21
+ end
22
+
23
+ end
@@ -0,0 +1,37 @@
1
+ class ServoThrottle < ArduinoSketch
2
+
3
+ # potentiometer to control servo
4
+ # with a bit of hysteresis
5
+ # use analog pin for sensor
6
+ # need to format the output of sensor_position and sensor_amount
7
+
8
+
9
+ external_vars :sensor_position => "int, 0", :servo_amount => "int, 0"
10
+
11
+ output_pin 5, :as => :my_lcd, :device => :sf_lcd
12
+ input_pin 1, :as => :sensor
13
+ output_pin 2, :as => :my_servo, :device => :servo
14
+
15
+
16
+ def loop
17
+ servo_refresh
18
+ #delay 9 # comment out if using servo status, since it will add enough delay
19
+ sensor_position = analogRead(sensor)
20
+ servo_amount = (add_hysteresis(sensor_position, 10)*0.36)
21
+ my_servo.position servo_amount
22
+ servo_status
23
+
24
+ end
25
+
26
+ def servo_status
27
+
28
+ my_lcd.home # line 0, col 0
29
+ my_lcd.print "Read Send"
30
+ my_lcd.setxy 0,1 # line 1, col 0
31
+ my_lcd.print sensor_position # need method of blanking out previous reading
32
+ my_lcd.setxy 6,1
33
+ my_lcd.print servo_amount
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,48 @@
1
+ class SparkfunLcd < ArduinoSketch
2
+
3
+
4
+ input_pin 6, :as => :button_one, :latch => :off
5
+ input_pin 7, :as => :button_two, :latch => :off
6
+ input_pin 8, :as => :button_three, :latch => :off
7
+ output_pin 13, :as => :led
8
+
9
+ swser_LCDsf 5, :as => :my_lcd
10
+
11
+
12
+
13
+
14
+ #serial_begin # not necessary when using :device => :sf_lcd or :pa_lcd
15
+
16
+ def loop
17
+ check_buttons
18
+ end
19
+
20
+
21
+ # need a bit
22
+
23
+ def say_hello
24
+ my_lcd.home # line 0, col 0
25
+ my_lcd.print "All your base "
26
+ my_lcd.setxy 0,1 # line 1, col 0
27
+ my_lcd.print "are belong to us"
28
+
29
+ end
30
+
31
+ def say_ruby
32
+ my_lcd.home # line 0, col 0
33
+ my_lcd.print " Ruby + Arduino "
34
+ my_lcd.setxy 0,1 # line 1, col 0
35
+ my_lcd.print " RAD 0.2.4+ "
36
+ # un comment to change display startup
37
+ #myLCD.setcmd 0x7C, 10
38
+ end
39
+
40
+ def check_buttons
41
+ read_and_toggle button_one, led
42
+ say_hello if read_input button_two
43
+ say_ruby if read_input button_three
44
+
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,8 @@
1
+ class TimesMethod < ArduinoSketch
2
+
3
+ def loop
4
+ 5.times { delay 200 }
5
+ end
6
+
7
+
8
+ end
@@ -0,0 +1,10 @@
1
+ class Toggle < ArduinoSketch
2
+
3
+ output_pin 13, :as => :led
4
+
5
+ def loop
6
+ led.toggle
7
+ delay 300
8
+ end
9
+
10
+ end
@@ -0,0 +1,25 @@
1
+ class BlinkM < ArduinoPlugin
2
+
3
+ # scaffolding for blink_m
4
+
5
+
6
+
7
+
8
+
9
+
10
+ void simply_blink(void)
11
+ {
12
+
13
+ }
14
+
15
+
16
+ static void clear_blinkm( void )
17
+ {
18
+ Wire.beginTransmission(0x09);
19
+ Wire.send('c');
20
+ Wire.endTransmission();
21
+ }
22
+
23
+
24
+
25
+ end
@@ -79,7 +79,7 @@ void set_splash(){
79
79
  selectLineOne();
80
80
  Serial.print(" Ruby + Auduino");
81
81
  selectLineTwo();
82
- Serial.print(" RAD 0.2.3+ ");
82
+ Serial.print(" RAD 0.2.4+ ");
83
83
  Serial.print(0x7C, BYTE); // decimal 124, command flag for backlight stuff
84
84
  Serial.print(10, BYTE);
85
85
  }
@@ -160,7 +160,7 @@ end
160
160
  ## need a test for this
161
161
  ## fails on string interpolation, but since ruby_to_c also currently fails ...
162
162
  sketch_string = sketch_string.gsub(/#(?!\{.*\}).*/, "")
163
- plugin_signatures << plugin_string.scan(/^\s((int|void|unsigned|long|short).*\(.*\))/)
163
+ plugin_signatures << plugin_string.scan(/^\s((int|void|unsigned|long|short|uint8_t|static).*\(.*\))/)
164
164
  # gather just the method name and then add to #plugin_methods_hash
165
165
  plugin_signatures[0].map {|sig| "#{sig[0]}"}.each {|m| plugin_methods << m.gsub!(/^.*\s(\w*)\(.*\)/, '\1')}
166
166
  # we don't know the methods yet, so...
@@ -182,13 +182,13 @@ end
182
182
  first_process = plugin_string
183
183
  # todo: need to add plugin names to the methods, so we can add them as comments in the c code
184
184
  # gather the c methods
185
- $plugin_methods << first_process.scan(/^\s*(((int|void|unsigned|long|short).*\)).*(\n.*)*^\s*\})/)
186
- plugin_signatures << first_process.scan(/^\s((int|void|unsigned|long|short).*\(.*\))/)
185
+ $plugin_methods << first_process.scan(/^\s*(((int|void|unsigned|long|short|uint8_t|static).*\)).*(\n.*)*^\s*\})/)
186
+ plugin_signatures << first_process.scan(/^\s((int|void|unsigned|long|short|uint8_t|static).*\(.*\))/)
187
187
  $plugin_signatures << plugin_signatures[0].map {|sig| "#{sig[0]};"}
188
188
  ## strip out the methods and pass it back
189
189
  result = plugin_string
190
190
  # strip out the c methods so we have only ruby before eval
191
- result.gsub(/^\s*(int|void|unsigned|long|short).*(\n.*)*^\s*\}/, "" )
191
+ result.gsub(/^\s*(int|void|unsigned|long|short|uint8_t|static).*(\n.*)*^\s*\}/, "" )
192
192
 
193
193
  end
194
194
 
@@ -169,6 +169,7 @@ class ArduinoSketch
169
169
  $external_var_identifiers = []
170
170
  $sketch_methods = []
171
171
  $load_libraries = []
172
+ $include_wire = false
172
173
 
173
174
  @declarations = []
174
175
  @pin_modes = {:output => [], :input => []}
@@ -306,7 +307,6 @@ class ArduinoSketch
306
307
  if opts[:device]
307
308
  case opts[:device]
308
309
  when :servo
309
- puts "line 309"
310
310
  new_servo_setup(num, opts)
311
311
  return # don't use declarations, accessor, signatures below
312
312
  when :orig_servo
@@ -764,7 +764,9 @@ class ArduinoSketch
764
764
 
765
765
  raise ArgumentError, "can only define pin from Fixnum, got #{pin.class}" unless pin.is_a?(Fixnum)
766
766
  raise ArgumentError, "only pin 11 may be used for freq_out, got #{pin}" unless pin == 11
767
- raise ArgumentError, "the frequency or period option must be included. Example: :frequecy => 700" unless opts[:frequency] || opts[:period]
767
+ if opts[:enable]
768
+ raise ArgumentError, "enable option must include the frequency or period option" unless opts[:frequency] || opts[:period]
769
+ end
768
770
  if opts[:frequency]
769
771
  raise ArgumentError, "the frequency option must be an integer, got #{opts[:frequency].class}" unless opts[:frequency].is_a?(Fixnum)
770
772
  end
@@ -802,6 +804,7 @@ class ArduinoSketch
802
804
 
803
805
  @signatures << "FrequencyTimer2& #{opts[ :as ]}();"
804
806
 
807
+ @other_setup << "\tFrequencyTimer2::setPeriod(0L);" unless opts[:frequency] || opts[:period]
805
808
  @other_setup << "\tFrequencyTimer2::setPeriod(1000000L/#{opts[:frequency]});" if opts[:frequency]
806
809
  @other_setup << "\tFrequencyTimer2::setPeriod(#{opts[:period]});" if opts[:period]
807
810
  @other_setup << "\tFrequencyTimer2::enable();" if opts[:enable] == :true
@@ -818,6 +821,7 @@ class ArduinoSketch
818
821
 
819
822
  result << "#include <WProgram.h>\n"
820
823
  result << "#include <SoftwareSerial.h>\n"
824
+ result << "#include <Wire.h>\n" if $include_wire == true ##
821
825
  $load_libraries.each { |lib| result << "#include <#{lib}.h>" } unless $load_libraries.nil?
822
826
 
823
827
  result << comment_box( 'plugin directives' )
@@ -68,7 +68,7 @@ LIBRARY_ROOT = <%= params['libraries_root'] %>
68
68
  SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
69
69
  $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
70
70
  $(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
71
- $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
71
+ $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c <%= params['twi_c'] %>
72
72
  CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(SOFTWARE_SERIAL)/SoftwareSerial.cpp<%= params['libraries'].collect{|l| " $(LIBRARY_ROOT)/#{ l }/#{l }.cpp"}.join('') %>
73
73
  MCU = <%= params['mcu'] %>
74
74
  <% if params['asm_files'] %>ASRC = <%= params['asm_files'].join(' ') %><% end %>
@@ -92,8 +92,8 @@ CDEFS = -DF_CPU=$(F_CPU)
92
92
  CXXDEFS = -DF_CPU=$(F_CPU)
93
93
 
94
94
  # Place -I options here
95
- CINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %>
96
- +CXXINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %>
95
+ CINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %> <%= params['wire_h'] %>
96
+ +CXXINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %> <%= params['wire_h'] %>
97
97
 
98
98
  # Compiler flag to set the C Standard level.
99
99
  # c89 - "ANSI" C
@@ -7,7 +7,10 @@ class Makefile
7
7
  # build the sketch Makefile for the given template based on the values in its software and hardware config files
8
8
  def compose_for_sketch(sketch_name)
9
9
  params = hardware_params.merge software_params
10
- params['target'] = sketch_name
10
+ params['target'] = sketch_name.split("/").last
11
+
12
+ params['wire_h'] = $include_wire == true ? "-I#{params['arduino_root']}/hardware/libraries/Wire/" : ""
13
+ params['twi_c'] = $include_wire == true ? "#{params['arduino_root']}/hardware/libraries/Wire/utility/twi.c" : ""
11
14
 
12
15
  params['libraries_root'] = "#{File.expand_path(RAD_ROOT)}/vendor/libraries"
13
16
  params['libraries'] = $load_libraries # load only libraries used
@@ -1,7 +1,40 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../init.rb")
2
2
  require 'ruby_to_ansi_c'
3
3
 
4
- C_VAR_TYPES = "unsigned|int|long|double|str|char"
4
+ C_VAR_TYPES = "unsigned|int|long|double|str|char|byte"
5
+
6
+ # incredibly primitive tests
7
+ # rake test:compile or rake test:upload
8
+ # runs through all sketches in the example directory
9
+
10
+ def run_tests(sketch, type)
11
+ sh %{rake make:#{type} sketch=examples/#{sketch}}
12
+ end
13
+
14
+ namespace :test do
15
+
16
+ desc "iterate through all the sketches in the example directory"
17
+ task :upload => :gather do
18
+ @examples.each {|e| run_tests(e, "upload")}
19
+ end
20
+
21
+ task :compile => :gather do
22
+ @examples.each {|e| run_tests(e, "compile")}
23
+ end
24
+ end
25
+
26
+ desc "gather all tests"
27
+ task :gather do # => "make:upload" do
28
+ @examples = []
29
+ @test_results = []
30
+ Dir.entries( File.expand_path("#{RAD_ROOT}/examples/") ).each do |f|
31
+ if (f =~ /\.rb$/)
32
+ @examples << f.split('.').first
33
+ end
34
+ end
35
+
36
+ end
37
+
5
38
 
6
39
  namespace :make do
7
40
 
@@ -11,36 +44,37 @@ namespace :make do
11
44
  puts "Reset the Arduino and hit enter.\n==If your board doesn't need it, you can turn off this prompt in config/software.yml=="
12
45
  STDIN.gets.chomp
13
46
  end
14
- sh %{cd #{RAD_ROOT}/#{@sketch_name}; make upload}
47
+ sh %{cd #{RAD_ROOT}/#{@test_dir + @sketch_name}; make upload}
15
48
  end
16
-
49
+
17
50
  desc "generate a makefile and use it to compile the .cpp"
18
51
  task :compile => [:clean_sketch_dir, "build:sketch"] do # should also depend on "build:sketch"
19
- Makefile.compose_for_sketch( @sketch_name )
52
+ Makefile.compose_for_sketch( @test_dir + @sketch_name )
20
53
  # not allowed? sh %{export PATH=#{Makefile.software_params[:arduino_root]}/tools/avr/bin:$PATH}
21
- sh %{cd #{RAD_ROOT}/#{@sketch_name}; make depend; make}
54
+ sh %{cd #{RAD_ROOT}/#{@test_dir + @sketch_name}; make depend; make}
22
55
  end
23
56
 
24
57
  desc "generate a makefile and use it to compile the .cpp using the current .cpp file"
25
58
  task :compile_cpp => ["build:sketch_dir", :clean_sketch_dir] do # should also depend on "build:sketch"
26
- Makefile.compose_for_sketch( @sketch_name )
59
+ Makefile.compose_for_sketch( @test_dir + @sketch_name )
27
60
  # not allowed? sh %{export PATH=#{Makefile.software_params[:arduino_root]}/tools/avr/bin:$PATH}
28
- sh %{cd #{RAD_ROOT}/#{@sketch_name}; make depend; make}
61
+ sh %{cd #{RAD_ROOT}/#{@test_dir + @sketch_name}; make depend; make}
29
62
  end
30
63
 
31
64
  desc "generate a makefile and use it to compile the .cpp and upload it using current .cpp file"
32
65
  task :upload_cpp => ["build:sketch_dir", :clean_sketch_dir] do # should also depend on "build:sketch"
33
- Makefile.compose_for_sketch( @sketch_name )
66
+ Makefile.compose_for_sketch( @test_dir + @sketch_name )
34
67
  # not allowed? sh %{export PATH=#{Makefile.software_params[:arduino_root]}/tools/avr/bin:$PATH}
35
- sh %{cd #{RAD_ROOT}/#{@sketch_name}; make depend; make upload}
68
+ sh %{cd #{RAD_ROOT}/#{@test_dir + @sketch_name}; make depend; make upload}
36
69
  end
37
70
 
38
71
  task :clean_sketch_dir => ["build:file_list", "build:sketch_dir"] do
39
72
  @sketch_name = @sketch_class.split(".").first
40
- FileList.new(Dir.entries("#{RAD_ROOT}/#{@sketch_name}")).exclude("#{@sketch_name}.cpp").exclude(/^\./).each do |f|
41
- sh %{rm #{RAD_ROOT}/#{@sketch_name}/#{f}}
73
+ FileList.new(Dir.entries("#{RAD_ROOT}/#{@test_dir + @sketch_name}")).exclude("#{@test_dir + @sketch_name}.cpp").exclude(/^\./).each do |f|
74
+ sh %{rm #{RAD_ROOT}/#{@test_dir + @sketch_name}/#{f}}
42
75
  end
43
76
  end
77
+
44
78
  end
45
79
 
46
80
  namespace :build do
@@ -48,10 +82,16 @@ namespace :build do
48
82
  desc "actually build the sketch"
49
83
  task :sketch => [:file_list, :sketch_dir, :gather_required_plugins, :plugin_setup, :setup] do
50
84
  klass = @sketch_class.split(".").first.split("_").collect{|c| c.capitalize}.join("")
51
- eval ArduinoSketch.pre_process(File.read(@sketch_class))
85
+ eval ArduinoSketch.pre_process(File.read(@test_dir + @sketch_class))
52
86
  c_methods = []
53
87
  sketch_signatures = []
54
- $sketch_methods.each {|m| c_methods << RADProcessor.translate(constantize(klass), m) }
88
+ # until we better understand RubyToC let's see what's happening on errors
89
+ $sketch_methods.each do |meth|
90
+ raw_rtc_meth = RADProcessor.translate(constantize(klass), meth)
91
+ puts "Translator Error: #{raw_rtc_meth.inspect}" if raw_rtc_meth[0..8] == "// ERROR:"
92
+ c_methods << raw_rtc_meth
93
+ end
94
+ #$sketch_methods.each {|m| c_methods << RADProcessor.translate(constantize(klass), m) }
55
95
  c_methods.each {|meth| sketch_signatures << "#{meth.scan(/^\w*\s?\*?\n.*\)/)[0].gsub("\n", " ")};" }
56
96
  clean_c_methods = []
57
97
  c_methods.join("\n").each_with_index do |e,i|
@@ -66,7 +106,7 @@ namespace :build do
66
106
  @setup.gsub!("// sketch signatures", "// sketch signatures\n#{ sketch_signatures.join("\n")}") unless sketch_signatures.empty?
67
107
  result = "#{@setup}\n#{c_methods_with_timer}\n"
68
108
  name = @sketch_class.split(".").first
69
- File.open("#{name}/#{name}.cpp", "w"){|f| f << result}
109
+ File.open("#{@test_dir}#{name}/#{name}.cpp", "w"){|f| f << result}
70
110
  end
71
111
 
72
112
  # needs to write the library include and the method signatures
@@ -87,7 +127,7 @@ namespace :build do
87
127
  end
88
128
  CODE
89
129
  end
90
- eval File.read(@sketch_class)
130
+ eval File.read(@test_dir + @sketch_class)
91
131
  @setup = @@as.compose_setup
92
132
  end
93
133
 
@@ -118,14 +158,14 @@ namespace :build do
118
158
  desc "determine which plugins to load based on use of methods in sketch"
119
159
  task :gather_required_plugins do
120
160
  @plugin_names.each do |name|
121
- ArduinoPlugin.check_for_plugin_use(File.read(@sketch_class), File.read("vendor/plugins/#{name}"), name )
161
+ ArduinoPlugin.check_for_plugin_use(File.read(@test_dir + @sketch_class), File.read("vendor/plugins/#{name}"), name )
122
162
  end
123
163
  puts "#{$plugins_to_load.length} of #{$plugin_methods_hash.length} plugins are being loaded: #{$plugins_to_load.join(", ")}"
124
164
  end
125
165
 
126
166
  desc "setup target directory named after your sketch class"
127
167
  task :sketch_dir => [:file_list] do
128
- mkdir_p "#{@sketch_class.split(".").first}"
168
+ mkdir_p "#{@test_dir + @sketch_class.split(".").first}"
129
169
  end
130
170
 
131
171
  task :file_list do
@@ -133,6 +173,12 @@ namespace :build do
133
173
  # perhaps we generate a constant when the project is generated an pop it here or in the init file
134
174
  @sketch_directory = File.expand_path("#{File.dirname(__FILE__)}/../../../").split("/").last
135
175
  # multiple sketches are possible with rake make:upload sketch=new_sketch
176
+ @test_dir = ""
177
+ if ENV['sketch'] =~ /^examples\//
178
+ # strip the example and set a directory variable
179
+ ENV['sketch'] = ENV['sketch'].gsub(/^examples\//, "")
180
+ @test_dir = "examples/"
181
+ end
136
182
  @sketch_class = ENV['sketch'] ? "#{ENV['sketch']}.rb" : "#{@sketch_directory}.rb"
137
183
  @file_names = []
138
184
  @plugin_names = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madrona-rad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Borenstein
@@ -48,11 +48,23 @@ files:
48
48
  - README.rdoc
49
49
  - Rakefile
50
50
  - bin/rad
51
+ - lib/examples/add_hysteresis.rb
52
+ - lib/examples/first_sound.rb
53
+ - lib/examples/frequency_generator.rb
54
+ - lib/examples/hello_servos.rb
55
+ - lib/examples/hello_world.rb
56
+ - lib/examples/orig_servo_throttle.rb
57
+ - lib/examples/servo_buttons.rb
58
+ - lib/examples/servo_throttle.rb
59
+ - lib/examples/sparkfun_lcd.rb
60
+ - lib/examples/times_method.rb
61
+ - lib/examples/toggle.rb
51
62
  - lib/libraries/FrequencyTimer2/keywords.txt
52
63
  - lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
53
64
  - lib/libraries/FrequencyTimer2/FrequencyTimer2.h
54
65
  - lib/libraries/Servo/keywords.txt
55
66
  - lib/libraries/Servo/Servo.cpp
67
+ - lib/plugins/blink_m.rb
56
68
  - lib/libraries/Servo/Servo.h
57
69
  - lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp
58
70
  - lib/libraries/SWSerLCDpa/SWSerLCDpa.h
@@ -118,6 +130,6 @@ rubyforge_project: rad
118
130
  rubygems_version: 1.2.0
119
131
  signing_key:
120
132
  specification_version: 2
121
- summary: Fork of the Ruby Arduino Development - 0.2.4.5.3
133
+ summary: Fork of the Ruby Arduino Development - 0.2.4.5.9
122
134
  test_files: []
123
135