simple_raspberrypi 0.3.0 → 0.4.0

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: e9fcff2fd025e211eb5669400edfd1cdf3e9f6fd
4
- data.tar.gz: f427f3e0a03abc2c3da2b845a35838c92637a203
3
+ metadata.gz: 2027937673fc6f0f43070ec99a847a2805135bb0
4
+ data.tar.gz: 4d1deb30a58c28b7d24ada46a924341a8637082b
5
5
  SHA512:
6
- metadata.gz: 9cb9087bdfcb433fefc6742e2bc5c163ad0e56a4bb5fe3218ecb8ece10c88e5f901050ea32a88b541a852435809d55ec48582877adcb91fcbc207e298d3d1be2
7
- data.tar.gz: 7c90ce6cd8d0bb6201004989bc93c25a2808be6488962c4c1f39ff3aac8d2e1e164d5fe62c63ed7bb73c68f97f1c56f1c2af44e72b34d1b5edff7794a4f7b72a
6
+ metadata.gz: d1dd00164ebc5966437db59350af614ab07a0de3b8eed2ba3cf2dce138b86fed894638a68b27884ddf96cea79f78edba83511792f1b243de32539f858f70cb66
7
+ data.tar.gz: fa5a1f736a03e25a802854b06a801f747919680b5fabb01cbee6bf5a0b2aaed0e94f0f0d73d2388d2881cb17f912ac2de2e69577b8b3afdca86459208504a79e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,80 +6,11 @@
6
6
  # difference being the class name and this gem has no dependencies.
7
7
 
8
8
 
9
- HIGH = 1
10
- LOW = 0
9
+ require 'rpi_pinout'
11
10
 
12
- class SimpleRaspberryPi
13
-
14
-
15
- class PinX
16
-
17
- def initialize(id)
18
-
19
- File.write '/sys/class/gpio/export', id
20
- File.write "/sys/class/gpio/gpio#{id}/direction", 'out'
21
-
22
- @id = id
23
-
24
- end
25
-
26
- def on(duration=nil)
27
-
28
- set_pin HIGH;
29
- @state = :on
30
- (sleep duration; self.off) if duration
31
- end
32
-
33
- def off(duration=nil)
34
-
35
- return if self.off?
36
- set_pin LOW
37
- @state = :off
38
- (sleep duration; self.on) if duration
39
- end
40
-
41
- alias high on # opposite of low
42
- alias open on # opposite of close
43
- alias lock on # opposite of unlock
44
-
45
- alias stop off
46
- alias low off
47
- alias close off
48
- alias unlock off
49
-
50
- def blink(seconds=0.5, duration: nil)
51
-
52
- @state = :blink
53
- t2 = Time.now + duration if duration
54
-
55
- Thread.new do
56
- while @state == :blink do
57
- (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds)
58
- self.off if duration and Time.now >= t2
59
- end
60
-
61
- end
62
- end
63
-
64
- alias oscillate blink
65
-
66
- def on?() @state == :on end
67
- def off?() @state == :off end
68
-
69
- # set val with 0 (off) or 1 (on)
70
- #
71
- def set_pin(val)
72
11
 
73
- state = @state
74
- File.write "/sys/class/gpio/gpio#{@id}/value", val
75
- @state = state
76
- end
12
+ class SimpleRaspberryPi
77
13
 
78
- def to_s()
79
- @id
80
- end
81
- end
82
-
83
14
  class Void
84
15
  def on(duration=nil) end
85
16
  def off() end
@@ -97,53 +28,24 @@ class SimpleRaspberryPi
97
28
  when Array
98
29
  x
99
30
  end
100
-
101
- unexport_all a
102
31
 
103
-
104
- @pins = a.map {|pin| PinX.new pin.to_i }
32
+ @pins = a.map {|pin| RPiPinOut.new pin }
105
33
 
106
34
  def @pins.[](i)
107
35
 
108
36
  if i.to_i >= self.length then
109
- puts "RPi warning: PinX instance #{i.inspect} not found"
37
+ puts "RPi warning: RPiPinOut instance #{i.inspect} not found"
110
38
  Void.new
111
39
  else
112
40
  self.at(i)
113
41
  end
114
42
  end
115
-
116
- at_exit do
117
-
118
- # to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export"
119
- # we unexport the pins we used
120
-
121
- unexport_all a
122
- end
43
+
123
44
  end
124
45
 
125
46
  def pin() @pins.first end
126
47
  def pins() @pins end
127
48
 
128
- def unexport_all(pins)
129
-
130
- pins.each do |pin|
131
-
132
- next unless File.exists? '/sys/class/gpio/gpio' + pin.to_s
133
-
134
- File.write "/sys/class/gpio/unexport", pin
135
-
136
- end
137
-
138
- end
139
-
140
- def on_exit
141
- unexport_all @pins
142
- end
143
-
144
- def self.unexport(a)
145
- a.each {|pin| File.write "/sys/class/gpio/unexport", pin }
146
- end
147
49
 
148
50
  end
149
51
 
@@ -152,4 +54,4 @@ if __FILE__ == $0 then
152
54
  # example
153
55
  my_rpi = SimpleRaspberryPi.new %w(17 22 18 4 23 25 27) # <-- each pin connects to an LED
154
56
  my_rpi.pins[ARGV.first.to_i].method(ARGV.last.to_sym).call
155
- end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_raspberrypi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,8 +31,28 @@ cert_chain:
31
31
  DpcoUbnNCQrmIiU2mO0RoRPAsnFBZaDdhAlDbXuBSyuSS3Ygv+owE8Y6XHhjq6lz
32
32
  VCYD0S+Rz1/Ltw==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-04-09 00:00:00.000000000 Z
35
- dependencies: []
34
+ date: 2016-04-10 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: rpi_pinout
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.0
36
56
  description:
37
57
  email: james@r0bertson.co.uk
38
58
  executables: []
@@ -63,5 +83,6 @@ rubyforge_project:
63
83
  rubygems_version: 2.4.8
64
84
  signing_key:
65
85
  specification_version: 4
66
- summary: Has the same features as the rpi gem, but does not require and gem dependencies.
86
+ summary: Has the same features as the rpi gem, but relies upon the rpi_pinout gem
87
+ instead of the pi_piper gem.
67
88
  test_files: []
metadata.gz.sig CHANGED
Binary file