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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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)
  18. : JoystickEvents(client), x52(x) { }
  19. void JoystickEventsButtons::OnGamePadChanged(const GamePadEventData& evt) {
  20. if (client) {
  21. client->OnGamePadChanged(evt);
  22. }
  23. }
  24. void JoystickEventsButtons::OnHatSwitch(uint8_t hat) {
  25. #ifdef DEBUG_BUTTON_MFD
  26. String text = "Hat is " + String(hat);
  27. x52->setMFDText(1, text.c_str());
  28. #endif
  29. if (client) {
  30. client->OnHatSwitch(hat);
  31. }
  32. }
  33. void JoystickEventsButtons::OnButtonUp(uint8_t but_id) {
  34. #ifdef DEBUG_BUTTON_MFD
  35. String text = "Button " + String(but_id) + " up";
  36. x52->setMFDText(1, text.c_str());
  37. #endif
  38. if (client) {
  39. client->OnButtonUp(but_id);
  40. }
  41. }
  42. void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
  43. #ifdef DEBUG_BUTTON_MFD
  44. String text = "Button " + String(but_id) + " down";
  45. x52->setMFDText(1, text.c_str());
  46. #endif
  47. if (but_id == 23) {
  48. x52->setLEDBrightness(2);
  49. x52->setMFDBrightness(2);
  50. } else if (but_id == 24) {
  51. x52->setLEDBrightness(1);
  52. x52->setMFDBrightness(1);
  53. } else if (but_id == 25) {
  54. x52->setLEDBrightness(0);
  55. x52->setMFDBrightness(0);
  56. }
  57. if (client) {
  58. client->OnButtonDown(but_id);
  59. }
  60. }
  61. void JoystickEventsButtons::OnMouseMoved(uint8_t x, uint8_t y) {
  62. if (client) {
  63. client->OnMouseMoved(x, y);
  64. }
  65. }