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.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "hid_parser.h"
  13. void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {
  14. Serial.print("X: ");
  15. PrintHex<uint16_t > (evt->X, 0x80);
  16. Serial.print("\tY: ");
  17. PrintHex<uint16_t > (evt->Y, 0x80);
  18. Serial.print("\tZ: ");
  19. PrintHex<uint8_t > (evt->Z, 0x80);
  20. Serial.print("\tRx: ");
  21. PrintHex<uint8_t > (evt->Rx, 0x80);
  22. Serial.print("\tRy: ");
  23. PrintHex<uint8_t > (evt->Ry, 0x80);
  24. Serial.print("\tRz: ");
  25. PrintHex<uint16_t > (evt->Rz, 0x80);
  26. Serial.print("\tSlider: ");
  27. PrintHex<uint8_t > (evt->Slider, 0x80);
  28. Serial.println("");
  29. }
  30. void JoystickEvents::OnHatSwitch(uint8_t hat) {
  31. Serial.print("Hat Switch: ");
  32. PrintHex<uint8_t > (hat, 0x80);
  33. Serial.println("");
  34. }
  35. void JoystickEvents::OnButtonUp(uint8_t but_id) {
  36. Serial.print("Up: ");
  37. Serial.println(but_id, DEC);
  38. }
  39. void JoystickEvents::OnButtonDn(uint8_t but_id) {
  40. Serial.print("Dn: ");
  41. Serial.println(but_id, DEC);
  42. }
  43. void JoystickEvents::OnMouseMoved(uint8_t x, uint8_t y) {
  44. Serial.print("Mouse X: ");
  45. PrintHex<uint8_t >(x, 0x80);
  46. Serial.print("\tY: ");
  47. PrintHex<uint8_t >(y, 0x80);
  48. Serial.println("");
  49. }