BBB 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d18e3e61eefcd87ec52cd8b251cd6799597573cd
4
- data.tar.gz: 4c282e7e33f04bc98aad8f2d0f4c41ad46208add
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDlkMDA1NjQxOGMzYzBmYThhMjA3NjU5MGZhOWE3MzM4YmIwYmI0Ng==
5
+ data.tar.gz: !binary |-
6
+ N2E0ZjE1MjYxMWMzMzAwODdkMGQyOTBlMGFiZmNkZTBmMDc5NmU2Mw==
5
7
  SHA512:
6
- metadata.gz: 87f7819d093f819abcb8bf98e4aab0561cb29716887b49fb3b507b18b00586689f9a158cd097e9f27402fcd8cd56208034a444dd130e307e1c176e95ab149098
7
- data.tar.gz: 22c811e2ed74ce86a22e3ddbb4e609f2d998e88a846f0e9ee735787ce38ae77b2531564896744cc034465bac9d0e36ae88093a047682aaa18a834b6d2adf7650
8
+ metadata.gz: !binary |-
9
+ YWIzODNmZGU0NzlkOWUxOWMyNWE3YjhkZTYxYjhlYjkyNjE5ZDliNjRmZmI1
10
+ OWFmY2YxODI1ODM2MGE2NzIyYjgzN2ViNTk4ODdlOWNjOTgyM2M1MzM1MzYz
11
+ ZDBkZDdhMDkwMjhmMjc1ODMxMmFlM2RiN2FhMTE4MmFhMWQ1NDc=
12
+ data.tar.gz: !binary |-
13
+ NmY4ZmJjNzkzOTlhNDY0MmZjNDBiMDM5M2NjNzY3YmFiZTA4ZWFiODg3N2Rj
14
+ ODMyZThmYjYxYjU3ODBiNTFiMzRhMGQ4NTgxYTQ5YjRhMjhmOGIyZjNmOGVl
15
+ N2NmZTI4MTdjNzVjYTMxYjZhOGM3OWM3YWM1MjFhNzNjYjc0MGM=
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ gem 'coveralls', require: false
6
6
 
7
7
  group :test do
8
8
  gem 'pry'
9
- gem 'rubysl', :platform => :rbx
10
- gem 'racc', :platform => :rbx
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
11
  end
data/Guardfile ADDED
@@ -0,0 +1,46 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
25
+
26
+ guard :rspec do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch('spec/spec_helper.rb') { "spec" }
30
+
31
+ # Rails example
32
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
+ watch('config/routes.rb') { "spec/routing" }
37
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
+
39
+ # Capybara features specs
40
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
41
+
42
+ # Turnip features and steps
43
+ watch(%r{^spec/acceptance/(.+)\.feature$})
44
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
45
+ end
46
+
@@ -20,30 +20,16 @@
20
20
  #
21
21
  require 'BBB'
22
22
 
23
- ##
24
- # Setup the AnalogPin Circuit
25
- #
26
- class Circuit < BBB::Circuit
27
- def initialize
28
- # Attach temperature sensor to pin P9_40
29
- attach BBB::Components::AnalogComponent, pin: :P9_40, as: :thermometer
30
- end
31
- end
32
-
33
23
  ##
34
24
  # Setup the actual Applicaiton
35
25
  #
36
26
  class TemperatureExampleApp < BBB::Application
37
- # Run this on the BeagleBoneBlack
38
- board BBB::Board::Base.new
39
-
40
- # Connect the circuit to the board
41
- circuit Circuit.new
27
+ attach BBB::Components::AnalogComponent, as: :thermometer
42
28
 
43
29
  def initialize
30
+ thermometer.connect(:P9_40)
44
31
  end
45
32
 
46
-
47
33
  # This is the basic run loop
48
34
  def run
49
35
  print "value: #{thermometer.read}\r"
@@ -0,0 +1,56 @@
1
+ #
2
+ # To run this example do this first:
3
+ #
4
+ # Make sure you run as root
5
+ # > sudo su
6
+ #
7
+ # Install BBB gem version 0.0.9 or higher
8
+ # > gem install BBB
9
+ #
10
+ # Then activate the ADC using the cape
11
+ # > echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
12
+ #
13
+ # No open up an IRB console and copy paste in this code
14
+ # > irb
15
+ #
16
+ # BE CAREFUL:
17
+ # The AIN pins only take 1.8V at max. So if you connect an output pin
18
+ # to an input pin make sure you use a voltage divider circuit. See here:
19
+ # http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/adc
20
+ #
21
+ require 'BBB'
22
+
23
+ ##
24
+ # Setup the AnalogPin Circuit
25
+ #
26
+ class Circuit < BBB::Circuit
27
+ def initialize
28
+ # Attach temperature sensor to pin P9_40
29
+ attach BBB::Components::AnalogComponent, pin: :P9_40, as: :ldr
30
+ attach BBB::Components::Led, pin: :P8_10, as: :led
31
+ end
32
+ end
33
+
34
+ ##
35
+ # Setup the actual Applicaiton
36
+ #
37
+ class LightSwitch < BBB::Application
38
+ # Run this on the BeagleBoneBlack
39
+ board BBB::Board::Base.new
40
+
41
+ # Connect the circuit to the board
42
+ circuit Circuit.new
43
+
44
+ # This is the basic run loop
45
+ def run
46
+ if ldr.read < 70
47
+ led.on!
48
+ else
49
+ led.off!
50
+ end
51
+ end
52
+ end
53
+
54
+ # Initialize the app
55
+ app = LightSwitch.new
56
+ app.start
data/examples/led.rb CHANGED
@@ -1,24 +1,15 @@
1
1
  require 'BBB'
2
2
 
3
- ##
4
- # Setup the LED Circuit
5
- #
6
- class Circuit < BBB::Circuit
7
- def initialize
8
- # Attach the led to pin P8_10
9
- attach BBB::Components::Led, pin: :P8_10, as: :led
10
- end
11
- end
12
-
13
3
  ##
14
4
  # Setup the actual Application
15
5
  #
16
6
  class LedExampleApplication < BBB::Application
17
- # Run this on the BeableBoneBlack
18
- board BBB::Board::Base.new
7
+ # Connect the led
8
+ attach BBB::Components::Led, as: :led
19
9
 
20
- # Connect the led circuit
21
- circuit Circuit.new
10
+ def initialize
11
+ led.connect(:P8_10)
12
+ end
22
13
 
23
14
  # This is the basic run loop
24
15
  def run
@@ -1,56 +1,51 @@
1
- #
2
- # To run this example do this first:
3
- #
4
- # Make sure you run as root
5
- # > sudo su
6
- #
7
- # Install BBB gem version 0.0.9 or higher
8
- # > gem install BBB
9
- #
10
- # Then activate the ADC using the cape
11
- # > echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
12
- #
13
- # No open up an IRB console and copy paste in this code
14
- # > irb
15
- #
16
- # BE CAREFUL:
17
- # The AIN pins only take 1.8V at max. So if you connect an output pin
18
- # to an input pin make sure you use a voltage divider circuit. See here:
19
- # http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/adc
20
- #
21
- require 'BBB'
22
-
23
- ##
24
- # Setup the AnalogPin Circuit
25
- #
26
- class Circuit < BBB::Circuit
27
- def initialize
28
- # Attach temperature sensor to pin P9_40
29
- attach BBB::Components::AnalogComponent, pin: :P9_40, as: :ldr
30
- attach BBB::Components::Led, pin: :P8_10, as: :led
31
- end
32
- end
1
+ require_relative '../lib/BBB'
33
2
 
34
- ##
35
- # Setup the actual Applicaiton
36
- #
37
3
  class LightSwitch < BBB::Application
38
- # Run this on the BeagleBoneBlack
39
- board BBB::Board::Base.new
4
+ attach BBB::Components::Led, as: :led
5
+ attach BBB::Components::Button, as: :button
40
6
 
41
- # Connect the circuit to the board
42
- circuit Circuit.new
7
+ def initialize
8
+ led.connect(:P8_10)
9
+ button.connect(:P8_19)
10
+
11
+ puts "Press the button to switch the light"
12
+ led.on!
13
+ read_button_state
14
+ end
43
15
 
44
- # This is the basic run loop
45
16
  def run
46
- if ldr.read < 70
47
- led.on!
48
- else
49
- led.off!
17
+ read_button_state
18
+
19
+ if current_button_state != last_button_state
20
+ if current_button_state == :high
21
+ if led.on?
22
+ led.off!
23
+ else
24
+ led.on!
25
+ end
26
+ end
27
+ store_button_state
50
28
  end
51
29
  end
30
+
31
+ private
32
+
33
+ def read_button_state
34
+ @button_state = button.state
35
+ end
36
+
37
+ def current_button_state
38
+ @button_state
39
+ end
40
+
41
+ def last_button_state
42
+ @last_button_state
43
+ end
44
+
45
+ def store_button_state
46
+ @last_button_state = @button_state
47
+ end
52
48
  end
53
49
 
54
- # Initialize the app
55
- app = LightSwitch.new
56
- app.start
50
+ LightSwitch.new.start
51
+
@@ -0,0 +1,99 @@
1
+ require 'sinatra'
2
+ require 'sinatra-websocket'
3
+
4
+ require 'BBB'
5
+
6
+ class Circuit < BBB::Circuit
7
+ def initialize
8
+ attach BBB::Components::Nunchuck, pin: "/dev/i2c-2", as: :nunchuck
9
+ end
10
+ end
11
+
12
+ class NunchuckService < BBB::Application
13
+ circuit Circuit.new
14
+
15
+ def start
16
+ Thread.new do
17
+ loop do
18
+ nunchuck.update
19
+ end
20
+ end
21
+ self
22
+ end
23
+
24
+ def add_socket(socket)
25
+ pressed = lambda { |value| socket.send("{c: 'pressed'}") }
26
+ released = lambda { |value| socket.send("{c: 'released'}") }
27
+
28
+ nunchuck.c.release_callbacks << pressed
29
+ nunchuck.c.press_callbacks << released
30
+ end
31
+
32
+ end
33
+
34
+ class NunchuckServer < Sinatra::Base
35
+ set :server, 'thin'
36
+ set :sockets, []
37
+ set :nunchuck, NunchuckService.new.start
38
+ enable :inline_templates
39
+
40
+ get '/' do
41
+ if !request.websocket?
42
+ erb :index
43
+ else
44
+ request.websocket do |ws|
45
+ ws.onopen do
46
+ ws.send("Hello World!")
47
+ ws.send("Opened the websocket")
48
+ settings.sockets << ws
49
+ settings.nunchuck.add_socket(ws)
50
+ end
51
+
52
+ ws.onclose do
53
+ warn("wetbsocket closed")
54
+ settings.sockets.delete(ws)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ run! if app_file == $0
61
+ end
62
+
63
+ __END__
64
+ @@ index
65
+ <html>
66
+ <body>
67
+ <h1>Simple Echo & Chat Server</h1>
68
+ <form id="form">
69
+ <input type="text" id="input" value="send a message"></input>
70
+ </form>
71
+ <div id="msgs"></div>
72
+ </body>
73
+
74
+ <script type="text/javascript">
75
+ window.onload = function(){
76
+ (function(){
77
+ var show = function(el){
78
+ return function(msg){ el.innerHTML = msg + '<br />' + el.innerHTML; }
79
+ }(document.getElementById('msgs'));
80
+
81
+ var ws = new WebSocket('ws://' + window.location.host + window.location.pathname);
82
+ ws.onopen = function() { show('websocket opened'); };
83
+ ws.onclose = function() { show('websocket closed'); }
84
+ ws.onmessage = function(m) { show('websocket message: ' + m.data); };
85
+
86
+ var sender = function(f){
87
+ var input = document.getElementById('input');
88
+ input.onclick = function(){ input.value = "" };
89
+ f.onsubmit = function(){
90
+ ws.send(input.value);
91
+ input.value = "send a message";
92
+ return false;
93
+ }
94
+ }(document.getElementById('form'));
95
+ })();
96
+ }
97
+ </script>
98
+ </html>
99
+
@@ -1,24 +1,21 @@
1
1
  require 'BBB'
2
2
 
3
- class Circuit < BBB::Circuit
4
- include BBB::Components
5
-
6
- def initialize
7
- attach Servo, pins: :P8_13, as: :servo
8
- attach AnalogComponent, pin: :P9_40, as: :ldr
9
- end
10
- end
11
-
12
3
  class LDRServo < BBB::Application
13
4
  attr_accessor :min, :max
14
5
 
15
- circuit Circuit.new
6
+ attach Servo, as: :servo
7
+ attach AnalogComponent, as: :ldr
16
8
 
17
9
  def initialize(min, max)
18
10
  @min = min
19
11
  @max = max
20
12
  end
21
13
 
14
+ def activate_components
15
+ servo.connect(:P8_13)
16
+ ldr.connect(:P9_40)
17
+ end
18
+
22
19
  def run
23
20
  servo.angle(angle)
24
21
  end
@@ -32,3 +29,7 @@ class LDRServo < BBB::Application
32
29
  end
33
30
 
34
31
  end
32
+
33
+ app = LDRServo.new(0,180)
34
+ app.angle(120)
35
+
data/lib/BBB.rb CHANGED
@@ -5,25 +5,8 @@ require "BBB/version"
5
5
 
6
6
  require "BBB/circuit"
7
7
  require "BBB/exceptions"
8
-
9
- require "BBB/pins/io/pin_mapper"
10
- require "BBB/pins/io/mapped"
11
- require "BBB/pins/io/cape"
12
- require "BBB/pins/io/ain"
13
- require "BBB/pins/io/gpio"
14
- require "BBB/pins/io/pwm"
15
- require "BBB/pins/io/i2c"
16
-
17
- require "BBB/pins/pinnable"
18
- require "BBB/pins/digital_pin"
19
- require "BBB/pins/analog_pin"
20
- require "BBB/pins/pwm_pin"
21
-
22
- require "BBB/components/pinnable"
23
- require "BBB/components/analog_component"
24
- require "BBB/components/led"
25
- require "BBB/components/servo"
26
-
8
+ require "BBB/pins"
9
+ require "BBB/components"
27
10
  require "BBB/application"
28
11
 
29
12
  module BBB