BBB 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/examples/analog_pin.rb +4 -6
- data/examples/{led.rb → blinker.rb} +2 -3
- data/examples/ldr_light_switch.rb +16 -22
- data/examples/light_switch.rb +10 -33
- data/examples/{nunchuck.rb → nunchuck_websocket.rb} +13 -13
- data/examples/quadcopter.rb +77 -0
- data/examples/servo_ldr.rb +104 -14
- data/lib/BBB.rb +16 -2
- data/lib/BBB/application.rb +10 -4
- data/lib/BBB/attachable.rb +77 -0
- data/lib/BBB/circuit.rb +7 -47
- data/lib/BBB/components/button.rb +45 -5
- data/lib/BBB/components/esc.rb +1 -1
- data/lib/BBB/components/led.rb +19 -0
- data/lib/BBB/components/nunchuck.rb +0 -43
- data/lib/BBB/components/pinnable.rb +4 -1
- data/lib/BBB/components/wii_motion_plus.rb +4 -0
- data/lib/BBB/configuration.rb +14 -0
- data/lib/BBB/pins/pinnable.rb +1 -1
- data/lib/BBB/version.rb +1 -1
- data/spec/application_spec.rb +27 -5
- data/spec/bbb_spec.rb +23 -0
- data/spec/configuration_spec.rb +16 -0
- data/spec/examples/analog_pin_spec.rb +13 -0
- data/spec/examples/blinker_spec.rb +17 -0
- data/spec/examples/ldr_light_switch_spec.rb +38 -0
- data/spec/examples/light_switch_spec.rb +47 -0
- data/spec/examples/nunchuck_websocket_spec.rb +20 -0
- data/spec/examples/quadcopter_spec.rb +90 -0
- data/spec/examples/servo_ldr_spec.rb +95 -0
- data/spec/pins/pinnable_spec.rb +4 -2
- data/spec/spec_helper.rb +1 -0
- metadata +26 -7
- data/examples/sketches.rb +0 -86
- data/spec/examples/led_spec.rb +0 -40
data/examples/sketches.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'bbb'
|
2
|
-
|
3
|
-
module Thunderball
|
4
|
-
class Copter << BBB::Application
|
5
|
-
##
|
6
|
-
# Use the BBB as the board, allows for possible ports to e.g. the Pi
|
7
|
-
#
|
8
|
-
board BBB::Board.new
|
9
|
-
|
10
|
-
##
|
11
|
-
# Load the thunderball layout
|
12
|
-
#
|
13
|
-
layout Thunderball::Circuit.new
|
14
|
-
|
15
|
-
attr_reader :stabalizer, :mover
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@stabalizer = Stabalizer.new(escs: escs,
|
19
|
-
gyro: gyro,
|
20
|
-
accelerometer: acc)
|
21
|
-
|
22
|
-
@mover = Mover.new(escs: escs)
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Once start is called the run function will be called in a loop
|
27
|
-
#
|
28
|
-
def run
|
29
|
-
stabalizer
|
30
|
-
move(:forward=>20, :right=>10)
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Stabalize function is just syntactic sugar to make the run method look nice.
|
35
|
-
#
|
36
|
-
def stabilize
|
37
|
-
stabalizer.update
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# move function is just syntactic sugar to make the run method look nice.
|
42
|
-
#
|
43
|
-
def move
|
44
|
-
mover.update
|
45
|
-
end
|
46
|
-
end # Copter
|
47
|
-
|
48
|
-
class Circuit < BBB::Circuit
|
49
|
-
def initialize
|
50
|
-
attach_escs
|
51
|
-
attach_led
|
52
|
-
end
|
53
|
-
|
54
|
-
def attach_escs
|
55
|
-
attach ESC, :pins=>[:P8_1, :P8_2], :as=>:esc_1, :group=>:escs
|
56
|
-
attach ESC, :pins=>[:P9_1, :P9_2], :as=>:esc_2, :group=>:escs
|
57
|
-
end
|
58
|
-
|
59
|
-
def attach_leds
|
60
|
-
attach Led, :pin=>:P9_12
|
61
|
-
end
|
62
|
-
end # Circuit
|
63
|
-
|
64
|
-
class Mover
|
65
|
-
def initialize(opts={})
|
66
|
-
@escs = opts[:escs]
|
67
|
-
end
|
68
|
-
|
69
|
-
def move
|
70
|
-
# Do some complex logic here with the escs
|
71
|
-
end
|
72
|
-
end # Mover
|
73
|
-
|
74
|
-
def Stabalizer
|
75
|
-
def initialize(opts={})
|
76
|
-
@escs = opts[:escs]
|
77
|
-
@gyo = opts[:gyro]
|
78
|
-
@accelerometer = opts[:accelerometer]
|
79
|
-
end
|
80
|
-
|
81
|
-
def stabalize
|
82
|
-
# Do someting complex with all the components
|
83
|
-
# and update all values
|
84
|
-
end
|
85
|
-
end #Stabalizer
|
86
|
-
end
|
data/spec/examples/led_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Blinking a Led" do
|
4
|
-
|
5
|
-
##
|
6
|
-
# Setup the actual Application
|
7
|
-
#
|
8
|
-
class LedExampleApplication < BBB::Application
|
9
|
-
# Connect the led
|
10
|
-
attach BBB::Components::Led, as: :led
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
led.connect(:P8_10, mock: true)
|
14
|
-
end
|
15
|
-
|
16
|
-
# This is the basic run loop
|
17
|
-
def run
|
18
|
-
led.on! # this does what you think it does
|
19
|
-
sleep(1) # sleep for 1 second, kind of blunt, since it blocks everthing.
|
20
|
-
led.off!
|
21
|
-
sleep(1)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Initialize and run the LedExampleApplication
|
26
|
-
|
27
|
-
it "should initialize" do
|
28
|
-
lambda{ LedExampleApplication.new}.should_not raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should respond to led" do
|
32
|
-
app = LedExampleApplication.new
|
33
|
-
app.respond_to?(:led).should be_true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should be able to turn led on" do
|
37
|
-
app = LedExampleApplication.new
|
38
|
-
lambda {app.led.on!}.should_not raise_error
|
39
|
-
end
|
40
|
-
end
|