rpi_pinout 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c3865e99a9d27a230205ff4efa1b6252edff80b
4
+ data.tar.gz: d7cf9bd882e556f377993047755ecc2985895a49
5
+ SHA512:
6
+ metadata.gz: 04058fe6f8fd455966ed1634a6915b8d24f5cf739d0e1e5f69c7bf12b86fedfa6d884f9769c1e721f0acc01b013e861b8da09e2a2a9b1f16c49a5c4a42598ca8
7
+ data.tar.gz: aa3b1f1ede8f33aa83547c43221f1cc906af2269c397a27fb8c45a9c7aaa5a05bad7bfdf3881d0ec27a900f5bb1a8c5da75f21ffbe576a660ed7a6be31526d1c
@@ -0,0 +1,2 @@
1
+ ��)m�X��q���EP�����g��BC������Tog�M,���P�$_&Sc3���g����}W�^�g��&�up|�� �\VĝHsZ XSz+`ڔ>��֠����G�Ŏ�ᄢ�ɣ\���#������ST�1�8�D�
2
+ �^�w���(w��*D� خC$�u���}�8�]V�K���E�@��Ei�q�W*�bU�[�7B��w*����d5-ȲFQ�7��aD��C_[��fe�-Q\>
Binary file
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: rpi_pinout.rb
4
+
5
+
6
+ HIGH = 1
7
+ LOW = 0
8
+
9
+
10
+ class RPiPinOut
11
+
12
+ def initialize(id)
13
+
14
+ unexport()
15
+
16
+ File.write '/sys/class/gpio/export', id
17
+ File.write "/sys/class/gpio/gpio#{id}/direction", 'out'
18
+
19
+ @id = id
20
+
21
+ at_exit { unexport() }
22
+
23
+ end
24
+
25
+ def on(duration=nil)
26
+
27
+ set_pin HIGH;
28
+ @state = :on
29
+ (sleep duration; self.off) if duration
30
+ end
31
+
32
+ def off(duration=nil)
33
+
34
+ return if self.off?
35
+ set_pin LOW
36
+ @state = :off
37
+ (sleep duration; self.on) if duration
38
+ end
39
+
40
+ alias high on # opposite of low
41
+ alias open on # opposite of close
42
+ alias lock on # opposite of unlock
43
+
44
+ alias stop off
45
+ alias low off
46
+ alias close off
47
+ alias unlock off
48
+
49
+ def blink(seconds=0.5, duration: nil)
50
+
51
+ @state = :blink
52
+ t2 = Time.now + duration if duration
53
+
54
+ Thread.new do
55
+ while @state == :blink do
56
+ (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds)
57
+ self.off if duration and Time.now >= t2
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+ alias oscillate blink
64
+
65
+ def on?() @state == :on end
66
+ def off?() @state == :off end
67
+
68
+ # set val with 0 (off) or 1 (on)
69
+ #
70
+ def set_pin(val)
71
+
72
+ state = @state
73
+ File.write "/sys/class/gpio/gpio#{@id}/value", val
74
+ @state = state
75
+
76
+ end
77
+
78
+ def to_s()
79
+ @id
80
+ end
81
+
82
+ private
83
+
84
+ # to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export"
85
+ # we unexport the pins we used
86
+ #
87
+ def unexport()
88
+
89
+ return unless File.exists? '/sys/class/gpio/gpio' + @id.to_s
90
+
91
+ File.write "/sys/class/gpio/unexport", @id
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpi_pinout
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
+ 8ixkARkWAmV1MB4XDTE2MDQxMDE3MzYxMVoXDTE3MDQxMDE3MzYxMVowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZP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llNIfKiZPR6dlA==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-04-10 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_pinout.rb
43
+ homepage: https://github.com/jrobertson/rpi_pinout
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. Used by the simple_raspberrypi gem
67
+ test_files: []
Binary file