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

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