atduskgreg-rad 0.2.5 → 0.3.0.1
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 +5 -0
- data/Manifest.txt +4 -2
- data/bin/rad +20 -20
- data/lib/examples/hello_array2.rb +34 -1
- data/lib/rad/arduino_sketch.rb +1 -0
- data/lib/rad/linux_installer.rb +132 -0
- data/{bin → test}/hello_world_test/Makefile +0 -0
- data/{bin → test}/hello_world_test/hello_world.cpp +0 -0
- metadata +6 -7
- data/lib/rad/rad_rewriter.rb +0 -94
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -3,8 +3,6 @@ License.txt
|
|
3
3
|
Manifest.txt
|
4
4
|
README.rdoc
|
5
5
|
Rakefile
|
6
|
-
bin/hello_world_test/Makefile
|
7
|
-
bin/hello_world_test/hello_world.cpp
|
8
6
|
bin/rad
|
9
7
|
lib/examples/add_hysteresis.rb
|
10
8
|
lib/examples/basic_blink.rb
|
@@ -103,10 +101,12 @@ lib/rad.rb
|
|
103
101
|
lib/rad/README.rdoc
|
104
102
|
lib/rad/arduino_plugin.rb
|
105
103
|
lib/rad/arduino_sketch.rb
|
104
|
+
lib/rad/darwin_installer.rb
|
106
105
|
lib/rad/generators/makefile/makefile.erb
|
107
106
|
lib/rad/generators/makefile/makefile.rb
|
108
107
|
lib/rad/hardware_library.rb
|
109
108
|
lib/rad/init.rb
|
109
|
+
lib/rad/linux_installer.rb
|
110
110
|
lib/rad/progressbar.rb
|
111
111
|
lib/rad/rad_processor.rb
|
112
112
|
lib/rad/rad_rewriter.rb
|
@@ -127,6 +127,8 @@ spec/models/sketch_compiler_spec.rb
|
|
127
127
|
spec/models/spec_helper.rb
|
128
128
|
spec/sim/hello_world_spec.rb
|
129
129
|
spec/spec.opts
|
130
|
+
test/hello_world_test/Makefile
|
131
|
+
test/hello_world_test/hello_world.cpp
|
130
132
|
test/test_array_processing.rb
|
131
133
|
test/test_plugin_loading.rb
|
132
134
|
test/test_translation_post_processing.rb
|
data/bin/rad
CHANGED
@@ -14,6 +14,8 @@ require 'readline'
|
|
14
14
|
|
15
15
|
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/version.rb"
|
16
16
|
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/progressbar.rb"
|
17
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/linux_installer.rb"
|
18
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/darwin_installer.rb"
|
17
19
|
|
18
20
|
class OptionParser #:nodoc:
|
19
21
|
|
@@ -94,28 +96,18 @@ end
|
|
94
96
|
|
95
97
|
|
96
98
|
if ARGV[0] == "install"
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
pbar.file_transfer_mode
|
106
|
-
end
|
107
|
-
},
|
108
|
-
:progress_proc => lambda {|s|
|
109
|
-
pbar.set s if pbar
|
110
|
-
}).read
|
111
|
-
pbar.finish
|
99
|
+
|
100
|
+
case RUBY_PLATFORM
|
101
|
+
when /linux/
|
102
|
+
LinuxInstaller.install!
|
103
|
+
when /darwin/
|
104
|
+
DarwinInstaller.install!
|
105
|
+
else
|
106
|
+
raise "Sorry. Can only install Arduino on Mac OS X. See here for Linux instructions: http://www.arduino.cc/playground/Learning/Linux"
|
112
107
|
end
|
113
|
-
|
114
|
-
`cd /Applications; unzip arduino-0012.zip`
|
115
|
-
`rm /Applications/arduino-0012.zip`
|
116
|
-
puts "installed Arduino here: /Applications/arduino-0012"
|
108
|
+
|
117
109
|
elsif ARGV[0] == "test"
|
118
|
-
test_dir = File.expand_path(File.dirname(__FILE__)) + "/../
|
110
|
+
test_dir = File.expand_path(File.dirname(__FILE__)) + "/../test/hello_world_test"
|
119
111
|
puts "Compiling hello_world.cpp to test your Arduino."
|
120
112
|
puts "cd #{test_dir}; make depend; make;"
|
121
113
|
`cd #{test_dir}; make depend; make;`
|
@@ -176,6 +168,14 @@ else
|
|
176
168
|
FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
|
177
169
|
puts "Successfully created your libraries directory."
|
178
170
|
|
171
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/AF_XPort/.", "#{sketch_name}/vendor/libraries/AF_XPort"
|
172
|
+
puts "Installed AF_XPort into #{sketch_name}/vendor/libraries"
|
173
|
+
puts
|
174
|
+
|
175
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/AFSoftSerial/.", "#{sketch_name}/vendor/libraries/AFSoftSerial"
|
176
|
+
puts "Installed AFSoftSerial into #{sketch_name}/vendor/libraries"
|
177
|
+
puts
|
178
|
+
|
179
179
|
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/DS1307/.", "#{sketch_name}/vendor/libraries/DS1307"
|
180
180
|
puts "Installed DS1307 into #{sketch_name}/vendor/libraries"
|
181
181
|
puts
|
@@ -24,7 +24,12 @@ class HelloArray2 < ArduinoSketch
|
|
24
24
|
array "int pizzas[] = {1,2,3,4}"
|
25
25
|
array "byte buffer[20] = {'A', 'B', 'Z', 'C', 'Y', 'D', 'W', 'E', '%', 'H', '*', '!', ')', '=', 'P', '-', '+', 'R', 'I', 'K'}"
|
26
26
|
|
27
|
-
|
27
|
+
## multidimensional arrays
|
28
|
+
array 'int @my_numbers[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}'
|
29
|
+
array 'char* @pizzas[2][4] = {{"margherita","funghi","napoletana","prosciutto cotto"},{"veggie","pepperoni","cheese","kitchen sink"}}'
|
30
|
+
|
31
|
+
|
32
|
+
output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
|
28
33
|
|
29
34
|
|
30
35
|
def setup
|
@@ -56,6 +61,8 @@ class HelloArray2 < ArduinoSketch
|
|
56
61
|
|
57
62
|
delay 3000
|
58
63
|
|
64
|
+
|
65
|
+
|
59
66
|
my_lcd.clearline 1, @names[2]
|
60
67
|
my_lcd.print " [ "
|
61
68
|
my_lcd.print pizzas[1]
|
@@ -63,6 +70,32 @@ class HelloArray2 < ArduinoSketch
|
|
63
70
|
|
64
71
|
delay 2000
|
65
72
|
|
73
|
+
my_lcd.clearscr "Multidimensional ?n"
|
74
|
+
|
75
|
+
0.upto(2) do |f|
|
76
|
+
0.upto(3) do |s|
|
77
|
+
my_lcd.print @my_numbers[f][s]
|
78
|
+
my_lcd.print ", "
|
79
|
+
delay 500
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
delay 1000
|
84
|
+
|
85
|
+
my_lcd.clearscr
|
86
|
+
|
87
|
+
0.upto(1) do |f|
|
88
|
+
0.upto(3) do |s|
|
89
|
+
my_lcd.print @pizzas[f][s]
|
90
|
+
my_lcd.print ", "
|
91
|
+
delay 500
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
delay 2000
|
98
|
+
|
66
99
|
my_lcd.clearscr "Array Load?n"
|
67
100
|
1.upto(20) do |x|
|
68
101
|
# buffer[x] = 64 + x # we cannot set array elements yet except to initialize in declaration
|
data/lib/rad/arduino_sketch.rb
CHANGED
@@ -204,6 +204,7 @@ class ArduinoSketch
|
|
204
204
|
def array(arg)
|
205
205
|
if arg
|
206
206
|
arg = arg.chomp.rstrip.lstrip
|
207
|
+
arg.sub!("@","__")
|
207
208
|
name = arg.scan(/\s*(\w*)\[\d*\]?/).first.first
|
208
209
|
# help rad_processor do a better job with array types
|
209
210
|
types = ["int", "long", "char*", "unsigned int", "unsigned long", "byte", "bool", "float" ]
|
@@ -0,0 +1,132 @@
|
|
1
|
+
class LinuxInstaller
|
2
|
+
|
3
|
+
# this is the thing we actually run to make something happen
|
4
|
+
def self.install!
|
5
|
+
puts "Welcome to the RAD Linux Installer!"
|
6
|
+
puts "-----------------------------------"
|
7
|
+
puts "Let's begin."
|
8
|
+
puts
|
9
|
+
|
10
|
+
check_or_warn_for_usb_driver
|
11
|
+
|
12
|
+
# of course we need rubygems
|
13
|
+
# maybe just rely on the user installing rubygems, because the ubuntu one sux
|
14
|
+
#check_or_install_package("rubygems")
|
15
|
+
#%x{gem update --system}
|
16
|
+
|
17
|
+
# we need java to make this ship float
|
18
|
+
check_or_nag_package("sun-java5-jre")
|
19
|
+
|
20
|
+
# remove a package that interferes with the arduino usb/serial driver
|
21
|
+
check_or_remove_package("brltty")
|
22
|
+
|
23
|
+
# install pre-requisites
|
24
|
+
check_or_install_package("binutils-avr")
|
25
|
+
check_or_install_package("gcc-avr")
|
26
|
+
check_or_install_package("avr-libc")
|
27
|
+
check_or_install_package("unzip")
|
28
|
+
check_or_install_package("wget")
|
29
|
+
|
30
|
+
# remove a probably out of date avrdude
|
31
|
+
check_or_remove_package("avrdude")
|
32
|
+
|
33
|
+
# install pre-requisites for avrdude if we wanted to build from source
|
34
|
+
# nah, it comes with the arduino binary
|
35
|
+
#check_or_install_package("gcc")
|
36
|
+
#check_or_install_package("bison")
|
37
|
+
#check_or_install_package("flex")
|
38
|
+
check_or_install_arduino
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.check_or_install_package(package_name)
|
42
|
+
package = %x{dpkg --get-selections | grep #{package_name}}
|
43
|
+
if package.include?("\tinstall")
|
44
|
+
puts "#{package_name} installed!"
|
45
|
+
else
|
46
|
+
puts "installing #{package_name}..."
|
47
|
+
%x{apt-get install -y #{package_name}}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.check_or_nag_package(package_name, custom_msg = nil)
|
52
|
+
package = %x{dpkg --get-selections | grep #{package_name}}
|
53
|
+
if package.include?("\tinstall")
|
54
|
+
puts "#{package_name} installed!"
|
55
|
+
else
|
56
|
+
puts "you will need to manually install #{package_name}! use the command below."
|
57
|
+
if custom_msg
|
58
|
+
puts custom_msg
|
59
|
+
else
|
60
|
+
puts "sudo apt-get install #{package_name}"
|
61
|
+
end
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.check_or_remove_package(package_name)
|
67
|
+
package = %x{dpkg --get-selections | grep #{package_name}}
|
68
|
+
|
69
|
+
#an easier way to check for installed packages?
|
70
|
+
if package.include?("\tinstall")
|
71
|
+
puts "removing #{package_name}..."
|
72
|
+
%x{apt-get remove -y #{package_name}}
|
73
|
+
else
|
74
|
+
puts "#{package_name} previously uninstalled!"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.check_or_warn_for_usb_driver
|
79
|
+
|
80
|
+
# check if usb device recognized by system
|
81
|
+
puts "Please plug in your arduino to your usb port... [hit enter to continue]"
|
82
|
+
STDIN.gets # we patiently wait
|
83
|
+
|
84
|
+
usb = %x{dmesg | tail | grep "FTDI USB Serial" | grep -c "now attached"}
|
85
|
+
|
86
|
+
if usb.to_i == 0
|
87
|
+
# maybe we can be nice here and offer to download and install the driver package
|
88
|
+
puts "the system is not recognizing your usb-serial driver, please re-install"
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.check_or_install_arduino
|
94
|
+
if File.exist?("/usr/local/arduino-0012")
|
95
|
+
puts "arduino software previously installed at /usr/local/arduino-0012 !"
|
96
|
+
else
|
97
|
+
puts "installing arduino software..."
|
98
|
+
%x{cd /usr/local/; wget http://arduino.cc/files/arduino-0012-linux.tgz}
|
99
|
+
%x{tar -C /usr/local -xzf /usr/local/arduino-0012-linux.tgz}
|
100
|
+
|
101
|
+
%x{ln -s /usr/local/arduino-0012/arduino ~/Desktop/arduino}
|
102
|
+
|
103
|
+
# gotta patch it so it can run from command line or anywhere
|
104
|
+
arduino_file = File.open("/usr/local/arduino-0012/arduino") {|f| f.read}
|
105
|
+
new_doc = arduino_file.split("\n")
|
106
|
+
new_doc[1] = "cd /usr/local/arduino-0012"
|
107
|
+
File.open("/usr/local/arduino-0012/arduino", "w") {|f| f.puts new_doc }
|
108
|
+
|
109
|
+
%x{mkdir -p /usr/local/arduino-0012/hardware/tools/avr/bin}
|
110
|
+
# there is a difference from what the makefile expects to where it is
|
111
|
+
%x{ln -s /usr/bin/avr-gcc /usr/local/arduino-0012/hardware/tools/avr/bin/avr-gcc}
|
112
|
+
%x{ln -s /usr/bin/avr-g++ /usr/local/arduino-0012/hardware/tools/avr/bin/avr-g++}
|
113
|
+
%x{ln -s /usr/bin/avr-ar /usr/local/arduino-0012/hardware/tools/avr/bin/avr-ar}
|
114
|
+
%x{ln -s /usr/bin/avr-objcopy /usr/local/arduino-0012/hardware/tools/avr/bin/avr-objcopy}
|
115
|
+
%x{ln -s /usr/local/arduino-0012/hardware/tools/avrdude /usr/local/arduino-0012/hardware/tools/avr/bin/avrdude}
|
116
|
+
%x{ln -s /usr/local/arduino-0012/hardware/tools/avrdude.conf /usr/local/arduino-0012/hardware/tools/avr/etc/avrdude.conf}
|
117
|
+
|
118
|
+
|
119
|
+
puts
|
120
|
+
puts "************************************************************************"
|
121
|
+
puts "** please add /usr/local/arduino-0012 to your path! **"
|
122
|
+
puts "** you will also need to run sudo update-alternatives --config java **"
|
123
|
+
puts "** to choose java-1.50-sun as the default java **"
|
124
|
+
puts "************************************************************************"
|
125
|
+
puts
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atduskgreg-rad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Borenstein
|
@@ -47,8 +47,8 @@ files:
|
|
47
47
|
- Manifest.txt
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
|
-
-
|
51
|
-
-
|
50
|
+
- test/hello_world_test/Makefile
|
51
|
+
- test/hello_world_test/hello_world.cpp
|
52
52
|
- bin/rad
|
53
53
|
- lib/examples/add_hysteresis.rb
|
54
54
|
- lib/examples/basic_blink.rb
|
@@ -153,7 +153,8 @@ files:
|
|
153
153
|
- lib/rad/init.rb
|
154
154
|
- lib/rad/progressbar.rb
|
155
155
|
- lib/rad/rad_processor.rb
|
156
|
-
- lib/rad/
|
156
|
+
- lib/rad/linux_installer.rb
|
157
|
+
- lib/rad/darwin_installer.rblib/rad/rad_rewriter.rb
|
157
158
|
- lib/rad/rad_type_checker.rb
|
158
159
|
- lib/rad/sim/arduino_sketch.rb
|
159
160
|
- lib/rad/sketch_compiler.rb
|
@@ -184,8 +185,6 @@ files:
|
|
184
185
|
- website/examples/gps_reader.rb.html
|
185
186
|
- website/examples/hello_world.rb.html
|
186
187
|
- website/examples/serial_motor.rb.html
|
187
|
-
- bin/Makefile
|
188
|
-
- bin/hello_world.cpp
|
189
188
|
has_rdoc: true
|
190
189
|
homepage: http://github.com/atduskreg/rad
|
191
190
|
post_install_message:
|
@@ -212,6 +211,6 @@ rubyforge_project: rad
|
|
212
211
|
rubygems_version: 1.2.0
|
213
212
|
signing_key:
|
214
213
|
specification_version: 2
|
215
|
-
summary: "RAD: Ruby Arduino Development - 0.
|
214
|
+
summary: "RAD: Ruby Arduino Development - 0.3.0.2"
|
216
215
|
test_files: []
|
217
216
|
|
data/lib/rad/rad_rewriter.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'ruby_to_ansi_c'
|
2
|
-
|
3
|
-
class RADRewriter < Rewriter
|
4
|
-
|
5
|
-
def process_iter(exp)
|
6
|
-
call = process exp.shift
|
7
|
-
var = process exp.shift
|
8
|
-
body = process exp.shift
|
9
|
-
|
10
|
-
var = s(:dasgn_curr, Unique.next) if var.nil?
|
11
|
-
|
12
|
-
assert_type call, :call
|
13
|
-
|
14
|
-
if call[2] != :each then # TODO: fix call[n] (api)
|
15
|
-
call.shift # :call
|
16
|
-
lhs = call.shift
|
17
|
-
method_name = call.shift
|
18
|
-
|
19
|
-
case method_name
|
20
|
-
when :downto then
|
21
|
-
var.shift #
|
22
|
-
start_value = lhs
|
23
|
-
finish_value = call.pop.pop # not sure about this
|
24
|
-
var_name = var.shift
|
25
|
-
body.find_and_replace_all(:dvar, :lvar)
|
26
|
-
result = s(:dummy,
|
27
|
-
s(:lasgn, var_name, start_value),
|
28
|
-
s(:while,
|
29
|
-
s(:call, s(:lvar, var_name), :>=,
|
30
|
-
s(:arglist, finish_value)),
|
31
|
-
s(:block,
|
32
|
-
body,
|
33
|
-
s(:lasgn, var_name,
|
34
|
-
s(:call, s(:lvar, var_name), :-,
|
35
|
-
s(:arglist, s(:lit, 1))))), true))
|
36
|
-
when :upto then
|
37
|
-
# REFACTOR: completely duped from above and direction changed
|
38
|
-
var.shift #
|
39
|
-
start_value = lhs
|
40
|
-
finish_value = call.pop.pop # not sure about this
|
41
|
-
var_name = var.shift
|
42
|
-
body.find_and_replace_all(:dvar, :lvar)
|
43
|
-
result = s(:dummy,
|
44
|
-
s(:lasgn, var_name, start_value),
|
45
|
-
s(:while,
|
46
|
-
s(:call, s(:lvar, var_name), :<=,
|
47
|
-
s(:arglist, finish_value)),
|
48
|
-
s(:block,
|
49
|
-
body,
|
50
|
-
s(:lasgn, var_name,
|
51
|
-
s(:call, s(:lvar, var_name), :+,
|
52
|
-
s(:arglist, s(:lit, 1))))), true))
|
53
|
-
when :times then
|
54
|
-
# REFACTOR: mostly duped from above and gave default start value of 0
|
55
|
-
# and a finish value that was the start value above
|
56
|
-
var.shift
|
57
|
-
start_value = s(:lit, 0)
|
58
|
-
finish_value = lhs
|
59
|
-
var_name = var.shift
|
60
|
-
body.find_and_replace_all(:dvar, :lvar)
|
61
|
-
result = s(:dummy,
|
62
|
-
s(:lasgn, var_name, start_value),
|
63
|
-
s(:while,
|
64
|
-
s(:call, s(:lvar, var_name), :<,
|
65
|
-
s(:arglist, finish_value)),
|
66
|
-
s(:block,
|
67
|
-
body,
|
68
|
-
s(:lasgn, var_name,
|
69
|
-
s(:call, s(:lvar, var_name), :+,
|
70
|
-
s(:arglist, s(:lit, 1))))), true))
|
71
|
-
when :define_method then
|
72
|
-
# BEFORE: [:iter, [:call, nil, :define_method, [:array, [:lit, :bmethod_added]]], [:dasgn_curr, :x], [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]
|
73
|
-
# we want to get it rewritten for the scope/block context, so:
|
74
|
-
# - throw call away
|
75
|
-
# - rewrite to args
|
76
|
-
# - plop body into a scope
|
77
|
-
# AFTER: [:block, [:args, :x], [:call, [:lvar, :x], :+, [:arglist, [:lit, 1]]]]
|
78
|
-
var.find_and_replace_all(:dasgn_curr, :args)
|
79
|
-
body.find_and_replace_all(:dvar, :lvar)
|
80
|
-
result = s(:block, var, body)
|
81
|
-
else
|
82
|
-
# HACK we butchered call up top
|
83
|
-
result = s(:iter, s(:call, lhs, method_name, call.shift), var, body)
|
84
|
-
end
|
85
|
-
else
|
86
|
-
if var.nil? then
|
87
|
-
var = s(:lvar, Unique.next)
|
88
|
-
end
|
89
|
-
|
90
|
-
s(:iter, call, var, body)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|