wiringpi 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
  3. data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
  4. data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
  5. data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
  6. data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
  7. data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
  12. data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
  13. data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
  14. data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
  15. data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
  16. data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
  17. data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
  18. data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  21. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  22. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  27. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  28. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  29. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  33. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  34. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  35. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  36. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  37. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  38. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  39. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  40. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  41. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  42. data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
  43. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  44. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  45. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  46. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  47. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  48. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  49. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  50. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  51. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  52. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  53. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  54. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  55. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  56. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  57. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  58. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  59. data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
  60. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  61. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  62. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  63. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  64. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  65. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  66. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  67. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  68. data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
  69. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  70. data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
  71. data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  78. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  121. data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
  122. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  123. data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
  124. data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
  125. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  127. data/ext/wiringpi/extconf.rb +7 -1
  128. data/ext/wiringpi/wiringpi_wrap.c +1741 -218
  129. data/lib/wiringpi.rb +24 -222
  130. data/lib/wiringpi/event.rb +21 -0
  131. data/lib/wiringpi/gpio.rb +139 -0
  132. data/lib/wiringpi/i2c.rb +26 -0
  133. data/lib/wiringpi/mcp23x17.rb +31 -0
  134. data/lib/wiringpi/serial.rb +49 -0
  135. data/lib/wiringpi/spi.rb +15 -0
  136. metadata +146 -22
  137. data/ext/wiringpi/wiringPi.c +0 -729
  138. data/ext/wiringpi/wiringPi.h +0 -69
@@ -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
- class Serial
5
+ HIGH = 1
6
+ LOW = 0
27
7
 
28
- @id = 0
29
- @device = '/dev/ttyAMA0'
30
- @baud = 9600
8
+ INPUT = 0
9
+ OUTPUT = 1
10
+ PWM_OUTPUT = 1
31
11
 
32
- def initialize(device='/dev/ttyAMA0',baud=9600)
12
+ PUD_OFF = 0
13
+ PUD_DOWN = 1
14
+ PUD_UP = 2
33
15
 
34
- @device = device
35
- @baud = baud
16
+ LSPFIRST = 0
17
+ MSBFIRST = 1
36
18
 
37
- @id = Wiringpi.serialOpen( @device,@baud )
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
- def serialGetchar
22
+ @name = 'Unknown'
23
+ @pin_base = 0
24
+ @pin_count = 0
25
+ @pin_end = 0
67
26
 
68
- Wiringpi.serialGetchar( @id )
27
+ attr_reader :name, :pin_base, :pin_count, :pin_end
69
28
 
70
- end
71
-
72
- end
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
- #Wiringpi.wiringPiGpioMode( @mode )
120
- @@init = true
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
@@ -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