madrona-rad 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/History.txt +75 -0
  2. data/License.txt +282 -0
  3. data/Manifest.txt +47 -0
  4. data/README.rdoc +51 -0
  5. data/Rakefile +139 -0
  6. data/bin/rad +197 -0
  7. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +267 -0
  8. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +64 -0
  9. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +254 -0
  10. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +57 -0
  11. data/lib/libraries/Servo/Servo.cpp +152 -0
  12. data/lib/libraries/Servo/Servo.h +33 -0
  13. data/lib/libraries/Servo/keywords.txt +25 -0
  14. data/lib/plugins/debounce.rb +116 -0
  15. data/lib/plugins/debug_output_to_lcd.rb +71 -0
  16. data/lib/plugins/input_output_state.rb +84 -0
  17. data/lib/plugins/mem_test.rb +37 -0
  18. data/lib/plugins/servo_pulse.rb +31 -0
  19. data/lib/plugins/servo_setup.rb +86 -0
  20. data/lib/plugins/smoother.rb +54 -0
  21. data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
  22. data/lib/rad/arduino_plugin.rb +202 -0
  23. data/lib/rad/arduino_sketch.rb +952 -0
  24. data/lib/rad/generators/makefile/makefile.erb +243 -0
  25. data/lib/rad/generators/makefile/makefile.rb +39 -0
  26. data/lib/rad/init.rb +12 -0
  27. data/lib/rad/rad_processor.rb +66 -0
  28. data/lib/rad/rad_rewriter.rb +94 -0
  29. data/lib/rad/tasks/build_and_make.rake +159 -0
  30. data/lib/rad/tasks/rad.rb +2 -0
  31. data/lib/rad/todo.txt +13 -0
  32. data/lib/rad/version.rb +9 -0
  33. data/lib/rad.rb +5 -0
  34. data/scripts/txt2html +67 -0
  35. data/setup.rb +1585 -0
  36. data/spec/models/arduino_sketch_spec.rb +82 -0
  37. data/spec/models/spec_helper.rb +2 -0
  38. data/spec/spec.opts +1 -0
  39. data/website/examples/assembler_test.rb.html +73 -0
  40. data/website/examples/gps_reader.rb.html +39 -0
  41. data/website/examples/hello_world.rb.html +38 -0
  42. data/website/examples/serial_motor.rb.html +41 -0
  43. data/website/index.html +177 -0
  44. data/website/index.txt +64 -0
  45. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  46. data/website/stylesheets/screen.css +169 -0
  47. data/website/template.rhtml +48 -0
  48. metadata +120 -0
data/bin/rad ADDED
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # no rubygems to load, so we fail silently
7
+ end
8
+
9
+ require 'optparse'
10
+ require 'fileutils'
11
+ require 'yaml'
12
+
13
+
14
+
15
+ class OptionParser #:nodoc:
16
+
17
+ def self.parse(args)
18
+ # defaults
19
+
20
+ options = {"hardware" => {
21
+ "serial_port" => '/dev/tty.usbserial*',
22
+ "mcu" => "atmega168",
23
+ "physical_reset" => false
24
+ },
25
+ "software" => {
26
+ "arduino_root" => "/Applications/arduino-0011"
27
+ }
28
+ }
29
+
30
+ opts = OptionParser.new do |opts|
31
+
32
+ opts.banner = <<-BANNER
33
+ Build a directory for your RAD Project and install RAD in its vendor sub-directory.
34
+
35
+ Usage: #{File.basename($0)} <sketch_dir_name> <options for config>
36
+ BANNER
37
+
38
+ opts.on("-p", "--port [SERIAL PORT]",
39
+ "Path to your serial port",
40
+ " (default: #{options['hardware']['serial_port']})") do |port|
41
+
42
+ options["hardware"]["serial_port"] = port if port
43
+ end
44
+
45
+ opts.on("-m", "--mcu [PROCESSOR TYPE]",
46
+ "Type of processor on your board",
47
+ " (default: #{options['hardware']['mcu']})") do |port|
48
+
49
+ options["hardware"]["serial_port"] = port if port
50
+ end
51
+
52
+ opts.on("-r", "--reset [RESET REQUIRED]",
53
+ "Require a hardware reset before uploading?",
54
+ " (default: #{options['hardware']['physical_reset']})") do |no_reset|
55
+ options["hardware"]["physical_reset"] = true unless no_reset
56
+ end
57
+
58
+ opts.on("-a", "--arduino [ARDUINO DIR]",
59
+ "Path to your Arduino install",
60
+ " (default: #{options['software']['arduino_root']})") do |arduino|
61
+ options["software"]["arduino_root"] = arduino if arduino
62
+ end
63
+
64
+ opts.on_tail("-h", "--help", "Show this message") do
65
+ puts opts
66
+ exit
67
+ end
68
+ end
69
+
70
+ opts.parse!(args)
71
+ [options, opts]
72
+ end
73
+
74
+ end
75
+
76
+
77
+ # home = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
78
+ # begin
79
+ # config = YAML::load open(home + "/.rad")
80
+ # rescue
81
+ # config = false
82
+ # end
83
+ #
84
+
85
+
86
+ # Handle options:
87
+ options, parser = OptionParser.parse(ARGV)
88
+ sketch_name = ARGV[0]
89
+ parser.parse!(["-h"]) unless sketch_name
90
+
91
+
92
+ # Build vendor/rad:
93
+
94
+ FileUtils.mkdir_p "#{sketch_name}/vendor/rad"
95
+ puts "Successfully created your sketch directory."
96
+
97
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/rad/.", "#{sketch_name}/vendor/rad"
98
+ puts "Installed RAD into #{sketch_name}/vendor/rad"
99
+ puts
100
+
101
+ # Build vendor/libraries:
102
+
103
+ FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
104
+ puts "Successfully created your libraries directory."
105
+
106
+
107
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Servo/.", "#{sketch_name}/vendor/libraries/Servo"
108
+ puts "Installed Servo into #{sketch_name}/vendor/libraries"
109
+ puts
110
+
111
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDpa/.", "#{sketch_name}/vendor/libraries/SWSerLCDpa"
112
+ puts "Installed SWSerLCDpa into #{sketch_name}/vendor/libraries"
113
+ puts
114
+
115
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDsf/.", "#{sketch_name}/vendor/libraries/SWSerLCDsf"
116
+ puts "Installed SWSerLCDsf into #{sketch_name}/vendor/libraries"
117
+ puts
118
+
119
+ # Build vendor/plugins:
120
+
121
+ FileUtils.mkdir_p "#{sketch_name}/vendor/plugins"
122
+ puts "Successfully created your plugins directory."
123
+
124
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/plugins/.", "#{sketch_name}/vendor/plugins"
125
+ puts "Installed Default plugins into #{sketch_name}/vendor/plugins"
126
+ puts
127
+
128
+ # Build sketch files, etc.:
129
+
130
+ FileUtils.touch "#{sketch_name}/#{sketch_name}.rb"
131
+ File.open("#{sketch_name}/#{sketch_name}.rb", "w") do |file|
132
+ file << <<-EOS
133
+ class #{sketch_name.split("_").collect{|c| c.capitalize}.join("")} < ArduinoSketch
134
+
135
+ # quick overview:
136
+ # external variables can be added.. use a comma separation, colons are added automatically
137
+ #
138
+ #external_vars :foo => "long unsigned, 0", :bar => "int"
139
+ # result "long unsigned foo = 0" and "int bar;"
140
+ # note while this is ruby, many methods and some operators you take for granted are not implemented
141
+ # some examples: blocks, case statements, +=
142
+ # keep it simple and remember that the arduino uses a simple loop
143
+ # you can branch out with your other methods here or use
144
+ # add_to_setup to call a method once (todo: look at signatures)
145
+ # since all the methods are converted to C, assumptions are made regarding variable types
146
+ # for example if we need integers to call serial_print hack = input + output + 1
147
+ # pin examples
148
+ # input_pin 10, :as => :back_on_button, :latch => :off
149
+ # input_pin 12, :as => :back_off_button, :latch => :off
150
+ # output_pin 5, :as => :red_led
151
+ # input_pin 8, :as => :red_button, :latch => :off, :adjust => 250
152
+ # output_pin 4, :as => :top_servo, :min => 700, :max => 2200
153
+
154
+ # three line servo (don't forget do declare servo_amount')
155
+ # sensor_position = analogRead(sensor)
156
+ # servo_amount = (sensor_position*2 + 500)
157
+ # move_servo top_servo, servo_amount
158
+ # one line debounce:
159
+ # debounce_toggle(button, led)
160
+ # debounce a read (returns high)
161
+ # do_something if debounce_read(button, led)
162
+
163
+
164
+
165
+ # hello world (uncomment to run)
166
+
167
+ #output_pin 13, :as => :led
168
+ # def loop
169
+ # blink led, 100
170
+ # end
171
+ end
172
+ EOS
173
+ end
174
+ puts "Added #{sketch_name}/#{sketch_name}.rb"
175
+
176
+ File.open("#{sketch_name}/Rakefile", 'w') do |file|
177
+ file << <<-EOS
178
+ require 'vendor/rad/init.rb'
179
+ EOS
180
+ end
181
+ puts "Added #{sketch_name}/Rakefile"
182
+
183
+ FileUtils.mkdir_p "#{sketch_name}/config"
184
+ puts "Added #{sketch_name}/config"
185
+
186
+ File.open("#{sketch_name}/config/hardware.yml", 'w') do |file|
187
+ file << options["hardware"].to_yaml
188
+ end
189
+ puts "Added #{sketch_name}/config/hardware.yml"
190
+
191
+ File.open("#{sketch_name}/config/software.yml", 'w') do |file|
192
+ file << options["software"].to_yaml
193
+ end
194
+ puts "Added #{sketch_name}/config/software.yml"
195
+
196
+ puts
197
+ puts "Run 'rake -T' inside your sketch dir to learn how to compile and upload it."
@@ -0,0 +1,267 @@
1
+ /*
2
+ SWSerLCDpa.cpp - Software serial to Peter Anderson controller chip based
3
+ LCD display library Adapted from SoftwareSerial.cpp (c) 2006 David A. Mellis
4
+ by Brian B. Riley, Underhill Center, Vermont, USA, July 2007
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ /******************************************************************************
22
+ * Includes
23
+ ******************************************************************************/
24
+
25
+ #include "WConstants.h"
26
+ #include "SWSerLCDpa.h"
27
+
28
+ /******************************************************************************
29
+ * Definitions
30
+ ******************************************************************************/
31
+
32
+ /******************************************************************************
33
+ * Constructors
34
+ ******************************************************************************/
35
+
36
+ SWSerLCDpa::SWSerLCDpa(uint8_t transmitPin)
37
+ {
38
+ _transmitPin = transmitPin;
39
+ _baudRate = 0;
40
+ pinMode(_transmitPin, OUTPUT);
41
+ _geometry = 0;
42
+ }
43
+
44
+ SWSerLCDpa::SWSerLCDpa(uint8_t transmitPin, int geometry)
45
+ {
46
+ _transmitPin = transmitPin;
47
+ _baudRate = 0;
48
+ pinMode(_transmitPin, OUTPUT);
49
+ _geometry = geometry;
50
+ }
51
+
52
+
53
+
54
+ /******************************************************************************
55
+ * User API
56
+ ******************************************************************************/
57
+
58
+ void SWSerLCDpa::begin(long speed)
59
+ {
60
+ _baudRate = speed;
61
+ _bitPeriod = 1000000 / _baudRate;
62
+
63
+ digitalWrite(_transmitPin, HIGH);
64
+ delayMicroseconds( _bitPeriod); // if we were low this establishes the end
65
+ delay(20);
66
+ clearscr();
67
+ if (_geometry)
68
+ setgeo(_geometry);
69
+
70
+ }
71
+
72
+ void SWSerLCDpa::print(uint8_t b)
73
+ {
74
+ if (_baudRate == 0)
75
+ return;
76
+
77
+ int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles
78
+ byte mask;
79
+
80
+ digitalWrite(_transmitPin, LOW);
81
+ delayMicroseconds(bitDelay);
82
+
83
+ for (mask = 0x01; mask; mask <<= 1) {
84
+ if (b & mask){ // choose bit
85
+ digitalWrite(_transmitPin,HIGH); // send 1
86
+ }
87
+ else{
88
+ digitalWrite(_transmitPin,LOW); // send 1
89
+ }
90
+ delayMicroseconds(bitDelay);
91
+ }
92
+
93
+ digitalWrite(_transmitPin, HIGH);
94
+ delayMicroseconds(bitDelay);
95
+ }
96
+
97
+ void SWSerLCDpa::print(const char *s)
98
+ {
99
+ while (*s) {
100
+ print(*s++);
101
+ delay(1);
102
+ }
103
+ }
104
+
105
+ void SWSerLCDpa::print(char c)
106
+ {
107
+ print((uint8_t) c);
108
+ }
109
+
110
+ void SWSerLCDpa::print(int n)
111
+ {
112
+ print((long) n);
113
+ }
114
+
115
+ void SWSerLCDpa::print(unsigned int n)
116
+ {
117
+ print((unsigned long) n);
118
+ }
119
+
120
+ void SWSerLCDpa::print(long n)
121
+ {
122
+ if (n < 0) {
123
+ print('-');
124
+ n = -n;
125
+ }
126
+ printNumber(n, 10);
127
+ }
128
+
129
+ void SWSerLCDpa::print(unsigned long n)
130
+ {
131
+ printNumber(n, 10);
132
+ }
133
+
134
+ void SWSerLCDpa::print(long n, int base)
135
+ {
136
+ if (base == 0)
137
+ print((char) n);
138
+ else if (base == 10)
139
+ print(n);
140
+ else
141
+ printNumber(n, base);
142
+ }
143
+
144
+ // -------- PHA unique codes -------------------------
145
+ void SWSerLCDpa::println(void)
146
+ {
147
+ print("?n");
148
+ delay(10);
149
+ }
150
+
151
+ void SWSerLCDpa::clearscr(void)
152
+ {
153
+ print("?f");
154
+ delay(100);
155
+ }
156
+
157
+ void SWSerLCDpa::home(void)
158
+ {
159
+ print("?a");
160
+ delay(10);
161
+ }
162
+
163
+
164
+ void SWSerLCDpa::setgeo(int geometry)
165
+ {
166
+ print("?G");
167
+ print(geometry);
168
+ delay(200);
169
+ }
170
+
171
+ void SWSerLCDpa::setintensity(int intensity)
172
+ {
173
+ print("?B");
174
+ if (intensity < 16)
175
+ print('0');
176
+ print(intensity, 16);
177
+ delay(200);
178
+ }
179
+
180
+ void SWSerLCDpa::intoBignum(void)
181
+ {
182
+ print("?>3");
183
+ }
184
+
185
+ void SWSerLCDpa::outofBignum(void)
186
+ {
187
+ print("?<");
188
+ }
189
+
190
+
191
+ void SWSerLCDpa::setxy(int x, int y)
192
+ {
193
+ print("?y");
194
+ print(y);
195
+ print("?x");
196
+ if (x < 10)
197
+ print('0');
198
+ print(x);
199
+ delay(10);
200
+ }
201
+
202
+
203
+ void SWSerLCDpa::println(char c)
204
+ {
205
+ print(c);
206
+ println();
207
+ }
208
+
209
+ void SWSerLCDpa::println(const char c[])
210
+ {
211
+ print(c);
212
+ println();
213
+ }
214
+
215
+ void SWSerLCDpa::println(uint8_t b)
216
+ {
217
+ print(b);
218
+ println();
219
+ }
220
+
221
+ void SWSerLCDpa::println(int n)
222
+ {
223
+ print(n);
224
+ println();
225
+ }
226
+
227
+ void SWSerLCDpa::println(long n)
228
+ {
229
+ print(n);
230
+ println();
231
+ }
232
+
233
+ void SWSerLCDpa::println(unsigned long n)
234
+ {
235
+ print(n);
236
+ println();
237
+ }
238
+
239
+ void SWSerLCDpa::println(long n, int base)
240
+ {
241
+ print(n, base);
242
+ println();
243
+ }
244
+
245
+ // Private Methods /////////////////////////////////////////////////////////////
246
+
247
+ void SWSerLCDpa::printNumber(unsigned long n, uint8_t base)
248
+ {
249
+ unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
250
+ unsigned long i = 0;
251
+
252
+ if (n == 0) {
253
+ print('0');
254
+ return;
255
+ }
256
+
257
+ while (n > 0) {
258
+ buf[i++] = n % base;
259
+ n /= base;
260
+ }
261
+
262
+ for (; i > 0; i--)
263
+ print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
264
+
265
+ delay(8);
266
+
267
+ }
@@ -0,0 +1,64 @@
1
+ /*
2
+ SWSerLCDpa.h - Software serial to Peter Anderson controller chip based
3
+ LCD display library Adapted from SoftwareSerial.cpp (c) 2006 David A. Mellis
4
+ by Brian B. Riley, Underhill Center, Vermont, USA, July 2007
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ #ifndef SWSerLCDpa_h
22
+ #define SWSerLCDpa_h
23
+
24
+ #include <inttypes.h>
25
+
26
+ class SWSerLCDpa
27
+ {
28
+ private:
29
+ uint8_t _transmitPin;
30
+ long _baudRate;
31
+ int _bitPeriod;
32
+ int _geometry;
33
+ void printNumber(unsigned long, uint8_t);
34
+ public:
35
+ SWSerLCDpa(uint8_t, int);
36
+ SWSerLCDpa(uint8_t);
37
+ void begin(long);
38
+ void print(char);
39
+ void print(const char[]);
40
+ void print(uint8_t);
41
+ void print(int);
42
+ void print(unsigned int);
43
+ void print(long);
44
+ void print(unsigned long);
45
+ void print(long, int);
46
+ void println(void);
47
+ void clearscr(void);
48
+ void home(void);
49
+ void setgeo(int);
50
+ void setintensity(int);
51
+ void intoBignum(void);
52
+ void outofBignum(void);
53
+ void setxy(int, int);
54
+ void println(char);
55
+ void println(const char[]);
56
+ void println(uint8_t);
57
+ void println(int);
58
+ void println(long);
59
+ void println(unsigned long);
60
+ void println(long, int);
61
+ };
62
+
63
+ #endif
64
+