wiringpi-ruby 2.1.2 → 2.1.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.
- checksums.yaml +4 -4
- data/lib/wiringpi.rb +7 -0
- data/lib/wiringpi/gpio.rb +31 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe5959820c3c16ef0299dc92155a7d41817840bc40a54e221eb029727706994
|
4
|
+
data.tar.gz: defdc2da075386ac4b98904d5e73242c00efcc901098bb26b05e065356a29038
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be801a9f95a83e9c18cc6f0f8c48d83eafa55f9324742cd559c01a32df1e98d72a3dbcf7ca14b43623e5a0d5167eb495cf8e1025382ed46f201ec27682df59b
|
7
|
+
data.tar.gz: 49647a809f4aea88dc79a57d5742eef5cffcf0512ab32189042dbfd7de331400dfe34a9d95ce63eb47c921486c8d0a67e656b53bb098bd5b51d74f31af844078
|
data/lib/wiringpi.rb
CHANGED
@@ -3,6 +3,12 @@ require 'wiringpi/wiringpi'
|
|
3
3
|
module WiringPi
|
4
4
|
extend self
|
5
5
|
|
6
|
+
# GPIO WiringPi PIN layout mode
|
7
|
+
GPIO_WPI = 0
|
8
|
+
GPIO_NORMAL = 1
|
9
|
+
GPIO_PHYSICAL = 2
|
10
|
+
GPIO_SYSTEM = 3
|
11
|
+
|
6
12
|
# GPIO signal
|
7
13
|
HIGH = 1
|
8
14
|
LOW = 0
|
@@ -11,6 +17,7 @@ module WiringPi
|
|
11
17
|
FALLING = :falling
|
12
18
|
RISING = :rising
|
13
19
|
|
20
|
+
# PIN mode
|
14
21
|
INPUT = 0
|
15
22
|
OUTPUT = 1
|
16
23
|
PWM_OUTPUT = 1
|
data/lib/wiringpi/gpio.rb
CHANGED
@@ -2,10 +2,11 @@ module WiringPi
|
|
2
2
|
class GPIO
|
3
3
|
attr_reader :modules, :pins
|
4
4
|
|
5
|
-
def initialize(&block)
|
6
|
-
|
5
|
+
def initialize(pin_layout = GPIO_WPI, &block)
|
6
|
+
@pin_layout = pin_layout
|
7
7
|
@pins = []
|
8
8
|
@modules = []
|
9
|
+
setup_wiring_pi
|
9
10
|
instance_eval &block if block_given?
|
10
11
|
end
|
11
12
|
|
@@ -23,13 +24,25 @@ module WiringPi
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def digital_read(pin)
|
26
|
-
|
27
|
-
|
27
|
+
pins = [pin] unless pin.is_a?(Array)
|
28
|
+
res = pins.collect { |pin| Wiringpi.digitalRead(pin) }
|
29
|
+
res.count == 1 ? res.first : res
|
28
30
|
end
|
29
31
|
|
30
32
|
def digital_write(pin, value)
|
31
|
-
|
32
|
-
|
33
|
+
pins = [pin] unless pin.is_a?(Array)
|
34
|
+
pins.each { |pin| Wiringpi.digitalWrite(pin, value) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def analog_read(pin)
|
38
|
+
pins = [pin] unless pin.is_a?(Array)
|
39
|
+
res = pins.collect { |pin| Wiringpi.analogRead(pin) }
|
40
|
+
res.count == 1 ? res.first : res
|
41
|
+
end
|
42
|
+
|
43
|
+
def analog_write(pin, value)
|
44
|
+
pins = [pin] unless pin.is_a?(Array)
|
45
|
+
pins.each { |pin| Wiringpi.analogWrite(pin, value) }
|
33
46
|
end
|
34
47
|
|
35
48
|
def pin_mode(pin, mode)
|
@@ -117,5 +130,17 @@ module WiringPi
|
|
117
130
|
@pins[offset + module_instance.pin_base] = 'ENABLED'
|
118
131
|
end
|
119
132
|
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def setup_wiring_pi
|
137
|
+
case @pin_layout
|
138
|
+
when GPIO_WPI; Wiringpi.wiringPiSetup
|
139
|
+
when GPIO_NORMAL; Wiringpi.wiringPiSetupGpio
|
140
|
+
when GPIO_PHYSICAL; Wiringpi.wiringPiSetupPhys
|
141
|
+
when GPIO_SYSTEM; Wiringpi.wiringPiSetupSys
|
142
|
+
else raise 'unknown pin layout to setup'
|
143
|
+
end
|
144
|
+
end
|
120
145
|
end
|
121
146
|
end
|