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_buttons.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <Arduino.h>
  13. #include "data.h"
  14. #include "x52.h"
  15. #include "events.h"
  16. #define DEBUG_BUTTON_MFD
  17. JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client) : JoystickEvents(client), x52(x) {
  18. }
  19. void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
  20. if (client) {
  21. client->OnGamePadChanged(evt);
  22. }
  23. }
  24. void JoystickEventsButtons::OnHatSwitch(uint8_t hat) {
  25. if (client) {
  26. client->OnHatSwitch(hat);
  27. }
  28. }
  29. void JoystickEventsButtons::OnButtonUp(uint8_t but_id) {
  30. if (client) {
  31. client->OnButtonUp(but_id);
  32. }
  33. }
  34. void JoystickEventsButtons::OnButtonDn(uint8_t but_id) {
  35. if (client) {
  36. client->OnButtonDn(but_id);
  37. }
  38. #ifdef DEBUG_BUTTON_MFD
  39. String text = "Button " + String(but_id) + " down";
  40. x52->setMFDText(1, text.c_str());
  41. #endif
  42. if (but_id == 23) {
  43. x52->setLEDBrightness(2);
  44. x52->setMFDBrightness(2);
  45. } else if (but_id == 24) {
  46. x52->setLEDBrightness(1);
  47. x52->setMFDBrightness(1);
  48. } else if (but_id == 25) {
  49. x52->setLEDBrightness(0);
  50. x52->setMFDBrightness(0);
  51. }
  52. }
  53. void JoystickEventsButtons::OnMouseMoved(uint8_t x, uint8_t y) {
  54. if (client) {
  55. client->OnMouseMoved(x, y);
  56. }
  57. }