BBB 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/BBB.rb +13 -17
- data/lib/BBB/application.rb +4 -21
- data/lib/BBB/circuit.rb +18 -33
- data/lib/BBB/components/analog_component.rb +29 -6
- data/lib/BBB/components/led.rb +39 -9
- data/lib/BBB/components/pinnable.rb +90 -4
- data/lib/BBB/components/servo.rb +43 -0
- data/lib/BBB/pins/analog_pin.rb +39 -0
- data/lib/BBB/pins/digital_pin.rb +106 -0
- data/lib/BBB/pins/io/ain.rb +58 -0
- data/lib/BBB/pins/io/gpio.rb +77 -0
- data/lib/BBB/pins/io/mapped.rb +39 -0
- data/lib/BBB/pins/io/pin_mapper.rb +224 -0
- data/lib/BBB/pins/io/pwm.rb +61 -0
- data/lib/BBB/pins/pinnable.rb +78 -0
- data/lib/BBB/pins/pwm_pin.rb +43 -0
- data/lib/BBB/version.rb +1 -1
- data/spec/application_spec.rb +1 -26
- data/spec/circuit_spec.rb +0 -1
- data/spec/components/analog_component_spec.rb +36 -0
- data/spec/components/led_spec.rb +14 -19
- data/spec/components/pinnable_spec.rb +73 -8
- data/spec/components/servo_spec.rb +6 -0
- data/spec/pins/analog_pin_spec.rb +33 -0
- data/spec/pins/digital_input_pin_spec.rb +13 -0
- data/spec/pins/digital_output_pin_spec.rb +14 -0
- data/spec/pins/digital_pin_spec.rb +66 -0
- data/spec/pins/io/mapped_spec.rb +41 -0
- data/spec/{board → pins/io}/pin_mapper_spec.rb +2 -2
- data/spec/pins/pinnable_spec.rb +68 -0
- data/spec/pins/pwm_pin_spec.rb +29 -0
- metadata +34 -37
- data/lib/BBB/adc/analog_pin.rb +0 -42
- data/lib/BBB/adc/setup.rb +0 -20
- data/lib/BBB/board/base.rb +0 -45
- data/lib/BBB/board/json_pin_mapper.rb +0 -203
- data/lib/BBB/board/pin_mapper.rb +0 -20
- data/lib/BBB/board/test_board.rb +0 -12
- data/lib/BBB/gpio/base.rb +0 -56
- data/lib/BBB/gpio/digital_pin.rb +0 -69
- data/lib/BBB/gpio/pin_converter.rb +0 -28
- data/lib/BBB/io/analog_pin.rb +0 -24
- data/lib/BBB/io/digital_pin.rb +0 -67
- data/lib/BBB/io/mock_pin.rb +0 -8
- data/lib/BBB/io/pinnable.rb +0 -12
- data/spec/adc/analog_pin_spec.rb +0 -100
- data/spec/adc/setup_spec.rb +0 -9
- data/spec/board/board_spec.rb +0 -49
- data/spec/gpio/base_spec.rb +0 -48
- data/spec/gpio/digital_pin_spec.rb +0 -100
- data/spec/gpio/pin_converter_spec.rb +0 -19
- data/spec/io/digital_pin_spec.rb +0 -14
- data/spec/io/mock_pin_spec.rb +0 -13
- data/spec/io/pinnable_spec.rb +0 -13
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::AnalogPin do
|
4
|
+
let(:pin) { BBB::Pins::AnalogPin.new(:P8_4, mock: true)}
|
5
|
+
|
6
|
+
it "includes pinnable" do
|
7
|
+
pin.pinnable?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#read from io" do
|
11
|
+
pin.io.should_receive(:read)
|
12
|
+
pin.read
|
13
|
+
end
|
14
|
+
|
15
|
+
it "#scale from io" do
|
16
|
+
pin.io.should_receive(:scale)
|
17
|
+
pin.scale
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#scale memorizes the scale" do
|
21
|
+
pin.io.should_receive(:scale).once.and_return(100)
|
22
|
+
pin.scale
|
23
|
+
pin.scale.should eql(100)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "private methods: " do
|
27
|
+
it "sets default_io" do
|
28
|
+
BBB::Pins::IO::AIN.should_receive(:new)
|
29
|
+
pin.send(:default_io)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::DigitalInputPin do
|
4
|
+
let(:pin) { BBB::Pins::DigitalInputPin.new(:P8_4, mock: true)}
|
5
|
+
|
6
|
+
it "initializes with the direction :input" do
|
7
|
+
pin.direction.should eql(:input)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is a kind of digital pin" do
|
11
|
+
pin.kind_of?(BBB::Pins::DigitalPin).should be_true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::DigitalOutputPin do
|
4
|
+
let(:pin) { BBB::Pins::DigitalOutputPin.new(:P8_4, mock: true)}
|
5
|
+
|
6
|
+
it "initializes with the direction :output" do
|
7
|
+
pin.direction.should eql(:output)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is a kind of digital pin" do
|
11
|
+
pin.kind_of?(BBB::Pins::DigitalPin).should be_true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::DigitalPin do
|
4
|
+
let(:input) { BBB::Pins::DigitalPin.new(:P8_4,
|
5
|
+
direction: :input,
|
6
|
+
mock: true)}
|
7
|
+
let(:output) { BBB::Pins::DigitalPin.new(:P8_4,
|
8
|
+
direction: :output,
|
9
|
+
mock: true)}
|
10
|
+
|
11
|
+
context "all pins" do
|
12
|
+
it "includes pinnable" do
|
13
|
+
input.pinnable?.should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "#direction gets memoized" do
|
17
|
+
input.opts.should_receive(:fetch).with(:direction).once
|
18
|
+
.and_return(:input)
|
19
|
+
2.times do
|
20
|
+
input.direction
|
21
|
+
end
|
22
|
+
|
23
|
+
input.direction.should eql(:input)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "input pins" do
|
28
|
+
|
29
|
+
it "#status forwards to io" do
|
30
|
+
input.io.should_receive(:read)
|
31
|
+
input.status
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
context "output pins" do
|
37
|
+
|
38
|
+
it "#off! #on!" do
|
39
|
+
output.off!
|
40
|
+
output.off?.should be_true
|
41
|
+
output.on?.should be_false
|
42
|
+
|
43
|
+
output.on!
|
44
|
+
output.on?.should be_true
|
45
|
+
output.off?.should be_false
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#on! #off!" do
|
49
|
+
output.on!
|
50
|
+
output.on?.should be_true
|
51
|
+
output.off?.should be_false
|
52
|
+
|
53
|
+
output.off!
|
54
|
+
output.off?.should be_true
|
55
|
+
output.on?.should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "private methods: " do
|
61
|
+
it "sets default_io" do
|
62
|
+
BBB::Pins::IO::GPIO.should_receive(:new)
|
63
|
+
input.send(:default_io)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::IO::Mapped do
|
4
|
+
class MockIO
|
5
|
+
include BBB::Pins::IO::Mapped
|
6
|
+
attr_reader :position
|
7
|
+
|
8
|
+
def initialize(position)
|
9
|
+
@position = position
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "maps GPIO pins" do
|
14
|
+
m = MockIO.new(:P8_3)
|
15
|
+
m.should_receive(:pin_map_key).and_return(:gpio)
|
16
|
+
m.pin_map
|
17
|
+
end
|
18
|
+
|
19
|
+
it "maps AIN pins" do
|
20
|
+
m = MockIO.new(:P9_40)
|
21
|
+
m.should_receive(:pin_map_key).and_return(:ain)
|
22
|
+
m.pin_map
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
it "maps PWM pins" do
|
27
|
+
m = MockIO.new(:P9_14)
|
28
|
+
m.should_receive(:pin_map_key).and_return(:pwm)
|
29
|
+
m.pin_map
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an argumenterror if a pin doesn't support the io type" do
|
33
|
+
m = MockIO.new(:P8_1)
|
34
|
+
m.should_receive(:pin_map_key).and_return(:pwm)
|
35
|
+
lambda do
|
36
|
+
m.pin_map
|
37
|
+
end.should raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::Pinnable do
|
4
|
+
class MockPin
|
5
|
+
include BBB::Pins::Pinnable
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:pin) { MockPin.new(:P8_13) }
|
9
|
+
|
10
|
+
it "returns true to pinnable?" do
|
11
|
+
pin.pinnable?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
context "initialization" do
|
15
|
+
it "sets @position" do
|
16
|
+
pin.position.should eql(:P8_13)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets @opts" do
|
20
|
+
pin = MockPin.new(:P8_13, foo: "bar")
|
21
|
+
pin.opts.should eql({foo: "bar"})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
context "mocking" do
|
27
|
+
it "sets mock when initialized with mock" do
|
28
|
+
pin = MockPin.new(:P8_13, mock: true)
|
29
|
+
pin.mock?.should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets no mock when not initialized with mock" do
|
33
|
+
pin = MockPin.new(:P8_13, mock: false)
|
34
|
+
pin.mock?.should be_false
|
35
|
+
|
36
|
+
pin = MockPin.new(:P8_13)
|
37
|
+
pin.mock?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "io" do
|
42
|
+
it "mock_io when mock given" do
|
43
|
+
pin = MockPin.new(:P8_13, mock: true)
|
44
|
+
pin.io.kind_of?(StringIO).should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "default_io when no mock given" do
|
48
|
+
lambda do
|
49
|
+
pin = MockPin.new(:P8_13, mock: false)
|
50
|
+
pin.io
|
51
|
+
end.should raise_error(NotImplementedError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "private methods" do
|
56
|
+
it "raises error on #default_io" do
|
57
|
+
lambda do
|
58
|
+
pin.send(:default_io)
|
59
|
+
end.should raise_error(NotImplementedError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns StringIO on #mock_io" do
|
63
|
+
StringIO.should_receive(:new).and_return("foo")
|
64
|
+
pin.send(:mock_io).should eql("foo")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::Pins::PWMPin do
|
4
|
+
let(:pin) { BBB::Pins::PWMPin.new(:P8_14, mock: true) }
|
5
|
+
|
6
|
+
it "includes pinnable" do
|
7
|
+
pin.pinnable?.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
%w(duty polarity period run).each do |method|
|
11
|
+
it "##{method}=(value) && ##{method}" do
|
12
|
+
pin.public_send("#{method}=", 123)
|
13
|
+
pin.public_send(method).should eql(123)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "##{method}=(value) converts to ints" do
|
17
|
+
pin.public_send("#{method}=", 123.123)
|
18
|
+
pin.public_send(method).should eql(123)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "private methods" do
|
23
|
+
it "should default to PWM" do
|
24
|
+
BBB::Pins::IO::PWM.should_receive(:new)
|
25
|
+
pin.send(:default_io)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: BBB
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -93,42 +93,39 @@ files:
|
|
93
93
|
- examples/light_switch.rb
|
94
94
|
- examples/sketches.rb
|
95
95
|
- lib/BBB.rb
|
96
|
-
- lib/BBB/adc/analog_pin.rb
|
97
|
-
- lib/BBB/adc/setup.rb
|
98
96
|
- lib/BBB/application.rb
|
99
|
-
- lib/BBB/board/base.rb
|
100
|
-
- lib/BBB/board/json_pin_mapper.rb
|
101
|
-
- lib/BBB/board/pin_mapper.rb
|
102
|
-
- lib/BBB/board/test_board.rb
|
103
97
|
- lib/BBB/circuit.rb
|
104
98
|
- lib/BBB/components/analog_component.rb
|
105
99
|
- lib/BBB/components/led.rb
|
106
100
|
- lib/BBB/components/pinnable.rb
|
101
|
+
- lib/BBB/components/servo.rb
|
107
102
|
- lib/BBB/exceptions.rb
|
108
|
-
- lib/BBB/
|
109
|
-
- lib/BBB/
|
110
|
-
- lib/BBB/
|
111
|
-
- lib/BBB/io/
|
112
|
-
- lib/BBB/io/
|
113
|
-
- lib/BBB/io/
|
114
|
-
- lib/BBB/io/
|
103
|
+
- lib/BBB/pins/analog_pin.rb
|
104
|
+
- lib/BBB/pins/digital_pin.rb
|
105
|
+
- lib/BBB/pins/io/ain.rb
|
106
|
+
- lib/BBB/pins/io/gpio.rb
|
107
|
+
- lib/BBB/pins/io/mapped.rb
|
108
|
+
- lib/BBB/pins/io/pin_mapper.rb
|
109
|
+
- lib/BBB/pins/io/pwm.rb
|
110
|
+
- lib/BBB/pins/pinnable.rb
|
111
|
+
- lib/BBB/pins/pwm_pin.rb
|
115
112
|
- lib/BBB/version.rb
|
116
113
|
- resources/pin_mappings.json
|
117
114
|
- resources/pin_mappings.json.comment
|
118
|
-
- spec/adc/analog_pin_spec.rb
|
119
|
-
- spec/adc/setup_spec.rb
|
120
115
|
- spec/application_spec.rb
|
121
|
-
- spec/board/board_spec.rb
|
122
|
-
- spec/board/pin_mapper_spec.rb
|
123
116
|
- spec/circuit_spec.rb
|
117
|
+
- spec/components/analog_component_spec.rb
|
124
118
|
- spec/components/led_spec.rb
|
125
119
|
- spec/components/pinnable_spec.rb
|
126
|
-
- spec/
|
127
|
-
- spec/
|
128
|
-
- spec/
|
129
|
-
- spec/
|
130
|
-
- spec/
|
131
|
-
- spec/io/
|
120
|
+
- spec/components/servo_spec.rb
|
121
|
+
- spec/pins/analog_pin_spec.rb
|
122
|
+
- spec/pins/digital_input_pin_spec.rb
|
123
|
+
- spec/pins/digital_output_pin_spec.rb
|
124
|
+
- spec/pins/digital_pin_spec.rb
|
125
|
+
- spec/pins/io/mapped_spec.rb
|
126
|
+
- spec/pins/io/pin_mapper_spec.rb
|
127
|
+
- spec/pins/pinnable_spec.rb
|
128
|
+
- spec/pins/pwm_pin_spec.rb
|
132
129
|
- spec/spec_helper.rb
|
133
130
|
homepage:
|
134
131
|
licenses:
|
@@ -145,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
142
|
version: '0'
|
146
143
|
segments:
|
147
144
|
- 0
|
148
|
-
hash: -
|
145
|
+
hash: -2248503626551464727
|
149
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
147
|
none: false
|
151
148
|
requirements:
|
@@ -154,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
151
|
version: '0'
|
155
152
|
segments:
|
156
153
|
- 0
|
157
|
-
hash: -
|
154
|
+
hash: -2248503626551464727
|
158
155
|
requirements: []
|
159
156
|
rubyforge_project:
|
160
157
|
rubygems_version: 1.8.25
|
@@ -162,18 +159,18 @@ signing_key:
|
|
162
159
|
specification_version: 3
|
163
160
|
summary: Helper functions to ruby around on the BeagleBone Black
|
164
161
|
test_files:
|
165
|
-
- spec/adc/analog_pin_spec.rb
|
166
|
-
- spec/adc/setup_spec.rb
|
167
162
|
- spec/application_spec.rb
|
168
|
-
- spec/board/board_spec.rb
|
169
|
-
- spec/board/pin_mapper_spec.rb
|
170
163
|
- spec/circuit_spec.rb
|
164
|
+
- spec/components/analog_component_spec.rb
|
171
165
|
- spec/components/led_spec.rb
|
172
166
|
- spec/components/pinnable_spec.rb
|
173
|
-
- spec/
|
174
|
-
- spec/
|
175
|
-
- spec/
|
176
|
-
- spec/
|
177
|
-
- spec/
|
178
|
-
- spec/io/
|
167
|
+
- spec/components/servo_spec.rb
|
168
|
+
- spec/pins/analog_pin_spec.rb
|
169
|
+
- spec/pins/digital_input_pin_spec.rb
|
170
|
+
- spec/pins/digital_output_pin_spec.rb
|
171
|
+
- spec/pins/digital_pin_spec.rb
|
172
|
+
- spec/pins/io/mapped_spec.rb
|
173
|
+
- spec/pins/io/pin_mapper_spec.rb
|
174
|
+
- spec/pins/pinnable_spec.rb
|
175
|
+
- spec/pins/pwm_pin_spec.rb
|
179
176
|
- spec/spec_helper.rb
|
data/lib/BBB/adc/analog_pin.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module BBB
|
2
|
-
module ADC
|
3
|
-
class AnalogPin
|
4
|
-
attr_reader :position, :pin_map, :mock
|
5
|
-
attr_reader :file_handle
|
6
|
-
|
7
|
-
def initialize(position, opts={})
|
8
|
-
self.position = position
|
9
|
-
@mock = opts.fetch(:mock, false)
|
10
|
-
@file_handle = get_file_handle(mock)
|
11
|
-
end
|
12
|
-
|
13
|
-
def position=(position)
|
14
|
-
map = Board::PinMapper.map(position, :ain)
|
15
|
-
unless map.respond_to?(:ain) && !map.ain.nil?
|
16
|
-
raise ArgumentError, "#{position} is not a valid AIN pin position"
|
17
|
-
end
|
18
|
-
|
19
|
-
@pin_map = map
|
20
|
-
@position = position
|
21
|
-
end
|
22
|
-
|
23
|
-
def ain_path
|
24
|
-
"/sys/devices/ocp.3/helper.15/AIN#{pin_map.ain}"
|
25
|
-
end
|
26
|
-
|
27
|
-
def read
|
28
|
-
file_handle.rewind
|
29
|
-
file_handle.read.to_i
|
30
|
-
end
|
31
|
-
|
32
|
-
def scale
|
33
|
-
pin_map.scale
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_file_handle(mock=false)
|
37
|
-
mock ? StringIO.new : File.open(ain_path, "r")
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|