atduskgreg-rad 0.2.5
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 +104 -0
- data/License.txt +282 -0
- data/Manifest.txt +142 -0
- data/README.rdoc +55 -0
- data/Rakefile +142 -0
- data/bin/hello_world_test/Makefile +436 -0
- data/bin/hello_world_test/hello_world.cpp +23 -0
- data/bin/rad +302 -0
- data/lib/examples/add_hysteresis.rb +13 -0
- data/lib/examples/basic_blink.rb +10 -0
- data/lib/examples/blink_m_address_assignment.rb +104 -0
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/blink_m_multi.rb +61 -0
- data/lib/examples/blink_with_serial.rb +16 -0
- data/lib/examples/configure_pa_lcd_boot.rb +91 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +26 -0
- data/lib/examples/external_variables.rb +32 -0
- data/lib/examples/first_sound.rb +23 -0
- data/lib/examples/frequency_generator.rb +30 -0
- data/lib/examples/hello_array.rb +48 -0
- data/lib/examples/hello_array2.rb +79 -0
- data/lib/examples/hello_array_eeprom.rb +59 -0
- data/lib/examples/hello_clock.rb +84 -0
- data/lib/examples/hello_eeprom.rb +51 -0
- data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
- data/lib/examples/hello_format_print.rb +94 -0
- data/lib/examples/hello_lcd_charset.rb +75 -0
- data/lib/examples/hello_pa_lcd.rb +59 -0
- data/lib/examples/hello_servos.rb +88 -0
- data/lib/examples/hello_spectra_sound.rb +38 -0
- data/lib/examples/hello_world.rb +11 -0
- data/lib/examples/hello_xbee.rb +12 -0
- data/lib/examples/hysteresis_duel.rb +39 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/midi_beat_box.rb +86 -0
- data/lib/examples/midi_scales.rb +94 -0
- data/lib/examples/motor_knob.rb +30 -0
- data/lib/examples/servo_buttons.rb +23 -0
- data/lib/examples/servo_calibrate_continuous.rb +92 -0
- data/lib/examples/servo_throttle.rb +40 -0
- data/lib/examples/software_serial.rb +10 -0
- data/lib/examples/sparkfun_lcd.rb +48 -0
- data/lib/examples/spectra_soft_pot.rb +34 -0
- data/lib/examples/times_method.rb +8 -0
- data/lib/examples/toggle.rb +10 -0
- data/lib/examples/twitter.rb +57 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
- data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
- data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
- data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
- data/lib/libraries/DS1307/DS1307.cpp +162 -0
- data/lib/libraries/DS1307/DS1307.h +66 -0
- data/lib/libraries/DS1307/keywords.txt +18 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
- data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
- data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
- data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
- data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
- data/lib/libraries/LoopTimer/keywords.txt +27 -0
- data/lib/libraries/OneWire/OneWire.cpp +194 -0
- data/lib/libraries/OneWire/OneWire.h +63 -0
- data/lib/libraries/OneWire/keywords.txt +35 -0
- data/lib/libraries/OneWire/readme.txt +13 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +296 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
- data/lib/libraries/Servo/Servo.cpp +192 -0
- data/lib/libraries/Servo/Servo.h +61 -0
- data/lib/libraries/Stepper/Stepper.cpp +220 -0
- data/lib/libraries/Stepper/Stepper.h +86 -0
- data/lib/libraries/Stepper/keywords.txt +28 -0
- data/lib/libraries/Wire/Wire.cpp +262 -0
- data/lib/libraries/Wire/Wire.h +67 -0
- data/lib/libraries/Wire/keywords.txt +31 -0
- data/lib/libraries/Wire/twi.h +57 -0
- data/lib/libraries/Wire/utility/twi.c +449 -0
- data/lib/libraries/Wire/utility/twi.h +57 -0
- data/lib/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink.rb +25 -0
- data/lib/plugins/blink_m.rb +356 -0
- data/lib/plugins/debounce.rb +138 -0
- data/lib/plugins/debug_output_to_lcd.rb +71 -0
- data/lib/plugins/hysteresis.rb +52 -0
- data/lib/plugins/input_output_state.rb +84 -0
- data/lib/plugins/lcd_padding.rb +58 -0
- data/lib/plugins/mem_test.rb +37 -0
- data/lib/plugins/midi.rb +60 -0
- data/lib/plugins/parallax_ping.rb +50 -0
- data/lib/plugins/servo_pulse.rb +31 -0
- data/lib/plugins/servo_setup.rb +86 -0
- data/lib/plugins/smoother.rb +54 -0
- data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
- data/lib/plugins/spectra_symbol.rb +79 -0
- data/lib/plugins/twitter_connect.rb +145 -0
- data/lib/rad.rb +5 -0
- data/lib/rad/README.rdoc +5 -0
- data/lib/rad/arduino_plugin.rb +246 -0
- data/lib/rad/arduino_sketch.rb +627 -0
- data/lib/rad/generators/makefile/makefile.erb +243 -0
- data/lib/rad/generators/makefile/makefile.rb +38 -0
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +14 -0
- data/lib/rad/progressbar.rb +236 -0
- data/lib/rad/rad_processor.rb +128 -0
- data/lib/rad/rad_rewriter.rb +94 -0
- data/lib/rad/rad_type_checker.rb +26 -0
- data/lib/rad/sim/arduino_sketch.rb +57 -0
- data/lib/rad/sketch_compiler.rb +47 -0
- data/lib/rad/tasks/build_and_make.rake +210 -0
- data/lib/rad/tasks/rad.rb +2 -0
- data/lib/rad/todo.txt +13 -0
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/arduino_sketch_spec.rb +82 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/models/spec_helper.rb +2 -0
- data/spec/sim/hello_world_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/test/test_array_processing.rb +179 -0
- data/test/test_plugin_loading.rb +151 -0
- data/test/test_translation_post_processing.rb +185 -0
- data/test/test_variable_processing.rb +238 -0
- data/website/examples/assembler_test.rb.html +73 -0
- data/website/examples/gps_reader.rb.html +39 -0
- data/website/examples/hello_world.rb.html +38 -0
- data/website/examples/serial_motor.rb.html +41 -0
- data/website/index.html +178 -0
- data/website/index.txt +64 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +169 -0
- data/website/template.rhtml +48 -0
- metadata +217 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Hardware: motor control circuit (i.e. TIP-120 control pin)
|
|
2
|
+
# connected at pin 7.
|
|
3
|
+
# Demo: http://www.youtube.com/watch?v=7OguEBfdTe0
|
|
4
|
+
|
|
5
|
+
class SerialMotor < ArduinoSketch
|
|
6
|
+
output_pin 7, :as => :motor
|
|
7
|
+
serial_begin
|
|
8
|
+
|
|
9
|
+
def loop
|
|
10
|
+
digitalWrite(motor, serial_read) if serial_available
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/rad/arduino_sketch.rb")
|
|
3
|
+
|
|
4
|
+
context "Arduino#serial_begin" do
|
|
5
|
+
setup do
|
|
6
|
+
@as = ArduinoSketch.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
specify "should default baud_rate to 9600" do
|
|
10
|
+
@as.serial_begin
|
|
11
|
+
@as.instance_variable_get("@other_setup").should include("Serial.begin(9600);")
|
|
12
|
+
end
|
|
13
|
+
specify "should set an alternate baud_rate if told" do
|
|
14
|
+
@as.serial_begin :rate => 2400
|
|
15
|
+
@as.instance_variable_get("@other_setup").should include("Serial.begin(2400);")
|
|
16
|
+
end
|
|
17
|
+
specify "should add the correct function call to the composed_setup" do
|
|
18
|
+
@as.serial_begin
|
|
19
|
+
@as.compose_setup.should match(Regexp.new(Regexp.escape("Serial.begin(9600);")))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
context "Arduino Base" do
|
|
25
|
+
setup do
|
|
26
|
+
@as = ArduinoSketch.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
specify "output_pin method without :as arg. should add the pin to the pin_mode hash's output list and leave the declarations alone" do
|
|
30
|
+
@as.output_pin 1
|
|
31
|
+
@as.instance_variable_get("@declarations").first.should == nil
|
|
32
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(1)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
specify "output_pin method with :as arg. should add the pin to the pin_mode hash's output list write the appropriate declaration and accessor" do
|
|
36
|
+
@as.output_pin 3, :as => :led
|
|
37
|
+
@as.instance_variable_get("@declarations").first.should == "int _led = 3;"
|
|
38
|
+
@as.instance_variable_get("@accessors").first.should == "int led(){\nreturn _led;\n}"
|
|
39
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(3)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
specify "output_pins method should add the pin to the pin_mode hash's output list and leave the declarations and accessors alone" do
|
|
43
|
+
@as.output_pins [5,4,3,2]
|
|
44
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(5)
|
|
45
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(4)
|
|
46
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(3)
|
|
47
|
+
@as.instance_variable_get("@pin_modes")[:output].should include(2)
|
|
48
|
+
@as.instance_variable_get("@declarations").first.should == nil
|
|
49
|
+
@as.instance_variable_get("@accessors").first.should == nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
specify "input_pin method with :as arg. should add the pin to the pin_mode hash's input list write the appropriate declaration and accessor" do
|
|
53
|
+
@as.input_pin 1, :as => :knob
|
|
54
|
+
@as.instance_variable_get("@declarations").first.should == "int _knob = 1;"
|
|
55
|
+
@as.instance_variable_get("@accessors").first.should == "int knob(){\nreturn _knob;\n}"
|
|
56
|
+
@as.instance_variable_get("@pin_modes")[:input].should include(1)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
specify "input_pins method should add the pins to the pin_mode hash's input list and leave the declarations and accessors alone" do
|
|
60
|
+
@as.input_pins [5,4,3,2]
|
|
61
|
+
@as.instance_variable_get("@pin_modes")[:input].should include(5)
|
|
62
|
+
@as.instance_variable_get("@pin_modes")[:input].should include(4)
|
|
63
|
+
@as.instance_variable_get("@pin_modes")[:input].should include(3)
|
|
64
|
+
@as.instance_variable_get("@pin_modes")[:input].should include(2)
|
|
65
|
+
@as.instance_variable_get("@declarations").first.should == nil
|
|
66
|
+
@as.instance_variable_get("@accessors").first.should == nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
specify "compose_setup should append each appropriate pinMode statement and :as accessor to the setup_function string with a newline" do
|
|
70
|
+
@as.output_pins [1, 2]
|
|
71
|
+
@as.input_pin 3, :as => :button
|
|
72
|
+
|
|
73
|
+
result = @as.send :compose_setup
|
|
74
|
+
|
|
75
|
+
result.should match(Regexp.new(Regexp.escape("pinMode(1, OUTPUT);\n")))
|
|
76
|
+
result.should match(Regexp.new(Regexp.escape("pinMode(2, OUTPUT);\n")))
|
|
77
|
+
result.should match(Regexp.new(Regexp.escape("pinMode(3, INPUT);\n")))
|
|
78
|
+
result.should match(Regexp.new(Regexp.escape("int _button = 3;\n")))
|
|
79
|
+
result.should match(Regexp.new(Regexp.escape("int button(){\nreturn _button;\n}")))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/rad/sketch_compiler.rb")
|
|
3
|
+
|
|
4
|
+
context "SketchCompiler#sketch_methods" do
|
|
5
|
+
before do
|
|
6
|
+
@as = File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/i2c_with_clock_chip.rb"
|
|
7
|
+
@sc = SketchCompiler.new @as
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should locate all the methods defined in the sketch" do
|
|
11
|
+
@sc.sketch_methods.should include( "loop")
|
|
12
|
+
@sc.sketch_methods.should include( "printlz")
|
|
13
|
+
@sc.sketch_methods.should include( "print_hexbyte")
|
|
14
|
+
@sc.sketch_methods.should include( "clear_bottom_line")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "SketchCompiler#process_constants" do
|
|
19
|
+
before do
|
|
20
|
+
@as = File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/external_variable_fu.rb"
|
|
21
|
+
@sc = SketchCompiler.new @as
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should correctly process constants" do
|
|
25
|
+
@sc.process_constants
|
|
26
|
+
@sc.body.should_not match(/HIGH/)
|
|
27
|
+
@sc.body.should_not match(/LOW/)
|
|
28
|
+
@sc.body.should_not match(/ON/)
|
|
29
|
+
@sc.body.should_not match(/OFF/)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "SketchCompiler.new" do
|
|
34
|
+
before do
|
|
35
|
+
@as = File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/add_hysteresis.rb"
|
|
36
|
+
end
|
|
37
|
+
it "should correctly absolutize a path with /../ that starts at /" do
|
|
38
|
+
SketchCompiler.new(@as).path.should == "/Users/greg/code/rad/lib/examples/add_hysteresis.rb"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should correct absolutize a relative path" do
|
|
42
|
+
SketchCompiler.new("lib/examples/add_hysteresis.rb").path.should == "/Users/greg/code/rad/lib/examples/add_hysteresis.rb"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should load the body of the sketch" do
|
|
46
|
+
sc = SketchCompiler.new @as
|
|
47
|
+
sc.body.should == open(@as).read
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "SketchCompiler#sketch_class" do
|
|
53
|
+
before do
|
|
54
|
+
@sc = SketchCompiler.new File.expand_path(File.dirname(__FILE__)) + "/../../lib/examples/add_hysteresis.rb"
|
|
55
|
+
end
|
|
56
|
+
it "should calculate correctly from the path" do
|
|
57
|
+
@sc.klass.should == "AddHysteresis"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "SketchCompiler#create_build_dir! without a path prefix" do
|
|
62
|
+
before do
|
|
63
|
+
@sc = SketchCompiler.new("lib/examples/add_hysteresis.rb")
|
|
64
|
+
end
|
|
65
|
+
it "should create the sketch dir in the correct place" do
|
|
66
|
+
@sc.should_receive( :mkdir_p ).with( "/Users/greg/code/rad/lib/examples/add_hysteresis" )
|
|
67
|
+
@sc.create_build_dir!
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "SketchCompiler#create_build_dir! with a path prefix" do
|
|
72
|
+
before do
|
|
73
|
+
@sc = SketchCompiler.new("lib/examples/add_hysteresis.rb")
|
|
74
|
+
end
|
|
75
|
+
it "should create the sketch dir in the correct place" do
|
|
76
|
+
@sc.should_receive( :mkdir_p ).with( "prefix/add_hysteresis" )
|
|
77
|
+
@sc.create_build_dir! "prefix"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "SketchCompiler#build_dir" do
|
|
82
|
+
before do
|
|
83
|
+
@sc = SketchCompiler.new("lib/examples/add_hysteresis.rb")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
it "should be correct with a default target_dir" do
|
|
88
|
+
@sc.build_dir.should == "/Users/greg/code/rad/lib/examples/add_hysteresis"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should be correct with an altered target_dir" do
|
|
92
|
+
@sc.target_dir = "examples"
|
|
93
|
+
@sc.build_dir.should == "examples/add_hysteresis"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + './models/spec_helper.rb'
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/rad/sim/arduino_sketch.rb")
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../examples/hello_world.rb" )
|
|
4
|
+
|
|
5
|
+
context "ArduinoSketch running HelloWorld example" do
|
|
6
|
+
it "should successfully make an instance" do
|
|
7
|
+
lambda{HelloWorld.new}.should_not raise_error
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "HelloWorld#led" do
|
|
12
|
+
it "should return a correctly configured Pin" do
|
|
13
|
+
p = HelloWorld.new.led
|
|
14
|
+
p.type.should == :output
|
|
15
|
+
p.num.should == 7
|
|
16
|
+
p.value.should == false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "HelloWorld#digitalWrite" do
|
|
21
|
+
setup do
|
|
22
|
+
@h = HelloWorld.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should set the value of the pin to true if told to" do
|
|
26
|
+
@h.digitalWrite(@h.led, ON)
|
|
27
|
+
@h.led.value.should == true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should set the value of the pin to false if told to" do
|
|
31
|
+
@h.digitalWrite(@h.led, OFF)
|
|
32
|
+
@h.led.value.should == false
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "HelloWorld#delay" do
|
|
37
|
+
it "should maybe keep track of the time in some way?"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "HelloWorld#loop" do
|
|
41
|
+
it "should execute the loop in the context of the instance"
|
|
42
|
+
end
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--colour
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
$TESTING = true
|
|
2
|
+
|
|
3
|
+
# need to tell it where we are
|
|
4
|
+
# lets review these
|
|
5
|
+
# neee to remove this constant from tests and pull it from rad
|
|
6
|
+
C_VAR_TYPES = "unsigned|int|long|double|str|char|byte|float|bool"
|
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/variable_processing"
|
|
8
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/arduino_sketch"
|
|
9
|
+
require 'test/unit'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestArrayProcessing < Test::Unit::TestCase
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
@t = ArduinoSketch.new
|
|
16
|
+
# vars
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# with July 25 2008 rework of arrays, this needs reworking/pruning
|
|
20
|
+
|
|
21
|
+
def test_int_array
|
|
22
|
+
name = "foo_a"
|
|
23
|
+
value_string = "int tomatoes[]"
|
|
24
|
+
expected = "int tomatoes[];"
|
|
25
|
+
result = @t.array(value_string)
|
|
26
|
+
assert_equal(expected, result[0])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_int_array_with_semi
|
|
30
|
+
name = "foo_b"
|
|
31
|
+
value_string = "int tomatoes[];"
|
|
32
|
+
expected = "int tomatoes[];"
|
|
33
|
+
result = @t.array(value_string)
|
|
34
|
+
assert_equal(expected, result[0])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_int_array_with_assignment
|
|
38
|
+
name = "foo_c"
|
|
39
|
+
value_string = "int tomatoes[] = {1,2,3,4}"
|
|
40
|
+
expected = "int tomatoes[] = {1,2,3,4};"
|
|
41
|
+
result = @t.array(value_string)
|
|
42
|
+
assert_equal(expected, result[0])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_int_array_with_assignment_and_semi
|
|
46
|
+
name = "foo_d"
|
|
47
|
+
value_string = "int tomatoes[] = {1,2,3};"
|
|
48
|
+
expected = "int tomatoes[] = {1,2,3};"
|
|
49
|
+
result = @t.array(value_string)
|
|
50
|
+
assert_equal(expected, result[0])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_unsigned_int_array
|
|
54
|
+
name = "foo_e"
|
|
55
|
+
value_string = "unsigned int tomatoes[]"
|
|
56
|
+
expected = "unsigned int tomatoes[];"
|
|
57
|
+
result = @t.array(value_string)
|
|
58
|
+
assert_equal(expected, result[0])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_unsigned_int_array_with_assignment
|
|
62
|
+
name = "foo_f"
|
|
63
|
+
value_string = "unsigned int tomatoes[] = {1,2,3};"
|
|
64
|
+
expected = "unsigned int tomatoes[] = {1,2,3};"
|
|
65
|
+
result = @t.array(value_string)
|
|
66
|
+
assert_equal(expected, result[0])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
### adding defines
|
|
70
|
+
|
|
71
|
+
def test_define_numbers
|
|
72
|
+
name = "foo_g"
|
|
73
|
+
value_string = "NUMBERS 10"
|
|
74
|
+
expected = "#define NUMBERS 10"
|
|
75
|
+
result = @t.define(value_string)
|
|
76
|
+
assert_equal(expected, result[0])
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_define_numbers_type
|
|
80
|
+
name = "foo_gg"
|
|
81
|
+
value_string = "NUMBERS 10"
|
|
82
|
+
expected = "long"
|
|
83
|
+
result = @t.define(value_string)
|
|
84
|
+
assert_equal(expected, result[1])
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_define_value_type_long_via_gvar
|
|
88
|
+
name = "foo_ggg"
|
|
89
|
+
value_string = "NUMBERS 10"
|
|
90
|
+
expected = "long"
|
|
91
|
+
result = @t.define(value_string)
|
|
92
|
+
assert_equal(expected, $define_types["NUMBERS"])
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_define_string
|
|
96
|
+
name = "foo_h"
|
|
97
|
+
value_string = "TEXT word"
|
|
98
|
+
expected = "#define TEXT \"word\""
|
|
99
|
+
result = @t.define(value_string)
|
|
100
|
+
assert_equal(expected, result[0])
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_define_string_type
|
|
104
|
+
name = "foo_hh"
|
|
105
|
+
value_string = "TEXT word"
|
|
106
|
+
expected = "str"
|
|
107
|
+
result = @t.define(value_string)
|
|
108
|
+
assert_equal(expected, result[1])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_define_string_type__via_gvar
|
|
112
|
+
name = "foo_hhh"
|
|
113
|
+
value_string = "TEXT word"
|
|
114
|
+
expected = "str"
|
|
115
|
+
result = @t.define(value_string)
|
|
116
|
+
assert_equal(expected, $define_types["TEXT"])
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_define_stings_with_spaces
|
|
120
|
+
name = "foo_i"
|
|
121
|
+
value_string = "TEXT words with spaces"
|
|
122
|
+
expected = "#define TEXT \"words with spaces\""
|
|
123
|
+
result = @t.define(value_string)
|
|
124
|
+
assert_equal(expected, result[0])
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_define_stings_with_spaces_type
|
|
128
|
+
name = "foo_ii"
|
|
129
|
+
value_string = "TEXT words with spaces"
|
|
130
|
+
expected = "str"
|
|
131
|
+
result = @t.define(value_string)
|
|
132
|
+
assert_equal(expected, result[1])
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_define_stings_with_spaces_type_via_gvar
|
|
136
|
+
name = "foo_iii"
|
|
137
|
+
value_string = "TEXT words with spaces"
|
|
138
|
+
expected = "str"
|
|
139
|
+
result = @t.define(value_string)
|
|
140
|
+
assert_equal(expected, $define_types["TEXT"])
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def test_define_float
|
|
144
|
+
name = "foo_j"
|
|
145
|
+
value_string = "FLOAT 10.0"
|
|
146
|
+
expected = "#define FLOAT 10.0"
|
|
147
|
+
result = @t.define(value_string)
|
|
148
|
+
assert_equal(expected, result[0])
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_define_float_type
|
|
152
|
+
name = "foo_jj"
|
|
153
|
+
value_string = "FLOAT 10.0"
|
|
154
|
+
expected = "float"
|
|
155
|
+
result = @t.define(value_string)
|
|
156
|
+
assert_equal(expected, result[1])
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_define_float_type_via_gvar
|
|
161
|
+
name = "foo_jjj"
|
|
162
|
+
value_string = "FLOAT 10.0"
|
|
163
|
+
expected = "float"
|
|
164
|
+
result = @t.define(value_string)
|
|
165
|
+
assert_equal(expected, $define_types["FLOAT"])
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
#
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# question for brian... do we need variable assignment with no value when
|
|
178
|
+
# we have "" and 0
|
|
179
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
$TESTING = true
|
|
4
|
+
|
|
5
|
+
# this is a test stub for now
|
|
6
|
+
# lets review these
|
|
7
|
+
# neee to remove this constant from tests and pull it from rad
|
|
8
|
+
PLUGIN_C_VAR_TYPES = "int|void|unsigned|long|short|uint8_t|static|char\\*|byte"
|
|
9
|
+
|
|
10
|
+
require "rubygems"
|
|
11
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/rad_processor.rb"
|
|
12
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/rad_rewriter.rb"
|
|
13
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/rad_type_checker.rb"
|
|
14
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/variable_processing"
|
|
15
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/arduino_sketch"
|
|
16
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/arduino_plugin"
|
|
17
|
+
require 'test/unit'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestPluginLoading < Test::Unit::TestCase
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def setup
|
|
28
|
+
$external_var_identifiers = ["__foo", "__toggle", "wiggle"]
|
|
29
|
+
$define_types = { "KOOL" => "long", "ZAK" => "str"}
|
|
30
|
+
$array_types = { "my_array" => "int"}
|
|
31
|
+
$plugin_directives = []
|
|
32
|
+
$plugin_external_variables = []
|
|
33
|
+
$plugin_signatures =[]
|
|
34
|
+
$plugin_methods = []
|
|
35
|
+
$add_to_setup = []
|
|
36
|
+
$load_libraries = []
|
|
37
|
+
$plugin_structs = {}
|
|
38
|
+
$plugin_methods_hash = {}
|
|
39
|
+
$plugins_to_load = []
|
|
40
|
+
plugin_signatures = []
|
|
41
|
+
plugin_methods = []
|
|
42
|
+
|
|
43
|
+
@plugin_string =<<-STR
|
|
44
|
+
class PluginTesting < ArduinoPlugin
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
#
|
|
50
|
+
# BlinkM_funcs.h -- Arduino library to control BlinkM
|
|
51
|
+
# --------------
|
|
52
|
+
#
|
|
53
|
+
#
|
|
54
|
+
# Note: original version of this file lives with the BlinkMTester sketch
|
|
55
|
+
#
|
|
56
|
+
# 2007, Tod E. Kurt, ThingM, http://thingm.com/
|
|
57
|
+
#
|
|
58
|
+
# version: 20080203
|
|
59
|
+
#
|
|
60
|
+
# history:
|
|
61
|
+
# 20080101 - initial release
|
|
62
|
+
# 20080203 - added setStartupParam(), bugfix receiveBytes() from Dan Julio
|
|
63
|
+
# 20080727 - ported to rad jd barnhart
|
|
64
|
+
#
|
|
65
|
+
# first step, declare output pin 19 as i2c
|
|
66
|
+
## output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
include_wire
|
|
70
|
+
|
|
71
|
+
add_blink_m_struct
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Not needed when pin is declared with :enable => :true
|
|
76
|
+
|
|
77
|
+
static int BlinkM_sendBack(byte addr)
|
|
78
|
+
{
|
|
79
|
+
int num = 0x11;
|
|
80
|
+
char buf[5];
|
|
81
|
+
itoa(num, buf, 16);
|
|
82
|
+
return "cool"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static char* another_method(byte addr)
|
|
86
|
+
{
|
|
87
|
+
int num = 0x11;
|
|
88
|
+
char buf[5];
|
|
89
|
+
itoa(num, buf, 16);
|
|
90
|
+
return "cool"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
STR
|
|
95
|
+
|
|
96
|
+
@sketch_string =<<-STR
|
|
97
|
+
class SanMiquel < ArduinoSketch
|
|
98
|
+
|
|
99
|
+
# looking for hints? check out the examples directory
|
|
100
|
+
# example sketches can be uploaded to your arduino with
|
|
101
|
+
# rake make:upload sketch=examples/hello_world
|
|
102
|
+
# just replace hello_world with other examples
|
|
103
|
+
|
|
104
|
+
def loop
|
|
105
|
+
delay 100
|
|
106
|
+
my_lcd.home "k"
|
|
107
|
+
my_lcd.setxy 0,1
|
|
108
|
+
|
|
109
|
+
BlinkM_sendBack 10
|
|
110
|
+
delay 1000
|
|
111
|
+
test_address
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
STR
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# remove these external variables and parens on variables
|
|
122
|
+
# need to actually run code through ruby_to_c for some of these tests
|
|
123
|
+
|
|
124
|
+
def test_int
|
|
125
|
+
name = "foo_a"
|
|
126
|
+
# check_for_plugin_use(sketch_string, plugin_string, file_name)
|
|
127
|
+
ArduinoPlugin.check_for_plugin_use(@sketch_string, @plugin_string, "hello_plugins")
|
|
128
|
+
value_string = "int(__toggle = 0);"
|
|
129
|
+
expected = ["hello_plugins"]
|
|
130
|
+
result = $plugins_to_load
|
|
131
|
+
assert_equal(expected, result)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_two
|
|
135
|
+
name = "foo_a"
|
|
136
|
+
# check_for_plugin_use(sketch_string, plugin_string, file_name)
|
|
137
|
+
ArduinoPlugin.check_for_plugin_use(@sketch_string, @plugin_string, "hello_plugins")
|
|
138
|
+
value_string = "int(__toggle = 0);"
|
|
139
|
+
expected = {"hello_plugins"=>["BlinkM_sendBack", "another_method"]}
|
|
140
|
+
result = $plugin_methods_hash
|
|
141
|
+
assert_equal(expected, result)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## need to look at unsigned long
|
|
147
|
+
## need parens removal tests
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
end
|