/source/pad.c

http://github.com/tenshou/fail0verflow2 · C · 78 lines · 46 code · 32 blank · 0 comment · 8 complexity · 558548de2caf95e5f5602221d63e60b3 MD5 · raw file

  1. #include "pad.h"
  2. #include <sysutil/events.h>
  3. unsigned temp_pad = 0, new_pad = 0, old_pad = 0;
  4. PadInfo padinfo;
  5. PadData paddata;
  6. int pad_alive=0;
  7. int rumble1_on = 0;
  8. int rumble2_on = 0;
  9. int last_rumble = 0;
  10. unsigned ps3pad_read()
  11. {
  12. int n;
  13. PadActParam actparam;
  14. unsigned butt = 0;
  15. pad_alive = 0;
  16. sysCheckCallback();
  17. ioPadGetInfo(&padinfo);
  18. for(n = 0; n < MAX_PADS; n++) {
  19. if(padinfo.status[n]) {
  20. ioPadGetData(n, &paddata);
  21. pad_alive = 1;
  22. butt = (paddata.button[2] << 8) | (paddata.button[3] & 0xff);
  23. break;
  24. }
  25. }
  26. if(!pad_alive) butt = 0;
  27. else {
  28. actparam.small_motor = 0;
  29. actparam.large_motor = 0;
  30. if(rumble1_on) {
  31. actparam.large_motor = 255;
  32. rumble1_on++;
  33. if(rumble1_on > 15) rumble1_on = 0;
  34. }
  35. if(rumble2_on) {
  36. actparam.small_motor = 1;
  37. rumble2_on++;
  38. if(rumble2_on > 10) rumble2_on = 0;
  39. }
  40. last_rumble = n;
  41. ioPadSetActDirect(n, &actparam);
  42. }
  43. temp_pad = butt;
  44. new_pad = temp_pad & (~old_pad); old_pad = temp_pad;
  45. return butt;
  46. }