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.

joystick_events.h 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Saitek X52 Arduino USB Host Shield Library.
  3. * Copyright 2016 by Thomas Buck <xythobuz@xythobuz.de>
  4. *
  5. * Based on the USB Host Library HID Joystick example
  6. * https://www.circuitsathome.com/mcu/hid-joystick-code-sample
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation, version 2.
  11. */
  12. #ifndef __JOYSTICK_EVENTS_H__
  13. #define __JOYSTICK_EVENTS_H__
  14. class GamePadEventData {
  15. public:
  16. GamePadEventData(uint16_t v) : X(v), Y(v), Z(v), Rx(v), Ry(v), Rz(v), Slider(v) { }
  17. GamePadEventData(uint16_t x, uint16_t y, uint8_t z, uint8_t rx, uint8_t ry,
  18. uint16_t rz, uint8_t slider)
  19. : X(x), Y(y), Z(z), Rx(rx), Ry(ry), Rz(rz), Slider(slider) { }
  20. uint16_t X, Y, Rz; // 11bit, 11bit, 10bit
  21. uint8_t Z, Rx, Ry, Slider;
  22. };
  23. class JoystickEvents {
  24. public:
  25. JoystickEvents(JoystickEvents* _client = NULL) : client(_client) { }
  26. virtual void OnGamePadChanged(const GamePadEventData& evt) = 0;
  27. virtual void OnHatSwitch(uint8_t hat) = 0;
  28. virtual void OnButtonUp(uint8_t but_id) = 0;
  29. virtual void OnButtonDn(uint8_t but_id) = 0;
  30. virtual void OnMouseMoved(uint8_t x, uint8_t y) = 0;
  31. protected:
  32. JoystickEvents* client;
  33. };
  34. class JoystickEventsDeadZone : public JoystickEvents {
  35. public:
  36. virtual void OnGamePadChanged(const GamePadEventData& evt);
  37. virtual void OnHatSwitch(uint8_t hat);
  38. virtual void OnButtonUp(uint8_t but_id);
  39. virtual void OnButtonDn(uint8_t but_id);
  40. virtual void OnMouseMoved(uint8_t x, uint8_t y);
  41. protected:
  42. const static GamePadEventData deadZone;
  43. const static uint8_t deadZoneMouseX, deadZoneMouseY;
  44. const static GamePadEventData centerValue;
  45. const static uint8_t centerMouseX, centerMouseY;
  46. };
  47. #endif // __JOYSTICK_EVENTS_H__