pi_piper 1.0.1 → 1.0.2
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/Manifest +1 -0
- data/README.md +16 -1
- data/Rakefile +2 -2
- data/lib/pi_piper/pin.rb +11 -4
- data/pi_piper.gemspec +1 -1
- metadata +1 -1
data/Manifest
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Sample usage:
|
|
9
9
|
require 'pi_piper'
|
10
10
|
|
11
11
|
PiPiper.watch :pin => 23 do |pin|
|
12
|
-
puts "Pin changed from #{pin.
|
12
|
+
puts "Pin changed from #{pin.last_value} to #{pin.value}"
|
13
13
|
end
|
14
14
|
|
15
15
|
PiPiper.wait
|
@@ -17,6 +17,21 @@ PiPiper.wait
|
|
17
17
|
|
18
18
|
Your block will be called when a change to the pin's state is detected.
|
19
19
|
|
20
|
+
Additionally you can use pins as output too:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
pin = PiPiper::Pin.new(:pin => 17, :direction => :out)
|
24
|
+
pin.on
|
25
|
+
sleep 1
|
26
|
+
pin.off
|
27
|
+
```
|
28
|
+
|
29
|
+
## Example projects
|
30
|
+
|
31
|
+
Looking for more examples/sample code for Pi Piper? Then check out the following example projects, complete with circuit diagrams:
|
32
|
+
|
33
|
+
* [Morse Code](https://github.com/jwhitehorn/pi_piper/wiki/Morse-Code)
|
34
|
+
|
20
35
|
## License
|
21
36
|
|
22
37
|
Copyright (c) 2013, [Jason Whitehorn](https://github.com/jwhitehorn)
|
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('pi_piper', '1.0.
|
5
|
+
Echoe.new('pi_piper', '1.0.2') 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"
|
9
9
|
p.email = "jason.whitehorn@gmail.com"
|
10
|
-
p.ignore_pattern = ["examples
|
10
|
+
p.ignore_pattern = ["examples/**/*"]
|
11
11
|
p.development_dependencies = []
|
12
12
|
end
|
13
13
|
|
data/lib/pi_piper/pin.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
module PiPiper
|
2
2
|
class Pin
|
3
|
-
attr_reader :pin, :last_value
|
3
|
+
attr_reader :pin, :last_value, :direction, :invert
|
4
4
|
|
5
5
|
def initialize(options)
|
6
6
|
@pin = options[:pin]
|
7
|
+
@direction = options[:direction].nil? ? :in : options[:direction]
|
8
|
+
@invert = options[:invert].nil? ? false : options[:invert]
|
9
|
+
|
10
|
+
File.open("/sys/class/gpio/export", "w") { |f| f.write("#{@pin}") }
|
11
|
+
File.open("/sys/class/gpio/gpio#{pin}/direction", "w") { |f| f.write(@direction == :out ? "out" : "in") }
|
12
|
+
|
7
13
|
@last_value = value
|
8
14
|
end
|
9
15
|
|
10
16
|
def on
|
11
|
-
File.open(filename, 'w') {|f| f.write("1") }
|
17
|
+
File.open(filename, 'w') {|f| f.write("1") } if direction == :out
|
12
18
|
end
|
13
19
|
|
14
20
|
def on?
|
@@ -16,7 +22,7 @@ module PiPiper
|
|
16
22
|
end
|
17
23
|
|
18
24
|
def off
|
19
|
-
File.open(filename, 'w') {|f| f.write("0") }
|
25
|
+
File.open(filename, 'w') {|f| f.write("0") } if direction == :out
|
20
26
|
end
|
21
27
|
|
22
28
|
def off?
|
@@ -28,7 +34,8 @@ module PiPiper
|
|
28
34
|
end
|
29
35
|
|
30
36
|
def value
|
31
|
-
File.read(filename).to_i
|
37
|
+
val = File.read(filename).to_i
|
38
|
+
invert ? (val ^ 1) : val
|
32
39
|
end
|
33
40
|
|
34
41
|
private
|
data/pi_piper.gemspec
CHANGED