Control drones with a proper joystick
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.

hidjoystickrptparser.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if !defined(__HIDJOYSTICKRPTPARSER_H__)
  2. #define __HIDJOYSTICKRPTPARSER_H__
  3. #include <hid.h>
  4. /*
  5. * Adapted for the Saitek X52 flight controller
  6. */
  7. struct GamePadEventData {
  8. uint16_t X, Y, Rz; // 11bit, 11bit, 10bit
  9. uint8_t Z, Rx, Ry, Slider;
  10. };
  11. class JoystickEvents {
  12. public:
  13. virtual void OnGamePadChanged(const GamePadEventData *evt);
  14. virtual void OnHatSwitch(uint8_t hat);
  15. virtual void OnButtonUp(uint8_t but_id);
  16. virtual void OnButtonDn(uint8_t but_id);
  17. virtual void OnMouseMoved(uint8_t x, uint8_t y);
  18. };
  19. #define RPT_GEMEPAD_LEN 8
  20. #define BUFFER_SIZE 16
  21. class JoystickReportParser : public HIDReportParser {
  22. JoystickEvents *joyEvents;
  23. uint8_t buf[BUFFER_SIZE];
  24. uint8_t oldPad[RPT_GEMEPAD_LEN];
  25. uint8_t oldHat;
  26. uint64_t oldButtons;
  27. uint8_t oldMouse;
  28. GamePadEventData buffer;
  29. public:
  30. JoystickReportParser(JoystickEvents *evt);
  31. virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *bufPart);
  32. };
  33. #endif // __HIDJOYSTICKRPTPARSER_H__