wiringpi2 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.
- data/ext/wiringpi/WiringPi/examples/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/gertboard.c +94 -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 +99 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +129 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +83 -0
- data/ext/wiringpi/WiringPi/examples/piface.c +74 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +93 -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/speed.c +123 -0
- data/ext/wiringpi/WiringPi/examples/test1.c +111 -0
- data/ext/wiringpi/WiringPi/examples/test2.c +58 -0
- data/ext/wiringpi/WiringPi/examples/tone.c +59 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1371 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.c +239 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.h +40 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.c +380 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.h +46 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +155 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -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 +195 -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/piFace.c +179 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +50 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +130 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +34 -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 +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +108 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +1664 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +227 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +119 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +213 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4378 -0
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +131 -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
- data/lib/wiringpi2.rb +42 -0
- metadata +122 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* file.c:
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
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
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* isr-osc.c:
|
|
3
|
+
* Wait for Interrupt test program - ISR method - interrupt oscillator
|
|
4
|
+
*
|
|
5
|
+
* How to test:
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
|
|
8
|
+
* before we do that YOU must make sure that they are both setup
|
|
9
|
+
* the right way. If they are set to outputs and one is high and one low,
|
|
10
|
+
* then you connect the wire, you'll create a short and that won't be good.
|
|
11
|
+
*
|
|
12
|
+
* Before making the connection, type:
|
|
13
|
+
* gpio mode 0 output
|
|
14
|
+
* gpio write 0 0
|
|
15
|
+
* gpio mode 1 input
|
|
16
|
+
* then you can connect them together.
|
|
17
|
+
*
|
|
18
|
+
* Run the program, then:
|
|
19
|
+
* gpio write 0 1
|
|
20
|
+
* gpio write 0 0
|
|
21
|
+
*
|
|
22
|
+
* at which point it will trigger an interrupt and the program will
|
|
23
|
+
* then do the up/down toggling for itself and run at full speed, and
|
|
24
|
+
* it will report the number of interrupts recieved every second.
|
|
25
|
+
*
|
|
26
|
+
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
|
|
27
|
+
***********************************************************************
|
|
28
|
+
* This file is part of wiringPi:
|
|
29
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
30
|
+
*
|
|
31
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
32
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
33
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
34
|
+
* (at your option) any later version.
|
|
35
|
+
*
|
|
36
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
37
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
38
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
39
|
+
* GNU Lesser General Public License for more details.
|
|
40
|
+
*
|
|
41
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
42
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
43
|
+
***********************************************************************
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
#include <stdio.h>
|
|
47
|
+
#include <string.h>
|
|
48
|
+
#include <errno.h>
|
|
49
|
+
#include <stdlib.h>
|
|
50
|
+
#include <wiringPi.h>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// What GPIO input are we using?
|
|
54
|
+
// This is a wiringPi pin number
|
|
55
|
+
|
|
56
|
+
#define OUT_PIN 0
|
|
57
|
+
#define IN_PIN 1
|
|
58
|
+
|
|
59
|
+
// globalCounter:
|
|
60
|
+
// Global variable to count interrupts
|
|
61
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
|
62
|
+
|
|
63
|
+
static volatile int globalCounter = 0 ;
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* myInterrupt:
|
|
67
|
+
*********************************************************************************
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
void myInterrupt (void)
|
|
71
|
+
{
|
|
72
|
+
digitalWrite (OUT_PIN, 1) ;
|
|
73
|
+
++globalCounter ;
|
|
74
|
+
digitalWrite (OUT_PIN, 0) ;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
*********************************************************************************
|
|
80
|
+
* main
|
|
81
|
+
*********************************************************************************
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
int main (void)
|
|
85
|
+
{
|
|
86
|
+
int myCounter = 0 ;
|
|
87
|
+
int lastCounter = 0 ;
|
|
88
|
+
|
|
89
|
+
if (wiringPiSetup () < 0)
|
|
90
|
+
{
|
|
91
|
+
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
|
92
|
+
return 1 ;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pinMode (OUT_PIN, OUTPUT) ;
|
|
96
|
+
pinMode (IN_PIN, INPUT) ;
|
|
97
|
+
|
|
98
|
+
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
|
99
|
+
{
|
|
100
|
+
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
|
101
|
+
return 1 ;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (;;)
|
|
105
|
+
{
|
|
106
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
|
107
|
+
|
|
108
|
+
while (myCounter == globalCounter)
|
|
109
|
+
delay (1000) ;
|
|
110
|
+
|
|
111
|
+
printf (" Done. counter: %6d: %6d\n",
|
|
112
|
+
globalCounter, myCounter - lastCounter) ;
|
|
113
|
+
lastCounter = myCounter ;
|
|
114
|
+
myCounter = globalCounter ;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return 0 ;
|
|
118
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* isr.c:
|
|
3
|
+
* Wait for Interrupt test program - ISR method
|
|
4
|
+
*
|
|
5
|
+
* How to test:
|
|
6
|
+
* Use the SoC's pull-up and pull down resistors that are avalable
|
|
7
|
+
* on input pins. So compile & run this program (via sudo), then
|
|
8
|
+
* in another terminal:
|
|
9
|
+
* gpio mode 0 up
|
|
10
|
+
* gpio mode 0 down
|
|
11
|
+
* at which point it should trigger an interrupt. Toggle the pin
|
|
12
|
+
* up/down to generate more interrupts to test.
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2013 Gordon Henderson.
|
|
15
|
+
***********************************************************************
|
|
16
|
+
* This file is part of wiringPi:
|
|
17
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
18
|
+
*
|
|
19
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
20
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
21
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
22
|
+
* (at your option) any later version.
|
|
23
|
+
*
|
|
24
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
25
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
26
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
27
|
+
* GNU Lesser General Public License for more details.
|
|
28
|
+
*
|
|
29
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
30
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
31
|
+
***********************************************************************
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include <string.h>
|
|
36
|
+
#include <errno.h>
|
|
37
|
+
#include <stdlib.h>
|
|
38
|
+
#include <wiringPi.h>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// What GPIO input are we using?
|
|
42
|
+
// This is a wiringPi pin number
|
|
43
|
+
|
|
44
|
+
#define BUTTON_PIN 0
|
|
45
|
+
|
|
46
|
+
// globalCounter:
|
|
47
|
+
// Global variable to count interrupts
|
|
48
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
|
49
|
+
|
|
50
|
+
static volatile int globalCounter = 0 ;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* myInterrupt:
|
|
55
|
+
*********************************************************************************
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
void myInterrupt (void)
|
|
59
|
+
{
|
|
60
|
+
++globalCounter ;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
*********************************************************************************
|
|
66
|
+
* main
|
|
67
|
+
*********************************************************************************
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
int main (void)
|
|
71
|
+
{
|
|
72
|
+
int myCounter = 0 ;
|
|
73
|
+
|
|
74
|
+
if (wiringPiSetup () < 0)
|
|
75
|
+
{
|
|
76
|
+
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
|
77
|
+
return 1 ;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
|
81
|
+
{
|
|
82
|
+
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
|
83
|
+
return 1 ;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
for (;;)
|
|
88
|
+
{
|
|
89
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
|
90
|
+
|
|
91
|
+
while (myCounter == globalCounter)
|
|
92
|
+
delay (100) ;
|
|
93
|
+
|
|
94
|
+
printf (" Done. counter: %5d\n", globalCounter) ;
|
|
95
|
+
myCounter = globalCounter ;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return 0 ;
|
|
99
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
* Copyright (c) 2012 Gordon Henderson.
|
|
8
|
+
***********************************************************************
|
|
9
|
+
* This file is part of wiringPi:
|
|
10
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
11
|
+
*
|
|
12
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
13
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
* (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
* GNU Lesser General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
+
***********************************************************************
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <stdint.h>
|
|
30
|
+
|
|
31
|
+
#include <unistd.h>
|
|
32
|
+
#include <string.h>
|
|
33
|
+
#include <time.h>
|
|
34
|
+
|
|
35
|
+
#include <wiringPi.h>
|
|
36
|
+
#include <lcd.h>
|
|
37
|
+
|
|
38
|
+
int main (void)
|
|
39
|
+
{
|
|
40
|
+
int i, j ;
|
|
41
|
+
int fd1, fd2 ;
|
|
42
|
+
|
|
43
|
+
char message1 [256] ;
|
|
44
|
+
char message2 [256] ;
|
|
45
|
+
char buf1 [30] ;
|
|
46
|
+
char buf2 [30] ;
|
|
47
|
+
|
|
48
|
+
struct tm *t ;
|
|
49
|
+
time_t tim ;
|
|
50
|
+
|
|
51
|
+
printf ("Raspberry Pi LCD test program\n") ;
|
|
52
|
+
|
|
53
|
+
if (wiringPiSetup () == -1)
|
|
54
|
+
exit (1) ;
|
|
55
|
+
|
|
56
|
+
fd1 = lcdInit (4, 20, 4, 8, 9, 4,5,6,7,0,0,0,0) ;
|
|
57
|
+
fd2 = lcdInit (2, 16, 4, 8, 10, 4,5,6,7,0,0,0,0) ;
|
|
58
|
+
|
|
59
|
+
//fd1 = lcdInit (4, 20, 8, 8, 9, 0,1,2,3,4,5,6,7) ;
|
|
60
|
+
//fd2 = lcdInit (2, 16, 8, 8, 10, 0,1,2,3,4,5,6,7) ;
|
|
61
|
+
|
|
62
|
+
if (fd1 == -1)
|
|
63
|
+
{
|
|
64
|
+
printf ("lcdInit 1 failed\n") ;
|
|
65
|
+
return 1 ;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (fd2 == -1)
|
|
69
|
+
{
|
|
70
|
+
printf ("lcdInit 2 failed\n") ;
|
|
71
|
+
return 1 ;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
sleep (1) ;
|
|
75
|
+
|
|
76
|
+
lcdPosition (fd1, 0, 0) ; lcdPuts (fd1, " Gordon Henderson") ;
|
|
77
|
+
lcdPosition (fd1, 0, 1) ; lcdPuts (fd1, " --------------") ;
|
|
78
|
+
/*
|
|
79
|
+
lcdPosition (fd1, 0, 2) ; lcdPuts (fd1, " 00:00:00") ;
|
|
80
|
+
lcdPosition (fd1, 0, 3) ; lcdPuts (fd1, " DD:MM:YY") ;
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
lcdPosition (fd2, 0, 0) ; lcdPuts (fd2, "Gordon Henderson") ;
|
|
84
|
+
lcdPosition (fd2, 0, 1) ; lcdPuts (fd2, "----------------") ;
|
|
85
|
+
|
|
86
|
+
sleep (2) ;
|
|
87
|
+
|
|
88
|
+
sprintf (message1, "%s", " http://projects.drogon.net/ ") ;
|
|
89
|
+
sprintf (message2, "%s", " This is a long message to go into the smaller display just for a demonstration of what we can do. ") ;
|
|
90
|
+
|
|
91
|
+
for (;;)
|
|
92
|
+
{
|
|
93
|
+
i = 0 ;
|
|
94
|
+
j = 0 ;
|
|
95
|
+
for (;;)
|
|
96
|
+
{
|
|
97
|
+
strncpy (buf1, &message1 [i], 20) ;
|
|
98
|
+
buf1 [20] = 0 ;
|
|
99
|
+
lcdPosition (fd1, 0, 1) ;
|
|
100
|
+
lcdPuts (fd1, buf1) ;
|
|
101
|
+
++i ;
|
|
102
|
+
if (i == strlen (message1) - 20)
|
|
103
|
+
i = 0 ;
|
|
104
|
+
|
|
105
|
+
strncpy (buf2, &message2 [j], 16) ;
|
|
106
|
+
buf2 [16] = 0 ;
|
|
107
|
+
lcdPosition (fd2, 0, 1) ;
|
|
108
|
+
lcdPuts (fd2, buf2) ;
|
|
109
|
+
++j ;
|
|
110
|
+
if (j == strlen (message2) - 16)
|
|
111
|
+
j = 0 ;
|
|
112
|
+
|
|
113
|
+
tim = time (NULL) ;
|
|
114
|
+
t = localtime (&tim) ;
|
|
115
|
+
|
|
116
|
+
sprintf (buf1, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
|
|
117
|
+
lcdPosition (fd1, 5, 2) ;
|
|
118
|
+
lcdPuts (fd1, buf1) ;
|
|
119
|
+
|
|
120
|
+
sprintf (buf1, "%02d/%02d/%02d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
|
|
121
|
+
lcdPosition (fd1, 4, 3) ;
|
|
122
|
+
lcdPuts (fd1, buf1) ;
|
|
123
|
+
|
|
124
|
+
delay (250) ;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return 0 ;
|
|
129
|
+
}
|
|
@@ -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,83 @@
|
|
|
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
|
+
#define OK_LED 16
|
|
43
|
+
|
|
44
|
+
int main ()
|
|
45
|
+
{
|
|
46
|
+
int fd, i ;
|
|
47
|
+
|
|
48
|
+
if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
|
|
49
|
+
{
|
|
50
|
+
fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
|
|
51
|
+
return 1 ;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
write (fd, "none\n", 5) ;
|
|
55
|
+
close (fd) ;
|
|
56
|
+
|
|
57
|
+
if (wiringPiSetupGpio () < 0)
|
|
58
|
+
{
|
|
59
|
+
fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
|
|
60
|
+
return 1 ;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
softPwmCreate (OK_LED, 0, 100) ;
|
|
64
|
+
|
|
65
|
+
for (;;)
|
|
66
|
+
{
|
|
67
|
+
for (i = 0 ; i <= 100 ; ++i)
|
|
68
|
+
{
|
|
69
|
+
softPwmWrite (OK_LED, i) ;
|
|
70
|
+
delay (10) ;
|
|
71
|
+
}
|
|
72
|
+
delay (50) ;
|
|
73
|
+
|
|
74
|
+
for (i = 100 ; i >= 0 ; --i)
|
|
75
|
+
{
|
|
76
|
+
softPwmWrite (OK_LED, i) ;
|
|
77
|
+
delay (10) ;
|
|
78
|
+
}
|
|
79
|
+
delay (10) ;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return 0 ;
|
|
83
|
+
}
|