blob: 1a485bdf21f7ddce0f8aa1446f9c09c7227e1e44 [file] [log] [blame]
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01001
2#include <stdio.h>
3#include <errno.h>
4#include <string.h>
5
6#include <wiringPi.h>
7#include <piNes.h>
8
9#define BLANK "| "
10
11int main ()
12{
13 int joystick ;
14 unsigned int buttons ;
15
16 if (wiringPiSetup () == -1)
17 {
18 fprintf (stdout, "oops: %s\n", strerror (errno)) ;
19 return 1 ;
20 }
21
22 if ((joystick = setupNesJoystick (2, 1, 0)) == -1)
23 {
24 fprintf (stdout, "Unable to setup joystick\n") ;
25 return 1 ;
26 }
27
28 for (;;)
29 {
30 buttons = readNesJoystick (joystick) ;
31
32 if ((buttons & NES_UP) != 0) printf ("| UP " ) ; else printf (BLANK) ;
33 if ((buttons & NES_DOWN) != 0) printf ("| DOWN " ) ; else printf (BLANK) ;
34 if ((buttons & NES_LEFT) != 0) printf ("| LEFT " ) ; else printf (BLANK) ;
35 if ((buttons & NES_RIGHT) != 0) printf ("|RIGHT " ) ; else printf (BLANK) ;
36 if ((buttons & NES_SELECT) != 0) printf ("|SELECT" ) ; else printf (BLANK) ;
37 if ((buttons & NES_START) != 0) printf ("|START " ) ; else printf (BLANK) ;
38 if ((buttons & NES_A) != 0) printf ("| A " ) ; else printf (BLANK) ;
39 if ((buttons & NES_B) != 0) printf ("| B " ) ; else printf (BLANK) ;
40 printf ("|\n") ;
41 }
42
43 return 0 ;
44}