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
@@ -0,0 +1,286 @@
|
|
1
|
+
/*
|
2
|
+
* lcd.c:
|
3
|
+
* Text-based LCD driver.
|
4
|
+
* This is designed to drive the parallel interface LCD drivers
|
5
|
+
* based in the Hitachi HD44780U controller and compatables.
|
6
|
+
*
|
7
|
+
* This test program assumes the following:
|
8
|
+
*
|
9
|
+
* 8-bit displays:
|
10
|
+
* GPIO 0-7 is connected to display data pins 0-7.
|
11
|
+
* GPIO 11 is the RS pin.
|
12
|
+
* GPIO 10 is the Strobe/E pin.
|
13
|
+
*
|
14
|
+
* For 4-bit interface:
|
15
|
+
* GPIO 4-7 is connected to display data pins 4-7.
|
16
|
+
* GPIO 11 is the RS pin.
|
17
|
+
* GPIO 10 is the Strobe/E pin.
|
18
|
+
*
|
19
|
+
* Copyright (c) 2012-2013 Gordon Henderson.
|
20
|
+
***********************************************************************
|
21
|
+
* This file is part of wiringPi:
|
22
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
23
|
+
*
|
24
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
25
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
26
|
+
* the Free Software Foundation, either version 3 of the License, or
|
27
|
+
* (at your option) any later version.
|
28
|
+
*
|
29
|
+
* wiringPi is distributed in the hope that it will be useful,
|
30
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32
|
+
* GNU Lesser General Public License for more details.
|
33
|
+
*
|
34
|
+
* You should have received a copy of the GNU Lesser General Public License
|
35
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
36
|
+
***********************************************************************
|
37
|
+
*/
|
38
|
+
|
39
|
+
#include <stdio.h>
|
40
|
+
#include <stdlib.h>
|
41
|
+
#include <stdint.h>
|
42
|
+
|
43
|
+
#include <unistd.h>
|
44
|
+
#include <string.h>
|
45
|
+
#include <time.h>
|
46
|
+
|
47
|
+
#include <wiringPi.h>
|
48
|
+
#include <lcd.h>
|
49
|
+
|
50
|
+
#ifndef TRUE
|
51
|
+
# define TRUE (1==1)
|
52
|
+
# define FALSE (1==2)
|
53
|
+
#endif
|
54
|
+
|
55
|
+
static unsigned char newChar [8] =
|
56
|
+
{
|
57
|
+
0b11111,
|
58
|
+
0b10001,
|
59
|
+
0b10001,
|
60
|
+
0b10101,
|
61
|
+
0b11111,
|
62
|
+
0b10001,
|
63
|
+
0b10001,
|
64
|
+
0b11111,
|
65
|
+
} ;
|
66
|
+
|
67
|
+
|
68
|
+
// Global lcd handle:
|
69
|
+
|
70
|
+
static int lcdHandle ;
|
71
|
+
|
72
|
+
/*
|
73
|
+
* usage:
|
74
|
+
*********************************************************************************
|
75
|
+
*/
|
76
|
+
|
77
|
+
int usage (const char *progName)
|
78
|
+
{
|
79
|
+
fprintf (stderr, "Usage: %s bits cols rows\n", progName) ;
|
80
|
+
return EXIT_FAILURE ;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
/*
|
85
|
+
* scrollMessage:
|
86
|
+
*********************************************************************************
|
87
|
+
*/
|
88
|
+
|
89
|
+
static const char *message =
|
90
|
+
" "
|
91
|
+
"Wiring Pi by Gordon Henderson. HTTP://WIRINGPI.COM/"
|
92
|
+
" " ;
|
93
|
+
|
94
|
+
void scrollMessage (int line, int width)
|
95
|
+
{
|
96
|
+
char buf [32] ;
|
97
|
+
static int position = 0 ;
|
98
|
+
static int timer = 0 ;
|
99
|
+
|
100
|
+
if (millis () < timer)
|
101
|
+
return ;
|
102
|
+
|
103
|
+
timer = millis () + 200 ;
|
104
|
+
|
105
|
+
strncpy (buf, &message [position], width) ;
|
106
|
+
buf [width] = 0 ;
|
107
|
+
lcdPosition (lcdHandle, 0, line) ;
|
108
|
+
lcdPuts (lcdHandle, buf) ;
|
109
|
+
|
110
|
+
if (++position == (strlen (message) - width))
|
111
|
+
position = 0 ;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
/*
|
116
|
+
* pingPong:
|
117
|
+
* Bounce a character - only on 4-line displays
|
118
|
+
*********************************************************************************
|
119
|
+
*/
|
120
|
+
|
121
|
+
static void pingPong (int lcd, int cols)
|
122
|
+
{
|
123
|
+
static int position = 0 ;
|
124
|
+
static int dir = 0 ;
|
125
|
+
|
126
|
+
if (dir == 0) // Setup
|
127
|
+
{
|
128
|
+
dir = 1 ;
|
129
|
+
lcdPosition (lcdHandle, 0, 3) ;
|
130
|
+
lcdPutchar (lcdHandle, '*') ;
|
131
|
+
return ;
|
132
|
+
}
|
133
|
+
|
134
|
+
lcdPosition (lcdHandle, position, 3) ;
|
135
|
+
lcdPutchar (lcdHandle, ' ') ;
|
136
|
+
position += dir ;
|
137
|
+
|
138
|
+
if (position == cols)
|
139
|
+
{
|
140
|
+
dir = -1 ;
|
141
|
+
--position ;
|
142
|
+
}
|
143
|
+
|
144
|
+
if (position < 0)
|
145
|
+
{
|
146
|
+
dir = 1 ;
|
147
|
+
++position ;
|
148
|
+
}
|
149
|
+
|
150
|
+
lcdPosition (lcdHandle, position, 3) ;
|
151
|
+
lcdPutchar (lcdHandle, '#') ;
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
/*
|
156
|
+
* waitForEnter:
|
157
|
+
*********************************************************************************
|
158
|
+
*/
|
159
|
+
|
160
|
+
static void waitForEnter (void)
|
161
|
+
{
|
162
|
+
printf ("Press ENTER to continue: ") ;
|
163
|
+
(void)fgetc (stdin) ;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
/*
|
168
|
+
* The works
|
169
|
+
*********************************************************************************
|
170
|
+
*/
|
171
|
+
|
172
|
+
int main (int argc, char *argv[])
|
173
|
+
{
|
174
|
+
int i ;
|
175
|
+
int lcd ;
|
176
|
+
int bits, rows, cols ;
|
177
|
+
|
178
|
+
struct tm *t ;
|
179
|
+
time_t tim ;
|
180
|
+
|
181
|
+
char buf [32] ;
|
182
|
+
|
183
|
+
if (argc != 4)
|
184
|
+
return usage (argv [0]) ;
|
185
|
+
|
186
|
+
printf ("Raspberry Pi LCD test\n") ;
|
187
|
+
printf ("=====================\n") ;
|
188
|
+
|
189
|
+
bits = atoi (argv [1]) ;
|
190
|
+
cols = atoi (argv [2]) ;
|
191
|
+
rows = atoi (argv [3]) ;
|
192
|
+
|
193
|
+
if (!((rows == 1) || (rows == 2) || (rows == 4)))
|
194
|
+
{
|
195
|
+
fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
|
196
|
+
return EXIT_FAILURE ;
|
197
|
+
}
|
198
|
+
|
199
|
+
if (!((cols == 16) || (cols == 20)))
|
200
|
+
{
|
201
|
+
fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
|
202
|
+
return EXIT_FAILURE ;
|
203
|
+
}
|
204
|
+
|
205
|
+
wiringPiSetup () ;
|
206
|
+
|
207
|
+
if (bits == 4)
|
208
|
+
lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
|
209
|
+
else
|
210
|
+
lcdHandle = lcdInit (rows, cols, 8, 11,10, 0,1,2,3,4,5,6,7) ;
|
211
|
+
|
212
|
+
if (lcdHandle < 0)
|
213
|
+
{
|
214
|
+
fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
|
215
|
+
return -1 ;
|
216
|
+
}
|
217
|
+
|
218
|
+
lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
|
219
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ;
|
220
|
+
|
221
|
+
waitForEnter () ;
|
222
|
+
|
223
|
+
if (rows > 1)
|
224
|
+
{
|
225
|
+
lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ;
|
226
|
+
|
227
|
+
if (rows == 4)
|
228
|
+
{
|
229
|
+
lcdPosition (lcdHandle, 0, 2) ;
|
230
|
+
for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
|
231
|
+
lcdPuts (lcdHandle, "=-") ;
|
232
|
+
lcdPuts (lcdHandle, "=3") ;
|
233
|
+
|
234
|
+
lcdPosition (lcdHandle, 0, 3) ;
|
235
|
+
for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
|
236
|
+
lcdPuts (lcdHandle, "-=") ;
|
237
|
+
lcdPuts (lcdHandle, "-4") ;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
waitForEnter () ;
|
242
|
+
|
243
|
+
lcdCharDef (lcdHandle, 2, newChar) ;
|
244
|
+
|
245
|
+
lcdClear (lcdHandle) ;
|
246
|
+
lcdPosition (lcdHandle, 0, 0) ;
|
247
|
+
lcdPuts (lcdHandle, "User Char: ") ;
|
248
|
+
lcdPutchar (lcdHandle, 2) ;
|
249
|
+
|
250
|
+
lcdCursor (lcdHandle, TRUE) ;
|
251
|
+
lcdCursorBlink (lcdHandle, TRUE) ;
|
252
|
+
|
253
|
+
waitForEnter () ;
|
254
|
+
|
255
|
+
lcdCursor (lcdHandle, FALSE) ;
|
256
|
+
lcdCursorBlink (lcdHandle, FALSE) ;
|
257
|
+
lcdClear (lcdHandle) ;
|
258
|
+
|
259
|
+
for (;;)
|
260
|
+
{
|
261
|
+
scrollMessage (0, cols) ;
|
262
|
+
|
263
|
+
if (rows == 1)
|
264
|
+
continue ;
|
265
|
+
|
266
|
+
tim = time (NULL) ;
|
267
|
+
t = localtime (&tim) ;
|
268
|
+
|
269
|
+
sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
|
270
|
+
|
271
|
+
lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
|
272
|
+
lcdPuts (lcdHandle, buf) ;
|
273
|
+
|
274
|
+
if (rows == 2)
|
275
|
+
continue ;
|
276
|
+
|
277
|
+
sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
|
278
|
+
|
279
|
+
lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
|
280
|
+
lcdPuts (lcdHandle, buf) ;
|
281
|
+
|
282
|
+
pingPong (lcd, cols) ;
|
283
|
+
}
|
284
|
+
|
285
|
+
return 0 ;
|
286
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* lowPower.c:
|
3
|
+
* Check the Pi's LOW-Power signal.
|
4
|
+
*
|
5
|
+
* This is a demonstration program that could be turned into some sort
|
6
|
+
* of logger via e.g. syslog - however it's also probably something
|
7
|
+
* that might be better handled by a future kernel - who knows.
|
8
|
+
*
|
9
|
+
* Copyright (c) 2014 Gordon Henderson.
|
10
|
+
***********************************************************************
|
11
|
+
* This file is part of wiringPi:
|
12
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
13
|
+
*
|
14
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
15
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
16
|
+
* the Free Software Foundation, either version 3 of the License, or
|
17
|
+
* (at your option) any later version.
|
18
|
+
*
|
19
|
+
* wiringPi is distributed in the hope that it will be useful,
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
* GNU Lesser General Public License for more details.
|
23
|
+
*
|
24
|
+
* You should have received a copy of the GNU Lesser General Public License
|
25
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
***********************************************************************
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include <stdio.h>
|
30
|
+
#include <time.h>
|
31
|
+
#include <wiringPi.h>
|
32
|
+
|
33
|
+
|
34
|
+
#define LOW_POWER 35
|
35
|
+
|
36
|
+
/*
|
37
|
+
* lowPower:
|
38
|
+
* This is an ISR that waits for the low-power signal going low and
|
39
|
+
* prints the result.
|
40
|
+
*********************************************************************************
|
41
|
+
*/
|
42
|
+
|
43
|
+
void lowPower (void)
|
44
|
+
{
|
45
|
+
time_t t ;
|
46
|
+
|
47
|
+
time (&t) ;
|
48
|
+
printf ("%s: LOW POWER DETECTED\n", ctime (&t)) ;
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
/*
|
53
|
+
*********************************************************************************
|
54
|
+
* main
|
55
|
+
*********************************************************************************
|
56
|
+
*/
|
57
|
+
|
58
|
+
int main (void)
|
59
|
+
{
|
60
|
+
wiringPiSetupGpio () ; // GPIO mode as it's an internal pin
|
61
|
+
|
62
|
+
wiringPiISR (LOW_POWER, INT_EDGE_FALLING, &lowPower) ;
|
63
|
+
|
64
|
+
for (;;)
|
65
|
+
delay (1000) ;
|
66
|
+
|
67
|
+
return 0 ;
|
68
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
* nes.c:
|
3
|
+
* Test program for an old NES controller connected to the Pi.
|
4
|
+
*
|
5
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
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 <stdio.h>
|
26
|
+
#include <errno.h>
|
27
|
+
#include <string.h>
|
28
|
+
|
29
|
+
#include <wiringPi.h>
|
30
|
+
#include <piNes.h>
|
31
|
+
|
32
|
+
#define BLANK "| "
|
33
|
+
|
34
|
+
int main ()
|
35
|
+
{
|
36
|
+
int joystick ;
|
37
|
+
unsigned int buttons ;
|
38
|
+
|
39
|
+
if (wiringPiSetup () == -1)
|
40
|
+
{
|
41
|
+
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
|
42
|
+
return 1 ;
|
43
|
+
}
|
44
|
+
|
45
|
+
if ((joystick = setupNesJoystick (2, 1, 0)) == -1)
|
46
|
+
{
|
47
|
+
fprintf (stdout, "Unable to setup joystick\n") ;
|
48
|
+
return 1 ;
|
49
|
+
}
|
50
|
+
|
51
|
+
for (;;)
|
52
|
+
{
|
53
|
+
buttons = readNesJoystick (joystick) ;
|
54
|
+
|
55
|
+
if ((buttons & NES_UP) != 0) printf ("| UP " ) ; else printf (BLANK) ;
|
56
|
+
if ((buttons & NES_DOWN) != 0) printf ("| DOWN " ) ; else printf (BLANK) ;
|
57
|
+
if ((buttons & NES_LEFT) != 0) printf ("| LEFT " ) ; else printf (BLANK) ;
|
58
|
+
if ((buttons & NES_RIGHT) != 0) printf ("|RIGHT " ) ; else printf (BLANK) ;
|
59
|
+
if ((buttons & NES_SELECT) != 0) printf ("|SELECT" ) ; else printf (BLANK) ;
|
60
|
+
if ((buttons & NES_START) != 0) printf ("|START " ) ; else printf (BLANK) ;
|
61
|
+
if ((buttons & NES_A) != 0) printf ("| A " ) ; else printf (BLANK) ;
|
62
|
+
if ((buttons & NES_B) != 0) printf ("| B " ) ; else printf (BLANK) ;
|
63
|
+
printf ("|\n") ;
|
64
|
+
}
|
65
|
+
|
66
|
+
return 0 ;
|
67
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
* okLed.c:
|
3
|
+
* Make the OK LED on the Pi Pulsate...
|
4
|
+
*
|
5
|
+
* Originally posted to the Raspberry Pi forums:
|
6
|
+
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
|
7
|
+
*
|
8
|
+
* Compile this and store it somewhere, then kick it off at boot time
|
9
|
+
* e.g. by putting it in /etc/rc.local and running it in the
|
10
|
+
* background &
|
11
|
+
*
|
12
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
13
|
+
***********************************************************************
|
14
|
+
* This file is part of wiringPi:
|
15
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
16
|
+
*
|
17
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
18
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
19
|
+
* the Free Software Foundation, either version 3 of the License, or
|
20
|
+
* (at your option) any later version.
|
21
|
+
*
|
22
|
+
* wiringPi is distributed in the hope that it will be useful,
|
23
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25
|
+
* GNU Lesser General Public License for more details.
|
26
|
+
*
|
27
|
+
* You should have received a copy of the GNU Lesser General Public License
|
28
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
29
|
+
***********************************************************************
|
30
|
+
*/
|
31
|
+
|
32
|
+
#include <stdio.h>
|
33
|
+
#include <errno.h>
|
34
|
+
#include <string.h>
|
35
|
+
#include <fcntl.h>
|
36
|
+
#include <unistd.h>
|
37
|
+
#include <math.h>
|
38
|
+
|
39
|
+
#include <wiringPi.h>
|
40
|
+
#include <softPwm.h>
|
41
|
+
|
42
|
+
// The OK/Act LED is connected to BCM_GPIO pin 16
|
43
|
+
|
44
|
+
#define OK_LED 16
|
45
|
+
|
46
|
+
int main ()
|
47
|
+
{
|
48
|
+
int fd, i ;
|
49
|
+
|
50
|
+
wiringPiSetupGpio () ;
|
51
|
+
|
52
|
+
// Change the trigger on the OK/Act LED to "none"
|
53
|
+
|
54
|
+
if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
|
55
|
+
{
|
56
|
+
fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
|
57
|
+
return 1 ;
|
58
|
+
}
|
59
|
+
write (fd, "none\n", 5) ;
|
60
|
+
close (fd) ;
|
61
|
+
|
62
|
+
softPwmCreate (OK_LED, 0, 100) ;
|
63
|
+
|
64
|
+
for (;;)
|
65
|
+
{
|
66
|
+
for (i = 0 ; i <= 100 ; ++i)
|
67
|
+
{
|
68
|
+
softPwmWrite (OK_LED, i) ;
|
69
|
+
delay (10) ;
|
70
|
+
}
|
71
|
+
delay (50) ;
|
72
|
+
|
73
|
+
for (i = 100 ; i >= 0 ; --i)
|
74
|
+
{
|
75
|
+
softPwmWrite (OK_LED, i) ;
|
76
|
+
delay (10) ;
|
77
|
+
}
|
78
|
+
delay (10) ;
|
79
|
+
}
|
80
|
+
|
81
|
+
return 0 ;
|
82
|
+
}
|