pi_piper 1.0.2 → 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/pi_piper.rb +2 -3
- data/lib/pi_piper/pin.rb +30 -10
- data/pi_piper.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('pi_piper', '1.
|
5
|
+
Echoe.new('pi_piper', '1.1') do |p|
|
6
6
|
p.description = "Event driven Raspberry Pi GPIO library"
|
7
7
|
p.url = "http://github.com/jwhitehorn/pi_piper"
|
8
8
|
p.author = "Jason Whitehorn"
|
data/lib/pi_piper.rb
CHANGED
@@ -4,10 +4,9 @@ module PiPiper
|
|
4
4
|
|
5
5
|
def PiPiper.watch(options)
|
6
6
|
Thread.new do
|
7
|
+
pin = PiPiper::Pin.new(options)
|
7
8
|
loop do
|
8
|
-
|
9
|
-
pin = PiPiper::Pin.new(:pin => options[:pin])
|
10
|
-
until pin.changed? do sleep sleep_time end
|
9
|
+
pin.wait_for_change
|
11
10
|
yield pin
|
12
11
|
end
|
13
12
|
end.abort_on_exception = true
|
data/lib/pi_piper/pin.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module PiPiper
|
2
2
|
class Pin
|
3
|
-
attr_reader :pin, :last_value, :direction, :invert
|
3
|
+
attr_reader :pin, :last_value, :value, :direction, :invert
|
4
4
|
|
5
5
|
def initialize(options)
|
6
6
|
@pin = options[:pin]
|
7
7
|
@direction = options[:direction].nil? ? :in : options[:direction]
|
8
8
|
@invert = options[:invert].nil? ? false : options[:invert]
|
9
|
-
|
9
|
+
|
10
10
|
File.open("/sys/class/gpio/export", "w") { |f| f.write("#{@pin}") }
|
11
|
-
File.open(
|
11
|
+
File.open(direction_file, "w") { |f| f.write(@direction == :out ? "out" : "in") }
|
12
12
|
|
13
|
-
|
13
|
+
read
|
14
14
|
end
|
15
15
|
|
16
16
|
def on
|
17
|
-
File.open(
|
17
|
+
File.open(value_file, 'w') {|f| f.write("1") } if direction == :out
|
18
18
|
end
|
19
19
|
|
20
20
|
def on?
|
@@ -22,7 +22,7 @@ module PiPiper
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def off
|
25
|
-
File.open(
|
25
|
+
File.open(value_file, 'w') {|f| f.write("0") } if direction == :out
|
26
26
|
end
|
27
27
|
|
28
28
|
def off?
|
@@ -32,16 +32,36 @@ module PiPiper
|
|
32
32
|
def changed?
|
33
33
|
last_value != value
|
34
34
|
end
|
35
|
+
|
36
|
+
def wait_for_change
|
37
|
+
fd = File.open(value_file, "r")
|
38
|
+
File.open(edge_file, "w") { |f| f.write("both") }
|
39
|
+
loop do
|
40
|
+
fd.read
|
41
|
+
IO.select(nil, nil, [fd], nil)
|
42
|
+
read
|
43
|
+
break if changed?
|
44
|
+
end
|
45
|
+
end
|
35
46
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
47
|
+
def read
|
48
|
+
@last_value = @value
|
49
|
+
val = File.read(value_file).to_i
|
50
|
+
@value = invert ? (val ^ 1) : val
|
39
51
|
end
|
40
52
|
|
41
53
|
private
|
42
|
-
def
|
54
|
+
def value_file
|
43
55
|
"/sys/class/gpio/gpio#{pin}/value"
|
44
56
|
end
|
57
|
+
|
58
|
+
def edge_file
|
59
|
+
"/sys/class/gpio/gpio#{pin}/edge"
|
60
|
+
end
|
61
|
+
|
62
|
+
def direction_file
|
63
|
+
"/sys/class/gpio/gpio#{pin}/direction"
|
64
|
+
end
|
45
65
|
|
46
66
|
end
|
47
67
|
end
|
data/pi_piper.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "pi_piper"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jason Whitehorn"]
|
9
|
-
s.date = "2013-01-
|
9
|
+
s.date = "2013-01-12"
|
10
10
|
s.description = "Event driven Raspberry Pi GPIO library"
|
11
11
|
s.email = "jason.whitehorn@gmail.com"
|
12
12
|
s.extra_rdoc_files = ["README.md", "lib/pi_piper.rb", "lib/pi_piper/pin.rb"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pi_piper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Event driven Raspberry Pi GPIO library
|
15
15
|
email: jason.whitehorn@gmail.com
|