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_cppm.cpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include "data.h"
  13. #include "cppm.h"
  14. #include "events.h"
  15. #define CHANNEL_THROTTLE 2
  16. #define CHANNEL_PITCH 1
  17. #define CHANNEL_ROLL 0
  18. #define CHANNEL_YAW 3
  19. #define CHANNEL_AUX1 4
  20. #define CHANNEL_AUX2 5
  21. JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(client) {
  22. for (uint8_t i = 0; i < channels; i++) {
  23. values[i] = 1500;
  24. }
  25. values[CHANNEL_AUX1] = 200;
  26. values[CHANNEL_AUX2] = 200;
  27. cppmCopy(values);
  28. }
  29. void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
  30. values[CHANNEL_THROTTLE] = evt.Z;
  31. values[CHANNEL_PITCH] = evt.Y;
  32. values[CHANNEL_ROLL] = evt.X;
  33. values[CHANNEL_YAW] = evt.Rz;
  34. values[CHANNEL_AUX1] = evt.Ry;
  35. values[CHANNEL_AUX2] = evt.Slider;
  36. cppmCopy(values);
  37. }
  38. void JoystickEventsCPPM::OnHatSwitch(uint8_t hat) {
  39. }
  40. void JoystickEventsCPPM::OnButtonUp(uint8_t but_id) {
  41. }
  42. void JoystickEventsCPPM::OnButtonDn(uint8_t but_id) {
  43. }
  44. void JoystickEventsCPPM::OnMouseMoved(uint8_t x, uint8_t y) {
  45. }