neo_rad 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ =Welcome to RAD (Ruby Arduino Development) Quick Start Documentation
2
+
3
+ ArduinoSketch is the main access point for working with RAD. Sub-classes of ArduinoSketch have access to a wide array of convenient class methods (documented below) for doing the most common kinds of setup needed when programming the Arduino such as configuring input and output pins and establishing serial connections. Here is the canonical 'hello world' example of blinking a single LED in RAD:
4
+
5
+ test... to be continued if it works..
@@ -0,0 +1,246 @@
1
+ ## RAD plugins -- the start
2
+
3
+ ## June 25, 2008
4
+ ## jd@jdbarnhart.com
5
+ ##
6
+
7
+
8
+ # Disclaimer: This is only a first run at the notion of plugins and started off as just a way to keep from adding everything to ArduinoSketch.
9
+ # ArduinoPlugin is the RAD class for adding "plugins" which add functionality such as servo control, special lcd screen methods, debounce methods, etc.. Sub-classes of ArduinoPlugin (the plugins) add class methods for doing thing beyond the most common kinds of setup needed when programming the Arduino. Here is an example of controlling a servo:
10
+ #
11
+ # class MoveServo < ArduinoSketch
12
+ #
13
+ # external_vars :sensor_position => "int, 0", :servo_amount => "int, 0"
14
+ #
15
+ # output_pin 4, :as => :my_servo, :min => 700, :max => 2200
16
+ # input_pin 1, :as => :sensor
17
+ # def loop
18
+ # sensor_position = analogRead(sensor)
19
+ # servo_amount = (sensor_position*2 + 500)
20
+ # move_servo my_servo, servo_amount
21
+ # end
22
+ # end
23
+ #
24
+ #
25
+ # Here's one for latching an led
26
+
27
+ # output_pin 5, :as => :red_led
28
+ # input_pin 8, :as => :red_button, :latch => :off, # optional adjustment to amount of time for debounce (default 200) :adjust => 250
29
+ # # latch sets the led as on or off initially and sets up a array of structs to keep timing and state
30
+ #
31
+ # def loop
32
+ # debounce_toggle(red_button, red_led)
33
+ # end
34
+ # end
35
+ #
36
+ # Since this is a first pass, there is work to do here, such as
37
+ # checking if plugin methods are needed and only loading those that are,
38
+ # more compreshensive plugin organization (more railsish with tests, etc)
39
+ # a scheme to encourage plugin authors and provide an easy way to avoid method and variable namespace collisions
40
+ # a scheme to flag when a prerequisite plugin is required
41
+ # on with the show:
42
+
43
+
44
+
45
+ class ArduinoPlugin
46
+
47
+ def initialize #:nodoc:
48
+
49
+ $plugin_directives = $plugin_directives || []
50
+ $plugin_external_variables = $plugin_external_variables || []
51
+ # moved to check_for_plugin_use $plugin_structs = $plugin_structs || {}
52
+ $plugin_signatures = $plugin_signatures || []
53
+ $plugin_methods = $plugin_methods || []
54
+ # $plugin_methods_hash = $plugin_methods_hash || {} ### new
55
+ # $plugins_to_load = $plugins_to_load || [] ### new
56
+ $add_to_setup = $add_to_setup || []
57
+ $load_libraries = $load_libraries || []
58
+
59
+
60
+ end
61
+
62
+ # c declarations are automatic
63
+ # you won't need them in the plugins
64
+ # so, the first thing we can do is gather all the plugin methods, and scan the
65
+ # sketch available plugins...
66
+ # if the sketch has them, we include the plugins in the build...
67
+ # otherwise not..
68
+
69
+ def include_wire
70
+ $load_libraries << "Wire" unless $load_libraries.include?("Wire")
71
+ end
72
+
73
+
74
+ def add_to_setup(*args)
75
+ if args
76
+ args.each do |arg|
77
+ $add_to_setup << arg
78
+ end
79
+ end
80
+ end
81
+
82
+
83
+ def plugin_directives(*args)
84
+ if args
85
+ args.each do |arg|
86
+ $plugin_directives << arg
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ def external_variables(*args)
93
+ if args
94
+ args.each do |arg|
95
+ puts self.class
96
+ puts "\tadding plugin external variables: #{arg}"
97
+ # colons aptional
98
+ colon = arg[arg.length - 1, 1] == ";" ? '' : ';'
99
+ $plugin_external_variables << "#{arg}#{colon}"
100
+ end
101
+ end
102
+ end
103
+
104
+ def add_blink_m_struct
105
+ $plugin_structs[:blink_m] = <<-STR
106
+ typedef struct _blinkm_script_line {
107
+ uint8_t dur;
108
+ uint8_t cmd[4]; // cmd,arg1,arg2,arg3
109
+ } blinkm_script_line;
110
+ STR
111
+ end
112
+
113
+ def self.add_blink_m_struct
114
+ $plugin_structs[:blink_m] = <<-STR
115
+ typedef struct _blinkm_script_line {
116
+ uint8_t dur;
117
+ uint8_t cmd[4]; // cmd,arg1,arg2,arg3
118
+ } blinkm_script_line;
119
+ STR
120
+ end
121
+
122
+ def add_debounce_struct
123
+ $plugin_structs[:debounce] = <<-STR
124
+ struct debounce {
125
+ int state;
126
+ int read;
127
+ int prev;
128
+ unsigned long time;
129
+ unsigned long adjust;
130
+ };
131
+ STR
132
+ end
133
+
134
+
135
+ def add_servo_struct
136
+ $plugin_structs[:servo] = <<-STR
137
+ struct servo {
138
+ int pin;
139
+ long unsigned pulseWidth;
140
+ long unsigned lastPulse;
141
+ long unsigned startPulse;
142
+ long unsigned refreshTime;
143
+ int min;
144
+ int max;
145
+ };
146
+ STR
147
+ end
148
+
149
+ def self.add_debounce_struct
150
+ $plugin_structs[:debounce] = <<-STR
151
+ struct debounce {
152
+ int state;
153
+ int read;
154
+ int prev;
155
+ unsigned long time;
156
+ unsigned long adjust;
157
+ };
158
+ STR
159
+ end
160
+
161
+
162
+ def self.add_servo_struct
163
+ $plugin_structs[:servo] = <<-STR
164
+ struct servo {
165
+ int pin;
166
+ long unsigned pulseWidth;
167
+ long unsigned lastPulse;
168
+ long unsigned startPulse;
169
+ long unsigned refreshTime;
170
+ int min;
171
+ int max;
172
+ };
173
+ STR
174
+ end
175
+
176
+ def self.add_sensor_struct
177
+ $plugin_structs[:sensor] = <<-STR
178
+ struct hysteresis {
179
+ int pin;
180
+ int state;
181
+ };
182
+ STR
183
+ end
184
+
185
+ def self.add_spectra_struct
186
+ $plugin_structs[:spectra] = <<-STR
187
+ struct spectra {
188
+ int pin;
189
+ int state;
190
+ int r1;
191
+ int r2;
192
+ int r3;
193
+ };
194
+ STR
195
+ end
196
+
197
+
198
+ def self.check_for_plugin_use(sketch_string, plugin_string, file_name) # rename klass to filename
199
+ $plugin_structs = $plugin_structs || {}
200
+ $plugin_methods_hash = $plugin_methods_hash || {}
201
+ $plugins_to_load = $plugins_to_load || []
202
+ plugin_signatures = []
203
+ plugin_methods = []
204
+ ## need a test for this
205
+ ## fails on string interpolation, but since ruby_to_c also currently fails ...
206
+ sketch_string = sketch_string.gsub(/#(?!\{.*\}).*/, "")
207
+ plugin_signatures << plugin_string.scan(/^\s*(((#{PLUGIN_C_VAR_TYPES})\s*)+\w*\(.*\))/)
208
+ # gather just the method name and then add to #plugin_methods_hash
209
+ plugin_signatures[0].map {|sig| "#{sig[0]}"}.each {|m| plugin_methods << m.gsub!(/^.*\s(\w*)\(.*\)/, '\1')}
210
+ # we don't know the methods yet, so...
211
+ $plugin_methods_hash[file_name] = plugin_methods
212
+ $plugin_methods_hash.each do |k,meths|
213
+ meths.each do |meth|
214
+ if sketch_string.include?(meth)
215
+ # load this plugin...
216
+ $plugins_to_load << k unless $plugins_to_load.include?(k)
217
+ end
218
+ end
219
+ end
220
+
221
+ end
222
+
223
+
224
+ def self.process(plugin_string)
225
+ plugin_signatures = []
226
+ first_process = plugin_string
227
+ # todo: need to add plugin names to the methods, so we can add them as comments in the c code
228
+ # gather the c methods
229
+ $plugin_methods << first_process.scan(/^\s*(((#{PLUGIN_C_VAR_TYPES}).*\)).*(\n.*)*^\s*\})/)
230
+ plugin_signatures << first_process.scan(/^\s((#{PLUGIN_C_VAR_TYPES}).*\(.*\))/)
231
+ $plugin_signatures << plugin_signatures[0].map {|sig| "#{sig[0]};"}
232
+ ## strip out the methods and pass it back
233
+ result = plugin_string
234
+ # strip out the c methods so we have only ruby before eval
235
+ result.gsub(/^\s*(#{PLUGIN_C_VAR_TYPES}).*(\n.*)*^\s*\}/, "" )
236
+
237
+ end
238
+
239
+ private
240
+
241
+ def add_struct(struct)
242
+
243
+
244
+ end
245
+
246
+ end