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 +13 -5
- data/Gemfile +2 -2
- data/Guardfile +46 -0
- data/examples/analog_pin.rb +2 -16
- data/examples/ldr_light_switch.rb +56 -0
- data/examples/led.rb +5 -14
- data/examples/light_switch.rb +42 -47
- data/examples/nunchuck.rb +99 -0
- data/examples/servo_ldr.rb +11 -10
- data/lib/BBB.rb +2 -19
- data/lib/BBB/application.rb +5 -21
- data/lib/BBB/circuit.rb +49 -42
- data/lib/BBB/components.rb +9 -0
- data/lib/BBB/components/analog_component.rb +0 -9
- data/lib/BBB/components/button.rb +25 -0
- data/lib/BBB/components/esc.rb +68 -19
- data/lib/BBB/components/led.rb +0 -9
- data/lib/BBB/components/nunchuck.rb +197 -0
- data/lib/BBB/components/pinnable.rb +70 -18
- data/lib/BBB/components/servo.rb +21 -11
- data/lib/BBB/components/wii_motion_plus.rb +229 -0
- data/lib/BBB/pins.rb +13 -0
- data/lib/BBB/pins/i2c.rb +22 -0
- data/lib/BBB/pins/io/gpio.rb +6 -2
- data/lib/BBB/pins/io/i2c.rb +10 -9
- data/lib/BBB/pins/io/pin_mapper.rb +2 -2
- data/lib/BBB/pins/pinnable.rb +3 -3
- data/lib/BBB/version.rb +1 -1
- data/spec/application_spec.rb +4 -14
- data/spec/circuit_spec.rb +6 -9
- data/spec/components/analog_component_spec.rb +7 -2
- data/spec/components/led_spec.rb +1 -1
- data/spec/components/pinnable_spec.rb +16 -6
- data/spec/components/servo_spec.rb +47 -1
- data/spec/examples/led_spec.rb +40 -0
- data/spec/pins/digital_pin_spec.rb +1 -0
- data/spec/pins/io/pin_mapper_spec.rb +0 -4
- metadata +24 -14
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDlkMDA1NjQxOGMzYzBmYThhMjA3NjU5MGZhOWE3MzM4YmIwYmI0Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2E0ZjE1MjYxMWMzMzAwODdkMGQyOTBlMGFiZmNkZTBmMDc5NmU2Mw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWIzODNmZGU0NzlkOWUxOWMyNWE3YjhkZTYxYjhlYjkyNjE5ZDliNjRmZmI1
|
10
|
+
OWFmY2YxODI1ODM2MGE2NzIyYjgzN2ViNTk4ODdlOWNjOTgyM2M1MzM1MzYz
|
11
|
+
ZDBkZDdhMDkwMjhmMjc1ODMxMmFlM2RiN2FhMTE4MmFhMWQ1NDc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmY4ZmJjNzkzOTlhNDY0MmZjNDBiMDM5M2NjNzY3YmFiZTA4ZWFiODg3N2Rj
|
14
|
+
ODMyZThmYjYxYjU3ODBiNTFiMzRhMGQ4NTgxYTQ5YjRhMjhmOGIyZjNmOGVl
|
15
|
+
N2NmZTI4MTdjNzVjYTMxYjZhOGM3OWM3YWM1MjFhNzNjYjc0MGM=
|
data/Gemfile
CHANGED
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
|
+
|
data/examples/analog_pin.rb
CHANGED
@@ -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
|
-
|
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
|
-
#
|
18
|
-
|
7
|
+
# Connect the led
|
8
|
+
attach BBB::Components::Led, as: :led
|
19
9
|
|
20
|
-
|
21
|
-
|
10
|
+
def initialize
|
11
|
+
led.connect(:P8_10)
|
12
|
+
end
|
22
13
|
|
23
14
|
# This is the basic run loop
|
24
15
|
def run
|
data/examples/light_switch.rb
CHANGED
@@ -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
|
-
|
39
|
-
|
4
|
+
attach BBB::Components::Led, as: :led
|
5
|
+
attach BBB::Components::Button, as: :button
|
40
6
|
|
41
|
-
|
42
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
55
|
-
|
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
|
+
|
data/examples/servo_ldr.rb
CHANGED
@@ -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
|
-
|
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/
|
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
|