pi_piper 1.9.9 → 2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,70 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
- require 'pi_piper.rb'
4
- require 'rspec'
5
- require 'mocha/api'
6
-
7
- include PiPiper
@@ -1,44 +0,0 @@
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
@@ -1,140 +0,0 @@
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