pi_piper 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -2,4 +2,4 @@ Manifest
2
2
  README.md
3
3
  Rakefile
4
4
  lib/pi_piper.rb
5
- pi_piper.gemspec
5
+ lib/pi_piper/pin.rb
data/README.md CHANGED
@@ -0,0 +1,30 @@
1
+ ## Overview
2
+
3
+ pi_piper brings event driven programming to the Raspberry Pi's GPIO pins. To get started:
4
+
5
+ sudo gem install pi_piper
6
+
7
+ Sample usage:
8
+ ```ruby
9
+ require 'pi_piper'
10
+
11
+ PiPiper.watch :pin => 23 do |pin|
12
+ puts "Pin changed from #{pin.last_reading} to #{pin.reading}"
13
+ end
14
+
15
+ PiPiper.wait
16
+ ```
17
+
18
+ Your block will be called when a change to the pin's state is detected.
19
+
20
+ ## License
21
+
22
+ Copyright (c) 2013, [Jason Whitehorn](https://github.com/jwhitehorn)
23
+ All rights reserved.
24
+
25
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
26
+
27
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
28
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
29
+
30
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('pi_piper', '1.0') do |p|
5
+ Echoe.new('pi_piper', '1.0.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"
9
9
  p.email = "jason.whitehorn@gmail.com"
10
10
  p.ignore_pattern = ["examples/*"]
11
- p.development_dependencies = ['gpio']
11
+ p.development_dependencies = []
12
12
  end
13
13
 
14
14
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -1,19 +1,19 @@
1
- require 'gpio'
1
+ Dir[File.dirname(__FILE__) + '/pi_piper/*.rb'].each {|file| require file }
2
2
 
3
- class PiPiper
3
+ module PiPiper
4
4
 
5
- def self.watch(options)
5
+ def PiPiper.watch(options)
6
6
  Thread.new do
7
7
  loop do
8
8
  sleep_time = options[:poll] || 0.1
9
- pin = GPIO::InputPin.new(:pin => options[:pin])
9
+ pin = PiPiper::Pin.new(:pin => options[:pin])
10
10
  until pin.changed? do sleep sleep_time end
11
11
  yield pin
12
12
  end
13
13
  end.abort_on_exception = true
14
14
  end
15
15
 
16
- def self.wait
16
+ def PiPiper.wait
17
17
  loop do sleep 1 end
18
18
  end
19
19
 
@@ -0,0 +1,40 @@
1
+ module PiPiper
2
+ class Pin
3
+ attr_reader :pin, :last_value
4
+
5
+ def initialize(options)
6
+ @pin = options[:pin]
7
+ @last_value = value
8
+ end
9
+
10
+ def on
11
+ File.open(filename, 'w') {|f| f.write("1") }
12
+ end
13
+
14
+ def on?
15
+ value == 1
16
+ end
17
+
18
+ def off
19
+ File.open(filename, 'w') {|f| f.write("0") }
20
+ end
21
+
22
+ def off?
23
+ value == 0
24
+ end
25
+
26
+ def changed?
27
+ last_value != value
28
+ end
29
+
30
+ def value
31
+ File.read(filename).to_i
32
+ end
33
+
34
+ private
35
+ def filename
36
+ "/sys/class/gpio/gpio#{pin}/value"
37
+ end
38
+
39
+ end
40
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pi_piper"
5
- s.version = "1.0"
5
+ s.version = "1.0.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-10"
9
+ s.date = "2013-01-11"
10
10
  s.description = "Event driven Raspberry Pi GPIO library"
11
11
  s.email = "jason.whitehorn@gmail.com"
12
- s.extra_rdoc_files = ["README.md", "lib/pi_piper.rb"]
13
- s.files = ["Manifest", "README.md", "Rakefile", "lib/pi_piper.rb", "pi_piper.gemspec"]
12
+ s.extra_rdoc_files = ["README.md", "lib/pi_piper.rb", "lib/pi_piper/pin.rb"]
13
+ s.files = ["Manifest", "README.md", "Rakefile", "lib/pi_piper.rb", "lib/pi_piper/pin.rb", "pi_piper.gemspec"]
14
14
  s.homepage = "http://github.com/jwhitehorn/pi_piper"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pi_piper", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
@@ -22,11 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.specification_version = 3
23
23
 
24
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<gpio>, [">= 0"])
26
25
  else
27
- s.add_dependency(%q<gpio>, [">= 0"])
28
26
  end
29
27
  else
30
- s.add_dependency(%q<gpio>, [">= 0"])
31
28
  end
32
29
  end
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.0'
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: gpio
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
+ dependencies: []
30
14
  description: Event driven Raspberry Pi GPIO library
31
15
  email: jason.whitehorn@gmail.com
32
16
  executables: []
@@ -34,11 +18,13 @@ extensions: []
34
18
  extra_rdoc_files:
35
19
  - README.md
36
20
  - lib/pi_piper.rb
21
+ - lib/pi_piper/pin.rb
37
22
  files:
38
23
  - Manifest
39
24
  - README.md
40
25
  - Rakefile
41
26
  - lib/pi_piper.rb
27
+ - lib/pi_piper/pin.rb
42
28
  - pi_piper.gemspec
43
29
  homepage: http://github.com/jwhitehorn/pi_piper
44
30
  licenses: []