Skip to content

Commit c7b7a01

Browse files
committed
Removed current changes to #pin_wait_for, will move into another branch. Removed commented out driver line and added a placeholder in the spec_helper until 3.0 PiPiper is released
1 parent 80ffa73 commit c7b7a01

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

lib/pi_piper/sysfs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
require 'pi_piper/sysfs/driver'
44

55
module PiPiper
6-
self.driver = PiPiper::Sysfs::Driver.new
6+
self.driver = PiPiper::Sysfs::Driver
77
end

lib/pi_piper/sysfs/driver.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'filewatcher'
2-
31
module PiPiper
42
module Sysfs
53
class Driver < PiPiper::Driver
@@ -47,15 +45,21 @@ def pin_set_trigger(pin, trigger)
4745

4846
def pin_wait_for(pin, trigger)
4947
pin_set_trigger(pin, trigger)
50-
value = pin_read(pin)
51-
52-
FileWatcher.new([value_file(pin)]).watch do |filename, event|
53-
next unless event == :changed || event == :new
54-
next unless pin_value_changed?(pin, trigger, value)
55-
break
48+
fd = File.open(value_file(pin), 'r')
49+
value = nil
50+
51+
loop do
52+
fd.read
53+
IO.select(nil, nil, [fd], nil)
54+
last_value = value
55+
value = self.pin_read(pin)
56+
if last_value != value
57+
next if trigger == :rising and value == 0
58+
next if trigger == :falling and value == 1
59+
break
60+
end
5661
end
5762

58-
true
5963
end
6064

6165
# Specific behaviours

pi_piper-sysfs.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
2424
spec.require_paths = ["lib/pi_piper"]
2525

2626
spec.add_runtime_dependency 'pi_piper', ">= 2.0.0"
27-
spec.add_runtime_dependency 'filewatcher', '~> 0.5.3'
2827

2928
spec.add_development_dependency "bundler", "~> 1.11"
3029
spec.add_development_dependency "rake", "~> 10.0"

spec/pi_piper/sysfs/driver_spec.rb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
describe PiPiper::Sysfs::Driver do
22
let(:pins) { '@exported_pins' }
3-
let(:filewatcher) { double('FileWatcher') }
43

54
before(:each) do
65
allow(File).to receive(:write).with('/sys/class/gpio/export', 4)
@@ -143,24 +142,8 @@
143142
end
144143
end
145144

146-
describe '#pin_wait_for' do
147-
before(:each) do
148-
subject.pin_direction(4, :in)
149-
allow(filewatcher).to receive(:watch).and_yield('', :new)
150-
allow(FileWatcher).to receive(:new).and_return(filewatcher)
151-
end
152-
153-
it 'should wait for pin to trigger :rising' do
154-
expect(subject).to receive(:pin_set_trigger).with(4, :rising)
155-
allow(subject).to receive(:pin_read).with(4).and_return(0, 1)
156-
expect(subject.pin_wait_for(4, :rising)).to be(true)
157-
end
158-
159-
it 'should wait for pin to trigger :falling' do
160-
expect(subject).to receive(:pin_set_trigger).with(4, :falling)
161-
allow(subject).to receive(:pin_read).with(4).and_return(1, 0)
162-
expect(subject.pin_wait_for(4, :falling)).to be(true)
163-
end
145+
xdescribe '#pin_wait_for' do
146+
164147
end
165148

166149
describe '#close' do

spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module PiPiper
2+
def self.driver=(driver)
3+
# Placeholder for testing, PiPiper 3.0 contains this so we can remove
4+
end
5+
end
6+
17
require 'pi_piper'
28
require 'simplecov'
39
SimpleCov.start

0 commit comments

Comments
 (0)