You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 line
1.1 KiB

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