pi_piper 2.0.beta.1 → 2.0.beta.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cecbad62bc8eeedf7e061bfc03396691f584ee82
4
- data.tar.gz: 5c22774ad6b6c737019baa7802c99934668f537a
3
+ metadata.gz: 14f0ac39d4e0f23013f42d657d6bc68ccca9433b
4
+ data.tar.gz: 3bb43ad2e9d6a72300f08990ca6b98850eae6026
5
5
  SHA512:
6
- metadata.gz: dac9621e23d30b021ead1b74f30496fedfa93474346bb1656fb5a9f1a882e7bedfbdff87c28e6b3b4c3c84adb39427599a37c1eedd3c9fde9f318c22e7e3d5c7
7
- data.tar.gz: 7167326e0245ee3a3272fc926298b94d7aa2b4e893c5b20f8ce5bb6a84414efca45bb5776adac1454a60f4e8f7c2eb4b3c9d792c623c5926ccbdfa006d89f008
6
+ metadata.gz: 9a1358e44e9a4648d132323dfcd24bb1494cc2a5e77145499e5292372c6e317659c507421e4aebc34926529b194760b55b1bfe5517997c8166179d3d5230f819
7
+ data.tar.gz: ce642bff726a8b60382ef781ca85b4097707bfe7f0154b6bb4f50cc442e838e4a8108b053583aa540578a082575b457dce7c303dfff0c51df0901b47cc2d58d5
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gem 'echoe'
4
4
  gem 'rake'
5
5
  gem 'ffi'
6
6
  gem 'rspec'
7
+ gem "eventmachine", "~> 1.0.3"
@@ -9,6 +9,7 @@ GEM
9
9
  rake (>= 0.9.2)
10
10
  rdoc (>= 3.6.1)
11
11
  rubyforge (>= 2.0.4)
12
+ eventmachine (1.0.3)
12
13
  ffi (1.4.0)
13
14
  gemcutter (0.7.1)
14
15
  json_pure (1.7.7)
@@ -30,6 +31,7 @@ PLATFORMS
30
31
 
31
32
  DEPENDENCIES
32
33
  echoe
34
+ eventmachine (~> 1.0.3)
33
35
  ffi
34
36
  rake
35
37
  rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## Overview
2
2
 
3
+ [![Build Status](https://travis-ci.org/jwhitehorn/pi_piper.png)](https://travis-ci.org/jwhitehorn/pi_piper)
4
+
3
5
  Pi Piper brings event driven programming to the Raspberry Pi's GPIO pins. Pi Piper works with all revisions of the Raspberry Pi,
4
6
  and has been tested with Ruby 1.9.3 & 2.0 under both [Raspbian "wheezy"](http://www.raspberrypi.org/downloads) and [Occidentalis v0.2](http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/occidentalis-v0-dot-2).
5
7
 
data/Rakefile CHANGED
@@ -5,15 +5,16 @@ require 'rake/testtask'
5
5
 
6
6
  #rake manifest
7
7
  #rake build_gemspec
8
- #rake release
8
+ #gem build pi_piper.gemspec
9
+ #gem push xxx.gem
9
10
 
10
- Echoe.new('pi_piper', '2.0.beta.1') do |p|
11
+ Echoe.new('pi_piper', '2.0.beta.3') do |p|
11
12
  p.description = "Event driven Raspberry Pi GPIO library"
12
13
  p.url = "http://github.com/jwhitehorn/pi_piper"
13
14
  p.author = "Jason Whitehorn"
14
15
  p.email = "jason.whitehorn@gmail.com"
15
16
  p.ignore_pattern = ["examples/**/*", "spec/**/*"]
16
- p.dependencies = ['ffi']
17
+ p.dependencies = ['ffi', 'eventmachine 1.0.3']
17
18
  end
18
19
 
19
20
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -1,4 +1,5 @@
1
- Dir[File.dirname(__FILE__) + '/pi_piper/*.rb'].each {|file| require file unless file.end_with?('bcm2835.rb') }
1
+ require 'eventmachine'
2
+ Dir[File.dirname(__FILE__) + '/pi_piper/*.rb'].each {|file| require file }#unless file.end_with?('bcm2835.rb') }
2
3
 
3
4
  module PiPiper
4
5
  extend self
@@ -32,8 +33,44 @@ module PiPiper
32
33
  options[:trigger] = options.delete(:goes) == :high ? :rising : :falling
33
34
  watch options, &block
34
35
  end
36
+
37
+ #Defines an event block to be called on a regular schedule. The block will be passed the slave output.
38
+ #
39
+ # @param [Hash] options A hash of options.
40
+ # @option options [Fixnum] :every A frequency of time (in seconds) to poll the SPI slave.
41
+ # @option options [Fixnum] :slave The slave number to poll.
42
+ # @option options [Number|Array] :write Data to poll the SPI slave with.
43
+ def poll_spi(options, &block)
44
+ EM::PeriodicTimer.new(options[:every]) do
45
+ Spi.begin options[:slave] do
46
+ output = write options[:write]
47
+ block.call output
48
+ end
49
+ end
50
+ end
51
+
52
+ #Defines an event block to be called when SPI slave output meets certain characteristics.
53
+ #The block will be passed the slave output.
54
+ #
55
+ # @param [Hash] options A hash of options.
56
+ # @option options [Fixnum] :every A frequency of time (in seconds) to poll the SPI slave.
57
+ # @option options [Fixnum] :slave The slave number to poll.
58
+ # @option options [Number|Array] :write Data to poll the SPI slave with.
59
+ # @option options [Fixnum] :eq Tests for SPI slave output equality.
60
+ # @option options [Fixnum] :lt Tests for SPI slave output less than supplied value.
61
+ # @option options [Fixnum] :gt Tests for SPI slave output greater than supplied value.
62
+ def when_spi(options, &block)
63
+ poll_spi options do |value|
64
+ if (options[:eq] && value == options[:eq]) ||
65
+ (options[:lt] && value < options[:lt]) ||
66
+ (options[:gt] && value > options[:gt])
67
+ block.call value
68
+ end
69
+ end
70
+ end
35
71
 
36
72
  #Prevents the main thread from exiting. Required when using PiPiper.watch
73
+ # @deprecated Please use EventMachine.run instead
37
74
  def wait
38
75
  loop do sleep 1 end
39
76
  end
@@ -32,9 +32,9 @@ module PiPiper
32
32
  File.open("/sys/class/gpio/gpio#{pin}/value", 'w') {|f| f.write("#{value}") }
33
33
  end
34
34
 
35
- def self.pin_output(pin)
35
+ def Bcm2835.pin_output(pin)
36
36
  File.open("/sys/class/gpio/export", "w") { |f| f.write("#{pin}") }
37
- File.open(direction_file, "w") { |f| f.write("out") }
37
+ File.open("/sys/class/gpio/gpio#{pin}/direction", "w") { |f| f.write("out") }
38
38
  end
39
39
 
40
40
  def self.pin_read(pin)
@@ -54,11 +54,11 @@ module PiPiper
54
54
  :bcm2835_spi_setChipSelectPolarity, [:uint8, :uint8], :void
55
55
 
56
56
  #I2C support...
57
- attach_function :i2c_begin, :bcm2835_i2c_begin, [], :void
58
- attach_function :i2c_end, :bcm2835_i2c_end, [], :void
59
- attach_function :i2c_write, :bcm2835_i2c_write, [:pointer, :uint], :uint8
60
- attach_function :i2c_set_address,:bcm2835_i2c_setSlaveAddress, [:uint8], :void
61
- attach_function :i2c_set_clock_divider, :bcm2835_i2c_setClockDivider, [:uint16], :void
57
+ #attach_function :i2c_begin, :bcm2835_i2c_begin, [], :void
58
+ #attach_function :i2c_end, :bcm2835_i2c_end, [], :void
59
+ #attach_function :i2c_write, :bcm2835_i2c_write, [:pointer, :uint], :uint8
60
+ #attach_function :i2c_set_address,:bcm2835_i2c_setSlaveAddress, [:uint8], :void
61
+ #attach_function :i2c_set_clock_divider, :bcm2835_i2c_setClockDivider, [:uint16], :void
62
62
 
63
63
  def self.i2c_allowed_clocks
64
64
  [100.kilohertz,
@@ -1,15 +1,17 @@
1
+ #require 'bcm2835.rb'
1
2
  module PiPiper
2
3
 
3
4
  #Hardware abstraction manager. Not intended for direct use.
4
5
  class Platform
6
+ @@driver = nil
5
7
 
6
8
  #gets the current platform driver. Defaults to BCM2835.
7
9
  def self.driver
8
10
  unless @@driver
9
- require 'bcm2835.rb'
11
+ #require 'bcm2835.rb'
10
12
  PiPiper::Bcm2835.init
11
13
  @@driver = PiPiper::Bcm2835
12
- at_exit { PiPiper::Bcm2835.close }
14
+ at_exit { Bcm2835.close }
13
15
  end
14
16
  @@driver
15
17
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pi_piper"
5
- s.version = "2.0.beta.1"
5
+ s.version = "2.0.beta.3"
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-09-06"
9
+ s.date = "2013-09-11"
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/bcm2835.rb", "lib/pi_piper/frequency.rb", "lib/pi_piper/i2c.rb", "lib/pi_piper/libbcm2835.img", "lib/pi_piper/pin.rb", "lib/pi_piper/platform.rb", "lib/pi_piper/spi.rb"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pi_piper", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "pi_piper"
18
- s.rubygems_version = "2.0.3"
18
+ s.rubygems_version = "2.0.0"
19
19
  s.summary = "Event driven Raspberry Pi GPIO library"
20
20
 
21
21
  if s.respond_to? :specification_version then
@@ -23,10 +23,13 @@ Gem::Specification.new do |s|
23
23
 
24
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
25
  s.add_runtime_dependency(%q<ffi>, [">= 0"])
26
+ s.add_runtime_dependency(%q<eventmachine>, ["= 1.0.3"])
26
27
  else
27
28
  s.add_dependency(%q<ffi>, [">= 0"])
29
+ s.add_dependency(%q<eventmachine>, ["= 1.0.3"])
28
30
  end
29
31
  else
30
32
  s.add_dependency(%q<ffi>, [">= 0"])
33
+ s.add_dependency(%q<eventmachine>, ["= 1.0.3"])
31
34
  end
32
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.beta.1
4
+ version: 2.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Whitehorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.3
27
41
  description: Event driven Raspberry Pi GPIO library
28
42
  email: jason.whitehorn@gmail.com
29
43
  executables: []
@@ -78,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
92
  version: '1.2'
79
93
  requirements: []
80
94
  rubyforge_project: pi_piper
81
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.0.0
82
96
  signing_key:
83
97
  specification_version: 4
84
98
  summary: Event driven Raspberry Pi GPIO library