chip-gpio 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/lib/chip-gpio/Pin.rb +93 -0
- data/lib/chip-gpio.rb +5 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c05d8afb47e67805d726995618357de224aa20dc
|
4
|
+
data.tar.gz: c7cfb492c7bee9e1fa1319af5d1d9573fa716d42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28016cd4417117c0e84547906627e973c8543affaca6576980d56527d890265fde2e014ff8ea9b17b790b2b13fa01df1479740c915ec56aa00e6d4435402c641
|
7
|
+
data.tar.gz: d4016aff487ffc22fe071c0bed1c353cb0b282c786783c8fce8d5f1def9cb5981ce6eb00864c5b9208c3ef9da8b7340ceed329846f4139c0440985f0c89c4326
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
module ChipGPIO
|
2
|
+
module Pin
|
3
|
+
class Pin
|
4
|
+
attr_reader :gpio_number
|
5
|
+
|
6
|
+
def initialize(gpio_number)
|
7
|
+
@gpio_number = gpio_number
|
8
|
+
@base_path = "/sys/class/gpio/gpio#{@gpio_number}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def available?
|
12
|
+
return File.exist?(@base_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def export
|
16
|
+
File.open("/sys/class/gpio/export", "w") { |f| f.write(@gpio_number.to_s) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def unexport
|
20
|
+
File.open("/sys/class/gpio/unexport", "w") { |f| f.write(@gpio_number.to_s) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def value
|
24
|
+
throw "Pin is not currently available" if !self.available?
|
25
|
+
|
26
|
+
v = File.read("#{@base_path}/value")
|
27
|
+
#assume that values will always be numeric
|
28
|
+
match = /([0-9]+)/.match(v)
|
29
|
+
|
30
|
+
return 0 if match.nil?
|
31
|
+
return 0 if match.captures.size == 0
|
32
|
+
return match.captures[0].to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
def value=(v)
|
36
|
+
throw "Pin is not currently available" if !self.available?
|
37
|
+
|
38
|
+
v = v.to_s
|
39
|
+
File.open("#{@base_path}/value", "w") { |f| f.write(v) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.chip_version
|
46
|
+
default_version = :v4_4
|
47
|
+
|
48
|
+
begin
|
49
|
+
version_string = File.read('/proc/version')
|
50
|
+
|
51
|
+
#grab the major and minor version of the Linux string; only match on NTC versions
|
52
|
+
#since custom builds will be weird
|
53
|
+
match = /Linux version ([0-9]+)\.([0-9]+).+-ntc.*/.match(version_string)
|
54
|
+
throw "Unable to parse /proc/version string" if match.nil?
|
55
|
+
throw "Unable to parse /proc/version string - could not find version numbers" if match.captures.size != 2
|
56
|
+
|
57
|
+
major = match.captures[0]
|
58
|
+
minor = match.captures[1]
|
59
|
+
|
60
|
+
if major == "4" && minor == "3"
|
61
|
+
return :v4_3
|
62
|
+
elsif major== "4" && minor == "4"
|
63
|
+
return :v4_4
|
64
|
+
else
|
65
|
+
throw "Unrecognized version #{major}.#{minor}"
|
66
|
+
end
|
67
|
+
rescue
|
68
|
+
puts "Unable to read version from /proc/version; using #{default_version} as default"
|
69
|
+
version = default_version
|
70
|
+
end
|
71
|
+
|
72
|
+
return version
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.get_pins
|
76
|
+
v = chip_version
|
77
|
+
cis = [132, 133, 134, 135, 136, 137, 138, 139 ]
|
78
|
+
|
79
|
+
case chip_version
|
80
|
+
when :v4_3
|
81
|
+
xio = [408, 409, 410, 411, 412, 413, 414, 415]
|
82
|
+
when :v4_4
|
83
|
+
xio = [1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023]
|
84
|
+
end
|
85
|
+
|
86
|
+
pins = {}
|
87
|
+
|
88
|
+
cis.each_with_index { |gpio, index| pins["CSI#{index}".to_sym] = Pin::Pin.new(gpio) }
|
89
|
+
xio.each_with_index { |gpio, index| pins["XIO#{index}".to_sym] = Pin::Pin.new(gpio) }
|
90
|
+
|
91
|
+
return pins
|
92
|
+
end
|
93
|
+
end
|
data/lib/chip-gpio.rb
ADDED
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chip-gpio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: foo
|
14
|
+
email: james@jameswilliams.me
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/chip-gpio.rb
|
21
|
+
- lib/chip-gpio/Pin.rb
|
22
|
+
homepage: http://github.com/willia4/chip-gpio
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A ruby gem to control the GPIO pens on the CHIP computer
|
46
|
+
test_files: []
|