madrona-rad 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ bin/.DS_Store
3
+ lib/.DS_Store
4
+ lib/libraries/.DS_Store
5
+ lib/rad/.DS_Store
data/Rakefile CHANGED
@@ -1,145 +1,54 @@
1
1
  require 'rubygems'
2
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
- $: << "../lib/" # HACK while I work out r2c/rad incompatibilities
13
- # gem "RubyToC" # HACK to deal with rubygems beta version activation bug
14
-
15
- RAD_ROOT = File.expand_path(File.dirname(__FILE__))
16
3
 
17
4
  begin
18
- require 'spec/rake/spectask'
19
- rescue LoadError
20
- puts 'To use rspec for testing you must install rspec gem:'
21
- puts '$ sudo gem install rspec'
22
- exit
23
- end
24
-
25
- include FileUtils
26
- require File.join(File.dirname(__FILE__), 'lib', 'rad', 'version')
27
-
28
- BIN = "rad"
29
- AUTHOR = 'Greg Borenstein' # can also be an array of Authors
30
- EMAIL = "greg@mfdz.com"
31
- 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."
32
- GEM_NAME = 'rad' # what ppl will type to install your gem
33
-
34
- @config_file = "~/.rubyforge/user-config.yml"
35
- @config = nil
36
- def rubyforge_username
37
- unless @config
38
- begin
39
- @config = YAML.load(File.read(File.expand_path(@config_file)))
40
- rescue
41
- puts <<-EOS
42
- ERROR: No rubyforge config file found: #{@config_file}"
43
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
44
- - See http://newgem.rubyforge.org/rubyforge.html for more details
45
- EOS
46
- exit
47
- end
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "madrona-rad"
8
+ gem.summary = %Q{RAD: Ruby Arduino Development - 0.4.1 -- 1.9 Ready!}
9
+ gem.description = %Q{Ruby Arduino Development: a framework for programming the Arduino physcial computing platform using Ruby}
10
+ gem.email = "jd@jdbarnhart.com"
11
+ gem.homepage = "http://github.com/madrona/madrona-rad"
12
+ gem.authors = ["JD Barnhart", "Greg Borenstein"]
13
+ gem.add_dependency "ruby2c", ">= 1.0.0.7"
14
+ gem.add_dependency "sexp_processor", ">=3.0.2"
15
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
48
17
  end
49
- @rubyforge_username ||= @config["username"]
50
- end
51
-
52
- RUBYFORGE_PROJECT = 'rad' # The unix name for your project
53
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
54
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
55
-
56
- NAME = "rad"
57
- REV = nil
58
- # UNCOMMENT IF REQUIRED:
59
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
60
- VERS = Rad::VERSION::STRING + (REV ? ".#{REV}" : "")
61
- CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
62
- RDOC_OPTS = ['--quiet', '--title', 'rad documentation',
63
- "--opname", "index.html",
64
- "--line-numbers",
65
- "--main", "README",
66
- "--inline-source"]
67
-
68
- class Hoe
69
- def extra_deps
70
- @extra_deps.reject { |x| Array(x).first == 'hoe' }
71
- end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
72
20
  end
73
21
 
74
- # Generate all the Rake tasks
75
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
76
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
77
- p.author = AUTHOR
78
- p.description = DESCRIPTION
79
- p.email = EMAIL
80
- p.summary = DESCRIPTION
81
- p.url = HOMEPATH
82
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
83
- p.test_globs = ["test/**/test_*.rb"]
84
- p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
85
-
86
- # == Optional
87
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
88
- p.extra_deps = [ ['ruby2c', '>= 1.0.0.6'] ]
89
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
90
27
  end
91
28
 
92
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
93
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
94
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
95
-
96
- desc 'Generate website files'
97
- task :website_generate do
98
- Dir['website/**/*.txt'].each do |txt|
99
- sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
100
39
  end
101
40
  end
102
41
 
103
- desc 'Upload website files to rubyforge'
104
- task :website_upload do
105
- host = "#{rubyforge_username}@rubyforge.org"
106
- remote_dir = "/var/www/gforge-projects/#{PATH}/"
107
- local_dir = 'website'
108
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
109
- end
110
-
111
- desc 'Generate and upload website files'
112
- task :website => [:website_generate, :website_upload, :publish_docs]
113
-
114
- desc 'Release the website and new gem version'
115
- task :deploy => [:check_version, :website, :release] do
116
- puts "Remember to create SVN tag:"
117
- puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
118
- "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
119
- puts "Suggested comment:"
120
- puts "Tagging release #{CHANGES}"
121
- end
42
+ task :test => :check_dependencies
122
43
 
123
- desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
124
- task :local_deploy => [:website_generate, :install_gem]
44
+ task :default => :test
125
45
 
126
- task :check_version do
127
- unless ENV['VERSION']
128
- puts 'Must pass a VERSION=x.y.z release version'
129
- exit
130
- end
131
- unless ENV['VERSION'] == VERS
132
- puts "Please update your version.rb to match the release version, currently #{VERS}"
133
- exit
134
- end
135
- end
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
136
49
 
137
- desc "Run the specs under spec/models"
138
- Spec::Rake::SpecTask.new do |t|
139
- t.spec_opts = ['--options', "spec/spec.opts"]
140
- t.spec_files = FileList['spec/models/*_spec.rb']
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "madrona-rad #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
141
54
  end
142
-
143
- desc "Default task is to run specs"
144
- task :default => :spec
145
-
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.1
File without changes
@@ -1,13 +1,5 @@
1
1
  class BlinkMAddressAssignment < ArduinoSketch
2
2
 
3
- # IMPORTANT -- This is one for four examples that fails with Ruby 1.9 support (latest ruby2c and parsetree)
4
- # the failing example is commented out and replaced with this hello world until I have a chance to resolve the issue -- jd
5
- output_pin 13, :as => :led
6
-
7
- def loop
8
- blink led, 100
9
- x = 4
10
- end
11
3
  # want to use more than one blink m?
12
4
  # since each blink m arrives with the same address,
13
5
  # we can't address each one individually
@@ -22,91 +14,91 @@ class BlinkMAddressAssignment < ArduinoSketch
22
14
  # address to 10, during the next four seconds to 11 and so on
23
15
  # difficult without a screen.
24
16
  # if you need to, program an led to help with the timing
25
-
17
+
26
18
 
27
- # @blink_m_start_address = 10
28
- # @flag = false
29
- # @addr1 = "10, byte"
30
- # @addr2 = "11, byte"
31
- # @addr3 = "12, byte"
32
- #
33
- # output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
34
- # input_pin 7, :as => :button_one, :device => :button
35
- # input_pin 8, :as => :button_two, :device => :button
36
- # input_pin 9, :as => :button_three, :device => :button
37
- #
38
- # output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
39
- #
40
- # def setup
41
- # delay 1000
42
- # my_lcd.setxy 0,0, "bienvenue"
43
- # delay 5000
44
- # end
45
- #
46
- # def loop
47
- #
48
- # if @flag == false
49
- # staging
50
- # else
51
- # test_address
52
- # end
53
- # delay 100
54
- # end
55
- #
56
- # def staging
57
- # my_lcd.setxy 0,0, "press button one to"
58
- # my_lcd.setxy 0,1, "set address to "
59
- # my_lcd.print @blink_m_start_address
60
- # my_lcd.setxy 0,2, "or two for status"
61
- # delay 60
62
- # my_lcd.setxy 0,3, " "
63
- # my_lcd.setxy 0,3
64
- # 800.times do |i|
65
- # return 0 if @flag == true
66
- # my_lcd.print "." if i % 50 == 0
67
- # delay 5
68
- # if button_one.read_input
69
- # assign_address
70
- # elsif button_two.read_input
71
- # test_address
72
- # end
73
- # end
74
- # @blink_m_start_address += 1
75
- # end
76
- #
77
- # def assign_address
78
- # @flag = true
79
- # my_lcd.clearscr "setting to "
80
- # my_lcd.print @blink_m_start_address
81
- # delay 100
82
- # BlinkM_setAddress @blink_m_start_address
83
- # my_lcd.clearscr "done"
84
- # control_it
85
- # end
86
- #
87
- # def control_it
88
- # delay 500
89
- # my_lcd.clearscr "stopping script"
90
- # BlinkM_stopScript @blink_m_start_address
91
- # my_lcd.clearscr "stopping script.."
92
- # delay 500
93
- # my_lcd.clearscr "fade to purple.."
94
- # BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
95
- # my_lcd.clearscr "fade to purple"
96
- # delay 500
97
- # BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
98
- # end
99
- #
100
- #
101
- # def test_address
102
- # my_lcd.clearscr
103
- # my_lcd.setxy 0,0, "testing address"
104
- # my_lcd.setxy 0,1
105
- # my_lcd.print blink_m_check_address_message @blink_m_start_address
106
- # delay 5000
107
- # end
108
- #
109
- #
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
+
110
102
 
111
103
 
112
104
  end
@@ -1,70 +1,61 @@
1
1
  class BlinkMMulti < ArduinoSketch
2
2
 
3
- # IMPORTANT -- This is one for four examples that fails with Ruby 1.9 support (latest ruby2c and parsetree)
4
- # the failing example is commented out and replaced with this hello world until I have a chance to resolve the issue -- jd
5
- output_pin 13, :as => :led
6
-
7
- def loop
8
- blink led, 100
9
- x = 4
10
- end
11
-
12
3
  # demonstrate control of individual blinkms
13
4
  # this assumes the leds have been assigned addresses 10, 11, 12
14
5
  # which can be done with blink m address assignment
15
6
 
16
7
  # two ways to address the blinkms, array and individual variables
17
- # @blink_addresses = [10,11,12]
18
- # @addr_all = "0, byte"
19
- # @addr1 = "10, byte"
20
- # @addr2 = "11, byte"
21
- # @addr3 = "12, byte"
22
- #
23
- # output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
24
- # input_pin 7, :as => :button_one, :device => :button
25
- # input_pin 8, :as => :button_two, :device => :button
26
- # input_pin 9, :as => :button_three, :device => :button
27
- # input_pin 10, :as => :button_four, :device => :button
28
- #
29
- # # display the action on a 4x20 pa_lcd, yours may be 9200 instead of 19,200
30
- #
31
- # output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
32
- #
33
- #
34
- # def loop
35
- # stop_and_fade(@addr1) if button_one.read_input
36
- # stop_and_fade(@addr2) if button_two.read_input
37
- # stop_and_fade(@addr3) if button_three.read_input
38
- # dance if button_four.read_input
39
- # end
40
- #
41
- # def stop_and_fade(addr)
42
- # f = 1 + addr # hack to coerce addr to int
43
- # my_lcd.clearscr
44
- # my_lcd.setxy 0,0, "blinkm # "
45
- # my_lcd.print addr
46
- # delay 700
47
- # BlinkM_stopScript addr
48
- # my_lcd.setxy 0,1, "stopping script.."
49
- # delay 700
50
- # my_lcd.setxy 0,2, "fade to purple.."
51
- # BlinkM_fadeToRGB(addr, 0xff,0x00,0xff)
52
- # end
53
- #
54
- # def dance
55
- # BlinkM_setFadeSpeed(@addr_all, 20) # 1-255, with 1 producing the slowest fade
56
- # my_lcd.clearscr
57
- # my_lcd.setxy 0,0, "Do the shimmy.."
58
- # my_lcd.setxy 0,1
59
- # @blink_addresses.each do |a|
60
- # BlinkM_fadeToRGB(a, 1,166,138)
61
- # delay 100
62
- # end
63
- # @blink_addresses.each do |a|
64
- # BlinkM_fadeToRGB(a, 35,0,112)
65
- # delay 100
66
- # end
67
- # end
68
-
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
+
69
60
 
70
61
  end