pi_piper 1.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Overview
2
2
 
3
- pi_piper brings event driven programming to the Raspberry Pi's GPIO pins. To get started:
3
+ Pi Piper brings event driven programming to the Raspberry Pi's GPIO pins. To get started:
4
4
 
5
5
  sudo gem install pi_piper
6
6
 
@@ -30,7 +30,8 @@ pin.off
30
30
 
31
31
  Looking for more examples/sample code for Pi Piper? Then check out the following example projects, complete with circuit diagrams:
32
32
 
33
- * [Morse Code](https://github.com/jwhitehorn/pi_piper/wiki/Morse-Code)
33
+ * [Project 1: Morse Code](https://github.com/jwhitehorn/pi_piper/wiki/Project-1:-Morse-Code)
34
+ * [Project 2: Simple Switch](https://github.com/jwhitehorn/pi_piper/wiki/Project-2:-Simple-Switch)
34
35
 
35
36
  ## License
36
37
 
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.1') do |p|
5
+ Echoe.new('pi_piper', '1.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"
@@ -3,9 +3,14 @@ module PiPiper
3
3
  attr_reader :pin, :last_value, :value, :direction, :invert
4
4
 
5
5
  def initialize(options)
6
+ options = {:direction => :in, :invert => false, :trigger => :both}.merge options
6
7
  @pin = options[:pin]
7
- @direction = options[:direction].nil? ? :in : options[:direction]
8
- @invert = options[:invert].nil? ? false : options[:invert]
8
+ @direction = options[:direction]
9
+ @invert = options[:invert]
10
+ @trigger = options[:trigger]
11
+
12
+ raise "Invalid direction. Options are :in or :out" unless [:in, :out].include? @direction
13
+ raise "Invalid trigger. Options are :rising, :falling, or :both" unless [:rising, :falling, :both].include? @trigger
9
14
 
10
15
  File.open("/sys/class/gpio/export", "w") { |f| f.write("#{@pin}") }
11
16
  File.open(direction_file, "w") { |f| f.write(@direction == :out ? "out" : "in") }
@@ -18,7 +23,7 @@ module PiPiper
18
23
  end
19
24
 
20
25
  def on?
21
- value == 1
26
+ not off?
22
27
  end
23
28
 
24
29
  def off
@@ -28,6 +33,10 @@ module PiPiper
28
33
  def off?
29
34
  value == 0
30
35
  end
36
+
37
+ def update_value(new_value)
38
+ new_value ? on : off
39
+ end
31
40
 
32
41
  def changed?
33
42
  last_value != value
@@ -40,7 +49,11 @@ module PiPiper
40
49
  fd.read
41
50
  IO.select(nil, nil, [fd], nil)
42
51
  read
43
- break if changed?
52
+ if changed?
53
+ next if @trigger == :rising and value == 0
54
+ next if @trigger == :falling and value == 1
55
+ break
56
+ end
44
57
  end
45
58
  end
46
59
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pi_piper"
5
- s.version = "1.1"
5
+ s.version = "1.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-12"
9
+ s.date = "2013-01-15"
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.1'
4
+ version: 1.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 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Event driven Raspberry Pi GPIO library
15
15
  email: jason.whitehorn@gmail.com