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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. struct GamePadEventData {
  15. GamePadEventData(uint16_t v) : X(v), Y(v), Z(v), Rx(v), Ry(v), Rz(v) { }
  16. uint16_t X, Y, Rz; // 11bit, 11bit, 10bit
  17. uint8_t Z, Rx, Ry, Slider;
  18. };
  19. class JoystickEvents {
  20. public:
  21. JoystickEvents();
  22. virtual void OnGamePadChanged(const GamePadEventData *evt);
  23. virtual void OnHatSwitch(uint8_t hat);
  24. virtual void OnButtonUp(uint8_t but_id);
  25. virtual void OnButtonDn(uint8_t but_id);
  26. virtual void OnMouseMoved(uint8_t x, uint8_t y);
  27. protected:
  28. GamePadEventData lastData;
  29. GamePadEventData deadZone;
  30. uint8_t lastMouseX, lastMouseY;
  31. uint8_t deadZoneMouseX, deadZoneMouseY;
  32. };
  33. #endif // __JOYSTICK_EVENTS_H__