BBB 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe BBB::Circuit do
4
+ let(:circuit) {BBB::Circuit.new}
5
+ let(:c) { BBB::Circuit.new }
6
+ # You can't really avoid some integration testing here
7
+ let(:led) { BBB::Components::Led }
8
+
9
+ it "initializes" do
10
+ lambda{ BBB::Circuit.new }.should_not raise_exception
11
+ end
12
+
13
+ context "#attach" do
14
+ it "initializes object when passed a class" do
15
+ c.attach led, as: :led
16
+ c.components.values.first.class.should eql(led)
17
+ end
18
+
19
+ it "keeps instance when passed an instance" do
20
+ instance = led.new
21
+ c.attach instance, as: :instance
22
+ c.components.values.first.should eql(instance)
23
+ end
24
+
25
+ context "naming" do
26
+ it "downcases class names" do
27
+ l = led.new
28
+ c.attach l, as: :led
29
+ c.led.should eql(l)
30
+ c.components[:led].should eql(l)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ class TestAttachCircuit < BBB::Circuit
37
+ def initialize
38
+ attach BBB::Components::Led, pin: :P8_1, as: :led
39
+ end
40
+ end
41
+
42
+ it "knows about the attached led" do
43
+ circuit = TestAttachCircuit.new
44
+ circuit.respond_to?(:led).should be_true
45
+ end
46
+
47
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::Components::Led do
4
+ let(:led) {BBB::Components::Led.new}
5
+
6
+ it "initializes off" do
7
+ led.off?.should be_true
8
+ end
9
+
10
+ it "set state: on" do
11
+ led.on!
12
+ led.on?.should be_true
13
+ end
14
+
15
+ it "set state: off" do
16
+ led.on!
17
+ led.off!
18
+ led.off?.should be_true
19
+ end
20
+
21
+ it "check state: on?" do
22
+ led.off!
23
+ led.on!
24
+ led.on?.should be_true
25
+ end
26
+
27
+ it "provides access to state "do
28
+ led.on!
29
+ led.state.should eql(:high)
30
+ led.off!
31
+ led.state.should eql(:low)
32
+ end
33
+
34
+ context "#pinnable include" do
35
+ it "responds to pinnable actions" do
36
+ led.respond_to?(:register_pin_positions)
37
+ end
38
+
39
+ it "sets the right pin position" do
40
+ led.register_pin_positions(:P8_3)
41
+ led.pin.position.should eql(:P8_3)
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::Components::Pinnable do
4
+ class DummyComponent
5
+ include BBB::Components::Pinnable
6
+
7
+ def initialize
8
+ pin = Struct.new(:position)
9
+ @pins = [pin.new(0), pin.new(1)]
10
+ end
11
+ end
12
+
13
+ it "knows how to register pins" do
14
+ comp = DummyComponent.new
15
+ comp.register_pin_positions(:P8_3, :P8_4)
16
+ comp.pins[0].position.should eql(:P8_3)
17
+ comp.pins[1].position.should eql(:P8_4)
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::GPIO::Base do
4
+ let(:gpio_81) { BBB::GPIO::Base.new(:p8_3, mock: true) }
5
+ let(:gpio_base) { BBB::GPIO::Base.new(:p8_3, mock: true) }
6
+
7
+ context "Statics values" do
8
+ [:gpio_path, :gpio_direction_input, :gpio_direction_output,
9
+ :export_path, :unexport_path, :gpio_pin_dir].each do |method|
10
+
11
+ it "#{method.to_s}" do
12
+ gpio_base.public_send(method).should_not be_nil
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+ it "should be able to mock using StringIO" do
19
+ BBB::GPIO::Base.new(:p8_3, mock: true).file_class.should eql(StringIO)
20
+ end
21
+
22
+ # Temporarily disabled, because of inability to mock the call to the
23
+ # gpio files
24
+ xit "should default to File class" do
25
+ BBB::GPIO::Base.new(:p8_3).file_class.should eql(File)
26
+ end
27
+
28
+ # Temporarily disabled, because of inability to mock the call to the
29
+ # gpio files
30
+ xit "should be able to explicitly set non mock File class" do
31
+ BBB::GPIO::Base.new(:p8_3, mock: false).file_class.should eql(File)
32
+ end
33
+
34
+ it "should have a file_class" do
35
+ gpio_base.respond_to?(:file_class).should be_true
36
+ end
37
+
38
+ context "Filesystem functions" do
39
+ it "should export" do
40
+ gpio_81.export.should eql(2)
41
+ end
42
+
43
+ it "should unexport" do
44
+ gpio_81.unexport.should eql(2)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::GPIO::DigitalPin do
4
+ let(:digital_pin) { BBB::GPIO::DigitalPin }
5
+ let(:input_pin) { BBB::GPIO::DigitalPin.new(:p8_9, :input, mock: true) }
6
+ let(:output_pin) { BBB::GPIO::DigitalPin.new(:p8_3, :output, mock: true) }
7
+
8
+ it "should initialize with a pin number and mode" do
9
+ lambda{ input_pin }.should_not raise_exception
10
+ end
11
+
12
+ it "should set the pin number" do
13
+ input_pin.position.should eql(:p8_9)
14
+ end
15
+
16
+ it "should set the mode" do
17
+ input_pin.mode.should eql(:input)
18
+ end
19
+
20
+ it "initialize with unknown mode pin raises exception" do
21
+ lambda{ digital_pin.new(:p8_3, "unknown", mock: true) }.should\
22
+ raise_exception(BBB::UnknownPinModeException)
23
+ end
24
+
25
+ context "direction" do
26
+ it "input pin" do
27
+ pin = input_pin
28
+ pin.direction.should eql(pin.gpio_direction_input)
29
+ end
30
+
31
+ it "output pin" do
32
+ pin = output_pin
33
+ pin.direction.should eql(pin.gpio_direction_output)
34
+ end
35
+ end
36
+
37
+ context "#set mode" do
38
+ ##
39
+ # Temporarily disabled because of inability to catch results of
40
+ # StringIO.open. Possible solution is factoring out the direction_file
41
+ # argument and then use a real file system call to a different file to test
42
+ # this.
43
+ xit "should set input mode" do
44
+ pin = input_pin
45
+ pin.set_mode.string.should eql(pin.direction.size)
46
+ end
47
+
48
+ ##
49
+ # Temporarily disabled because of inability to catch results of
50
+ # StringIO.open. Possible solution is factoring out the direction_file
51
+ # argument and then use a real file system call to a different file to test
52
+ # this.
53
+ xit "should set output mode" do
54
+ pin = output_pin
55
+ pin.set_mode.string.should eql(pin.direction.size)
56
+ end
57
+ end
58
+
59
+ it "#io input" do
60
+ pin = input_pin
61
+ StringIO.should_receive(:open).with(anything, "r")
62
+ pin.io
63
+ end
64
+
65
+ it "#io output" do
66
+ pin = output_pin
67
+ StringIO.should_receive(:open).with(anything, "w+")
68
+ pin.io
69
+ end
70
+
71
+ it "should not call the io file twice" do
72
+ pin = output_pin
73
+ StringIO.should_receive(:open).with(anything, "w+").once.and_return("foo")
74
+ pin.io; pin.io
75
+ end
76
+
77
+ it "should write :low as 0 to io" do
78
+ pin = output_pin
79
+ pin.io.should_receive(:write).with(0)
80
+ pin.write(:low)
81
+ end
82
+
83
+ it "should write :high as 1 to io" do
84
+ pin = output_pin
85
+ pin.io.should_receive(:write).with(1)
86
+ pin.write(:high)
87
+ end
88
+
89
+ it "should read 1 as :high from io" do
90
+ pin = output_pin
91
+ pin.io.should_receive(:read).and_return(1)
92
+ pin.read.should eql(:high)
93
+ end
94
+
95
+ it "should read 0 as :low from io" do
96
+ pin = output_pin
97
+ pin.io.should_receive(:read).and_return(0)
98
+ pin.read.should eql(:low)
99
+ end
100
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::GPIO::PinConverter do
4
+ let(:converter) { BBB::GPIO::PinConverter.new }
5
+
6
+ it "converts DigitalPin input to DigitalPin" do
7
+ pin = BBB::IO::DigitalPin.new(:input, nil, :P8_3)
8
+ result = converter.convert(pin, mock: true)
9
+ result.kind_of?(BBB::GPIO::DigitalPin).should be_true
10
+ result.mode.should eql(:input)
11
+ end
12
+
13
+ it "converts DigitalPin output to DigitalPin" do
14
+ pin = BBB::IO::DigitalPin.new(:output, nil, :P8_3)
15
+ result = converter.convert(pin, mock: true)
16
+ result.kind_of?(BBB::GPIO::DigitalPin).should be_true
17
+ result.mode.should eql(:output)
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::IO::DigitalPin do
4
+ let(:pin) { BBB::IO::DigitalPin.new }
5
+ it "should initialize" do
6
+ lambda do
7
+ BBB::IO::DigitalPin.new
8
+ end.should_not raise_exception
9
+ end
10
+
11
+ it "should respond to register_position" do
12
+ pin.respond_to?(:'position=').should be_true
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::IO::MockPin do
4
+ let(:pin) {BBB::IO::MockPin.new}
5
+
6
+ it "responds to read" do
7
+ pin.respond_to?(:read)
8
+ end
9
+
10
+ it "responds to write" do
11
+ pin.respond_to?(:write)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::IO::Pinnable do
4
+ class TestPin
5
+ include BBB::IO::Pinnable
6
+ end
7
+
8
+ it "registers positions" do
9
+ pin = TestPin.new
10
+ pin.position=:P8_3
11
+ pin.position.should eql(:P8_3)
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::PinMapper do
4
+ let(:mapper) { BBB::PinMapper }
5
+
6
+ it "should be able to map" do
7
+ mapper.map(:P8_3).should eql(38)
8
+ end
9
+
10
+ it "should upcase" do
11
+ mapper.map(:p8_3).should eql(38)
12
+ end
13
+
14
+ it "should raise an error when requesting an unknown pin" do
15
+ lambda{ mapper.map(:P10_1) }.should raise_exception(BBB::UnknownPinException)
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'BBB'
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.0.1
4
+ version: 0.0.2
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: 2013-10-14 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,13 +60,42 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - .travis.yml
63
64
  - BBB.gemspec
64
65
  - Gemfile
65
- - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
+ - examples/led.rb
69
+ - examples/sketches.rb
68
70
  - lib/BBB.rb
71
+ - lib/BBB/application.rb
72
+ - lib/BBB/board.rb
73
+ - lib/BBB/circuit.rb
74
+ - lib/BBB/components/led.rb
75
+ - lib/BBB/components/pinnable.rb
76
+ - lib/BBB/exceptions.rb
77
+ - lib/BBB/gpio/base.rb
78
+ - lib/BBB/gpio/digital_pin.rb
79
+ - lib/BBB/gpio/pin_converter.rb
80
+ - lib/BBB/io/digital_pin.rb
81
+ - lib/BBB/io/mock_pin.rb
82
+ - lib/BBB/io/pinnable.rb
83
+ - lib/BBB/pin_mapper.rb
84
+ - lib/BBB/test_board.rb
69
85
  - lib/BBB/version.rb
86
+ - spec/application_spec.rb
87
+ - spec/board_spec.rb
88
+ - spec/circuit_spec.rb
89
+ - spec/components/led_spec.rb
90
+ - spec/components/pinnable_spec.rb
91
+ - spec/gpio/base_spec.rb
92
+ - spec/gpio/digital_pin_spec.rb
93
+ - spec/gpio/pin_converter_spec.rb
94
+ - spec/io/digital_pin_spec.rb
95
+ - spec/io/mock_pin_spec.rb
96
+ - spec/io/pinnable_spec.rb
97
+ - spec/pin_mapper_spec.rb
98
+ - spec/spec_helper.rb
70
99
  homepage:
71
100
  licenses:
72
101
  - MIT
@@ -91,4 +120,17 @@ rubygems_version: 2.0.3
91
120
  signing_key:
92
121
  specification_version: 4
93
122
  summary: Helper functions to ruby around on the BeagleBone Black
94
- test_files: []
123
+ test_files:
124
+ - spec/application_spec.rb
125
+ - spec/board_spec.rb
126
+ - spec/circuit_spec.rb
127
+ - spec/components/led_spec.rb
128
+ - spec/components/pinnable_spec.rb
129
+ - spec/gpio/base_spec.rb
130
+ - spec/gpio/digital_pin_spec.rb
131
+ - spec/gpio/pin_converter_spec.rb
132
+ - spec/io/digital_pin_spec.rb
133
+ - spec/io/mock_pin_spec.rb
134
+ - spec/io/pinnable_spec.rb
135
+ - spec/pin_mapper_spec.rb
136
+ - spec/spec_helper.rb
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Wilco van Duinkerken
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.