neo_rad 0.4.0

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.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +112 -0
  3. data/License.txt +282 -0
  4. data/Manifest.txt +144 -0
  5. data/README.rdoc +1 -0
  6. data/Rakefile +142 -0
  7. data/bin/rad +302 -0
  8. data/lib/examples/add_hysteresis.rb +13 -0
  9. data/lib/examples/basic_blink.rb +10 -0
  10. data/lib/examples/blink_m_address_assignment.rb +104 -0
  11. data/lib/examples/blink_m_hello.rb +14 -0
  12. data/lib/examples/blink_m_multi.rb +61 -0
  13. data/lib/examples/blink_with_serial.rb +16 -0
  14. data/lib/examples/configure_pa_lcd_boot.rb +91 -0
  15. data/lib/examples/debounce_methods.rb +49 -0
  16. data/lib/examples/external_variable_fu.rb +26 -0
  17. data/lib/examples/external_variables.rb +32 -0
  18. data/lib/examples/first_sound.rb +23 -0
  19. data/lib/examples/frequency_generator.rb +30 -0
  20. data/lib/examples/hello_array.rb +48 -0
  21. data/lib/examples/hello_array2.rb +112 -0
  22. data/lib/examples/hello_array_eeprom.rb +59 -0
  23. data/lib/examples/hello_clock.rb +84 -0
  24. data/lib/examples/hello_eeprom.rb +51 -0
  25. data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
  26. data/lib/examples/hello_format_print.rb +94 -0
  27. data/lib/examples/hello_lcd_charset.rb +75 -0
  28. data/lib/examples/hello_pa_lcd.rb +59 -0
  29. data/lib/examples/hello_servos.rb +88 -0
  30. data/lib/examples/hello_spectra_sound.rb +38 -0
  31. data/lib/examples/hello_world.rb +11 -0
  32. data/lib/examples/hello_xbee.rb +12 -0
  33. data/lib/examples/hysteresis_duel.rb +39 -0
  34. data/lib/examples/i2c_with_clock_chip.rb +124 -0
  35. data/lib/examples/midi_beat_box.rb +86 -0
  36. data/lib/examples/midi_scales.rb +94 -0
  37. data/lib/examples/motor_knob.rb +30 -0
  38. data/lib/examples/servo_buttons.rb +23 -0
  39. data/lib/examples/servo_calibrate_continuous.rb +92 -0
  40. data/lib/examples/servo_throttle.rb +40 -0
  41. data/lib/examples/software_serial.rb +10 -0
  42. data/lib/examples/sparkfun_lcd.rb +48 -0
  43. data/lib/examples/spectra_soft_pot.rb +34 -0
  44. data/lib/examples/times_method.rb +8 -0
  45. data/lib/examples/toggle.rb +10 -0
  46. data/lib/examples/twitter.rb +57 -0
  47. data/lib/examples/two_wire.rb +14 -0
  48. data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
  49. data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
  50. data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
  51. data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
  52. data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
  53. data/lib/libraries/DS1307/DS1307.cpp +162 -0
  54. data/lib/libraries/DS1307/DS1307.h +66 -0
  55. data/lib/libraries/DS1307/keywords.txt +18 -0
  56. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
  57. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
  58. data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
  59. data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
  60. data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
  61. data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
  62. data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
  63. data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
  64. data/lib/libraries/LoopTimer/keywords.txt +27 -0
  65. data/lib/libraries/OneWire/OneWire.cpp +194 -0
  66. data/lib/libraries/OneWire/OneWire.h +63 -0
  67. data/lib/libraries/OneWire/keywords.txt +35 -0
  68. data/lib/libraries/OneWire/readme.txt +13 -0
  69. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +296 -0
  70. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
  71. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
  72. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
  73. data/lib/libraries/Servo/Servo.cpp +192 -0
  74. data/lib/libraries/Servo/Servo.h +61 -0
  75. data/lib/libraries/Stepper/Stepper.cpp +220 -0
  76. data/lib/libraries/Stepper/Stepper.h +86 -0
  77. data/lib/libraries/Stepper/keywords.txt +28 -0
  78. data/lib/libraries/Wire/Wire.cpp +262 -0
  79. data/lib/libraries/Wire/Wire.h +67 -0
  80. data/lib/libraries/Wire/keywords.txt +31 -0
  81. data/lib/libraries/Wire/twi.h +57 -0
  82. data/lib/libraries/Wire/utility/twi.c +449 -0
  83. data/lib/libraries/Wire/utility/twi.h +57 -0
  84. data/lib/plugins/bitwise_ops.rb +54 -0
  85. data/lib/plugins/blink.rb +25 -0
  86. data/lib/plugins/blink_m.rb +356 -0
  87. data/lib/plugins/debounce.rb +138 -0
  88. data/lib/plugins/debug_output_to_lcd.rb +71 -0
  89. data/lib/plugins/hysteresis.rb +52 -0
  90. data/lib/plugins/input_output_state.rb +84 -0
  91. data/lib/plugins/lcd_padding.rb +58 -0
  92. data/lib/plugins/mem_test.rb +37 -0
  93. data/lib/plugins/midi.rb +60 -0
  94. data/lib/plugins/parallax_ping.rb +50 -0
  95. data/lib/plugins/servo_pulse.rb +31 -0
  96. data/lib/plugins/servo_setup.rb +86 -0
  97. data/lib/plugins/smoother.rb +54 -0
  98. data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
  99. data/lib/plugins/spectra_symbol.rb +79 -0
  100. data/lib/plugins/twitter_connect.rb +145 -0
  101. data/lib/rad/README.rdoc +5 -0
  102. data/lib/rad/arduino_plugin.rb +246 -0
  103. data/lib/rad/arduino_sketch.rb +628 -0
  104. data/lib/rad/darwin_installer.rb +23 -0
  105. data/lib/rad/generators/makefile/makefile.erb +243 -0
  106. data/lib/rad/generators/makefile/makefile.rb +38 -0
  107. data/lib/rad/hardware_library.rb +813 -0
  108. data/lib/rad/init.rb +15 -0
  109. data/lib/rad/linux_installer.rb +132 -0
  110. data/lib/rad/progressbar.rb +236 -0
  111. data/lib/rad/rad_processor.rb +128 -0
  112. data/lib/rad/rad_rewriter.rb +94 -0
  113. data/lib/rad/rad_type_checker.rb +26 -0
  114. data/lib/rad/sim/arduino_sketch.rb +57 -0
  115. data/lib/rad/sketch_compiler.rb +47 -0
  116. data/lib/rad/tasks/build_and_make.rake +210 -0
  117. data/lib/rad/tasks/rad.rb +2 -0
  118. data/lib/rad/todo.txt +13 -0
  119. data/lib/rad/variable_processing.rb +153 -0
  120. data/lib/rad/version.rb +9 -0
  121. data/lib/rad.rb +5 -0
  122. data/scripts/txt2html +67 -0
  123. data/setup.rb +1585 -0
  124. data/spec/examples/hello_world.rb +11 -0
  125. data/spec/examples/serial_motor.rb +12 -0
  126. data/spec/models/arduino_sketch_spec.rb +82 -0
  127. data/spec/models/sketch_compiler_spec.rb +96 -0
  128. data/spec/models/spec_helper.rb +2 -0
  129. data/spec/sim/hello_world_spec.rb +42 -0
  130. data/spec/spec.opts +1 -0
  131. data/test/hello_world_test/Makefile +436 -0
  132. data/test/hello_world_test/hello_world.cpp +23 -0
  133. data/test/test_array_processing.rb +179 -0
  134. data/test/test_plugin_loading.rb +151 -0
  135. data/test/test_translation_post_processing.rb +185 -0
  136. data/test/test_variable_processing.rb +238 -0
  137. data/website/examples/assembler_test.rb.html +73 -0
  138. data/website/examples/gps_reader.rb.html +39 -0
  139. data/website/examples/hello_world.rb.html +38 -0
  140. data/website/examples/serial_motor.rb.html +41 -0
  141. data/website/index.html +178 -0
  142. data/website/index.txt +64 -0
  143. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  144. data/website/stylesheets/screen.css +169 -0
  145. data/website/template.rhtml +48 -0
  146. metadata +222 -0
@@ -0,0 +1,11 @@
1
+ # Hardware: LED connected on pin 7
2
+
3
+ class HelloWorld < ArduinoSketch
4
+ output_pin 7, :as => :led
5
+ def loop
6
+ digitalWrite led, ON
7
+ delay 500
8
+ digitalWrite led, OFF
9
+ delay 500
10
+ end
11
+ end
@@ -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,2 @@
1
+ require 'rubygems'
2
+ require 'spec'
@@ -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