wiring_lmk 2.0.0

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 (87) hide show
  1. checksums.yaml +7 -0
  2. data/ext/wiringpi/WiringPi/devLib/ds1302.c +254 -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 +507 -0
  8. data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
  9. data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +684 -0
  10. data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
  11. data/ext/wiringpi/WiringPi/devLib/maxdetect.c +167 -0
  12. data/ext/wiringpi/WiringPi/devLib/maxdetect.h +40 -0
  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 +117 -0
  19. data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
  20. data/ext/wiringpi/WiringPi/gpio/extensions.c +700 -0
  21. data/ext/wiringpi/WiringPi/gpio/extensions.h +26 -0
  22. data/ext/wiringpi/WiringPi/gpio/gpio.c +1280 -0
  23. data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
  24. data/ext/wiringpi/WiringPi/gpio/readall.c +337 -0
  25. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
  26. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  27. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
  28. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  29. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  30. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  31. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  32. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  33. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  34. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  35. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  36. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  37. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  38. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
  39. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  40. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +234 -0
  41. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  42. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  43. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  44. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  45. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  46. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  47. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  48. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +113 -0
  49. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  50. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  51. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  52. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  53. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  54. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +92 -0
  55. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  56. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  57. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  58. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  59. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  60. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +168 -0
  61. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  62. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +247 -0
  63. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  64. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  65. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  66. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +113 -0
  67. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  68. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +3688 -0
  69. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +229 -0
  70. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +236 -0
  71. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  72. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +121 -0
  73. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
  74. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +253 -0
  75. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  76. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  77. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  78. data/ext/wiringpi/extconf.rb +8 -0
  79. data/ext/wiringpi/wiringpi_wrap.c +4396 -0
  80. data/lib/wiring_lmk.rb +42 -0
  81. data/lib/wiring_lmk/event.rb +21 -0
  82. data/lib/wiring_lmk/gpio.rb +139 -0
  83. data/lib/wiring_lmk/i2c.rb +26 -0
  84. data/lib/wiring_lmk/mcp23x17.rb +31 -0
  85. data/lib/wiring_lmk/serial.rb +49 -0
  86. data/lib/wiring_lmk/spi.rb +15 -0
  87. metadata +136 -0
@@ -0,0 +1,33 @@
1
+ /*
2
+ * pins.c:
3
+ * Just display a handy Pi pinnout diagram.
4
+ * Copyright (c) 2012-2015 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public License
20
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
21
+ ***********************************************************************
22
+ */
23
+
24
+
25
+ #include <stdio.h>
26
+
27
+ void doPins (void)
28
+ {
29
+ printf ("The pins command has been deprecated - sorry. Please use the\n") ;
30
+ printf (" gpio readall\n") ;
31
+ printf ("command to get a list of the pinnouts for your Pi.\n") ;
32
+ }
33
+
@@ -0,0 +1,337 @@
1
+ /*
2
+ * readall.c:
3
+ * The readall functions - getting a bit big, so split them out.
4
+ * Copyright (c) 2012-2013 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public License
20
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
21
+ ***********************************************************************
22
+ */
23
+
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <stdint.h>
28
+ #include <ctype.h>
29
+ #include <string.h>
30
+ #include <unistd.h>
31
+ #include <errno.h>
32
+ #include <fcntl.h>
33
+ #include <sys/types.h>
34
+ #include <sys/stat.h>
35
+
36
+ #include "wiringPi.h"
37
+
38
+ extern int wpMode ;
39
+
40
+ #ifndef TRUE
41
+ # define TRUE (1==1)
42
+ # define FALSE (1==2)
43
+ #endif
44
+
45
+ /*
46
+ * doReadallExternal:
47
+ * A relatively crude way to read the pins on an external device.
48
+ * We don't know the input/output mode of pins, but we can tell
49
+ * if it's an analog pin or a digital one...
50
+ *********************************************************************************
51
+ */
52
+
53
+ static void doReadallExternal (void)
54
+ {
55
+ int pin ;
56
+
57
+ printf ("+------+---------+--------+\n") ;
58
+ printf ("| Pin | Digital | Analog |\n") ;
59
+ printf ("+------+---------+--------+\n") ;
60
+
61
+ for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
62
+ printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
63
+
64
+ printf ("+------+---------+--------+\n") ;
65
+ }
66
+
67
+
68
+ /*
69
+ * doReadall:
70
+ * Read all the GPIO pins
71
+ * We also want to use this to read the state of pins on an externally
72
+ * connected device, so we need to do some fiddling with the internal
73
+ * wiringPi node structures - since the gpio command can only use
74
+ * one external device at a time, we'll use that to our advantage...
75
+ *********************************************************************************
76
+ */
77
+
78
+ static char *alts [] =
79
+ {
80
+ "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
81
+ } ;
82
+
83
+ static int physToWpi [64] =
84
+ {
85
+ -1, // 0
86
+ -1, -1, // 1, 2
87
+ 8, -1,
88
+ 9, -1,
89
+ 7, 15,
90
+ -1, 16,
91
+ 0, 1,
92
+ 2, -1,
93
+ 3, 4,
94
+ -1, 5,
95
+ 12, -1,
96
+ 13, 6,
97
+ 14, 10,
98
+ -1, 11, // 25, 26
99
+ 30, 31, // Actually I2C, but not used
100
+ 21, -1,
101
+ 22, 26,
102
+ 23, -1,
103
+ 24, 27,
104
+ 25, 28,
105
+ -1, 29,
106
+ -1, -1,
107
+ -1, -1,
108
+ -1, -1,
109
+ -1, -1,
110
+ -1, -1,
111
+ 17, 18,
112
+ 19, 20,
113
+ -1, -1, -1, -1, -1, -1, -1, -1, -1
114
+ } ;
115
+
116
+ static char *physNames [64] =
117
+ {
118
+ NULL,
119
+
120
+ " 3.3v", "5v ",
121
+ " SDA.1", "5V ",
122
+ " SCL.1", "0v ",
123
+ "GPIO. 7", "TxD ",
124
+ " 0v", "RxD ",
125
+ "GPIO. 0", "GPIO. 1",
126
+ "GPIO. 2", "0v ",
127
+ "GPIO. 3", "GPIO. 4",
128
+ " 3.3v", "GPIO. 5",
129
+ " MOSI", "0v ",
130
+ " MISO", "GPIO. 6",
131
+ " SCLK", "CE0 ",
132
+ " 0v", "CE1 ",
133
+ " SDA.0", "SCL.0 ",
134
+ "GPIO.21", "0v ",
135
+ "GPIO.22", "GPIO.26",
136
+ "GPIO.23", "0v ",
137
+ "GPIO.24", "GPIO.27",
138
+ "GPIO.25", "GPIO.28",
139
+ " 0v", "GPIO.29",
140
+ NULL, NULL,
141
+ NULL, NULL,
142
+ NULL, NULL,
143
+ NULL, NULL,
144
+ NULL, NULL,
145
+ "GPIO.17", "GPIO.18",
146
+ "GPIO.19", "GPIO.20",
147
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
148
+ } ;
149
+
150
+
151
+ /*
152
+ * readallPhys:
153
+ * Given a physical pin output the data on it and the next pin:
154
+ *| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
155
+ *********************************************************************************
156
+ */
157
+
158
+ static void readallPhys (int physPin)
159
+ {
160
+ int pin ;
161
+
162
+ if (physPinToGpio (physPin) == -1)
163
+ printf (" | | ") ;
164
+ else
165
+ printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
166
+
167
+ printf (" | %s", physNames [physPin]) ;
168
+
169
+ if (physToWpi [physPin] == -1)
170
+ printf (" | | ") ;
171
+ else
172
+ {
173
+ /**/ if (wpMode == WPI_MODE_GPIO)
174
+ pin = physPinToGpio (physPin) ;
175
+ else if (wpMode == WPI_MODE_PHYS)
176
+ pin = physPin ;
177
+ else
178
+ pin = physToWpi [physPin] ;
179
+
180
+ printf (" | %4s", alts [getAlt (pin)]) ;
181
+ printf (" | %d", digitalRead (pin)) ;
182
+ }
183
+
184
+ // Pin numbers:
185
+
186
+ printf (" | %2d", physPin) ;
187
+ ++physPin ;
188
+ printf (" || %-2d", physPin) ;
189
+
190
+ // Same, reversed
191
+
192
+ if (physToWpi [physPin] == -1)
193
+ printf (" | | ") ;
194
+ else
195
+ {
196
+ /**/ if (wpMode == WPI_MODE_GPIO)
197
+ pin = physPinToGpio (physPin) ;
198
+ else if (wpMode == WPI_MODE_PHYS)
199
+ pin = physPin ;
200
+ else
201
+ pin = physToWpi [physPin] ;
202
+
203
+ printf (" | %d", digitalRead (pin)) ;
204
+ printf (" | %-4s", alts [getAlt (pin)]) ;
205
+ }
206
+
207
+ printf (" | %-5s", physNames [physPin]) ;
208
+
209
+ if (physToWpi [physPin] == -1)
210
+ printf (" | | ") ;
211
+ else
212
+ printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
213
+
214
+ printf (" |\n") ;
215
+ }
216
+
217
+
218
+ void cmReadall (void)
219
+ {
220
+ int pin ;
221
+
222
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
223
+ printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
224
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
225
+
226
+ for (pin = 0 ; pin < 28 ; ++pin)
227
+ {
228
+ printf ("| %3d ", pin) ;
229
+ printf ("| %-4s ", alts [getAlt (pin)]) ;
230
+ printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
231
+ printf ("| ") ;
232
+ printf ("| %3d ", pin + 28) ;
233
+ printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
234
+ printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
235
+ printf ("|\n") ;
236
+ }
237
+
238
+ printf ("+-----+------+-------+ +-----+------+-------+\n") ;
239
+ }
240
+
241
+
242
+ /*
243
+ * abReadall:
244
+ * Read all the pins on the model A or B.
245
+ *********************************************************************************
246
+ */
247
+
248
+ void abReadall (int model, int rev)
249
+ {
250
+ int pin ;
251
+ char *type ;
252
+
253
+ if (model == PI_MODEL_A)
254
+ type = " A" ;
255
+ else if (rev == PI_VERSION_2)
256
+ type = "B2" ;
257
+ else
258
+ type = "B1" ;
259
+
260
+ printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
261
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
262
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
263
+ for (pin = 1 ; pin <= 26 ; pin += 2)
264
+ readallPhys (pin) ;
265
+
266
+ if (rev == PI_VERSION_2) // B version 2
267
+ {
268
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
269
+ for (pin = 51 ; pin <= 54 ; pin += 2)
270
+ readallPhys (pin) ;
271
+ }
272
+
273
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
274
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
275
+ printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
276
+ }
277
+
278
+
279
+ /*
280
+ * bPlusReadall:
281
+ * Read all the pins on the model B+
282
+ *********************************************************************************
283
+ */
284
+
285
+ void bPlusReadall (void)
286
+ {
287
+ int pin ;
288
+
289
+ printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
290
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
291
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
292
+ for (pin = 1 ; pin <= 40 ; pin += 2)
293
+ readallPhys (pin) ;
294
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
295
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
296
+ printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
297
+ }
298
+
299
+ //add for BananaPro by lemaker team
300
+ void BPReadAll(void)
301
+ {
302
+ int pin ;
303
+
304
+ printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
305
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
306
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
307
+ for (pin = 1 ; pin <= 40 ; pin += 2)
308
+ readallPhys (pin) ;
309
+ printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
310
+ printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
311
+ printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
312
+ }
313
+ //end 2014.09.26
314
+
315
+ void doReadall (void)
316
+ {
317
+ int model, rev, mem, maker, overVolted ;
318
+
319
+ if (wiringPiNodes != NULL) // External readall
320
+ {
321
+ doReadallExternal () ;
322
+ return ;
323
+ }
324
+
325
+ piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
326
+
327
+ /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
328
+ abReadall (model, rev) ;
329
+ else if (model == PI_MODEL_BP)
330
+ bPlusReadall () ;
331
+ else if (model == PI_MODEL_CM)
332
+ cmReadall () ;
333
+ else if (model == PI_MODEL_BPR) //add for BananaPro by lemaker team
334
+ BPReadAll();
335
+ else
336
+ printf ("Oops - unable to determine board type... model: %d\n", model) ;
337
+ }
@@ -0,0 +1,201 @@
1
+ /*
2
+ * drcSerial.c:
3
+ * Extend wiringPi with the DRC Serial protocol (e.g. to Arduino)
4
+ * Copyright (c) 2013 Gordon Henderson
5
+ ***********************************************************************
6
+ * This file is part of wiringPi:
7
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
8
+ *
9
+ * wiringPi is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (at your option) any later version.
13
+ *
14
+ * wiringPi is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with wiringPi.
21
+ * If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <stdio.h>
26
+ #include <time.h>
27
+ #include <string.h>
28
+ #include <errno.h>
29
+
30
+ #include "wiringPi.h"
31
+ #include "wiringSerial.h"
32
+
33
+ #include "drcSerial.h"
34
+
35
+ #ifndef TRUE
36
+ # define TRUE (1==1)
37
+ # define FALSE (1==2)
38
+ #endif
39
+
40
+
41
+ /*
42
+ * myPinMode:
43
+ * Change the pin mode on the remote DRC device
44
+ *********************************************************************************
45
+ */
46
+
47
+ static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
48
+ {
49
+ /**/ if (mode == OUTPUT)
50
+ serialPutchar (node->fd, 'o') ; // Input
51
+ else if (mode == PWM_OUTPUT)
52
+ serialPutchar (node->fd, 'p') ; // PWM
53
+ else
54
+ serialPutchar (node->fd, 'i') ; // Default to input
55
+
56
+ serialPutchar (node->fd, pin - node->pinBase) ;
57
+ }
58
+
59
+
60
+ /*
61
+ * myPullUpDnControl:
62
+ * ATmegas only have pull-up's on of off. No pull-downs.
63
+ *********************************************************************************
64
+ */
65
+
66
+ static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
67
+ {
68
+
69
+ // Force pin into input mode
70
+
71
+ serialPutchar (node->fd, 'i' ) ;
72
+ serialPutchar (node->fd, pin - node->pinBase) ;
73
+
74
+ /**/ if (mode == PUD_UP)
75
+ {
76
+ serialPutchar (node->fd, '1') ;
77
+ serialPutchar (node->fd, pin - node->pinBase) ;
78
+ }
79
+ else if (mode == PUD_OFF)
80
+ {
81
+ serialPutchar (node->fd, '0') ;
82
+ serialPutchar (node->fd, pin - node->pinBase) ;
83
+ }
84
+ }
85
+
86
+
87
+ /*
88
+ * myDigitalWrite:
89
+ *********************************************************************************
90
+ */
91
+
92
+ static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
93
+ {
94
+ serialPutchar (node->fd, value == 0 ? '0' : '1') ;
95
+ serialPutchar (node->fd, pin - node->pinBase) ;
96
+ }
97
+
98
+
99
+ /*
100
+ * myPwmWrite:
101
+ *********************************************************************************
102
+ */
103
+
104
+ static void myPwmWrite (struct wiringPiNodeStruct *node, int pin, int value)
105
+ {
106
+ serialPutchar (node->fd, 'v') ;
107
+ serialPutchar (node->fd, pin - node->pinBase) ;
108
+ serialPutchar (node->fd, value & 0xFF) ;
109
+ }
110
+
111
+
112
+ /*
113
+ * myAnalogRead:
114
+ *********************************************************************************
115
+ */
116
+
117
+ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
118
+ {
119
+ int vHi, vLo ;
120
+
121
+ serialPutchar (node->fd, 'a') ;
122
+ serialPutchar (node->fd, pin - node->pinBase) ;
123
+ vHi = serialGetchar (node->fd) ;
124
+ vLo = serialGetchar (node->fd) ;
125
+
126
+ return (vHi << 8) | vLo ;
127
+ }
128
+
129
+
130
+ /*
131
+ * myDigitalRead:
132
+ *********************************************************************************
133
+ */
134
+
135
+ static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
136
+ {
137
+ serialPutchar (node->fd, 'r') ; // Send read command
138
+ serialPutchar (node->fd, pin - node->pinBase) ;
139
+ return (serialGetchar (node->fd) == '0') ? 0 : 1 ;
140
+ }
141
+
142
+
143
+ /*
144
+ * drcSetup:
145
+ * Create a new instance of an DRC GPIO interface.
146
+ * Could be a variable nunber of pins here - we might not know in advance
147
+ * if it's an ATmega with 14 pins, or something with less or more!
148
+ *********************************************************************************
149
+ */
150
+
151
+ int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud)
152
+ {
153
+ int fd ;
154
+ int ok, tries ;
155
+ time_t then ;
156
+ struct wiringPiNodeStruct *node ;
157
+
158
+ if ((fd = serialOpen (device, baud)) < 0)
159
+ return wiringPiFailure (WPI_ALMOST, "Unable to open DRC device (%s): %s", device, strerror (errno)) ;
160
+
161
+ delay (10) ; // May need longer if it's an Uno that reboots on the open...
162
+
163
+ // Flush any pending input
164
+
165
+ while (serialDataAvail (fd))
166
+ (void)serialGetchar (fd) ;
167
+
168
+ ok = FALSE ;
169
+ for (tries = 1 ; (tries < 5) && (!ok) ; ++tries)
170
+ {
171
+ serialPutchar (fd, '@') ; // Ping
172
+ then = time (NULL) + 2 ;
173
+ while (time (NULL) < then)
174
+ if (serialDataAvail (fd))
175
+ {
176
+ if (serialGetchar (fd) == '@')
177
+ {
178
+ ok = TRUE ;
179
+ break ;
180
+ }
181
+ }
182
+ }
183
+
184
+ if (!ok)
185
+ {
186
+ serialClose (fd) ;
187
+ return wiringPiFailure (WPI_FATAL, "Unable to communicate with DRC serial device") ;
188
+ }
189
+
190
+ node = wiringPiNewNode (pinBase, numPins) ;
191
+
192
+ node->fd = fd ;
193
+ node->pinMode = myPinMode ;
194
+ node->pullUpDnControl = myPullUpDnControl ;
195
+ node->analogRead = myAnalogRead ;
196
+ node->digitalRead = myDigitalRead ;
197
+ node->digitalWrite = myDigitalWrite ;
198
+ node->pwmWrite = myPwmWrite ;
199
+
200
+ return 0 ;
201
+ }