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.

43 lines
1.1 KiB

  1. #include "le3dp_rptparser.h"
  2. JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
  3. joyEvents(evt)
  4. {}
  5. void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
  6. {
  7. bool match = true;
  8. // Checking if there are changes in report since the method was last called
  9. for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) {
  10. if( buf[i] != oldPad[i] ) {
  11. match = false;
  12. break;
  13. }
  14. }
  15. // Calling Game Pad event handler
  16. if (!match && joyEvents) {
  17. joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
  18. for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
  19. }
  20. }
  21. void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
  22. {
  23. Serial.print("X: ");
  24. PrintHex<uint16_t>(evt->x, 0x80);
  25. Serial.print(" Y: ");
  26. PrintHex<uint16_t>(evt->y, 0x80);
  27. Serial.print(" Hat Switch: ");
  28. PrintHex<uint8_t>(evt->hat, 0x80);
  29. Serial.print(" Twist: ");
  30. PrintHex<uint8_t>(evt->twist, 0x80);
  31. Serial.print(" Slider: ");
  32. PrintHex<uint8_t>(evt->slider, 0x80);
  33. Serial.print(" Buttons A: ");
  34. PrintHex<uint8_t>(evt->buttons_a, 0x80);
  35. Serial.print(" Buttons B: ");
  36. PrintHex<uint8_t>(evt->buttons_b, 0x80);
  37. Serial.println("");
  38. }