pi_piper 1.3.2 → 1.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'Pi_Piper' do
4
+ before (:each) do
5
+ Platform.driver = StubDriver.new
6
+ end
7
+
8
+ let(:pin_up) do
9
+ PiPiper::Pin.new(pin: 17, direction: :in, pull: :up)
10
+ end
11
+ let(:pin_down) do
12
+ PiPiper::Pin.new(pin: 17, direction: :in, pull: :down)
13
+ end
14
+ let(:pin_off) do
15
+ PiPiper::Pin.new(pin: 17, direction: :in, pull: :off)
16
+ end
17
+ let(:pin_float) do
18
+ PiPiper::Pin.new(pin: 17, direction: :in, pull: :float)
19
+ end
20
+
21
+ describe 'when a pin is created' do
22
+ it 'should raise an error for invalid :pull values' do
23
+ expect { PiPiper::Pin.new(pin: 17, direction: :in, pull: :wth) }.to(
24
+ raise_error(RuntimeError))
25
+ end
26
+
27
+ it 'should restrict allowed :pull values' do
28
+ expect(pin_up.pull?).to eq(:up)
29
+ expect(pin_down.pull?).to eq(:down)
30
+ expect(pin_off.pull?).to eq(:off)
31
+ expect(pin_float.pull?).to eq(:off)
32
+ end
33
+
34
+ xit 'should not accept pulls when direction is :out' do
35
+ expect{ raise }.not_to raise_error(RuntimeError)
36
+ end
37
+
38
+ xit 'should not allow pull! when direction is :out' do
39
+ expect{ raise }.not_to raise_error(RuntimeError)
40
+ end
41
+
42
+ xit 'should not allow subsequent pull resistor changes when direction is :out' do
43
+ expect(true).to eq(false)
44
+ end
45
+
46
+ xit 'should allow subsequent pull resistor changes when direction is :in' do
47
+ expect(true).to eq(false)
48
+ end
49
+ end
50
+
51
+ describe 'when pull mode is set to up' do
52
+ before :each do
53
+ @pin = pin_up
54
+ end
55
+
56
+ it 'must respond HIGH when floating pins are checked' do
57
+ expect(@pin.on?).to be(true)
58
+ end
59
+ end
60
+
61
+ describe 'when pull mode is set to down' do
62
+ before :each do
63
+ @pin = pin_down
64
+ end
65
+
66
+ it 'must respond LOW when floating pins are checked' do
67
+ expect(@pin.off?).to be(true)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'pi_piper.rb'
4
+ require 'rspec'
5
+ require 'mocha/api'
6
+
7
+ include PiPiper
@@ -0,0 +1,44 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'Spi' do
4
+ describe 'when in block' do
5
+ it 'should call spi_begin' do
6
+ driver = StubDriver.new
7
+ expect(driver).to receive(:spi_begin)
8
+
9
+ Platform.driver = driver
10
+ Spi.begin do
11
+ end
12
+ end
13
+
14
+ it 'should call spi_chip_select to set and unset chip' do
15
+ driver = StubDriver.new
16
+ expect(driver).to receive(:spi_chip_select).with(Spi::CHIP_SELECT_1)
17
+ expect(driver).to receive(:spi_chip_select).with(Spi::CHIP_SELECT_NONE)
18
+
19
+ Platform.driver = driver
20
+ Spi.begin(Spi::CHIP_SELECT_1) do
21
+ read
22
+ end
23
+ end
24
+ end
25
+
26
+ describe 'set mode' do
27
+ it 'should call spi_set_data_mode' do
28
+ driver = StubDriver.new
29
+ expect(driver).to receive(:spi_set_data_mode).with(Spi::SPI_MODE3)
30
+
31
+ Platform.driver = driver
32
+ Spi.set_mode(1, 1)
33
+ end
34
+ end
35
+
36
+ describe '#spidev_out' do
37
+ it 'should attempt to write data to spi' do
38
+ driver = StubDriver.new
39
+ expect(driver).to receive(:spidev_out).with([0, 1, 2, 3, 4, 5])
40
+ Platform.driver = driver
41
+ Spi.spidev_out([0, 1, 2, 3, 4, 5])
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe StubDriver do
4
+ let(:stub_driver) { StubDriver.new }
5
+
6
+ before do
7
+ @logger = double
8
+ @driver = StubDriver.new(logger: @logger)
9
+ end
10
+
11
+ describe '#pin_input' do
12
+ it 'should set pin as input' do
13
+ stub_driver.pin_input(10)
14
+ expect(stub_driver.pin_direction(10)).to eq(:in)
15
+ end
16
+
17
+ it 'should log that pin is set' do
18
+ expect(@logger).to receive(:debug).with('Pin #10 -> Input')
19
+ @driver.pin_input(10)
20
+ end
21
+ end
22
+
23
+ describe '#pin_output' do
24
+ it 'should set pin as output' do
25
+ stub_driver.pin_output(10)
26
+ expect(stub_driver.pin_direction(10)).to eq(:out)
27
+ end
28
+
29
+ it 'should log that pin is set' do
30
+ expect(@logger).to receive(:debug).with('Pin #10 -> Output')
31
+ @driver.pin_output(10)
32
+ end
33
+ end
34
+
35
+ describe '#pin_set' do
36
+ it 'should set pin value' do
37
+ stub_driver.pin_set(22, 42)
38
+ expect(stub_driver.pin_read(22)).to eq(42)
39
+ end
40
+
41
+ it 'should log the new pin value' do
42
+ expect(@logger).to receive(:debug).with('Pin #21 -> 22')
43
+ @driver.pin_set(21, 22)
44
+ end
45
+ end
46
+
47
+ describe '#pin_set_pud' do
48
+ it 'should set pin value' do
49
+ stub_driver.pin_set_pud(12, Pin::GPIO_PUD_UP)
50
+ expect(stub_driver.pin_read(12)).to eq(Pin::GPIO_HIGH)
51
+ end
52
+
53
+ it 'should not overwrite set value' do
54
+ stub_driver.pin_set(12, 0)
55
+ stub_driver.pin_set_pud(12, Pin::GPIO_PUD_DOWN)
56
+ expect(stub_driver.pin_read(12)).to eq(Pin::GPIO_LOW)
57
+ end
58
+
59
+ it 'should log the new pin value' do
60
+ expect(@logger).to receive(:debug).with('PinPUD #21 -> 22')
61
+ @driver.pin_set_pud(21, 22)
62
+ end
63
+ end
64
+
65
+ describe '#spidev_out' do
66
+ it 'should log the array sent to ada_spi_out' do
67
+ expect(@logger).to receive(:debug).with("SPIDEV -> \u0000\u0001\u0002")
68
+ @driver.spidev_out([0x00, 0x01, 0x02])
69
+ end
70
+ end
71
+
72
+ describe '#spi_begin' do
73
+ it 'should should clear spi data' do
74
+ expect(@logger).to receive(:debug)
75
+ @driver.spi_transfer_bytes([0x01, 0x02])
76
+ expect(@logger).to receive(:debug).with('SPI Begin')
77
+ @driver.spi_begin
78
+ expect(@driver.send(:spi_data)).to eq([])
79
+ end
80
+ end
81
+
82
+ describe '#spi_transfer_bytes' do
83
+ it 'should log and store sent data' do
84
+ expect(@logger).to receive(:debug).with('SPI CS0 <- [1, 2, 3]')
85
+ @driver.spi_transfer_bytes([0x01, 0x02, 0x03])
86
+ expect(@driver.send(:spi_data)).to eq([0x01, 0x02, 0x03])
87
+ end
88
+ end
89
+
90
+ describe '#spi_chip_select' do
91
+ it 'should return default 0 if nothing provided' do
92
+ expect(@logger).to receive(:debug).with('SPI Chip Select = 0')
93
+ expect(@driver.spi_chip_select).to eq(0)
94
+ end
95
+
96
+ it 'should set chip select value if passed in' do
97
+ expect(@logger).to receive(:debug).with('SPI Chip Select = 3').twice
98
+ @driver.spi_chip_select(3)
99
+ expect(@driver.spi_chip_select).to eq(3)
100
+ end
101
+ end
102
+
103
+ describe '#reset' do
104
+ it 'should not reset unless asked' do
105
+ StubDriver.new()
106
+ StubDriver.pin_set(1,3)
107
+ expect(StubDriver.pin_read(1)).to eq(3)
108
+ StubDriver.reset
109
+ expect(StubDriver.pin_read(1)).to be_nil
110
+ end
111
+ end
112
+
113
+ describe '#release_pins' do
114
+ before(:each) do
115
+ StubDriver.new
116
+ StubDriver.pin_input(4)
117
+ StubDriver.pin_output(6)
118
+ end
119
+
120
+ it 'should keep track of open pins and release them' do
121
+ expect(@driver).to receive(:release_pin).with(4)
122
+ expect(@driver).to receive(:release_pin).with(6)
123
+
124
+ StubDriver.release_pins
125
+ end
126
+
127
+ it 'should remove released pins' do
128
+ StubDriver.release_pins
129
+
130
+ expect(StubDriver.pin_direction(4)).to be_nil
131
+ expect(StubDriver.pin_direction(6)).to be_nil
132
+ end
133
+
134
+ it 'should keep track of released pins' do
135
+ StubDriver.release_pins
136
+ expect(@driver).not_to receive(:release_pin)
137
+ StubDriver.release_pins
138
+ end
139
+ end
140
+ end
metadata CHANGED
@@ -1,27 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Whitehorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
25
81
  - !ruby/object:Gem::Version
26
82
  version: '0'
27
83
  description: Event driven Raspberry Pi GPIO library
@@ -32,46 +88,83 @@ extra_rdoc_files:
32
88
  - README.md
33
89
  - lib/pi_piper.rb
34
90
  - lib/pi_piper/bcm2835.rb
35
- - lib/pi_piper/libbcm2835.img
91
+ - lib/pi_piper/frequency.rb
92
+ - lib/pi_piper/i2c.rb
93
+ - lib/pi_piper/libbcm2835.so
36
94
  - lib/pi_piper/pin.rb
95
+ - lib/pi_piper/platform.rb
37
96
  - lib/pi_piper/spi.rb
38
97
  files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".travis.yml"
101
+ - Gemfile
102
+ - Gemfile.lock
39
103
  - Manifest
40
104
  - README.md
41
105
  - Rakefile
106
+ - examples/2_bit_counter/2_bit_counter.rb
107
+ - examples/7-segment/7-segment.rb
108
+ - examples/dsl_switch/dsl_switch.rb
109
+ - examples/mcp3008/circuit.png
110
+ - examples/mcp3008/mcp3008.rb
111
+ - examples/mcp3008_spi/mcp3008_spi.rb
112
+ - examples/morse_code/circuit.png
113
+ - examples/morse_code/morse_code.rb
114
+ - examples/simple_switch/circuit.png
115
+ - examples/simple_switch/simple_switch.rb
42
116
  - lib/pi_piper.rb
43
117
  - lib/pi_piper/bcm2835.rb
44
- - lib/pi_piper/libbcm2835.img
118
+ - lib/pi_piper/frequency.rb
119
+ - lib/pi_piper/i2c.rb
120
+ - lib/pi_piper/libbcm2835.so
45
121
  - lib/pi_piper/pin.rb
122
+ - lib/pi_piper/pin_error.rb
123
+ - lib/pi_piper/pin_values.rb
124
+ - lib/pi_piper/platform.rb
46
125
  - lib/pi_piper/spi.rb
126
+ - lib/pi_piper/stub_driver.rb
47
127
  - pi_piper.gemspec
128
+ - spec/i2c_spec.rb
129
+ - spec/pin_spec.rb
130
+ - spec/pull_mode_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/spi_spec.rb
133
+ - spec/stub_driver_spec.rb
48
134
  homepage: http://github.com/jwhitehorn/pi_piper
49
135
  licenses: []
50
136
  metadata: {}
51
137
  post_install_message:
52
138
  rdoc_options:
53
- - --line-numbers
54
- - --inline-source
55
- - --title
139
+ - "--line-numbers"
140
+ - "--inline-source"
141
+ - "--title"
56
142
  - Pi_piper
57
- - --main
143
+ - "--main"
58
144
  - README.md
59
145
  require_paths:
60
146
  - lib
61
147
  required_ruby_version: !ruby/object:Gem::Requirement
62
148
  requirements:
63
- - - '>='
149
+ - - ">="
64
150
  - !ruby/object:Gem::Version
65
151
  version: '0'
66
152
  required_rubygems_version: !ruby/object:Gem::Requirement
67
153
  requirements:
68
- - - '>='
154
+ - - ">="
69
155
  - !ruby/object:Gem::Version
70
156
  version: '1.2'
71
157
  requirements: []
72
158
  rubyforge_project: pi_piper
73
- rubygems_version: 2.0.0
159
+ rubygems_version: 2.4.5
74
160
  signing_key:
75
161
  specification_version: 4
76
162
  summary: Event driven Raspberry Pi GPIO library
77
- test_files: []
163
+ test_files:
164
+ - spec/i2c_spec.rb
165
+ - spec/pin_spec.rb
166
+ - spec/pull_mode_spec.rb
167
+ - spec/spec_helper.rb
168
+ - spec/spi_spec.rb
169
+ - spec/stub_driver_spec.rb
170
+ has_rdoc:
Binary file