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.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/Gemfile.lock +12 -42
- data/README.md +8 -38
- data/Rakefile +7 -8
- data/lib/pi_piper.rb +2 -41
- data/lib/pi_piper/bcm2835.rb +12 -46
- data/lib/pi_piper/i2c.rb +1 -4
- data/lib/pi_piper/libbcm2835.img +0 -0
- data/lib/pi_piper/pin.rb +43 -98
- data/lib/pi_piper/platform.rb +4 -6
- data/lib/pi_piper/spi.rb +15 -30
- data/pi_piper.gemspec +8 -19
- metadata +14 -99
- data/.gitignore +0 -4
- data/.rspec +0 -3
- data/.travis.yml +0 -8
- data/examples/2_bit_counter/2_bit_counter.rb +0 -22
- data/examples/7-segment/7-segment.rb +0 -37
- data/examples/dsl_switch/dsl_switch.rb +0 -15
- data/examples/mcp3008/circuit.png +0 -0
- data/examples/mcp3008/mcp3008.rb +0 -55
- data/examples/mcp3008_spi/mcp3008_spi.rb +0 -24
- data/examples/morse_code/circuit.png +0 -0
- data/examples/morse_code/morse_code.rb +0 -43
- data/examples/simple_switch/circuit.png +0 -0
- data/examples/simple_switch/simple_switch.rb +0 -10
- data/lib/pi_piper/libbcm2835.so +0 -0
- data/lib/pi_piper/pin_error.rb +0 -3
- data/lib/pi_piper/pin_values.rb +0 -10
- data/lib/pi_piper/stub_driver.rb +0 -107
- data/spec/i2c_spec.rb +0 -83
- data/spec/pin_spec.rb +0 -149
- data/spec/pull_mode_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -7
- data/spec/spi_spec.rb +0 -44
- data/spec/stub_driver_spec.rb +0 -140
data/spec/pull_mode_spec.rb
DELETED
@@ -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
|
data/spec/spec_helper.rb
DELETED
data/spec/spi_spec.rb
DELETED
@@ -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
|
data/spec/stub_driver_spec.rb
DELETED
@@ -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
|