pi_piper 1.9.9 → 2.0.beta.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.
@@ -2,18 +2,14 @@ module PiPiper
2
2
 
3
3
  #Hardware abstraction manager. Not intended for direct use.
4
4
  class Platform
5
- @@driver = nil
6
5
 
7
6
  #gets the current platform driver. Defaults to BCM2835.
8
7
  def self.driver
9
8
  unless @@driver
10
- require 'pi_piper/bcm2835'
9
+ require 'bcm2835.rb'
11
10
  PiPiper::Bcm2835.init
12
11
  @@driver = PiPiper::Bcm2835
13
- at_exit do
14
- Bcm2835.release_pins
15
- Bcm2835.close
16
- end
12
+ at_exit { PiPiper::Bcm2835.close }
17
13
  end
18
14
  @@driver
19
15
  end
@@ -21,5 +17,7 @@ module PiPiper
21
17
  def self.driver=(instance)
22
18
  @@driver = instance
23
19
  end
20
+
24
21
  end
22
+
25
23
  end
@@ -28,6 +28,9 @@
28
28
  #++
29
29
 
30
30
 
31
+
32
+
33
+
31
34
  module PiPiper
32
35
  # class for SPI interfaces on the Raspberry Pi
33
36
  class Spi
@@ -45,24 +48,18 @@ module PiPiper
45
48
  # No CS, control it yourself
46
49
  CHIP_SELECT_NONE = 3
47
50
 
48
- # SPI Modes
49
- SPI_MODE0 = 0
50
- SPI_MODE1 = 1
51
- SPI_MODE2 = 2
52
- SPI_MODE3 = 3
53
-
54
51
  #Sets the SPI mode. Defaults to mode (0,0).
55
52
  def self.set_mode(cpol, cpha)
56
53
  mode = SPI_MODE0 #default
57
54
  mode = SPI_MODE1 if cpol == 0 and cpha == 1
58
55
  mode = SPI_MODE2 if cpol == 1 and cpha == 0
59
56
  mode = SPI_MODE3 if cpol == 1 and cpha == 1
60
- Platform.driver.spi_set_data_mode mode
57
+ Bcm2835.spi_set_data_mode mode
61
58
  end
62
59
 
63
60
  #Begin an SPI block. All SPI communications should be wrapped in a block.
64
61
  def self.begin(chip=nil, &block)
65
- Platform.driver.spi_begin
62
+ Bcm2835.spi_begin
66
63
  chip = CHIP_SELECT_0 if !chip && block_given?
67
64
  spi = new(chip)
68
65
 
@@ -75,19 +72,7 @@ module PiPiper
75
72
 
76
73
  # Not needed when #begin is called with a block
77
74
  def self.end
78
- Platform.driver.spi_end
79
- end
80
-
81
- # Uses /dev/spidev0.0 to write to the SPI
82
- # NOTE: Requires that you have /dev/spidev0.0
83
- # see: http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/overview
84
- # most likely requires `chmod 666 /dev/spidev0.0`
85
- #
86
- # @example Writing red, green, blue to a string of WS2801 pixels
87
- # PiPiper::Spi.spidev_out([255,0,0,0,255,0,0,0,255])
88
- #
89
- def self.spidev_out(array)
90
- Platform.driver.spidev_out(array)
75
+ Bcm2835.spi_end
91
76
  end
92
77
 
93
78
  # Sets the SPI clock frequency
@@ -107,7 +92,7 @@ module PiPiper
107
92
  20000000 => 16 #20 MHz
108
93
  }
109
94
  divider = options[frequency]
110
- Platform.driver.spi_clock(divider)
95
+ Bcm2835.spi_clock(divider)
111
96
  end
112
97
 
113
98
  def bit_order(order=MSBFIRST)
@@ -119,7 +104,7 @@ module PiPiper
119
104
  end
120
105
  end
121
106
 
122
- Platform.driver.spi_bit_order(order)
107
+ Bcm2835.spi_bit_order(order)
123
108
  end
124
109
 
125
110
  # Activate a specific chip so that communication can begin
@@ -141,13 +126,13 @@ module PiPiper
141
126
  # @yield
142
127
  # @param [optional, CHIP_SELECT_*] chip the chip select line options
143
128
  def chip_select(chip=CHIP_SELECT_0)
144
- chip = @chip if @chip
145
- Platform.driver.spi_chip_select(chip)
129
+ chip = @chip if @chip
130
+ Bcm2835.spi_chip_select(chip)
146
131
  if block_given?
147
132
  begin
148
133
  yield
149
134
  ensure
150
- Platform.driver.spi_chip_select(CHIP_SELECT_NONE)
135
+ Bcm2835.spi_chip_select(CHIP_SELECT_NONE)
151
136
  end
152
137
  end
153
138
  end
@@ -166,7 +151,7 @@ module PiPiper
166
151
  chip = @chip if @chip
167
152
  chip = CHIP_SELECT_0 unless chip
168
153
 
169
- Platform.driver.spi_chip_select_polarity(chip, active_low ? 0 : 1)
154
+ Bcm2835.spi_chip_select_polarity(chip, active_low ? 0 : 1)
170
155
  end
171
156
 
172
157
  # Read from the bus
@@ -186,7 +171,7 @@ module PiPiper
186
171
  if count
187
172
  write([0xFF] * count)
188
173
  else
189
- enable { Platform.driver.spi_transfer(0) }
174
+ enable { Bcm2835.spi_transfer(0) }
190
175
  end
191
176
  end
192
177
 
@@ -212,9 +197,9 @@ module PiPiper
212
197
  enable do
213
198
  case data
214
199
  when Numeric
215
- Platform.driver.spi_transfer(data)
200
+ Bcm2835.spi_transfer(data)
216
201
  when Enumerable
217
- Platform.driver.spi_transfer_bytes(data)
202
+ Bcm2835.spi_transfer_bytes(data)
218
203
  else
219
204
  raise ArgumentError.new("#{data.class} is not valid data. Use Numeric or an Enumerable of numbers")
220
205
  end
@@ -1,43 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'pi_piper/version'
1
+ # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "pi_piper"
8
- s.version = PiPiper::VERSION
5
+ s.version = "2.0.beta.1"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Jason Whitehorn"]
12
- s.date = "2013-09-14"
9
+ s.date = "2013-09-06"
13
10
  s.description = "Event driven Raspberry Pi GPIO library"
14
11
  s.email = "jason.whitehorn@gmail.com"
15
- 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.so", "lib/pi_piper/pin.rb", "lib/pi_piper/platform.rb", "lib/pi_piper/spi.rb"]
16
- s.files = `git ls-files -z`.split("\x0")
17
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
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"]
13
+ s.files = ["Gemfile", "Gemfile.lock", "Manifest", "README.md", "Rakefile", "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", "pi_piper.gemspec"]
18
14
  s.homepage = "http://github.com/jwhitehorn/pi_piper"
19
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pi_piper", "--main", "README.md"]
20
16
  s.require_paths = ["lib"]
21
17
  s.rubyforge_project = "pi_piper"
22
- s.rubygems_version = "2.0.0"
18
+ s.rubygems_version = "2.0.3"
23
19
  s.summary = "Event driven Raspberry Pi GPIO library"
24
20
 
25
- if s.respond_to? :specification_version
21
+ if s.respond_to? :specification_version then
26
22
  s.specification_version = 4
27
23
 
28
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
25
  s.add_runtime_dependency(%q<ffi>, [">= 0"])
30
- s.add_runtime_dependency(%q<eventmachine>, ["= 1.0.9"])
31
26
  else
32
27
  s.add_dependency(%q<ffi>, [">= 0"])
33
- s.add_dependency(%q<eventmachine>, ["= 1.0.9"])
34
28
  end
35
29
  else
36
30
  s.add_dependency(%q<ffi>, [">= 0"])
37
- s.add_dependency(%q<eventmachine>, ["= 1.0.9"])
38
31
  end
39
-
40
- s.add_development_dependency 'rspec'
41
- s.add_development_dependency 'mocha'
42
- s.add_development_dependency 'simplecov'
43
32
  end
metadata CHANGED
@@ -1,83 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.9
4
+ version: 2.0.beta.1
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-14 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
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.9
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.9
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: mocha
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
24
+ - - '>='
81
25
  - !ruby/object:Gem::Version
82
26
  version: '0'
83
27
  description: Event driven Raspberry Pi GPIO library
@@ -90,81 +34,52 @@ extra_rdoc_files:
90
34
  - lib/pi_piper/bcm2835.rb
91
35
  - lib/pi_piper/frequency.rb
92
36
  - lib/pi_piper/i2c.rb
93
- - lib/pi_piper/libbcm2835.so
37
+ - lib/pi_piper/libbcm2835.img
94
38
  - lib/pi_piper/pin.rb
95
39
  - lib/pi_piper/platform.rb
96
40
  - lib/pi_piper/spi.rb
97
41
  files:
98
- - ".gitignore"
99
- - ".rspec"
100
- - ".travis.yml"
101
42
  - Gemfile
102
43
  - Gemfile.lock
103
44
  - Manifest
104
45
  - README.md
105
46
  - Rakefile
106
- - examples/2_bit_counter/2_bit_counter.rb
107
- - examples/7-segment/7-segment.rb
108
- - examples/dsl_switch/dsl_switch.rb
109
- - examples/mcp3008/circuit.png
110
- - examples/mcp3008/mcp3008.rb
111
- - examples/mcp3008_spi/mcp3008_spi.rb
112
- - examples/morse_code/circuit.png
113
- - examples/morse_code/morse_code.rb
114
- - examples/simple_switch/circuit.png
115
- - examples/simple_switch/simple_switch.rb
116
47
  - lib/pi_piper.rb
117
48
  - lib/pi_piper/bcm2835.rb
118
49
  - lib/pi_piper/frequency.rb
119
50
  - lib/pi_piper/i2c.rb
120
- - lib/pi_piper/libbcm2835.so
51
+ - lib/pi_piper/libbcm2835.img
121
52
  - lib/pi_piper/pin.rb
122
- - lib/pi_piper/pin_error.rb
123
- - lib/pi_piper/pin_values.rb
124
53
  - lib/pi_piper/platform.rb
125
54
  - lib/pi_piper/spi.rb
126
- - lib/pi_piper/stub_driver.rb
127
55
  - pi_piper.gemspec
128
- - spec/i2c_spec.rb
129
- - spec/pin_spec.rb
130
- - spec/pull_mode_spec.rb
131
- - spec/spec_helper.rb
132
- - spec/spi_spec.rb
133
- - spec/stub_driver_spec.rb
134
56
  homepage: http://github.com/jwhitehorn/pi_piper
135
57
  licenses: []
136
58
  metadata: {}
137
59
  post_install_message:
138
60
  rdoc_options:
139
- - "--line-numbers"
140
- - "--inline-source"
141
- - "--title"
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --title
142
64
  - Pi_piper
143
- - "--main"
65
+ - --main
144
66
  - README.md
145
67
  require_paths:
146
68
  - lib
147
69
  required_ruby_version: !ruby/object:Gem::Requirement
148
70
  requirements:
149
- - - ">="
71
+ - - '>='
150
72
  - !ruby/object:Gem::Version
151
73
  version: '0'
152
74
  required_rubygems_version: !ruby/object:Gem::Requirement
153
75
  requirements:
154
- - - ">="
76
+ - - '>='
155
77
  - !ruby/object:Gem::Version
156
78
  version: '1.2'
157
79
  requirements: []
158
80
  rubyforge_project: pi_piper
159
- rubygems_version: 2.4.5
81
+ rubygems_version: 2.0.3
160
82
  signing_key:
161
83
  specification_version: 4
162
84
  summary: Event driven Raspberry Pi GPIO library
163
- test_files:
164
- - spec/i2c_spec.rb
165
- - spec/pin_spec.rb
166
- - spec/pull_mode_spec.rb
167
- - spec/spec_helper.rb
168
- - spec/spi_spec.rb
169
- - spec/stub_driver_spec.rb
170
- has_rdoc:
85
+ test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- pkg/*
2
- *.swp
3
- *.gem
4
- coverage/*
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format documentation
3
- --require spec_helper
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
-
6
- before_install:
7
- - gem install bundler
8
- - gem update
@@ -1,22 +0,0 @@
1
- require 'pi_piper'
2
-
3
- puts "Press the switch to get started"
4
- pin17 = PiPiper::Pin.new(:pin => 17, :direction => :out)
5
- pin27 = PiPiper::Pin.new(:pin => 27, :direction => :out)
6
-
7
- pin17.off
8
- pin27.off
9
-
10
- sum = 0
11
-
12
- PiPiper.watch :pin => 22, :trigger => :rising do |pin|
13
- sum = sum + 1
14
- display = sum % 4
15
- puts sum
16
-
17
- pin17.update_value(display == 2 || display == 3)
18
- pin27.update_value(display == 1 || display == 3)
19
- end
20
-
21
- PiPiper.wait
22
-
@@ -1,37 +0,0 @@
1
- require 'pi_piper'
2
-
3
- s1 = PiPiper::Pin.new(:direction => :out, :pin => 27)
4
- s2 = PiPiper::Pin.new(:direction => :out, :pin => 24)
5
- s3 = PiPiper::Pin.new(:direction => :out, :pin => 23)
6
- s4 = PiPiper::Pin.new(:direction => :out, :pin => 25)
7
- s5 = PiPiper::Pin.new(:direction => :out, :pin => 18)
8
- s6 = PiPiper::Pin.new(:direction => :out, :pin => 22)
9
- s7 = PiPiper::Pin.new(:direction => :out, :pin => 17)
10
-
11
-
12
- pins = [s1, s2, s3, s4, s5, s6, s7]
13
-
14
- zero = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.on; s6.on; s7.off; }
15
- one = Proc.new { s1.off; s2.off; s3.on; s4.on; s5.off; s6.off; s7.off; }
16
- two = Proc.new { s1.off; s2.on; s3.on; s4.off; s5.on; s6.on; s7.on; }
17
- three = Proc.new { s1.off; s2.on; s3.on; s4.on; s5.on; s6.off; s7.on; }
18
- four = Proc.new { s1.on; s2.off; s3.on; s4.on;; s5.off; s6.off; s7.on; }
19
- five = Proc.new { s1.on; s2.on; s3.off; s4.on; s5.on; s6.off; s7.on; }
20
- six = Proc.new { s1.on; s2.on; s3.off; s4.on; s5.on; s6.on; s7.on; }
21
- seven = Proc.new { s1.off; s2.on; s3.on; s4.on; s5.off; s6.off; s7.off; }
22
- eight = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.on; s6.on; s7.on; }
23
- nine = Proc.new { s1.on; s2.on; s3.on; s4.on; s5.off; s6.off; s7.on; }
24
-
25
- numbers = [zero, one, two, three, four, five, six, seven, eight, nine]
26
-
27
- pins.each { |p| p.off }
28
-
29
- PiPiper.watch :pin => 4, :trigger => :rising do
30
- (0..250).each do
31
- pins.each { |p| p.update_value(Random.rand(2) == 1) }
32
- end
33
- number = Random.rand(10)
34
- numbers[number].call
35
- end
36
-
37
- PiPiper.wait