rpi_pinin 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8726d0bf63ceeba143de791ae04b776397e33f20
4
+ data.tar.gz: ea7bd528d0bff144a33980087193a6cb9aba9871
5
+ SHA512:
6
+ metadata.gz: 2c35c7c4134d1457df0a52138561be4071f093179b893cf674758e0fe7ff4425b57577b458cb7371805b327b6fdbd57aced9f44a635a07f510b8bdf2cc028917
7
+ data.tar.gz: 51402d1bfe10c9693267f4e1d1ad50730e29d7f706daa6817931a9340b67d45529d19273ef8f5050c3830591d0db7d8584c4e77324f165a9f335caa261dd3b55
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/rpi_pinin.rb ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: rpi_pinin.rb
4
+
5
+
6
+
7
+ class RPiPinIn
8
+
9
+ def initialize(id)
10
+
11
+ @id = id
12
+ unexport()
13
+
14
+ File.write '/sys/class/gpio/export', id
15
+ File.write "/sys/class/gpio/gpio#{id}/direction", 'out'
16
+ File.write "/sys/class/gpio/gpio#{id}/direction", 'high'
17
+
18
+ at_exit { unexport() }
19
+
20
+ end
21
+
22
+ # override this method if you wish
23
+ #
24
+ def on_change(value)
25
+
26
+ end
27
+
28
+ # override this method if you wish
29
+ #
30
+ def on_high()
31
+
32
+ end
33
+
34
+ def watch_high()
35
+
36
+ watch() do |value|
37
+
38
+ if value == '1' then
39
+
40
+ yield if block_given?
41
+ on_high()
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ def watch()
50
+
51
+ old_value = read_value()
52
+
53
+ loop do
54
+
55
+ value = read_value()
56
+
57
+ if value != old_value then
58
+
59
+ yield(value) if block_given?
60
+ on_change(value)
61
+
62
+ end
63
+
64
+ old_value = value
65
+ end
66
+
67
+ end
68
+
69
+
70
+ def to_s()
71
+ @id
72
+ end
73
+
74
+ private
75
+
76
+ def read_value()
77
+ File.read("/sys/class/gpio/gpio#{@id}/value").chomp == '0' ? '1' : '0'
78
+ end
79
+
80
+ # to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export"
81
+ # we unexport the pins we used
82
+ #
83
+ def unexport()
84
+
85
+ return unless File.exists? '/sys/class/gpio/gpio' + @id.to_s
86
+
87
+ File.write "/sys/class/gpio/unexport", @id
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpi_pinin
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
+ 8ixkARkWAmV1MB4XDTE2MDQxMTE3NTEzM1oXDTE3MDQxMTE3NTEzM1owSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAKZW3bNdPL5+gMEtDmj3S5tuNLFVGWlq+roFTXhjR6fl2l/6O8Eq/VpreD3N
19
+ x8+Uhcrg7g82lmWRe4elkY44TrIUiddqTXSBfQjJOVtmR+boCe+z62JbV1noQ1JH
20
+ i52GFuHLWwjbM6R09/2H1T1naLRTBaamJs9Otoc3xZUbaozqlHd7Ef351s0Gym9G
21
+ YzeHeYmEWetOkwV5TouvV5mhEzs03GR7662fI1Fwc4dakhNiwF6SBRwPjnxgPj7/
22
+ sQ6LVjsTCKt3xcN45ky55r7JygIMtjvsTqDWnwoTkaHWGqUWwLF4RrQ+u16afkLN
23
+ R5ZKBEBV18rLeAycAg+s86P4NOsCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUwO880tQnqac4ZdyvPJd/zfMuPgMwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAYRnK0wzu
27
+ k4FiakF7i3BEB/5paJHNLjBtq1dGns5N6Lazdn0gcWtuqlCYNYFCDugE8VuHXoZG
28
+ sSetl8u2xtenBkhLdBDgdSLTlhqErxyaJWMzev9hFoZon7ByFOmO2us44dJa39cr
29
+ nth2qHaOqX/uWUH18KETGz1N7hisZNkl+ogPoNH7JDxvehV81VaStjxESOIqO0v6
30
+ OxlVo5Ka+VuFE5qdCBmuF4/iZ2jmSdQ7uLQZ8j39M74VlWu6S0QYy07ZGr0ql9v+
31
+ 9Oh5kTRHGmS+rAppl7kr+5B23zGsyZypeBNXBco1AWMlnIkPo8XBFIYBeddBnFHa
32
+ WL47T3Gs0w9mvQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-04-11 00:00:00.000000000 Z
35
+ dependencies: []
36
+ description:
37
+ email: james@r0bertson.co.uk
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/rpi_pinin.rb
43
+ homepage: https://github.com/jrobertson/rpi_pinin
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Represents a Raspberry Pi GPIO pin in e.g. to read a button press.
67
+ test_files: []
metadata.gz.sig ADDED
Binary file