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.
- checksums.yaml +7 -0
- data/History.txt +112 -0
- data/License.txt +282 -0
- data/Manifest.txt +144 -0
- data/README.rdoc +1 -0
- data/Rakefile +142 -0
- data/bin/rad +302 -0
- 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 +112 -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/software_serial.rb +10 -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/DS1307/keywords.txt +18 -0
- 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 +296 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
- 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 +628 -0
- data/lib/rad/darwin_installer.rb +23 -0
- data/lib/rad/generators/makefile/makefile.erb +243 -0
- data/lib/rad/generators/makefile/makefile.rb +38 -0
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +15 -0
- data/lib/rad/linux_installer.rb +132 -0
- data/lib/rad/progressbar.rb +236 -0
- 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 +210 -0
- data/lib/rad/tasks/rad.rb +2 -0
- data/lib/rad/todo.txt +13 -0
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +9 -0
- data/lib/rad.rb +5 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/arduino_sketch_spec.rb +82 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/models/spec_helper.rb +2 -0
- data/spec/sim/hello_world_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/test/hello_world_test/Makefile +436 -0
- data/test/hello_world_test/hello_world.cpp +23 -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/examples/assembler_test.rb.html +73 -0
- data/website/examples/gps_reader.rb.html +39 -0
- data/website/examples/hello_world.rb.html +38 -0
- data/website/examples/serial_motor.rb.html +41 -0
- data/website/index.html +178 -0
- data/website/index.txt +64 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +169 -0
- data/website/template.rhtml +48 -0
- metadata +222 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/clean'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
require 'rake/packagetask'
|
|
6
|
+
require 'rake/gempackagetask'
|
|
7
|
+
require 'rake/rdoctask'
|
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
|
9
|
+
require 'fileutils'
|
|
10
|
+
require 'hoe'
|
|
11
|
+
|
|
12
|
+
RAD_ROOT = File.expand_path(File.dirname(__FILE__))
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
require 'spec/rake/spectask'
|
|
16
|
+
rescue LoadError
|
|
17
|
+
puts 'To use rspec for testing you must install rspec gem:'
|
|
18
|
+
puts '$ sudo gem install rspec'
|
|
19
|
+
exit
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
include FileUtils
|
|
23
|
+
require File.join(File.dirname(__FILE__), 'lib', 'rad', 'version')
|
|
24
|
+
|
|
25
|
+
BIN = "rad"
|
|
26
|
+
AUTHOR = 'Greg Borenstein' # can also be an array of Authors
|
|
27
|
+
EMAIL = "greg@mfdz.com"
|
|
28
|
+
DESCRIPTION = "A framework for programming the Arduino physcial computing platform using Ruby. RAD converts Ruby scripts written using a set of Rails-like conventions and helpers into C source code which can be compiled and run on the Arduino microcontroller."
|
|
29
|
+
GEM_NAME = 'rad' # what ppl will type to install your gem
|
|
30
|
+
|
|
31
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
|
32
|
+
@config = nil
|
|
33
|
+
def rubyforge_username
|
|
34
|
+
unless @config
|
|
35
|
+
begin
|
|
36
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
|
37
|
+
rescue
|
|
38
|
+
puts <<-EOS
|
|
39
|
+
ERROR: No rubyforge config file found: #{@config_file}"
|
|
40
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
41
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
|
42
|
+
EOS
|
|
43
|
+
exit
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
@rubyforge_username ||= @config["username"]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
RUBYFORGE_PROJECT = 'rad' # The unix name for your project
|
|
50
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
51
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
52
|
+
|
|
53
|
+
NAME = "rad"
|
|
54
|
+
REV = nil
|
|
55
|
+
# UNCOMMENT IF REQUIRED:
|
|
56
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
|
57
|
+
VERS = Rad::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
58
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
|
|
59
|
+
RDOC_OPTS = ['--quiet', '--title', 'rad documentation',
|
|
60
|
+
"--opname", "index.html",
|
|
61
|
+
"--line-numbers",
|
|
62
|
+
"--main", "README",
|
|
63
|
+
"--inline-source"]
|
|
64
|
+
|
|
65
|
+
class Hoe
|
|
66
|
+
def extra_deps
|
|
67
|
+
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Generate all the Rake tasks
|
|
72
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
73
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
74
|
+
p.author = AUTHOR
|
|
75
|
+
p.description = DESCRIPTION
|
|
76
|
+
p.email = EMAIL
|
|
77
|
+
p.summary = DESCRIPTION
|
|
78
|
+
p.url = HOMEPATH
|
|
79
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
80
|
+
p.test_globs = ["test/**/test_*.rb"]
|
|
81
|
+
p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
|
|
82
|
+
|
|
83
|
+
# == Optional
|
|
84
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
85
|
+
p.extra_deps = [ ['RubyToC', '>= 1.0.0'] ]
|
|
86
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
|
|
90
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
91
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
92
|
+
|
|
93
|
+
desc 'Generate website files'
|
|
94
|
+
task :website_generate do
|
|
95
|
+
Dir['website/**/*.txt'].each do |txt|
|
|
96
|
+
sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
desc 'Upload website files to rubyforge'
|
|
101
|
+
task :website_upload do
|
|
102
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
|
103
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
|
104
|
+
local_dir = 'website'
|
|
105
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
desc 'Generate and upload website files'
|
|
109
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
|
110
|
+
|
|
111
|
+
desc 'Release the website and new gem version'
|
|
112
|
+
task :deploy => [:check_version, :website, :release] do
|
|
113
|
+
puts "Remember to create SVN tag:"
|
|
114
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
|
115
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
|
116
|
+
puts "Suggested comment:"
|
|
117
|
+
puts "Tagging release #{CHANGES}"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
|
121
|
+
task :local_deploy => [:website_generate, :install_gem]
|
|
122
|
+
|
|
123
|
+
task :check_version do
|
|
124
|
+
unless ENV['VERSION']
|
|
125
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
|
126
|
+
exit
|
|
127
|
+
end
|
|
128
|
+
unless ENV['VERSION'] == VERS
|
|
129
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
|
130
|
+
exit
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
desc "Run the specs under spec/models"
|
|
135
|
+
Spec::Rake::SpecTask.new do |t|
|
|
136
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
137
|
+
t.spec_files = FileList['spec/models/*_spec.rb']
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
desc "Default task is to run specs"
|
|
141
|
+
task :default => :spec
|
|
142
|
+
|
data/bin/rad
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
require 'open-uri'
|
|
13
|
+
require 'readline'
|
|
14
|
+
|
|
15
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/version.rb"
|
|
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"
|
|
19
|
+
|
|
20
|
+
class OptionParser #:nodoc:
|
|
21
|
+
|
|
22
|
+
def self.parse(args)
|
|
23
|
+
# defaults
|
|
24
|
+
|
|
25
|
+
options = {"hardware" => {
|
|
26
|
+
"serial_port" => '/dev/tty.usbserial*',
|
|
27
|
+
"mcu" => "atmega168",
|
|
28
|
+
"physical_reset" => false
|
|
29
|
+
},
|
|
30
|
+
"software" => {
|
|
31
|
+
"arduino_root" => "/Applications/arduino-0012"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
opts = OptionParser.new do |opts|
|
|
36
|
+
|
|
37
|
+
opts.banner = <<-BANNER
|
|
38
|
+
Build a directory for your RAD Project and install RAD in its vendor sub-directory.
|
|
39
|
+
|
|
40
|
+
Usage: #{File.basename($0)} <sketch_dir_name> <options for config>
|
|
41
|
+
BANNER
|
|
42
|
+
|
|
43
|
+
opts.on("-p", "--port [SERIAL PORT]",
|
|
44
|
+
"Path to your serial port",
|
|
45
|
+
" (default: #{options['hardware']['serial_port']})") do |port|
|
|
46
|
+
|
|
47
|
+
options["hardware"]["serial_port"] = port if port
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
opts.on("-m", "--mcu [PROCESSOR TYPE]",
|
|
51
|
+
"Type of processor on your board",
|
|
52
|
+
" (default: #{options['hardware']['mcu']})") do |port|
|
|
53
|
+
|
|
54
|
+
options["hardware"]["serial_port"] = port if port
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
opts.on("-r", "--reset [RESET REQUIRED]",
|
|
58
|
+
"Require a hardware reset before uploading?",
|
|
59
|
+
" (default: #{options['hardware']['physical_reset']})") do |no_reset|
|
|
60
|
+
options["hardware"]["physical_reset"] = true unless no_reset
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
opts.on("-a", "--arduino [ARDUINO DIR]",
|
|
64
|
+
"Path to your Arduino install",
|
|
65
|
+
" (default: #{options['software']['arduino_root']})") do |arduino|
|
|
66
|
+
options["software"]["arduino_root"] = arduino if arduino
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
opts.on("-v", "--version [VERSION]",
|
|
70
|
+
"RAD version number",
|
|
71
|
+
" (#{Rad::VERSION::STRING})") do
|
|
72
|
+
puts Rad::VERSION::STRING
|
|
73
|
+
exit
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
|
77
|
+
puts opts
|
|
78
|
+
exit
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
opts.parse!(args)
|
|
83
|
+
[options, opts]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# home = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
|
|
90
|
+
# begin
|
|
91
|
+
# config = YAML::load open(home + "/.rad")
|
|
92
|
+
# rescue
|
|
93
|
+
# config = false
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if ARGV[0] == "install"
|
|
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"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
elsif ARGV[0] == "test"
|
|
110
|
+
test_dir = File.expand_path(File.dirname(__FILE__)) + "/../test/hello_world_test"
|
|
111
|
+
puts "Compiling hello_world.cpp to test your Arduino."
|
|
112
|
+
puts "cd #{test_dir}; make depend; make;"
|
|
113
|
+
`cd #{test_dir}; make depend; make;`
|
|
114
|
+
puts
|
|
115
|
+
puts "Compilation successful."
|
|
116
|
+
puts
|
|
117
|
+
puts "Make sure your Arduino is connected and then hit return."
|
|
118
|
+
Readline::readline('')
|
|
119
|
+
|
|
120
|
+
`cd #{test_dir}; make upload`
|
|
121
|
+
|
|
122
|
+
# find the USB port to make sure the Arduino's actually plugged in
|
|
123
|
+
options, parser = OptionParser.parse(ARGV)
|
|
124
|
+
usb_port = options["hardware"]["serial_port"]
|
|
125
|
+
port_name = usb_port.split("/").last
|
|
126
|
+
port_dir = usb_port.split("/")[0..(usb_port.split("/").length-2)].join("/")
|
|
127
|
+
unless `ls #{port_dir}`.split(/\n/).any?{|d| d.match(/#{port_name}/)}
|
|
128
|
+
puts
|
|
129
|
+
puts "******************************************************"
|
|
130
|
+
puts "*** It looks like your Arduino is not plugged in. ***"
|
|
131
|
+
puts "*** Plug it in and try again. ***"
|
|
132
|
+
puts "*** ***"
|
|
133
|
+
puts "*** NOTE: If your usb port is not /dev/tty.usb* ***"
|
|
134
|
+
puts "*** pass it in to this script with the -p option. ***"
|
|
135
|
+
puts "******************************************************"
|
|
136
|
+
else
|
|
137
|
+
puts
|
|
138
|
+
puts "******************************************************"
|
|
139
|
+
puts "*** Success! ***"
|
|
140
|
+
puts "*** If your Arduino's light starts blinking soon, ***"
|
|
141
|
+
puts "*** then your Arduino environment is ***"
|
|
142
|
+
puts "*** correctly configured. ***"
|
|
143
|
+
puts "*** ***"
|
|
144
|
+
puts "*** Otherwise something is not hooked up properly. ***"
|
|
145
|
+
puts "******************************************************"
|
|
146
|
+
end
|
|
147
|
+
puts
|
|
148
|
+
puts "cleaning up..."
|
|
149
|
+
`rm #{test_dir}/hello_world.hex #{test_dir}/core.a #{test_dir}/hello_world.elf`
|
|
150
|
+
else
|
|
151
|
+
# Handle options:
|
|
152
|
+
options, parser = OptionParser.parse(ARGV)
|
|
153
|
+
sketch_name = ARGV[0]
|
|
154
|
+
parser.parse!(["-h"]) unless sketch_name
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# Build vendor/rad:
|
|
158
|
+
|
|
159
|
+
FileUtils.mkdir_p "#{sketch_name}/vendor/rad"
|
|
160
|
+
puts "Successfully created your sketch directory."
|
|
161
|
+
|
|
162
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/rad/.", "#{sketch_name}/vendor/rad"
|
|
163
|
+
puts "Installed RAD into #{sketch_name}/vendor/rad"
|
|
164
|
+
puts
|
|
165
|
+
|
|
166
|
+
# Build vendor/libraries:
|
|
167
|
+
|
|
168
|
+
FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
|
|
169
|
+
puts "Successfully created your libraries directory."
|
|
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
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/DS1307/.", "#{sketch_name}/vendor/libraries/DS1307"
|
|
180
|
+
puts "Installed DS1307 into #{sketch_name}/vendor/libraries"
|
|
181
|
+
puts
|
|
182
|
+
|
|
183
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/FrequencyTimer2/.", "#{sketch_name}/vendor/libraries/FrequencyTimer2"
|
|
184
|
+
puts "Installed FrequencyTimer2 into #{sketch_name}/vendor/libraries"
|
|
185
|
+
puts
|
|
186
|
+
|
|
187
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/I2CEEPROM/.", "#{sketch_name}/vendor/libraries/I2CEEPROM"
|
|
188
|
+
puts "Installed I2CEEPROM into #{sketch_name}/vendor/libraries"
|
|
189
|
+
puts
|
|
190
|
+
|
|
191
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/LoopTimer/.", "#{sketch_name}/vendor/libraries/LoopTimer"
|
|
192
|
+
puts "Installed LoopTimer into #{sketch_name}/vendor/libraries"
|
|
193
|
+
puts
|
|
194
|
+
|
|
195
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/OneWire/.", "#{sketch_name}/vendor/libraries/OneWire"
|
|
196
|
+
puts "Installed OneWire into #{sketch_name}/vendor/libraries"
|
|
197
|
+
puts
|
|
198
|
+
|
|
199
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Servo/.", "#{sketch_name}/vendor/libraries/Servo"
|
|
200
|
+
puts "Installed Servo into #{sketch_name}/vendor/libraries"
|
|
201
|
+
puts
|
|
202
|
+
|
|
203
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Stepper/.", "#{sketch_name}/vendor/libraries/Stepper"
|
|
204
|
+
puts "Installed Stepper into #{sketch_name}/vendor/libraries"
|
|
205
|
+
puts
|
|
206
|
+
|
|
207
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDpa/.", "#{sketch_name}/vendor/libraries/SWSerLCDpa"
|
|
208
|
+
puts "Installed SWSerLCDpa into #{sketch_name}/vendor/libraries"
|
|
209
|
+
puts
|
|
210
|
+
|
|
211
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDsf/.", "#{sketch_name}/vendor/libraries/SWSerLCDsf"
|
|
212
|
+
puts "Installed SWSerLCDsf into #{sketch_name}/vendor/libraries"
|
|
213
|
+
puts
|
|
214
|
+
|
|
215
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Wire/.", "#{sketch_name}/vendor/libraries/Wire"
|
|
216
|
+
puts "Installed Wire into #{sketch_name}/vendor/libraries"
|
|
217
|
+
puts
|
|
218
|
+
|
|
219
|
+
# Build examples -- used for basic testing
|
|
220
|
+
|
|
221
|
+
FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
|
|
222
|
+
puts "Successfully created your examples directory."
|
|
223
|
+
|
|
224
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/examples/.", "#{sketch_name}/examples"
|
|
225
|
+
puts "Installed examples into #{sketch_name}/examples"
|
|
226
|
+
puts
|
|
227
|
+
|
|
228
|
+
# Build test -- used testing
|
|
229
|
+
|
|
230
|
+
# FIXME: this should put the tests into the vendor/tests directory instead.
|
|
231
|
+
|
|
232
|
+
# FileUtils.mkdir_p "#{sketch_name}/test"
|
|
233
|
+
# puts "Successfully created your test directory."
|
|
234
|
+
#
|
|
235
|
+
# FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/test/.", "#{sketch_name}/test"
|
|
236
|
+
# puts "Installed tests into #{sketch_name}/test"
|
|
237
|
+
# puts
|
|
238
|
+
|
|
239
|
+
# Build vendor/plugins:
|
|
240
|
+
|
|
241
|
+
FileUtils.mkdir_p "#{sketch_name}/vendor/plugins"
|
|
242
|
+
puts "Successfully created your plugins directory."
|
|
243
|
+
|
|
244
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/plugins/.", "#{sketch_name}/vendor/plugins"
|
|
245
|
+
puts "Installed Default plugins into #{sketch_name}/vendor/plugins"
|
|
246
|
+
puts
|
|
247
|
+
|
|
248
|
+
# Add an default sketch directory # needed to run test:compile
|
|
249
|
+
|
|
250
|
+
FileUtils.mkdir_p "#{sketch_name}/#{sketch_name}"
|
|
251
|
+
puts "Successfully created your default sketch directory."
|
|
252
|
+
|
|
253
|
+
# Build sketch files, etc.:
|
|
254
|
+
|
|
255
|
+
FileUtils.touch "#{sketch_name}/#{sketch_name}.rb"
|
|
256
|
+
File.open("#{sketch_name}/#{sketch_name}.rb", "w") do |file|
|
|
257
|
+
file << <<-EOS
|
|
258
|
+
class #{sketch_name.split("_").collect{|c| c.capitalize}.join("")} < ArduinoSketch
|
|
259
|
+
|
|
260
|
+
# looking for hints? check out the examples directory
|
|
261
|
+
# example sketches can be uploaded to your arduino with
|
|
262
|
+
# rake make:upload sketch=examples/hello_world
|
|
263
|
+
# just replace hello_world with other examples
|
|
264
|
+
|
|
265
|
+
def loop
|
|
266
|
+
# your code here
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
end
|
|
270
|
+
EOS
|
|
271
|
+
end
|
|
272
|
+
puts "Added #{sketch_name}/#{sketch_name}.rb"
|
|
273
|
+
|
|
274
|
+
File.open("#{sketch_name}/Rakefile", 'w') do |file|
|
|
275
|
+
file << <<-EOS
|
|
276
|
+
require 'vendor/rad/init.rb'
|
|
277
|
+
EOS
|
|
278
|
+
end
|
|
279
|
+
puts "Added #{sketch_name}/Rakefile"
|
|
280
|
+
|
|
281
|
+
FileUtils.mkdir_p "#{sketch_name}/config"
|
|
282
|
+
puts "Added #{sketch_name}/config"
|
|
283
|
+
|
|
284
|
+
File.open("#{sketch_name}/config/hardware.yml", 'w') do |file|
|
|
285
|
+
file << options["hardware"].to_yaml
|
|
286
|
+
end
|
|
287
|
+
puts "Added #{sketch_name}/config/hardware.yml"
|
|
288
|
+
|
|
289
|
+
File.open("#{sketch_name}/config/software.yml", 'w') do |file|
|
|
290
|
+
file << options["software"].to_yaml
|
|
291
|
+
end
|
|
292
|
+
puts "Added #{sketch_name}/config/software.yml"
|
|
293
|
+
|
|
294
|
+
puts
|
|
295
|
+
puts "Run 'rake -T' inside your sketch dir to learn how to compile and upload it."
|
|
296
|
+
|
|
297
|
+
puts "***************************************************"
|
|
298
|
+
puts "*** Please note: This version supports ***"
|
|
299
|
+
puts "*** Arduino 12 only! ***"
|
|
300
|
+
puts "*** run rad install arduino to upgrade ***"
|
|
301
|
+
puts "***************************************************"
|
|
302
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
class BlinkMAddressAssignment < ArduinoSketch
|
|
2
|
+
|
|
3
|
+
# want to use more than one blink m?
|
|
4
|
+
# since each blink m arrives with the same address,
|
|
5
|
+
# we can't address each one individually
|
|
6
|
+
#
|
|
7
|
+
# so the first thing we need to do is give each one a new address
|
|
8
|
+
# that's the purpose of this sketch
|
|
9
|
+
#
|
|
10
|
+
# install one blinkm at a time
|
|
11
|
+
# a pa_lcd screen makes this easier
|
|
12
|
+
# the screen will start at address ten and increment approximately every
|
|
13
|
+
# four seconds. Pressing during the first four seconds sets the blnikm
|
|
14
|
+
# address to 10, during the next four seconds to 11 and so on
|
|
15
|
+
# difficult without a screen.
|
|
16
|
+
# if you need to, program an led to help with the timing
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@blink_m_start_address = 10
|
|
20
|
+
@flag = false
|
|
21
|
+
@addr1 = "10, byte"
|
|
22
|
+
@addr2 = "11, byte"
|
|
23
|
+
@addr3 = "12, byte"
|
|
24
|
+
|
|
25
|
+
output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
|
|
26
|
+
input_pin 7, :as => :button_one, :device => :button
|
|
27
|
+
input_pin 8, :as => :button_two, :device => :button
|
|
28
|
+
input_pin 9, :as => :button_three, :device => :button
|
|
29
|
+
|
|
30
|
+
output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
|
|
31
|
+
|
|
32
|
+
def setup
|
|
33
|
+
delay 1000
|
|
34
|
+
my_lcd.setxy 0,0, "bienvenue"
|
|
35
|
+
delay 5000
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def loop
|
|
39
|
+
|
|
40
|
+
if @flag == false
|
|
41
|
+
staging
|
|
42
|
+
else
|
|
43
|
+
test_address
|
|
44
|
+
end
|
|
45
|
+
delay 100
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def staging
|
|
49
|
+
my_lcd.setxy 0,0, "press button one to"
|
|
50
|
+
my_lcd.setxy 0,1, "set address to "
|
|
51
|
+
my_lcd.print @blink_m_start_address
|
|
52
|
+
my_lcd.setxy 0,2, "or two for status"
|
|
53
|
+
delay 60
|
|
54
|
+
my_lcd.setxy 0,3, " "
|
|
55
|
+
my_lcd.setxy 0,3
|
|
56
|
+
800.times do |i|
|
|
57
|
+
return 0 if @flag == true
|
|
58
|
+
my_lcd.print "." if i % 50 == 0
|
|
59
|
+
delay 5
|
|
60
|
+
if button_one.read_input
|
|
61
|
+
assign_address
|
|
62
|
+
elsif button_two.read_input
|
|
63
|
+
test_address
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
@blink_m_start_address += 1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def assign_address
|
|
70
|
+
@flag = true
|
|
71
|
+
my_lcd.clearscr "setting to "
|
|
72
|
+
my_lcd.print @blink_m_start_address
|
|
73
|
+
delay 100
|
|
74
|
+
BlinkM_setAddress @blink_m_start_address
|
|
75
|
+
my_lcd.clearscr "done"
|
|
76
|
+
control_it
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def control_it
|
|
80
|
+
delay 500
|
|
81
|
+
my_lcd.clearscr "stopping script"
|
|
82
|
+
BlinkM_stopScript @blink_m_start_address
|
|
83
|
+
my_lcd.clearscr "stopping script.."
|
|
84
|
+
delay 500
|
|
85
|
+
my_lcd.clearscr "fade to purple.."
|
|
86
|
+
BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
|
|
87
|
+
my_lcd.clearscr "fade to purple"
|
|
88
|
+
delay 500
|
|
89
|
+
BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_address
|
|
94
|
+
my_lcd.clearscr
|
|
95
|
+
my_lcd.setxy 0,0, "testing address"
|
|
96
|
+
my_lcd.setxy 0,1
|
|
97
|
+
my_lcd.print blink_m_check_address_message @blink_m_start_address
|
|
98
|
+
delay 5000
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class BlinkMMulti < ArduinoSketch
|
|
2
|
+
|
|
3
|
+
# demonstrate control of individual blinkms
|
|
4
|
+
# this assumes the leds have been assigned addresses 10, 11, 12
|
|
5
|
+
# which can be done with blink m address assignment
|
|
6
|
+
|
|
7
|
+
# two ways to address the blinkms, array and individual variables
|
|
8
|
+
@blink_addresses = [10,11,12]
|
|
9
|
+
@addr_all = "0, byte"
|
|
10
|
+
@addr1 = "10, byte"
|
|
11
|
+
@addr2 = "11, byte"
|
|
12
|
+
@addr3 = "12, byte"
|
|
13
|
+
|
|
14
|
+
output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
|
|
15
|
+
input_pin 7, :as => :button_one, :device => :button
|
|
16
|
+
input_pin 8, :as => :button_two, :device => :button
|
|
17
|
+
input_pin 9, :as => :button_three, :device => :button
|
|
18
|
+
input_pin 10, :as => :button_four, :device => :button
|
|
19
|
+
|
|
20
|
+
# display the action on a 4x20 pa_lcd, yours may be 9200 instead of 19,200
|
|
21
|
+
|
|
22
|
+
output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def loop
|
|
26
|
+
stop_and_fade(@addr1) if button_one.read_input
|
|
27
|
+
stop_and_fade(@addr2) if button_two.read_input
|
|
28
|
+
stop_and_fade(@addr3) if button_three.read_input
|
|
29
|
+
dance if button_four.read_input
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def stop_and_fade(addr)
|
|
33
|
+
f = 1 + addr # hack to coerce addr to int
|
|
34
|
+
my_lcd.clearscr
|
|
35
|
+
my_lcd.setxy 0,0, "blinkm # "
|
|
36
|
+
my_lcd.print addr
|
|
37
|
+
delay 700
|
|
38
|
+
BlinkM_stopScript addr
|
|
39
|
+
my_lcd.setxy 0,1, "stopping script.."
|
|
40
|
+
delay 700
|
|
41
|
+
my_lcd.setxy 0,2, "fade to purple.."
|
|
42
|
+
BlinkM_fadeToRGB(addr, 0xff,0x00,0xff)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def dance
|
|
46
|
+
BlinkM_setFadeSpeed(@addr_all, 20) # 1-255, with 1 producing the slowest fade
|
|
47
|
+
my_lcd.clearscr
|
|
48
|
+
my_lcd.setxy 0,0, "Do the shimmy.."
|
|
49
|
+
my_lcd.setxy 0,1
|
|
50
|
+
@blink_addresses.each do |a|
|
|
51
|
+
BlinkM_fadeToRGB(a, 1,166,138)
|
|
52
|
+
delay 100
|
|
53
|
+
end
|
|
54
|
+
@blink_addresses.each do |a|
|
|
55
|
+
BlinkM_fadeToRGB(a, 35,0,112)
|
|
56
|
+
delay 100
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
end
|