rad 0.2.2 → 0.2.9
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 +34 -0
- data/Manifest.txt +113 -7
- data/{README.txt → README.rdoc} +17 -5
- data/Rakefile +3 -0
- data/bin/rad +106 -1
- 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/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/{SWSerLCDpa → DS1307}/keywords.txt +1 -1
- 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 +93 -47
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +16 -9
- 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/README.rdoc +5 -0
- data/lib/rad/arduino_plugin.rb +246 -0
- data/lib/rad/arduino_sketch.rb +351 -257
- data/lib/rad/generators/makefile/makefile.erb +1 -1
- data/lib/rad/generators/makefile/makefile.rb +9 -10
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +3 -1
- 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 +146 -24
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +1 -1
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/sim/hello_world_spec.rb +42 -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/index.html +22 -7
- data/website/stylesheets/screen.css +32 -1
- metadata +130 -13
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
module ExternalVariableProcessing
|
|
2
|
+
# issues
|
|
3
|
+
# testing
|
|
4
|
+
# add checking for colon
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## need to clean this up
|
|
8
|
+
## need to test
|
|
9
|
+
def process_external_vars(klass)
|
|
10
|
+
vars = eval "#{klass}.instance_variables"
|
|
11
|
+
local_vars = []
|
|
12
|
+
vars.each { |v| local_vars << ":#{v.gsub("@", "")}" }
|
|
13
|
+
loc_vars = local_vars.join(", ")
|
|
14
|
+
# add accessors
|
|
15
|
+
klass.module_eval "class << self; attr_accessor #{loc_vars} end"
|
|
16
|
+
local_vars.each do |symbol|
|
|
17
|
+
name = symbol.gsub(":","")
|
|
18
|
+
t_var = eval "#{klass}.#{name}"
|
|
19
|
+
pre_process_vars(name, t_var)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def pre_process_vars(name, var)
|
|
25
|
+
# puts
|
|
26
|
+
# puts
|
|
27
|
+
case var
|
|
28
|
+
when Integer
|
|
29
|
+
# puts "pre_process: #{name}, #{var}, #{var.inspect} got #{var.class} 29"
|
|
30
|
+
value = var
|
|
31
|
+
type = "int"
|
|
32
|
+
post_process_vars(name, type, value)
|
|
33
|
+
when Float
|
|
34
|
+
# puts "pre_process: #{name}, #{var}, #{var.inspect} got #{var.class} 34"
|
|
35
|
+
value = var
|
|
36
|
+
type = "float"
|
|
37
|
+
post_process_vars(name, type, value)
|
|
38
|
+
when String
|
|
39
|
+
# puts "pre_process: #{name}, #{var.inspect} got #{var.class} on 39"
|
|
40
|
+
if var.match(",").nil? && var =~ /long|byte|unsigned|int|short/
|
|
41
|
+
# puts "pre_process #{name}, #{var.inspect} got #{var.class} level three sublevel"
|
|
42
|
+
type = var
|
|
43
|
+
value = nil
|
|
44
|
+
post_process_vars(name, type, value)
|
|
45
|
+
else
|
|
46
|
+
value = var.split(",").first.lstrip
|
|
47
|
+
type = var.split(",")[1].nil? ? nil : var.split(",")[1].lstrip
|
|
48
|
+
translate_variables( name , type, value )
|
|
49
|
+
end
|
|
50
|
+
when TrueClass
|
|
51
|
+
# puts "pre_process: #{name}, #{var}, #{var.inspect} got #{var.class} on 50"
|
|
52
|
+
value = 1
|
|
53
|
+
type = "bool"
|
|
54
|
+
post_process_vars(name, type, value)
|
|
55
|
+
when FalseClass
|
|
56
|
+
# puts "pre_process: #{name}, #{var}, #{var.inspect} got #{var.class} on 55"
|
|
57
|
+
value = 0
|
|
58
|
+
type = "bool"
|
|
59
|
+
post_process_vars(name, type, value)
|
|
60
|
+
when Array
|
|
61
|
+
post_process_arrays(name, var)
|
|
62
|
+
else
|
|
63
|
+
raise ArgumentError, "not sure what to do here... got #{name} with value #{var} which is a #{var.class}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def translate_variables(name, type = nil, value = nil)
|
|
69
|
+
|
|
70
|
+
unless type.nil?
|
|
71
|
+
check_variable_type(type)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# classify the values
|
|
75
|
+
if value.class == Fixnum
|
|
76
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is a fixnum, got #{value.class} on 74"
|
|
77
|
+
elsif value.class == Float
|
|
78
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is a float, got #{value.class} on 76"
|
|
79
|
+
elsif value =~ /^-(\d|x)*$/
|
|
80
|
+
value = value.to_i
|
|
81
|
+
type = "int" if type.nil?
|
|
82
|
+
elsif value =~ /^-(\d|\.|x)*$/
|
|
83
|
+
value = value.to_f
|
|
84
|
+
unless type.nil?
|
|
85
|
+
raise ArgumentError, "#{value} should be a float got #{type}" unless type == "float"
|
|
86
|
+
end
|
|
87
|
+
type = "float" if type.nil?
|
|
88
|
+
|
|
89
|
+
elsif value[0,1] !~ /\d/
|
|
90
|
+
# puts value[0,1]
|
|
91
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is a number of some type, got #{value.class} on 79"
|
|
92
|
+
type = "char*"
|
|
93
|
+
value = "\"#{value}\""
|
|
94
|
+
elsif value !~ /(\.|x)/
|
|
95
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is an integer, got #{value.class} on 83"
|
|
96
|
+
value = value.to_i
|
|
97
|
+
type = "int" if type.nil?
|
|
98
|
+
elsif value =~ /(\d*\.\d*)/ # and no
|
|
99
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is a float, got #{value.class} on 87"
|
|
100
|
+
value = value.to_f
|
|
101
|
+
type = "float"
|
|
102
|
+
elsif value =~ /0x\d\d/
|
|
103
|
+
# puts "translate_variables: #{name}, #{value}, #{type} is a byte, got #{value.class} on 91"
|
|
104
|
+
type = "byte"
|
|
105
|
+
else
|
|
106
|
+
raise ArgumentError, "not sure what to do with a value of #{value} with a type like #{type}"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
post_process_vars(name, type, value)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def post_process_vars(name, type, value = nil)
|
|
115
|
+
value = " = #{value}" if value
|
|
116
|
+
$external_var_identifiers << "__#{name}" unless $external_var_identifiers.include?("__#{name}")
|
|
117
|
+
$external_vars << "#{type} __#{name}#{value};"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def post_process_arrays(name, var)
|
|
121
|
+
type = c_type(var[0])
|
|
122
|
+
$array_types[name] = type
|
|
123
|
+
assignment = var.inspect.gsub("[","{").gsub("]","}")
|
|
124
|
+
c_style_array = "#{type} __#{name}[] = #{assignment};"
|
|
125
|
+
$external_var_identifiers << "__#{name}" unless $external_var_identifiers.include?("__#{name}")
|
|
126
|
+
$external_array_vars << c_style_array unless $external_array_vars.include?(c_style_array)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def check_variable_type(type)
|
|
130
|
+
unless type =~ /#{C_VAR_TYPES}/
|
|
131
|
+
raise ArgumentError, "the following variable types are supported \n #{C_VAR_TYPES.gsub("|",", ")} got #{type}"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def c_type(typ)
|
|
136
|
+
type =
|
|
137
|
+
case typ
|
|
138
|
+
when Integer
|
|
139
|
+
"int"
|
|
140
|
+
when String
|
|
141
|
+
"char*"
|
|
142
|
+
when TrueClass
|
|
143
|
+
"bool"
|
|
144
|
+
when FalseClass
|
|
145
|
+
"bool"
|
|
146
|
+
else
|
|
147
|
+
raise "Bug! Unknown type #{typ.inspect} in c_type"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
type
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
data/lib/rad/version.rb
CHANGED
|
@@ -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,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
|
|
@@ -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
|