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.

Saitek-X52-PPM.ino 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.h>
  13. #include <hiduniversal.h>
  14. #include <usbhub.h>
  15. #include "hid_parser.h"
  16. #include "x52.h"
  17. USB usb;
  18. USBHub hub(&usb);
  19. HIDUniversal hid(&usb);
  20. X52 x52(&usb, &hid);
  21. JoystickEvents joyevents;
  22. JoystickReportParser joy(&joyevents);
  23. void setup() {
  24. Serial.begin(115200);
  25. Serial.println("Start");
  26. if (usb.Init() == -1) {
  27. Serial.println("OSC did not start.");
  28. }
  29. delay(200);
  30. if (!hid.SetReportParser(0, &joy)) {
  31. ErrorMessage<uint8_t >(PSTR("SetReportParser"), 1);
  32. }
  33. }
  34. void loop() {
  35. usb.Task();
  36. static unsigned long lastTime = 0;
  37. static uint8_t d = 0;
  38. if ((millis() - lastTime) >= 500) {
  39. //x52.setDate(d, d, d);
  40. d++;
  41. lastTime = millis();
  42. String tmp = String(d);
  43. //x52.setMFDText(0, tmp.c_str());
  44. }
  45. if (Serial.available()) {
  46. char c = Serial.read();
  47. if (c == 't') {
  48. x52.setMFDText(0, "Arduino");
  49. x52.setMFDText(1, "Hello");
  50. x52.setMFDText(2, "World");
  51. } else if (c == '0') {
  52. x52.setMFDBrightness(0);
  53. } else if (c == '1') {
  54. x52.setMFDBrightness(1);
  55. } else if (c == '2') {
  56. x52.setMFDBrightness(2);
  57. } else if (c == '3') {
  58. x52.setLEDBrightness(0);
  59. } else if (c == '4') {
  60. x52.setLEDBrightness(1);
  61. } else if (c == '5') {
  62. x52.setLEDBrightness(2);
  63. } else if (c == 'q') {
  64. x52.setShift(1);
  65. } else if (c == 'w') {
  66. x52.setShift(0);
  67. } else if (c == 'a') {
  68. x52.setBlink(1);
  69. } else if (c == 's') {
  70. x52.setBlink(0);
  71. } else if (c == 'z') {
  72. x52.setDate(1, 1, 1);
  73. } else if (c == 'x') {
  74. x52.setTime(12, 42);
  75. x52.setTimeOffset(0, -120);
  76. x52.setTimeOffset(0, 240);
  77. } else {
  78. Serial.println("Unknown command!");
  79. }
  80. }
  81. }