wiringpi-ruby 2.0.0 → 2.0.1

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 (156) hide show
  1. checksums.yaml +4 -4
  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 +238 -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 +177 -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/devLib/scrollPhat.c +430 -0
  21. data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
  22. data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
  23. data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
  24. data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
  25. data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
  26. data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
  27. data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
  28. data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
  29. data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
  30. data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
  31. data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
  32. data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
  33. data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
  34. data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
  35. data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
  36. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
  37. data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
  38. data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
  39. data/ext/wiringpi/WiringPi/examples/blink-thread.c +61 -0
  40. data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
  41. data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
  42. data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
  43. data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
  44. data/ext/wiringpi/WiringPi/examples/blink8-drcn.c +61 -0
  45. data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
  46. data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
  47. data/ext/wiringpi/WiringPi/examples/delayTest.c +102 -0
  48. data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
  49. data/ext/wiringpi/WiringPi/examples/header.h +23 -0
  50. data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
  51. data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
  52. data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
  53. data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
  54. data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
  55. data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
  56. data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
  57. data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
  58. data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
  59. data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
  60. data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
  61. data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
  62. data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
  63. data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
  64. data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
  65. data/ext/wiringpi/WiringPi/examples/rht03.c +86 -0
  66. data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
  67. data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
  68. data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
  69. data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
  70. data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
  71. data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
  72. data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
  73. data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
  74. data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
  75. data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
  76. data/ext/wiringpi/WiringPi/gpio/gpio.c +1538 -0
  77. data/ext/wiringpi/WiringPi/gpio/readall.c +403 -0
  78. data/ext/wiringpi/WiringPi/version.h +3 -0
  79. data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
  80. data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
  81. data/ext/wiringpi/WiringPi/wiringPi/bmp180.c +237 -0
  82. data/ext/wiringpi/WiringPi/wiringPi/bmp180.h +34 -0
  83. data/ext/wiringpi/WiringPi/wiringPi/drcNet.c +405 -0
  84. data/ext/wiringpi/WiringPi/wiringPi/drcNet.h +42 -0
  85. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +196 -0
  86. data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
  87. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.c +146 -0
  88. data/ext/wiringpi/WiringPi/wiringPi/ds18b20.h +34 -0
  89. data/ext/wiringpi/WiringPi/wiringPi/htu21d.c +150 -0
  90. data/ext/wiringpi/WiringPi/wiringPi/htu21d.h +34 -0
  91. data/ext/wiringpi/WiringPi/wiringPi/max31855.c +99 -0
  92. data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
  93. data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
  94. data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
  95. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
  96. data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
  97. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
  98. data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
  99. data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
  100. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
  101. data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
  102. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +188 -0
  103. data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
  104. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +235 -0
  105. data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
  106. data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
  107. data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
  108. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
  109. data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
  110. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
  111. data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
  112. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +125 -0
  113. data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
  114. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
  115. data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
  116. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
  117. data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
  118. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
  119. data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
  120. data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
  121. data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
  122. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.c +95 -0
  123. data/ext/wiringpi/WiringPi/wiringPi/pseudoPins.h +26 -0
  124. data/ext/wiringpi/WiringPi/wiringPi/rht03.c +252 -0
  125. data/ext/wiringpi/WiringPi/wiringPi/rht03.h +25 -0
  126. data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
  127. data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
  128. data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +186 -0
  129. data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
  130. data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
  131. data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
  132. data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
  133. data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
  134. data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
  135. data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
  136. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2507 -0
  137. data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +269 -0
  138. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +233 -0
  139. data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
  140. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +144 -0
  141. data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
  142. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +225 -0
  143. data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
  144. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
  145. data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
  146. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +928 -0
  147. data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
  148. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.c +82 -0
  149. data/ext/wiringpi/WiringPi/wiringPiD/daemonise.h +9 -0
  150. data/ext/wiringpi/WiringPi/wiringPiD/drcNetCmd.h +43 -0
  151. data/ext/wiringpi/WiringPi/wiringPiD/network.c +330 -0
  152. data/ext/wiringpi/WiringPi/wiringPiD/network.h +31 -0
  153. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.c +126 -0
  154. data/ext/wiringpi/WiringPi/wiringPiD/runRemote.h +29 -0
  155. data/ext/wiringpi/WiringPi/wiringPiD/wiringpid.c +382 -0
  156. metadata +155 -1
@@ -0,0 +1,177 @@
1
+ /*
2
+ * piFace.:
3
+ * Copyright (c) 2012-2016 Gordon Henderson
4
+ *
5
+ * This file to interface with the PiFace peripheral device which
6
+ * has an MCP23S17 GPIO device connected via the SPI bus.
7
+ ***********************************************************************
8
+ * This file is part of wiringPi:
9
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
10
+ *
11
+ * wiringPi is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU Lesser General Public License as
13
+ * published by the Free Software Foundation, either version 3 of the
14
+ * License, or (at your option) any later version.
15
+ *
16
+ * wiringPi is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU Lesser General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU Lesser General Public
22
+ * License along with wiringPi.
23
+ * If not, see <http://www.gnu.org/licenses/>.
24
+ ***********************************************************************
25
+ */
26
+
27
+
28
+ #include <stdio.h>
29
+ #include <stdint.h>
30
+
31
+ #include <wiringPi.h>
32
+ #include <wiringPiSPI.h>
33
+
34
+ #include "../wiringPi/mcp23x0817.h"
35
+
36
+ #include "piFace.h"
37
+
38
+ #define PIFACE_SPEED 4000000
39
+ #define PIFACE_DEVNO 0
40
+
41
+
42
+
43
+ /*
44
+ * writeByte:
45
+ * Write a byte to a register on the MCP23S17 on the SPI bus.
46
+ *********************************************************************************
47
+ */
48
+
49
+ static void writeByte (uint8_t reg, uint8_t data)
50
+ {
51
+ uint8_t spiData [4] ;
52
+
53
+ spiData [0] = CMD_WRITE ;
54
+ spiData [1] = reg ;
55
+ spiData [2] = data ;
56
+
57
+ wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
58
+ }
59
+
60
+ /*
61
+ * readByte:
62
+ * Read a byte from a register on the MCP23S17 on the SPI bus.
63
+ *********************************************************************************
64
+ */
65
+
66
+ static uint8_t readByte (uint8_t reg)
67
+ {
68
+ uint8_t spiData [4] ;
69
+
70
+ spiData [0] = CMD_READ ;
71
+ spiData [1] = reg ;
72
+
73
+ wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
74
+
75
+ return spiData [2] ;
76
+ }
77
+
78
+
79
+ /*
80
+ * myDigitalWrite:
81
+ * Perform the digitalWrite function on the PiFace board
82
+ *********************************************************************************
83
+ */
84
+
85
+ void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
86
+ {
87
+ uint8_t mask, old ;
88
+
89
+ pin -= node->pinBase ;
90
+ mask = 1 << pin ;
91
+ old = readByte (MCP23x17_GPIOA) ;
92
+
93
+ if (value == 0)
94
+ old &= (~mask) ;
95
+ else
96
+ old |= mask ;
97
+
98
+ writeByte (MCP23x17_GPIOA, old) ;
99
+ }
100
+
101
+
102
+ /*
103
+ * myDigitalRead:
104
+ * Perform the digitalRead function on the PiFace board
105
+ *********************************************************************************
106
+ */
107
+
108
+ int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
109
+ {
110
+ uint8_t mask, reg ;
111
+
112
+ mask = 1 << ((pin - node->pinBase) & 7) ;
113
+
114
+ if (pin < 8)
115
+ reg = MCP23x17_GPIOB ; // Input regsiter
116
+ else
117
+ reg = MCP23x17_OLATA ; // Output latch regsiter
118
+
119
+ if ((readByte (reg) & mask) != 0)
120
+ return HIGH ;
121
+ else
122
+ return LOW ;
123
+ }
124
+
125
+
126
+ /*
127
+ * myPullUpDnControl:
128
+ * Perform the pullUpDnControl function on the PiFace board
129
+ *********************************************************************************
130
+ */
131
+
132
+ void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
133
+ {
134
+ uint8_t mask, old ;
135
+
136
+ mask = 1 << (pin - node->pinBase) ;
137
+ old = readByte (MCP23x17_GPPUB) ;
138
+
139
+ if (pud == 0)
140
+ old &= (~mask) ;
141
+ else
142
+ old |= mask ;
143
+
144
+ writeByte (MCP23x17_GPPUB, old) ;
145
+ }
146
+
147
+
148
+ /*
149
+ * piFaceSetup
150
+ * Setup the SPI interface and initialise the MCP23S17 chip
151
+ * We create one node with 16 pins - each if the first 8 pins being read
152
+ * and write - although the operations actually go to different
153
+ * hardware ports. The top 8 let you read the state of the output register.
154
+ *********************************************************************************
155
+ */
156
+
157
+ int piFaceSetup (const int pinBase)
158
+ {
159
+ int x ;
160
+ struct wiringPiNodeStruct *node ;
161
+
162
+ if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
163
+ return x ;
164
+
165
+ // Setup the MCP23S17
166
+
167
+ writeByte (MCP23x17_IOCON, IOCON_INIT) ;
168
+ writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
169
+ writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
170
+
171
+ node = wiringPiNewNode (pinBase, 16) ;
172
+ node->digitalRead = myDigitalRead ;
173
+ node->digitalWrite = myDigitalWrite ;
174
+ node->pullUpDnControl = myPullUpDnControl ;
175
+
176
+ return 0 ;
177
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+ * piGlow.c:
3
+ * Easy access to the Pimoroni PiGlow board.
4
+ *
5
+ * Copyright (c) 2013 Gordon Henderson.
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+ #include <wiringPi.h>
26
+ #include <sn3218.h>
27
+
28
+ #include "piGlow.h"
29
+
30
+ #define PIGLOW_BASE 577
31
+
32
+ static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
33
+ static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
34
+ static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ;
35
+
36
+
37
+ /*
38
+ * piGlow1:
39
+ * Light up an individual LED
40
+ *********************************************************************************
41
+ */
42
+
43
+ void piGlow1 (const int leg, const int ring, const int intensity)
44
+ {
45
+ int *legLeds ;
46
+
47
+ if ((leg < 0) || (leg > 2)) return ;
48
+ if ((ring < 0) || (ring > 5)) return ;
49
+
50
+ /**/ if (leg == 0)
51
+ legLeds = leg0 ;
52
+ else if (leg == 1)
53
+ legLeds = leg1 ;
54
+ else
55
+ legLeds = leg2 ;
56
+
57
+ analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
58
+ }
59
+
60
+ /*
61
+ * piGlowLeg:
62
+ * Light up all 6 LEDs on a leg
63
+ *********************************************************************************
64
+ */
65
+
66
+ void piGlowLeg (const int leg, const int intensity)
67
+ {
68
+ int i ;
69
+ int *legLeds ;
70
+
71
+ if ((leg < 0) || (leg > 2))
72
+ return ;
73
+
74
+ /**/ if (leg == 0)
75
+ legLeds = leg0 ;
76
+ else if (leg == 1)
77
+ legLeds = leg1 ;
78
+ else
79
+ legLeds = leg2 ;
80
+
81
+ for (i = 0 ; i < 6 ; ++i)
82
+ analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
83
+ }
84
+
85
+
86
+ /*
87
+ * piGlowRing:
88
+ * Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
89
+ *********************************************************************************
90
+ */
91
+
92
+ void piGlowRing (const int ring, const int intensity)
93
+ {
94
+ if ((ring < 0) || (ring > 5))
95
+ return ;
96
+
97
+ analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
98
+ analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
99
+ analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
100
+ }
101
+
102
+ /*
103
+ * piGlowSetup:
104
+ * Initialise the board & remember the pins we're using
105
+ *********************************************************************************
106
+ */
107
+
108
+ void piGlowSetup (int clear)
109
+ {
110
+ sn3218Setup (PIGLOW_BASE) ;
111
+
112
+ if (clear)
113
+ {
114
+ piGlowLeg (0, 0) ;
115
+ piGlowLeg (1, 0) ;
116
+ piGlowLeg (2, 0) ;
117
+ }
118
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * piglow.h:
3
+ * Easy access to the Pimoroni PiGlow board.
4
+ *
5
+ * Copyright (c) 2013 Gordon Henderson.
6
+ ***********************************************************************
7
+ * This file is part of wiringPi:
8
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
9
+ *
10
+ * wiringPi is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU Lesser General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * wiringPi is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public License
21
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22
+ ***********************************************************************
23
+ */
24
+
25
+
26
+ #define PIGLOW_RED 0
27
+ #define PIGLOW_ORANGE 1
28
+ #define PIGLOW_YELLOW 2
29
+ #define PIGLOW_GREEN 3
30
+ #define PIGLOW_BLUE 4
31
+ #define PIGLOW_WHITE 5
32
+
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ extern void piGlow1 (const int leg, const int ring, const int intensity) ;
39
+ extern void piGlowLeg (const int leg, const int intensity) ;
40
+ extern void piGlowRing (const int ring, const int intensity) ;
41
+ extern void piGlowSetup (int clear) ;
42
+
43
+ #ifdef __cplusplus
44
+ }
45
+ #endif
@@ -0,0 +1,113 @@
1
+ /*
2
+ * piNes.c:
3
+ * Driver for the NES Joystick controller on the Raspberry Pi
4
+ * Copyright (c) 2012 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 <wiringPi.h>
26
+
27
+ #include "piNes.h"
28
+
29
+ #define MAX_NES_JOYSTICKS 8
30
+
31
+ #define NES_RIGHT 0x01
32
+ #define NES_LEFT 0x02
33
+ #define NES_DOWN 0x04
34
+ #define NES_UP 0x08
35
+ #define NES_START 0x10
36
+ #define NES_SELECT 0x20
37
+ #define NES_B 0x40
38
+ #define NES_A 0x80
39
+
40
+
41
+ #define PULSE_TIME 25
42
+
43
+ // Data to store the pins for each controller
44
+
45
+ struct nesPinsStruct
46
+ {
47
+ unsigned int cPin, dPin, lPin ;
48
+ } ;
49
+
50
+ static struct nesPinsStruct nesPins [MAX_NES_JOYSTICKS] ;
51
+
52
+ static int joysticks = 0 ;
53
+
54
+
55
+ /*
56
+ * setupNesJoystick:
57
+ * Create a new NES joystick interface, program the pins, etc.
58
+ *********************************************************************************
59
+ */
60
+
61
+ int setupNesJoystick (int dPin, int cPin, int lPin)
62
+ {
63
+ if (joysticks == MAX_NES_JOYSTICKS)
64
+ return -1 ;
65
+
66
+ nesPins [joysticks].dPin = dPin ;
67
+ nesPins [joysticks].cPin = cPin ;
68
+ nesPins [joysticks].lPin = lPin ;
69
+
70
+ digitalWrite (lPin, LOW) ;
71
+ digitalWrite (cPin, LOW) ;
72
+
73
+ pinMode (lPin, OUTPUT) ;
74
+ pinMode (cPin, OUTPUT) ;
75
+ pinMode (dPin, INPUT) ;
76
+
77
+ return joysticks++ ;
78
+ }
79
+
80
+
81
+ /*
82
+ * readNesJoystick:
83
+ * Do a single scan of the NES Joystick.
84
+ *********************************************************************************
85
+ */
86
+
87
+ unsigned int readNesJoystick (int joystick)
88
+ {
89
+ unsigned int value = 0 ;
90
+ int i ;
91
+
92
+ struct nesPinsStruct *pins = &nesPins [joystick] ;
93
+
94
+ // Toggle Latch - which presents the first bit
95
+
96
+ digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
97
+ digitalWrite (pins->lPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
98
+
99
+ // Read first bit
100
+
101
+ value = digitalRead (pins->dPin) ;
102
+
103
+ // Now get the next 7 bits with the clock
104
+
105
+ for (i = 0 ; i < 7 ; ++i)
106
+ {
107
+ digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
108
+ digitalWrite (pins->cPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
109
+ value = (value << 1) | digitalRead (pins->dPin) ;
110
+ }
111
+
112
+ return value ^ 0xFF ;
113
+ }