chip-gpio 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -1
- data/lib/chip-gpio/Pin.rb +26 -1
- data/lib/chip-gpio.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8af98f1f1873ef8bd513eed9a2546b20b449513
|
4
|
+
data.tar.gz: b6e7064d8fed34237b3d6de85eb1660195f1457f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cb2f46f63722d1b27d51e04216f44bf041140685acafa0170df1dd4a6f2bf95b18632fc75a4aab8121faf97b9161cae51ebe2b4fcc61b649e6ceee133cc23c1
|
7
|
+
data.tar.gz: 28db799c54d20387fb94c8542678d53ac3eae0ccfeac56f3f20a2056e3c149e20c3764a7e89c6c23c61b290f905a6a676f7e25dc1127d56cead64477149d495c
|
data/README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
1
|
# chip-gpio
|
2
2
|
|
3
|
-
A ruby gem for controlling the GPIO pins on a $9 CHIP computer
|
3
|
+
A ruby gem for controlling the GPIO pins on a $9 CHIP computer.
|
4
|
+
|
5
|
+
Can currently set output values and read input values for CHIP computers running v4.3 or v4.4 images.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install chip-gpio
|
10
|
+
|
11
|
+
## Examples
|
12
|
+
|
13
|
+
### Initialize
|
14
|
+
|
15
|
+
require 'chip-gpio'
|
16
|
+
pins = ChipGPIO.get_pins
|
17
|
+
|
18
|
+
### Export pins
|
19
|
+
|
20
|
+
pins[:XIO7].available?
|
21
|
+
=> false
|
22
|
+
|
23
|
+
pins[:XIO7].export
|
24
|
+
pins[:XIO7].available?
|
25
|
+
=> true
|
26
|
+
|
27
|
+
### Set a value
|
28
|
+
|
29
|
+
pins[:XIO7].direction = :output
|
30
|
+
pins[:XIO7].value = 1
|
31
|
+
pins[:XIO7].value
|
32
|
+
=> 1
|
33
|
+
|
34
|
+
### Read a value
|
35
|
+
|
36
|
+
pins[:XIO7].direction = :output
|
37
|
+
pins[:XIO7].value
|
38
|
+
=> 1
|
data/lib/chip-gpio/Pin.rb
CHANGED
@@ -20,6 +20,31 @@ module ChipGPIO
|
|
20
20
|
File.open("/sys/class/gpio/unexport", "w") { |f| f.write(@gpio_number.to_s) }
|
21
21
|
end
|
22
22
|
|
23
|
+
def direction
|
24
|
+
v = File.read("#{@base_path}/direction").strip
|
25
|
+
case v
|
26
|
+
when "in"
|
27
|
+
return :input
|
28
|
+
when "out"
|
29
|
+
return :output
|
30
|
+
else
|
31
|
+
throw "Unexpected direction #{v}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def direction=(d)
|
36
|
+
case d
|
37
|
+
when :input
|
38
|
+
v = "in"
|
39
|
+
when :output
|
40
|
+
v = "out"
|
41
|
+
else
|
42
|
+
throw "Unexpected direction: #{d}; must be :input or :output"
|
43
|
+
end
|
44
|
+
|
45
|
+
File.open("#{@base_path}/direction", "w") { |f| f.write(v) }
|
46
|
+
end
|
47
|
+
|
23
48
|
def value
|
24
49
|
throw "Pin is not currently available" if !self.available?
|
25
50
|
|
@@ -34,7 +59,7 @@ module ChipGPIO
|
|
34
59
|
|
35
60
|
def value=(v)
|
36
61
|
throw "Pin is not currently available" if !self.available?
|
37
|
-
|
62
|
+
|
38
63
|
v = v.to_s
|
39
64
|
File.open("#{@base_path}/value", "w") { |f| f.write(v) }
|
40
65
|
end
|
data/lib/chip-gpio.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Williams
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: A ruby gem to control the GPIO pens on the CHIP computer
|
14
14
|
email: james@jameswilliams.me
|
15
15
|
executables: []
|
16
16
|
extensions: []
|