BBB 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/Gemfile +2 -0
- data/examples/analog_pin.rb +31 -0
- data/examples/led.rb +1 -1
- data/examples/sketches.rb +2 -2
- data/lib/BBB/adc/analog_pin.rb +41 -0
- data/lib/BBB/adc/setup.rb +20 -0
- data/lib/BBB/board/base.rb +45 -0
- data/lib/BBB/board/json_pin_mapper.rb +203 -0
- data/lib/BBB/board/pin_mapper.rb +19 -0
- data/lib/BBB/board/test_board.rb +12 -0
- data/lib/BBB/exceptions.rb +0 -1
- data/lib/BBB/gpio/base.rb +2 -2
- data/lib/BBB/io/analog_pin.rb +23 -0
- data/lib/BBB/io/digital_pin.rb +4 -4
- data/lib/BBB/version.rb +1 -1
- data/lib/BBB.rb +11 -3
- data/resources/pin_mappings.json +1535 -0
- data/resources/pin_mappings.json.comment +14 -0
- data/spec/adc/analog_pin_spec.rb +100 -0
- data/spec/adc/setup_spec.rb +9 -0
- data/spec/application_spec.rb +1 -1
- data/spec/{board_spec.rb → board/board_spec.rb} +6 -6
- data/spec/{pin_mapper_spec.rb → board/pin_mapper_spec.rb} +4 -4
- metadata +21 -15
- data/lib/BBB/board.rb +0 -41
- data/lib/BBB/pin_mapper.rb +0 -84
- data/lib/BBB/test_board.rb +0 -11
@@ -0,0 +1,14 @@
|
|
1
|
+
//
|
2
|
+
// 2013-11-30
|
3
|
+
//
|
4
|
+
// pin_mappings.json edited from the original Bonescript pin mapping file,
|
5
|
+
// bone.js. The original can be found here:
|
6
|
+
// https://github.com/jadonk/bonescript/blob/9c72cfe66fed6b2a4810471d1d0cc0a333bc24eb/node_modules/bonescript/bone.js
|
7
|
+
//
|
8
|
+
// The changes are:
|
9
|
+
// * remove javascript stuff, and turn it into JSON
|
10
|
+
//
|
11
|
+
// The JSON has the following main keys:
|
12
|
+
// * pinIndex key
|
13
|
+
// * uarts key
|
14
|
+
// * i2c
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BBB::ADC::AnalogPin do
|
4
|
+
let(:pin) { BBB::ADC::AnalogPin.new(:P9_39, :mock=>true) }
|
5
|
+
let(:pin_class) { BBB::ADC::AnalogPin }
|
6
|
+
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
|
10
|
+
describe "mock" do
|
11
|
+
it "initializes mock" do
|
12
|
+
lambda{ pin }.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "gets a mock handle when initialized with mock" do
|
16
|
+
pin.file_handle.class.should eql(StringIO)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "saves the mock value in instance variable" do
|
20
|
+
pin.mock.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "the real deal" do
|
25
|
+
before :each do
|
26
|
+
pin_class.any_instance.should_receive(:ain_path).and_return("some/file")
|
27
|
+
File.should_receive(:open).with("some/file","r").and_return(StringIO.new("foo"))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets file handle" do
|
31
|
+
pin_class.new(:P9_39).file_handle.read.should eql("foo")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "saves the mock value in an instance variable" do
|
35
|
+
pin_class.new(:P9_39).mock.should_not be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "sets the pin position" do
|
40
|
+
pin_class.any_instance.should_receive(:'position=')
|
41
|
+
pin
|
42
|
+
end
|
43
|
+
|
44
|
+
it "fails when initializing a non AIN pin position" do
|
45
|
+
lambda{pin_class.new(:P8_2, :mock=>true)}.should raise_error(ArgumentError)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#get_file_handle" do
|
51
|
+
before :all do
|
52
|
+
@p = BBB::ADC::AnalogPin.new(:P9_39, :mock=>true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "gets mock handle with mock argument" do
|
56
|
+
handle = @p.get_file_handle(true)
|
57
|
+
handle.class.should eql(StringIO)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "gets a File handle if explicit no mock" do
|
61
|
+
File.should_receive(:open).and_return("file")
|
62
|
+
handle = @p.get_file_handle(false)
|
63
|
+
handle.should eql("file")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "gets a File by default" do
|
67
|
+
File.should_receive(:open).and_return("file")
|
68
|
+
handle = @p.get_file_handle
|
69
|
+
handle.should eql("file")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#position=" do
|
74
|
+
it "sets the instance variable position" do
|
75
|
+
pin.position = :P9_40
|
76
|
+
pin.instance_variable_get("@position").should eql(:P9_40)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "sets the pin_map variable" do
|
80
|
+
p = pin
|
81
|
+
p.position = :P9_40
|
82
|
+
p.instance_variable_get("@pin_map").ain.should eql(1)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "#read calls the file handle" do
|
87
|
+
p = pin
|
88
|
+
p.file_handle.should_receive(:read).and_return("bazinga")
|
89
|
+
p.read.should eql("bazinga")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "#ain_path calls the map" do
|
93
|
+
path = pin.ain_path
|
94
|
+
path.should eql("/sys/devices/ocp.3/helper.15/AIN0")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "#scale tells the scale" do
|
98
|
+
pin.scale.should eql(4096)
|
99
|
+
end
|
100
|
+
end
|
data/spec/application_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BBB::Board do
|
4
|
-
let(:bbb) {BBB::TestBoard.new}
|
3
|
+
describe BBB::Board::Base do
|
4
|
+
let(:bbb) {BBB::Board::TestBoard.new}
|
5
5
|
|
6
6
|
it "initializes with a converter" do
|
7
|
-
BBB::Board.should_not_receive(:pin_converter)
|
7
|
+
BBB::Board::Base.should_not_receive(:pin_converter)
|
8
8
|
converter = "SomeConverter"
|
9
|
-
board = BBB::Board.new(converter)
|
9
|
+
board = BBB::Board::Base.new(converter)
|
10
10
|
board.pin_converter.should eql(converter)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "initializes with a default configuration" do
|
14
|
-
BBB::Board.should_receive(:pin_converter) { 'Default Config' }
|
15
|
-
board = BBB::Board.new
|
14
|
+
BBB::Board::Base.should_receive(:pin_converter) { 'Default Config' }
|
15
|
+
board = BBB::Board::Base.new
|
16
16
|
end
|
17
17
|
|
18
18
|
context "setting pins" do
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BBB::PinMapper do
|
4
|
-
let(:mapper) { BBB::PinMapper }
|
3
|
+
describe BBB::Board::PinMapper do
|
4
|
+
let(:mapper) { BBB::Board::PinMapper }
|
5
5
|
|
6
6
|
it "should be able to map" do
|
7
|
-
mapper.map(:P8_3).should eql(38)
|
7
|
+
mapper.map(:P8_3).gpio.should eql(38)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should upcase" do
|
11
|
-
mapper.map(:p8_3).should eql(38)
|
11
|
+
mapper.map(:p8_3).gpio.should eql(38)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should raise an error when requesting an unknown pin" do
|
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.0.4
|
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
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -72,11 +72,17 @@ files:
|
|
72
72
|
- Gemfile
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
|
+
- examples/analog_pin.rb
|
75
76
|
- examples/led.rb
|
76
77
|
- examples/sketches.rb
|
77
78
|
- lib/BBB.rb
|
79
|
+
- lib/BBB/adc/analog_pin.rb
|
80
|
+
- lib/BBB/adc/setup.rb
|
78
81
|
- lib/BBB/application.rb
|
79
|
-
- lib/BBB/board.rb
|
82
|
+
- lib/BBB/board/base.rb
|
83
|
+
- lib/BBB/board/json_pin_mapper.rb
|
84
|
+
- lib/BBB/board/pin_mapper.rb
|
85
|
+
- lib/BBB/board/test_board.rb
|
80
86
|
- lib/BBB/circuit.rb
|
81
87
|
- lib/BBB/components/led.rb
|
82
88
|
- lib/BBB/components/pinnable.rb
|
@@ -84,14 +90,18 @@ files:
|
|
84
90
|
- lib/BBB/gpio/base.rb
|
85
91
|
- lib/BBB/gpio/digital_pin.rb
|
86
92
|
- lib/BBB/gpio/pin_converter.rb
|
93
|
+
- lib/BBB/io/analog_pin.rb
|
87
94
|
- lib/BBB/io/digital_pin.rb
|
88
95
|
- lib/BBB/io/mock_pin.rb
|
89
96
|
- lib/BBB/io/pinnable.rb
|
90
|
-
- lib/BBB/pin_mapper.rb
|
91
|
-
- lib/BBB/test_board.rb
|
92
97
|
- lib/BBB/version.rb
|
98
|
+
- resources/pin_mappings.json
|
99
|
+
- resources/pin_mappings.json.comment
|
100
|
+
- spec/adc/analog_pin_spec.rb
|
101
|
+
- spec/adc/setup_spec.rb
|
93
102
|
- spec/application_spec.rb
|
94
|
-
- spec/board_spec.rb
|
103
|
+
- spec/board/board_spec.rb
|
104
|
+
- spec/board/pin_mapper_spec.rb
|
95
105
|
- spec/circuit_spec.rb
|
96
106
|
- spec/components/led_spec.rb
|
97
107
|
- spec/components/pinnable_spec.rb
|
@@ -101,7 +111,6 @@ files:
|
|
101
111
|
- spec/io/digital_pin_spec.rb
|
102
112
|
- spec/io/mock_pin_spec.rb
|
103
113
|
- spec/io/pinnable_spec.rb
|
104
|
-
- spec/pin_mapper_spec.rb
|
105
114
|
- spec/spec_helper.rb
|
106
115
|
homepage:
|
107
116
|
licenses:
|
@@ -116,18 +125,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
125
|
- - ! '>='
|
117
126
|
- !ruby/object:Gem::Version
|
118
127
|
version: '0'
|
119
|
-
segments:
|
120
|
-
- 0
|
121
|
-
hash: -528572071664081392
|
122
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
129
|
none: false
|
124
130
|
requirements:
|
125
131
|
- - ! '>='
|
126
132
|
- !ruby/object:Gem::Version
|
127
133
|
version: '0'
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
hash: -528572071664081392
|
131
134
|
requirements: []
|
132
135
|
rubyforge_project:
|
133
136
|
rubygems_version: 1.8.25
|
@@ -135,8 +138,11 @@ signing_key:
|
|
135
138
|
specification_version: 3
|
136
139
|
summary: Helper functions to ruby around on the BeagleBone Black
|
137
140
|
test_files:
|
141
|
+
- spec/adc/analog_pin_spec.rb
|
142
|
+
- spec/adc/setup_spec.rb
|
138
143
|
- spec/application_spec.rb
|
139
|
-
- spec/board_spec.rb
|
144
|
+
- spec/board/board_spec.rb
|
145
|
+
- spec/board/pin_mapper_spec.rb
|
140
146
|
- spec/circuit_spec.rb
|
141
147
|
- spec/components/led_spec.rb
|
142
148
|
- spec/components/pinnable_spec.rb
|
@@ -146,5 +152,5 @@ test_files:
|
|
146
152
|
- spec/io/digital_pin_spec.rb
|
147
153
|
- spec/io/mock_pin_spec.rb
|
148
154
|
- spec/io/pinnable_spec.rb
|
149
|
-
- spec/pin_mapper_spec.rb
|
150
155
|
- spec/spec_helper.rb
|
156
|
+
has_rdoc:
|
data/lib/BBB/board.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module BBB
|
2
|
-
class Board
|
3
|
-
attr_reader :gpio, :pin_converter
|
4
|
-
|
5
|
-
def initialize(pin_converter=nil)
|
6
|
-
@pin_converter = pin_converter || self.class.pin_converter
|
7
|
-
@pins = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
##
|
11
|
-
# Define methods for a GPIO::PIN
|
12
|
-
#
|
13
|
-
def setup_pin(pin)
|
14
|
-
@pins[pin.position] = pin
|
15
|
-
|
16
|
-
metaclass = class << self; self; end
|
17
|
-
metaclass.class_eval do
|
18
|
-
define_method("p#{pin.position.to_s[1..-1]}") do
|
19
|
-
@pins[pin.position].read
|
20
|
-
end
|
21
|
-
|
22
|
-
define_method("p#{pin.position.to_s[1..-1]}=") do |value|
|
23
|
-
@pins[pin.position].write value
|
24
|
-
end if pin.mode == :output
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def connect_io_pin(pin)
|
29
|
-
gpio_pin = pin_converter.convert(pin)
|
30
|
-
pin.pin_io = gpio_pin
|
31
|
-
setup_pin(pin)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def self.pin_converter
|
37
|
-
GPIO::PinConverter.new
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
data/lib/BBB/pin_mapper.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module BBB
|
2
|
-
class PinMapper
|
3
|
-
##
|
4
|
-
# Thanks to artoo-beaglebone
|
5
|
-
# https://github.com/hybridgroup/artoo-beaglebone/blob/master/lib/artoo/adaptors/beaglebone.rb
|
6
|
-
#
|
7
|
-
PINS = {
|
8
|
-
:P8_3 => 38,
|
9
|
-
:P8_4 => 39,
|
10
|
-
:P8_5 => 34,
|
11
|
-
:P8_6 => 35,
|
12
|
-
:P8_7 => 66,
|
13
|
-
:P8_8 => 67,
|
14
|
-
:P8_9 => 69,
|
15
|
-
:P8_10 => 68,
|
16
|
-
:P8_11 => 45,
|
17
|
-
:P8_12 => 44,
|
18
|
-
:P8_13 => 23,
|
19
|
-
:P8_14 => 26,
|
20
|
-
:P8_15 => 47,
|
21
|
-
:P8_16 => 46,
|
22
|
-
:P8_17 => 27,
|
23
|
-
:P8_18 => 65,
|
24
|
-
:P8_19 => 22,
|
25
|
-
:P8_20 => 63,
|
26
|
-
:P8_21 => 62,
|
27
|
-
:P8_22 => 37,
|
28
|
-
:P8_23 => 36,
|
29
|
-
:P8_24 => 33,
|
30
|
-
:P8_25 => 32,
|
31
|
-
:P8_26 => 61,
|
32
|
-
:P8_27 => 86,
|
33
|
-
:P8_28 => 88,
|
34
|
-
:P8_29 => 87,
|
35
|
-
:P8_30 => 89,
|
36
|
-
:P8_31 => 10,
|
37
|
-
:P8_32 => 11,
|
38
|
-
:P8_33 => 9,
|
39
|
-
:P8_34 => 81,
|
40
|
-
:P8_35 => 8,
|
41
|
-
:P8_36 => 80,
|
42
|
-
:P8_37 => 78,
|
43
|
-
:P8_38 => 79,
|
44
|
-
:P8_39 => 76,
|
45
|
-
:P8_40 => 77,
|
46
|
-
:P8_41 => 74,
|
47
|
-
:P8_42 => 75,
|
48
|
-
:P8_43 => 72,
|
49
|
-
:P8_44 => 73,
|
50
|
-
:P8_45 => 70,
|
51
|
-
:P8_46 => 71,
|
52
|
-
:P9_11 => 30,
|
53
|
-
:P9_12 => 60,
|
54
|
-
:P9_13 => 31,
|
55
|
-
:P9_14 => 50,
|
56
|
-
:P9_15 => 48,
|
57
|
-
:P9_16 => 51,
|
58
|
-
:P9_17 => 5,
|
59
|
-
:P9_18 => 4,
|
60
|
-
:P9_19 => 13,
|
61
|
-
:P9_20 => 12,
|
62
|
-
:P9_21 => 3,
|
63
|
-
:P9_22 => 2,
|
64
|
-
:P9_23 => 49,
|
65
|
-
:P9_24 => 15,
|
66
|
-
:P9_25 => 117,
|
67
|
-
:P9_26 => 14,
|
68
|
-
:P9_27 => 115,
|
69
|
-
:P9_28 => 113,
|
70
|
-
:P9_29 => 111,
|
71
|
-
:P9_30 => 112,
|
72
|
-
:P9_31 => 110
|
73
|
-
}
|
74
|
-
attr_reader :pins
|
75
|
-
|
76
|
-
def self.map(pin_symbol)
|
77
|
-
begin
|
78
|
-
PINS.fetch(pin_symbol.upcase.to_sym)
|
79
|
-
rescue Exception => e
|
80
|
-
raise UnknownPinException, "Pin #{pin_symbol} could not be mapped"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|