wiringpi 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
- data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
- data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/extconf.rb +7 -1
- data/ext/wiringpi/wiringpi_wrap.c +1741 -218
- data/lib/wiringpi.rb +24 -222
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- metadata +146 -22
- data/ext/wiringpi/wiringPi.c +0 -729
- data/ext/wiringpi/wiringPi.h +0 -69
data/lib/wiringpi.rb
CHANGED
@@ -1,240 +1,42 @@
|
|
1
1
|
require 'wiringpi/wiringpi'
|
2
|
-
|
3
|
-
WPI_MODE_PINS = 0 # Use sane pin numbering
|
4
|
-
WPI_MODE_GPIO = 1 # Use Broadcom barmy GPIO pin numbering
|
5
|
-
WPI_MODE_SYS = 2 # Use /sys/class/gpio method
|
6
|
-
|
7
|
-
# Constants for mode()
|
8
|
-
INPUT = 0
|
9
|
-
OUTPUT = 1
|
10
|
-
PWM_OUTPUT = 2
|
11
|
-
|
12
|
-
# Constants for digitalWrite()
|
13
|
-
HIGH = 1
|
14
|
-
LOW = 0
|
15
|
-
|
16
|
-
PUD_OFF = 0
|
17
|
-
PUD_DOWN = 1
|
18
|
-
PUD_UP = 2
|
19
|
-
|
20
|
-
# Bit-order for shiftOut and shiftIn
|
21
|
-
LSBFIRST = 0 # Least Significant Bit First
|
22
|
-
MSBFIRST = 1 # Most Significant Bit First
|
23
|
-
|
24
2
|
module WiringPi
|
3
|
+
extend self
|
25
4
|
|
26
|
-
|
5
|
+
HIGH = 1
|
6
|
+
LOW = 0
|
27
7
|
|
28
|
-
|
29
|
-
|
30
|
-
|
8
|
+
INPUT = 0
|
9
|
+
OUTPUT = 1
|
10
|
+
PWM_OUTPUT = 1
|
31
11
|
|
32
|
-
|
12
|
+
PUD_OFF = 0
|
13
|
+
PUD_DOWN = 1
|
14
|
+
PUD_UP = 2
|
33
15
|
|
34
|
-
|
35
|
-
|
16
|
+
LSPFIRST = 0
|
17
|
+
MSBFIRST = 1
|
36
18
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def serialClose
|
42
|
-
|
43
|
-
Wiringpi.serialClose( @id )
|
44
|
-
@id = 0
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def serialPutchar( char )
|
49
|
-
|
50
|
-
Wiringpi.serialPutchar( @id, char )
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def serialPuts( string )
|
55
|
-
|
56
|
-
Wiringpi.serialPuts( @id, string )
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def serialDataAvail
|
61
|
-
|
62
|
-
Wiringpi.serialDataAvail( @id )
|
63
|
-
|
64
|
-
end
|
19
|
+
class Modules
|
20
|
+
class ModuleBase
|
65
21
|
|
66
|
-
|
22
|
+
@name = 'Unknown'
|
23
|
+
@pin_base = 0
|
24
|
+
@pin_count = 0
|
25
|
+
@pin_end = 0
|
67
26
|
|
68
|
-
|
27
|
+
attr_reader :name, :pin_base, :pin_count, :pin_end
|
69
28
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
class GPIO
|
75
|
-
|
76
|
-
GPIO_PINS = [
|
77
|
-
0,1,4,7,8,9,10,11,14,15,17,18,21,22,23,24,25 # seemingly random indeed!
|
78
|
-
]
|
79
|
-
|
80
|
-
PINS = [
|
81
|
-
0,1,2,3,4,5,6,7, # basic IO pins
|
82
|
-
8,9, # i2c with 1k8 pull up resistor
|
83
|
-
10,11,12,13,14, # SPI pins, can also be used for IO
|
84
|
-
15,16,17
|
85
|
-
]
|
86
|
-
|
87
|
-
@mode = WPI_MODE_PINS
|
88
|
-
|
89
|
-
@@init = false # once wiringPiSetup has been called, we don't have to do it again
|
90
|
-
|
91
|
-
def initialize( mode=WPI_MODE_PINS )
|
92
|
-
|
93
|
-
@mode = mode
|
94
|
-
self.wiringPiSetup unless @@init
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def wiringPiMode( mode )
|
99
|
-
|
100
|
-
@mode = mode
|
101
|
-
Wiringpi.wiringPiGpioMode( @mode )
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
def wiringPiSetup
|
106
|
-
|
107
|
-
begin
|
108
|
-
if @mode == WPI_MODE_PINS
|
109
|
-
Wiringpi.wiringPiSetup
|
110
|
-
elsif @mode == WPI_MODE_GPIO
|
111
|
-
Wiringpi.wiringPiSetupGpio
|
112
|
-
elsif @mode == WPI_MODE_SYS
|
113
|
-
Wiringpi.wiringPiSetupSys
|
114
|
-
end
|
115
|
-
rescue Exception=>e
|
116
|
-
raise e
|
29
|
+
def new
|
30
|
+
@pin_end = @pin_base + @pin_count
|
31
|
+
updateName
|
117
32
|
end
|
118
33
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
def checkPin(pin)
|
125
|
-
|
126
|
-
( @mode = WPI_MODE_PINS and PINS.include?(pin) ) or ( @mode = WPI_MODE_GPIO and GPIO_PINS.include?(pin) )
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
def pinError(pin)
|
131
|
-
"invalid #{pin}, available gpio pins: #{PINS}" if @mode == WPI_MODE_PINS
|
132
|
-
"invalid #{pin}, available gpio pins: #{GPIO_PINS}" if @mode == WPI_MODE_GPIO
|
133
|
-
end
|
134
|
-
|
135
|
-
def read(pin)
|
136
|
-
|
137
|
-
raise ArgumentError, pinError(pin) unless checkPin(pin)
|
138
|
-
|
139
|
-
Wiringpi.digitalRead(pin)
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
def pwmWrite(pin,value)
|
144
|
-
|
145
|
-
raise ArgumentError, pinError(pin) unless checkPin(pin)
|
146
|
-
|
147
|
-
Wiringpi.pwmWrite(pin,value)
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
def write(pin,value)
|
152
|
-
|
153
|
-
raise ArgumentError, pinError(pin) unless checkPin(pin)
|
154
|
-
raise ArgumentError, 'invalid value' unless [0,1].include?(value)
|
155
|
-
|
156
|
-
Wiringpi.digitalWrite(pin,value)
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
def mode(pin,mode)
|
161
|
-
|
162
|
-
raise ArgumentError, pinError(pin) unless checkPin(pin)
|
163
|
-
raise ArgumentError, "invalid mode" unless [INPUT,OUTPUT,PWM_OUTPUT].include?(mode)
|
164
|
-
|
165
|
-
Wiringpi.pinMode(pin, mode)
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
=begin
|
170
|
-
shiftOutArray int dataPin, int clockPin, int latchPin, int[] bits
|
171
|
-
Shifts out an array of ints by converting them into bytes
|
172
|
-
and handing to Wiringpi.shiftOut, must contain only 1s or 0s
|
173
|
-
=end
|
174
|
-
def shiftOutArray(dataPin, clockPin, latchPin, bits)
|
175
|
-
|
176
|
-
raise ArgumentError, "invalid data pin, available gpio pins: #{PINS}" unless checkPin(dataPin)
|
177
|
-
raise ArgumentError, "invalid clock pin, available gpio pins: #{PINS}" unless checkPin(clockPin)
|
178
|
-
raise ArgumentError, "invalid latch pin, available gpio pins: #{PINS}" unless checkPin(latchPin)
|
179
|
-
|
180
|
-
Wiringpi.digitalWrite( latchPin, LOW )
|
181
|
-
|
182
|
-
bits.each_slice(8) do |slice|
|
183
|
-
Wiringpi.shiftOut(dataPin, clockPin, LSBFIRST, slice.reverse.join.to_i(2))
|
184
|
-
end
|
185
|
-
|
186
|
-
Wiringpi.digitalWrite( latchPin, HIGH )
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
=begin
|
191
|
-
shiftOut int dataPin, int clockPin, int latchPin, char
|
192
|
-
Shift out a single 8-bit integer 0-255
|
193
|
-
=end
|
194
|
-
def shiftOut(dataPin, clockPin, byteOrder, char)
|
195
|
-
|
196
|
-
#raise ArgumentError, "invalid data pin, available gpio pins: #{PINS}" unless checkPin(dataPin)
|
197
|
-
#raise ArgumentError, "invalid clock pin, available gpio pins: #{PINS}" unless checkPin(clockPin)
|
198
|
-
#raise ArgumentError, "invalid latch pin, available gpio pins: #{PINS}" unless checkPin(latchPin)
|
199
|
-
|
200
|
-
#Wiringpi.digitalWrite( latchPin, LOW )
|
201
|
-
|
202
|
-
Wiringpi.shiftOut(dataPin, clockPin, byteOrder, char)
|
203
|
-
|
204
|
-
#Wiringpi.digitalWrite( latchPin, HIGH )
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
=begin
|
209
|
-
readAll
|
210
|
-
Reads values of all pins and returns them as a hash
|
211
|
-
=end
|
212
|
-
def readAll
|
213
|
-
|
214
|
-
pinValues = Hash.new
|
215
|
-
|
216
|
-
if @mode == WPI_MODE_GPIO
|
217
|
-
|
218
|
-
GPIO_PINS.each do |pin|
|
219
|
-
|
220
|
-
pinValues[pin] = self.read(pin)
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
else
|
225
|
-
|
226
|
-
PINS.each do |pin|
|
227
|
-
|
228
|
-
pinValues[pin] = self.read(pin)
|
229
|
-
|
230
|
-
end
|
231
|
-
|
34
|
+
def updateName
|
35
|
+
@name = ' at offset ' + @pin_base.to_s
|
232
36
|
end
|
233
37
|
|
234
|
-
pinValues
|
235
|
-
|
236
38
|
end
|
237
|
-
|
238
39
|
end
|
239
40
|
|
240
41
|
end
|
42
|
+
Dir[File.dirname(__FILE__) + '/wiringpi/*.rb'].each {|file| require file }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class GPIO
|
3
|
+
def interrupt(pin, edge, &block)
|
4
|
+
Thread.new do
|
5
|
+
@value = digital_read(pin)
|
6
|
+
@last_value = value
|
7
|
+
loop do
|
8
|
+
@last_value = @value
|
9
|
+
@value = digital_read(pin)
|
10
|
+
|
11
|
+
if @value != @last_value
|
12
|
+
next if @value == 0 and edge == :falling_edge
|
13
|
+
next if @value == 1 and edge == :rising_edge
|
14
|
+
break
|
15
|
+
end
|
16
|
+
block.call @value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class GPIO
|
3
|
+
|
4
|
+
@modules = Array.new
|
5
|
+
@pins = Array.new
|
6
|
+
|
7
|
+
attr_reader :modules, :pins
|
8
|
+
|
9
|
+
def initialize(&block)
|
10
|
+
Wiringpi.wiringPiSetup
|
11
|
+
@pins = Array.new
|
12
|
+
instance_eval &block if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_byte(starting_pin)
|
16
|
+
bits = Array.new
|
17
|
+
8.times do |time|
|
18
|
+
bits << Wiringpi.digitalRead(starting_pin + time)
|
19
|
+
end
|
20
|
+
bits.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_byte(starting_pin, byte)
|
24
|
+
byte = byte.to_s(2) unless byte.length = 8
|
25
|
+
offset = starting_pin
|
26
|
+
byte.each_char do |bit|
|
27
|
+
Wiringpi.digitalWrite(offset, bit)
|
28
|
+
offset += 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def digital_read(pin)
|
33
|
+
if pin.respond_to?(:each)
|
34
|
+
pin.collect do |pin|
|
35
|
+
Wiringpi.digitalRead(pin)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
Wiringpi.digitalRead(pin)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def digital_write(pin, value)
|
43
|
+
if pin.respond_to?(:each)
|
44
|
+
pin.each do |pin|
|
45
|
+
Wiringpi.digitalWrite(pin, value)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
Wiringpi.digitalWrite(pin, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def pin_mode(pin, mode)
|
53
|
+
Wiringpi.pinMode(pin, mode)
|
54
|
+
end
|
55
|
+
|
56
|
+
def pull_up_dn_control(pin,mode)
|
57
|
+
Wiringpi.pullUpDnControl(pin, mode)
|
58
|
+
end
|
59
|
+
|
60
|
+
def delay(ms)
|
61
|
+
Wiringpi.delay(ms)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delay_microseconds(ms)
|
65
|
+
Wiringpi.delayMicroseconds(ms)
|
66
|
+
end
|
67
|
+
|
68
|
+
def millis()
|
69
|
+
return Wiringpi.millis()
|
70
|
+
end
|
71
|
+
|
72
|
+
def micros()
|
73
|
+
return Wiringpi.micros()
|
74
|
+
end
|
75
|
+
|
76
|
+
def pi_board_rev()
|
77
|
+
return Wiringpi.piBoardRev()
|
78
|
+
end
|
79
|
+
|
80
|
+
def wpi_pin_to_gpio(pin)
|
81
|
+
return Wiringpi.wpiPinToGpio(pin)
|
82
|
+
end
|
83
|
+
|
84
|
+
def phys_pin_to_gpio(pin)
|
85
|
+
return Wiringpi.physPinToGpio(pin)
|
86
|
+
end
|
87
|
+
|
88
|
+
def pwm_set_mode(mode)
|
89
|
+
return Wiringpi.pwmSetMode(mode)
|
90
|
+
end
|
91
|
+
|
92
|
+
def pwm_set_range(range)
|
93
|
+
return Wiringpi.pwmSetRange(range)
|
94
|
+
end
|
95
|
+
|
96
|
+
def pwm_set_clock(divisor)
|
97
|
+
return Wiringpi.pwmSetClock(divisor)
|
98
|
+
end
|
99
|
+
|
100
|
+
def soft_pwm_create(pin, initial_value, pwm_range)
|
101
|
+
return Wiringpi.softPwmCreate(pin, initial_value, pwm_range)
|
102
|
+
end
|
103
|
+
|
104
|
+
def soft_pwm_write(pin, value)
|
105
|
+
Wiringpi.softPwmWrite(pin, value)
|
106
|
+
end
|
107
|
+
|
108
|
+
def gpio_clock_set(pin, freq)
|
109
|
+
return Wiringpi.gpioClockSet(pin, freq)
|
110
|
+
end
|
111
|
+
|
112
|
+
def wait_for_interrupt(pin, ms)
|
113
|
+
Wiringpi.waitForInterrupt(pin, ms)
|
114
|
+
end
|
115
|
+
|
116
|
+
def wiringpi_isr(pin, mode, fn)
|
117
|
+
Wiringpi.wiringPiISR(pin, mode, fn)
|
118
|
+
end
|
119
|
+
|
120
|
+
def shift_out(dpin, cpin, order, val )
|
121
|
+
Wiringpi.shiftOut(dpin,cpin,order,val)
|
122
|
+
end
|
123
|
+
|
124
|
+
def shift_in(dpin, cpin, order)
|
125
|
+
Wiringpi.shiftIn(dpin,cpin,order)
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_module(module_instance)
|
129
|
+
@modules = Array.new if @modules.nil?
|
130
|
+
|
131
|
+
@modules << module_instance
|
132
|
+
puts 'Added module ' + module_instance.name.to_s
|
133
|
+
|
134
|
+
module_instance.pin_count.times do |offset|
|
135
|
+
@pins[offset + module_instance.pin_base] = 'ENABLED'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/wiringpi/i2c.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class I2C
|
3
|
+
@device_id = 0
|
4
|
+
def initialize(device_address)
|
5
|
+
@device_id = Wiringpi.wiringPiI2CSetup(device_address)
|
6
|
+
end
|
7
|
+
def read()
|
8
|
+
return Wiringpi.wiringPiI2CRead(@device_id)
|
9
|
+
end
|
10
|
+
def write(data)
|
11
|
+
return Wiringpi.wiringPiI2CWrite(@device_id,data)
|
12
|
+
end
|
13
|
+
def read_reg_8(reg)
|
14
|
+
return Wiringpi.wiringPiI2CReadReg8(@device_id,reg)
|
15
|
+
end
|
16
|
+
def write_reg_8(reg,data)
|
17
|
+
return Wiringpi.wiringPiI2CWriteReg8(@device_id,reg,data)
|
18
|
+
end
|
19
|
+
def read_reg_16(reg)
|
20
|
+
return Wiringpi.wiringPiI2CReadReg16(@device_id,reg)
|
21
|
+
end
|
22
|
+
def write_reg_16(reg,data)
|
23
|
+
return Wiringpi.wiringPiI2CWriteReg16(@device_id,reg,data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|