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/spec/bbb_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB do
|
4
|
+
|
5
|
+
it "has a single configuration" do
|
6
|
+
a = BBB.configuration
|
7
|
+
b = BBB.configuration
|
8
|
+
|
9
|
+
a.test_mode = false
|
10
|
+
b.test_mode.should be_false
|
11
|
+
|
12
|
+
a.should eql(b)
|
13
|
+
a.test_mode = true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "you can temporarily escape test mode" do
|
17
|
+
BBB.escape_test do
|
18
|
+
BBB.configuration.test_mode.should eql(false)
|
19
|
+
end
|
20
|
+
BBB.configuration.test_mode.should eql(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Configuration do
|
4
|
+
|
5
|
+
it "test mode on when testing" do
|
6
|
+
BBB.configuration.test_mode.should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be set to a different value" do
|
10
|
+
BBB.configuration.test_mode = false
|
11
|
+
BBB.configuration.test_mode.should be_false
|
12
|
+
BBB.configuration.test_mode = true
|
13
|
+
BBB.configuration.test_mode.should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../examples/analog_pin.rb'
|
3
|
+
|
4
|
+
describe Thermometer do
|
5
|
+
|
6
|
+
it "has a thermometer" do
|
7
|
+
described_class.new.respond_to?(:thermometer).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "thermometer responds to read" do
|
11
|
+
described_class.new.thermometer.respond_to?(:read).should be_true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative "../../examples/blinker"
|
3
|
+
|
4
|
+
describe Blinker do
|
5
|
+
|
6
|
+
# Initialize and run the LedExampleApplication
|
7
|
+
|
8
|
+
it "should respond to led" do
|
9
|
+
app = described_class.new
|
10
|
+
app.respond_to?(:led).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to turn led on" do
|
14
|
+
app = described_class.new
|
15
|
+
lambda {app.led.on!}.should_not raise_error
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../examples/ldr_light_switch'
|
3
|
+
|
4
|
+
describe LDRLightSwitch do
|
5
|
+
before :each do
|
6
|
+
@switch = described_class.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has an ldr" do
|
10
|
+
@switch.respond_to?(:ldr).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has an led" do
|
14
|
+
@switch.respond_to?(:led).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "led initializes off" do
|
18
|
+
@switch.led.off?.should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "switches on if the light is below threshold" do
|
22
|
+
@switch.threshold = 10
|
23
|
+
@switch.led.off!
|
24
|
+
|
25
|
+
@switch.ldr.should_receive(:read).and_return(5)
|
26
|
+
@switch.run
|
27
|
+
@switch.led.on?.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "switches off if the light is below threshold" do
|
31
|
+
@switch.threshold = 10
|
32
|
+
@switch.led.on!
|
33
|
+
|
34
|
+
@switch.ldr.should_receive(:read).and_return(15)
|
35
|
+
@switch.run
|
36
|
+
@switch.led.on?.should be_false
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../examples/light_switch'
|
3
|
+
|
4
|
+
describe LightSwitch do
|
5
|
+
|
6
|
+
it "turns on the light by default" do
|
7
|
+
LightSwitch.new.led.on?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
context "switching lights" do
|
11
|
+
|
12
|
+
it "toggles the light on button press" do
|
13
|
+
switch = LightSwitch.new
|
14
|
+
old_state = switch.led.status
|
15
|
+
switch.button.update(true)
|
16
|
+
old_state.should_not eql(switch.led.status)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "when keeping pressed do not switch" do
|
20
|
+
switch = LightSwitch.new
|
21
|
+
|
22
|
+
state0 = switch.led.status
|
23
|
+
switch.button.update(true)
|
24
|
+
|
25
|
+
state1 = switch.led.status
|
26
|
+
state0.should_not eql(state1)
|
27
|
+
|
28
|
+
switch.button.update(true)
|
29
|
+
state2 = switch.led.status
|
30
|
+
state2.should eql(state1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "when keeping released do not switch state" do
|
34
|
+
switch = LightSwitch.new
|
35
|
+
|
36
|
+
state0 = switch.led.status
|
37
|
+
switch.button.update(false)
|
38
|
+
|
39
|
+
state1 = switch.led.status
|
40
|
+
state0.should eql(state1)
|
41
|
+
|
42
|
+
switch.button.update(false)
|
43
|
+
state2 = switch.led.status
|
44
|
+
state2.should eql(state1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../examples/nunchuck_websocket'
|
3
|
+
|
4
|
+
|
5
|
+
describe NunchuckService do
|
6
|
+
|
7
|
+
it "initializes" do
|
8
|
+
lambda { described_class.new }.should_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
describe NunchuckServer do
|
15
|
+
|
16
|
+
it "initializes" do
|
17
|
+
lambda { described_class.new }.should_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../examples/quadcopter'
|
3
|
+
|
4
|
+
describe Quadcopter do
|
5
|
+
let(:copter) { described_class.new }
|
6
|
+
|
7
|
+
it "counts 4 escs" do
|
8
|
+
escs = copter.escs
|
9
|
+
escs.count.should eql(4)
|
10
|
+
classes = escs.map(&:class).uniq
|
11
|
+
classes.count.should eql(1)
|
12
|
+
classes.first.should eql(BBB::Components::ESC)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds to 1 wmp on the WiiMotionPlus" do
|
16
|
+
copter.wmp.class.should eql(BBB::Components::WMP)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "responds to the names of the escs" do
|
20
|
+
copter = described_class.new
|
21
|
+
copter.esc_lf.class.should eql(BBB::Components::ESC)
|
22
|
+
copter.esc_rf.class.should eql(BBB::Components::ESC)
|
23
|
+
copter.esc_lb.class.should eql(BBB::Components::ESC)
|
24
|
+
copter.esc_rb.class.should eql(BBB::Components::ESC)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a stabilizer" do
|
28
|
+
copter.respond_to?(:stabilizer).should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "passes the secs to the stabilizer" do
|
32
|
+
copter.stabilizer.escs.should eql(copter.escs)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "provides quick access to gyro on wmp" do
|
36
|
+
copter.gyro.should eql(copter.wmp.gyro)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should know about fly mode" do
|
40
|
+
copter.respond_to?(:fly_mode).should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "defaults to a hover fly mode" do
|
44
|
+
copter.fly_mode.should eql(:hover)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "consults the stabilizer for fly mode info" do
|
48
|
+
copter.stabilizer.should_receive(:mode).and_return("wicked acrobatics")
|
49
|
+
copter.fly_mode.should eql("wicked acrobatics")
|
50
|
+
end
|
51
|
+
|
52
|
+
context "complex attach commands" do
|
53
|
+
|
54
|
+
it "remembers both pins given" do
|
55
|
+
copter.esc_lf.positions.should eql([:P8_13, :P9_3])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "remembers a single pin given" do
|
59
|
+
copter.power_indicator.positions.should eql([:P8_6])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Stabilizer do
|
66
|
+
let(:stabilizer) { described_class.new }
|
67
|
+
|
68
|
+
it "reponds to hover" do
|
69
|
+
stabilizer.respond_to?(:hover).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "reponds to update" do
|
73
|
+
stabilizer.respond_to?(:update).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
[:escs, :gyro, :accelerometer].each do |key|
|
77
|
+
it "sets #{key} on initialization" do
|
78
|
+
number = rand(100)
|
79
|
+
instance = described_class.new(:"#{key}"=>number)
|
80
|
+
instance.send(key).should eql(number)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sets default mode to hover" do
|
85
|
+
stabilizer.mode.should eql(:hover)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative "../../examples/servo_ldr"
|
3
|
+
|
4
|
+
describe LDRServo do
|
5
|
+
|
6
|
+
context "Direction" do
|
7
|
+
it "keeps direction when equal measuement" do
|
8
|
+
finder = described_class.new
|
9
|
+
finder.ldr.should_receive(:read).twice.and_return(0)
|
10
|
+
old_direction = finder.direction
|
11
|
+
finder.run
|
12
|
+
finder.direction.should eql(old_direction)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "reverses direction when moving away from light" do
|
16
|
+
finder = described_class.new
|
17
|
+
finder.previous_value = 50
|
18
|
+
finder.ldr.should_receive(:read).and_return(30)
|
19
|
+
finder.servo.should_receive(:angle)
|
20
|
+
old_direction = finder.direction
|
21
|
+
|
22
|
+
finder.run
|
23
|
+
finder.direction.should_not eql(old_direction)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "continues direction when moving towards from light" do
|
27
|
+
finder = described_class.new
|
28
|
+
finder.previous_value = 30
|
29
|
+
finder.ldr.should_receive(:read).and_return(50)
|
30
|
+
finder.servo.should_receive(:angle)
|
31
|
+
old_direction = finder.direction
|
32
|
+
|
33
|
+
finder.run
|
34
|
+
finder.direction.should eql(old_direction)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "angle adjustment" do
|
40
|
+
it "not needed when receiving same value" do
|
41
|
+
finder = described_class.new
|
42
|
+
finder.ldr.should_receive(:read).twice.and_return(0)
|
43
|
+
finder.servo.should_not_receive(:angle)
|
44
|
+
finder.run
|
45
|
+
end
|
46
|
+
|
47
|
+
it "needed when moving away from light" do
|
48
|
+
finder = described_class.new
|
49
|
+
finder.previous_value = 50
|
50
|
+
finder.ldr.should_receive(:read).and_return(30)
|
51
|
+
finder.servo.should_receive(:angle)
|
52
|
+
finder.run
|
53
|
+
end
|
54
|
+
|
55
|
+
it "needed when moving towards light" do
|
56
|
+
finder = described_class.new
|
57
|
+
finder.previous_value = 30
|
58
|
+
finder.ldr.should_receive(:read).and_return(50)
|
59
|
+
finder.servo.should_receive(:angle)
|
60
|
+
finder.run
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "setting the angle" do
|
65
|
+
it "to maximum when given a value above maximm" do
|
66
|
+
finder = described_class.new
|
67
|
+
finder.angle=200
|
68
|
+
finder.angle.should eql(finder.max_servo_angle)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "to minimum when given a value below minumum" do
|
72
|
+
finder = described_class.new
|
73
|
+
finder.angle=-10
|
74
|
+
finder.angle.should eql(finder.min_servo_angle)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "to maximum when given maximum value" do
|
78
|
+
finder = described_class.new
|
79
|
+
finder.angle=finder.max_servo_angle
|
80
|
+
finder.angle.should eql(finder.max_servo_angle)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "to minimum when given a value below minumum" do
|
84
|
+
finder = described_class.new
|
85
|
+
finder.angle=finder.min_servo_angle
|
86
|
+
finder.angle.should eql(finder.min_servo_angle)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "to value when given a value within range" do
|
90
|
+
finder = described_class.new
|
91
|
+
finder.angle=100
|
92
|
+
finder.angle.should eql(100)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/pins/pinnable_spec.rb
CHANGED
@@ -33,8 +33,10 @@ describe BBB::Pins::Pinnable do
|
|
33
33
|
pin = MockPin.new(:P8_13, mock: false)
|
34
34
|
pin.mock?.should be_false
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
BBB.escape_test do
|
37
|
+
pin = MockPin.new(:P8_13)
|
38
|
+
pin.mock?.should be_false
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: BBB
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilco van Duinkerken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -95,14 +95,15 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- examples/analog_pin.rb
|
98
|
+
- examples/blinker.rb
|
98
99
|
- examples/ldr_light_switch.rb
|
99
|
-
- examples/led.rb
|
100
100
|
- examples/light_switch.rb
|
101
|
-
- examples/
|
101
|
+
- examples/nunchuck_websocket.rb
|
102
|
+
- examples/quadcopter.rb
|
102
103
|
- examples/servo_ldr.rb
|
103
|
-
- examples/sketches.rb
|
104
104
|
- lib/BBB.rb
|
105
105
|
- lib/BBB/application.rb
|
106
|
+
- lib/BBB/attachable.rb
|
106
107
|
- lib/BBB/circuit.rb
|
107
108
|
- lib/BBB/components.rb
|
108
109
|
- lib/BBB/components/analog_component.rb
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- lib/BBB/components/pinnable.rb
|
114
115
|
- lib/BBB/components/servo.rb
|
115
116
|
- lib/BBB/components/wii_motion_plus.rb
|
117
|
+
- lib/BBB/configuration.rb
|
116
118
|
- lib/BBB/exceptions.rb
|
117
119
|
- lib/BBB/pins.rb
|
118
120
|
- lib/BBB/pins/analog_pin.rb
|
@@ -131,12 +133,20 @@ files:
|
|
131
133
|
- resources/pin_mappings.json
|
132
134
|
- resources/pin_mappings.json.comment
|
133
135
|
- spec/application_spec.rb
|
136
|
+
- spec/bbb_spec.rb
|
134
137
|
- spec/circuit_spec.rb
|
135
138
|
- spec/components/analog_component_spec.rb
|
136
139
|
- spec/components/led_spec.rb
|
137
140
|
- spec/components/pinnable_spec.rb
|
138
141
|
- spec/components/servo_spec.rb
|
139
|
-
- spec/
|
142
|
+
- spec/configuration_spec.rb
|
143
|
+
- spec/examples/analog_pin_spec.rb
|
144
|
+
- spec/examples/blinker_spec.rb
|
145
|
+
- spec/examples/ldr_light_switch_spec.rb
|
146
|
+
- spec/examples/light_switch_spec.rb
|
147
|
+
- spec/examples/nunchuck_websocket_spec.rb
|
148
|
+
- spec/examples/quadcopter_spec.rb
|
149
|
+
- spec/examples/servo_ldr_spec.rb
|
140
150
|
- spec/pins/analog_pin_spec.rb
|
141
151
|
- spec/pins/digital_input_pin_spec.rb
|
142
152
|
- spec/pins/digital_output_pin_spec.rb
|
@@ -173,12 +183,20 @@ specification_version: 4
|
|
173
183
|
summary: Helper functions to ruby around on the BeagleBone Black
|
174
184
|
test_files:
|
175
185
|
- spec/application_spec.rb
|
186
|
+
- spec/bbb_spec.rb
|
176
187
|
- spec/circuit_spec.rb
|
177
188
|
- spec/components/analog_component_spec.rb
|
178
189
|
- spec/components/led_spec.rb
|
179
190
|
- spec/components/pinnable_spec.rb
|
180
191
|
- spec/components/servo_spec.rb
|
181
|
-
- spec/
|
192
|
+
- spec/configuration_spec.rb
|
193
|
+
- spec/examples/analog_pin_spec.rb
|
194
|
+
- spec/examples/blinker_spec.rb
|
195
|
+
- spec/examples/ldr_light_switch_spec.rb
|
196
|
+
- spec/examples/light_switch_spec.rb
|
197
|
+
- spec/examples/nunchuck_websocket_spec.rb
|
198
|
+
- spec/examples/quadcopter_spec.rb
|
199
|
+
- spec/examples/servo_ldr_spec.rb
|
182
200
|
- spec/pins/analog_pin_spec.rb
|
183
201
|
- spec/pins/digital_input_pin_spec.rb
|
184
202
|
- spec/pins/digital_output_pin_spec.rb
|
@@ -189,3 +207,4 @@ test_files:
|
|
189
207
|
- spec/pins/pinnable_spec.rb
|
190
208
|
- spec/pins/pwm_pin_spec.rb
|
191
209
|
- spec/spec_helper.rb
|
210
|
+
has_rdoc:
|