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.

events.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <stdint.h>
  15. class GamePadEventData;
  16. class JoystickEvents {
  17. public:
  18. JoystickEvents(JoystickEvents* _client = 0) : client(_client) { }
  19. virtual void OnGamePadChanged(const GamePadEventData& evt) = 0;
  20. virtual void OnHatSwitch(uint8_t hat) = 0;
  21. virtual void OnButtonUp(uint8_t but_id) = 0;
  22. virtual void OnButtonDn(uint8_t but_id) = 0;
  23. virtual void OnMouseMoved(uint8_t x, uint8_t y) = 0;
  24. protected:
  25. JoystickEvents* client;
  26. };
  27. class JoystickEventsDeadZone : public JoystickEvents {
  28. public:
  29. JoystickEventsDeadZone(JoystickEvents* client = 0) : JoystickEvents(client) { }
  30. virtual void OnGamePadChanged(const GamePadEventData& evt);
  31. virtual void OnHatSwitch(uint8_t hat);
  32. virtual void OnButtonUp(uint8_t but_id);
  33. virtual void OnButtonDn(uint8_t but_id);
  34. virtual void OnMouseMoved(uint8_t x, uint8_t y);
  35. private:
  36. const static GamePadEventData deadZone;
  37. const static uint8_t deadZoneMouseX, deadZoneMouseY;
  38. const static GamePadEventData centerValue;
  39. const static uint8_t centerMouseX, centerMouseY;
  40. };
  41. class JoystickEventsCPPM : public JoystickEvents {
  42. public:
  43. JoystickEventsCPPM(JoystickEvents* client = 0);
  44. virtual void OnGamePadChanged(const GamePadEventData& evt);
  45. virtual void OnHatSwitch(uint8_t hat);
  46. virtual void OnButtonUp(uint8_t but_id);
  47. virtual void OnButtonDn(uint8_t but_id);
  48. virtual void OnMouseMoved(uint8_t x, uint8_t y);
  49. private:
  50. const static uint8_t channels = 8;
  51. uint16_t values[channels];
  52. };
  53. #endif // __JOYSTICK_EVENTS_H__