chip-gpio 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chip-gpio/Pin.rb +14 -33
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8af98f1f1873ef8bd513eed9a2546b20b449513
4
- data.tar.gz: b6e7064d8fed34237b3d6de85eb1660195f1457f
3
+ metadata.gz: d2bd88f0fd76071fd6292675337841d22465f029
4
+ data.tar.gz: ce6a49044b5748da33d16d5af5a2dfb7369668c2
5
5
  SHA512:
6
- metadata.gz: 9cb2f46f63722d1b27d51e04216f44bf041140685acafa0170df1dd4a6f2bf95b18632fc75a4aab8121faf97b9161cae51ebe2b4fcc61b649e6ceee133cc23c1
7
- data.tar.gz: 28db799c54d20387fb94c8542678d53ac3eae0ccfeac56f3f20a2056e3c149e20c3764a7e89c6c23c61b290f905a6a676f7e25dc1127d56cead64477149d495c
6
+ metadata.gz: ff287ee4e02d61680d5b1c927b56eb3ee64420d81bab7c8b5e8b8846da44d25774fe96839455f25e12d19f251514856dd8ce28b11001e07052e93a873b06fc5e
7
+ data.tar.gz: 2819b7e2d8f00def73258b74b66a821bedcdaca2afaa58eaf4b81a016d304ea431a90ec895af434e3e32ac01dffd6b84e1e1b489028bc0aaeded86e0a4d472f7
data/lib/chip-gpio/Pin.rb CHANGED
@@ -67,47 +67,28 @@ module ChipGPIO
67
67
 
68
68
  end
69
69
 
70
- def self.chip_version
71
- default_version = :v4_4
72
-
73
- begin
74
- version_string = File.read('/proc/version')
75
-
76
- #grab the major and minor version of the Linux string; only match on NTC versions
77
- #since custom builds will be weird
78
- match = /Linux version ([0-9]+)\.([0-9]+).+-ntc.*/.match(version_string)
79
- throw "Unable to parse /proc/version string" if match.nil?
80
- throw "Unable to parse /proc/version string - could not find version numbers" if match.captures.size != 2
81
-
82
- major = match.captures[0]
83
- minor = match.captures[1]
84
-
85
- if major == "4" && minor == "3"
86
- return :v4_3
87
- elsif major== "4" && minor == "4"
88
- return :v4_4
89
- else
90
- throw "Unrecognized version #{major}.#{minor}"
70
+ def self.get_xio_base
71
+ labels = Dir::glob("/sys/class/gpio/*/label")
72
+ labels.each do |label|
73
+ value = File.read(label).strip
74
+ if value == "pcf8574a"
75
+ base_path = File.dirname(label)
76
+ base_path = File.join(base_path, 'base')
77
+ base = File.read(base_path).strip
78
+ return base.to_i
91
79
  end
92
- rescue
93
- puts "Unable to read version from /proc/version; using #{default_version} as default"
94
- version = default_version
95
80
  end
96
81
 
97
- return version
82
+ throw "Could not find XIO base"
98
83
  end
99
84
 
100
85
  def self.get_pins
101
- v = chip_version
102
86
  cis = [132, 133, 134, 135, 136, 137, 138, 139 ]
87
+ xio = []
103
88
 
104
- case chip_version
105
- when :v4_3
106
- xio = [408, 409, 410, 411, 412, 413, 414, 415]
107
- when :v4_4
108
- xio = [1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023]
109
- end
110
-
89
+ xio_base = get_xio_base()
90
+ (0..7).each { |i| xio << (xio_base + i) }
91
+
111
92
  pins = {}
112
93
 
113
94
  cis.each_with_index { |gpio, index| pins["CSI#{index}".to_sym] = Pin::Pin.new(gpio) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chip-gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Williams