simple_raspberrypi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9a312a98099683aa6ab0e98cbb8b2534a4da409
4
+ data.tar.gz: 0a3eb6f11ea90086e4acb62e9773dcb3693ec60e
5
+ SHA512:
6
+ metadata.gz: 68cbdc71877e9c817641075f4b5cf57c4f29b7c840ca552083cc976a58961d0b992abefd3520fe0e24f4014abae5d6371489716a8844121b7caaeb49e4477981
7
+ data.tar.gz: b1ef413be15c4e4fb2f2f57024bac7b9920124b706efe239382322fe2f90ced51afd73f7c1977fc75c7ebd44fa3b127f038738ff9d2da73b46f412ffb2ae4cae
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: simple_raspberrypi.rb
4
+
5
+ # desc: This gem is the same as the rpi gem, with the only
6
+ # difference being the class name. Use this as an alternative
7
+ # to the rpi gem to avoid the possiblity of conflict with any
8
+ # other gems which may use a module called RPi (i.e. rpi_gpio gem).
9
+
10
+ require 'pi_piper'
11
+
12
+
13
+ class SimpleRaspberryPi
14
+ include PiPiper
15
+
16
+ @leds = []
17
+
18
+ class PinX < Pin
19
+
20
+ HIGH = 1
21
+ LOW = 0
22
+
23
+ def initialize(id)
24
+ @id = id
25
+ super(pin: id, direction: :out)
26
+ @state = self.value
27
+ end
28
+
29
+ def on(duration=nil)
30
+ super();
31
+ @state = :on
32
+ (sleep duration; self.off) if duration
33
+ end
34
+
35
+ def off(duration=nil)
36
+
37
+ return if self.off?
38
+ super()
39
+ @state = :off
40
+ (sleep duration; self.on) if duration
41
+ end
42
+
43
+ alias high on # opposite of low
44
+ alias open on # opposite of close
45
+ alias lock on # opposite of unlock
46
+
47
+ alias stop off
48
+ alias low off
49
+ alias close off
50
+ alias unlock off
51
+
52
+ def blink(seconds=0.5, duration: nil)
53
+
54
+ @state = :blink
55
+ t2 = Time.now + duration if duration
56
+
57
+ Thread.new do
58
+ while @state == :blink do
59
+ (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds)
60
+ self.off if duration and Time.now >= t2
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ alias oscillate blink
67
+
68
+ def on?() @state == :on end
69
+ def off?() @state == :off end
70
+
71
+ # set val with 0 (off) or 1 (on)
72
+ #
73
+ def set_pin(val)
74
+
75
+ state = @state
76
+ self.update_value val
77
+ @state = state
78
+ end
79
+
80
+ def to_s()
81
+ @id
82
+ end
83
+ end
84
+
85
+ class Void
86
+ def on(duration=nil) end
87
+ def off() end
88
+ def blink(seconds=0, duration=nil) end
89
+ alias stop off
90
+ end
91
+
92
+ def initialize(x=[])
93
+
94
+ a = case x
95
+ when Fixnum
96
+ [x]
97
+ when String
98
+ [x]
99
+ when Array
100
+ x
101
+ end
102
+
103
+ unexport_all a
104
+
105
+ @pins = a.map {|pin| PinX.new pin }
106
+
107
+ def @pins.[](i)
108
+
109
+ if i.to_i >= self.length then
110
+ puts "RPi warning: PinX instance #{i.inspect} not found"
111
+ Void.new
112
+ else
113
+ self.at(i)
114
+ end
115
+ end
116
+
117
+ at_exit do
118
+
119
+ # to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export"
120
+ # we unexport the pins we used
121
+
122
+ unexport_all a
123
+ end
124
+ end
125
+
126
+ def pin() @pins.first end
127
+ def pins() @pins end
128
+
129
+ def unexport_all(pins)
130
+
131
+ pins.each do |pin|
132
+
133
+ next unless File.exists? '/sys/class/gpio/gpio' + pin.to_s
134
+
135
+ uexp = open("/sys/class/gpio/unexport", "w")
136
+ uexp.write(pin)
137
+ uexp.close
138
+ end
139
+
140
+ end
141
+
142
+ def on_exit
143
+ unexport_all @pins
144
+ end
145
+
146
+ def self.unexport(a)
147
+ a.each do |pin|
148
+
149
+ uexp = open("/sys/class/gpio/unexport", "w")
150
+ uexp.write(pin)
151
+ uexp.close
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+
158
+ if __FILE__ == $0 then
159
+ # example
160
+ my_rpi = SimpleRaspberryPi.new %w(17 22 18 4 23 25 27) # <-- each pin connects to an LED
161
+ my_rpi.pins[ARGV.first.to_i].method(ARGV.last.to_sym).call
162
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_raspberrypi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MDIyMTEzMTUyNFoXDTE3MDIyMDEzMTUyNFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAMsnOIypGRRK8Kk8y7urusItgPYdK+jSrMISu1nTyWBJbYlSudZyJRPHEJ5r
19
+ 1ZZxvTqJLyXic2VqLlpxwp9J92RLdTToqcy8qd/4hXmH78o40FsK7Mn8keRt6L7T
20
+ 5QNRIem5WS5vftLw8ZXgH0+KZFc+IBxoHtpFrYutxJNetdOAQSek/r6pDDVMvwKn
21
+ SnYcBt0Lw3MRXyP95EWZpsF0ZvE9214z12uWvrc7L/JOzb4D6M3N8Z1+Nj23XRMm
22
+ cLJ/6bz9bLJ0Eye6PZpB7VZVe3ZJwcVfXv+UgCtTwtKEoRCbz3h7SQSNjk9nkKkr
23
+ UKU36O5wxHOWcg2SxbdwQCuRNccCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUEYONztwxgymTiZxruLUZmMsqu6YwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAQcC0+v+o
27
+ stXWlT0jFM0/0hJDe1oa3nalks0Qm7Mgs9IV97KzDWKKlW94f/u/W5llFpk+ia/3
28
+ 6rs4AY38ZNYUbqgaBXr2VpWZLYpJPvBXkPFovy/qVQVcVbfID5/EhifX2i4hrYvc
29
+ Oly24xWJqQcRC1kpqD7qGO8ED4ps8lLHBAbiwG2X2O2RB27VObu9FHP40g3TpskV
30
+ rbeRY2JtdPoyQgxI7/ioxtGGjO7bM6F6IvSt2GMa6SRNmG0+KZa8wIyowVcmaiD1
31
+ DpcoUbnNCQrmIiU2mO0RoRPAsnFBZaDdhAlDbXuBSyuSS3Ygv+owE8Y6XHhjq6lz
32
+ VCYD0S+Rz1/Ltw==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-02-21 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: pi_piper
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.9'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.9.9
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.9'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.9.9
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/simple_raspberrypi.rb
63
+ homepage: https://github.com/jrobertson/simple_raspberrypi
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Use this gem as an alternative to the rpi gem if you are experiencing class
87
+ or module conflict while using other gems which use the name RPi.
88
+ test_files: []
metadata.gz.sig ADDED
Binary file