Control drones with a proper joystick
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

x52.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Saitek X52 Arduino USB Host Shield Library.
  3. * Copyright 2016 by Thomas Buck <xythobuz@xythobuz.de>
  4. *
  5. * Based on "x52pro-linux" by Nirenjan Krishnan
  6. * https://github.com/nirenjan/x52pro-linux
  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. #ifndef __X52_H__
  13. #define __X52_H__
  14. #include <usbhid.h>
  15. #define X52_VENDOR_REQUEST 0x91
  16. #define X52_MFD_BRIGHTNESS 0xB1
  17. #define X52_LED_BRIGHTNESS 0xB2
  18. #define X52_MFD_CLEAR_LINE 0x08
  19. #define X52_MFD_WRITE_LINE 0x00
  20. #define X52_MFD_LINE1 0xD1
  21. #define X52_MFD_LINE2 0xD2
  22. #define X52_MFD_LINE3 0xD4
  23. #define X52_SHIFT_INDICATOR 0xFD
  24. #define X52_SHIFT_ON 0x51
  25. #define X52_SHIFT_OFF 0x50
  26. #define X52_BLINK_INDICATOR 0xB4
  27. #define X52_BLINK_ON 0x51
  28. #define X52_BLINK_OFF 0x50
  29. #define X52_DATE_DDMM 0xC4
  30. #define X52_DATE_YEAR 0xC8
  31. #define X52_TIME_CLOCK1 0xC0
  32. #define X52_OFFS_CLOCK2 0xC1
  33. #define X52_OFFS_CLOCK3 0xC2
  34. class X52 {
  35. public:
  36. X52(USB* u, USBHID* h);
  37. /*
  38. * Check if a valid PID/VID device has been found.
  39. */
  40. void initialize();
  41. /*
  42. * Set brightness of LEDs and MFD backlight.
  43. * Three states, 0=off, 1=dim, 2=on.
  44. */
  45. void setLEDBrightness(uint16_t val) { sendCommand(X52_LED_BRIGHTNESS, val); }
  46. void setMFDBrightness(uint16_t val) { sendCommand(X52_MFD_BRIGHTNESS, val); }
  47. /*
  48. * Print text on the MFD lines (0 - 2).
  49. * Maximum of 16 characters per line.
  50. */
  51. void setMFDText(uint8_t line, const char* text = " ");
  52. /*
  53. * Enable (1) or Disable(0) the MFD shift indicator.
  54. */
  55. void setShift(uint8_t state);
  56. /*
  57. * Fast blinking of Info and Hat LEDs.
  58. * State can be 0=off or 1=on.
  59. */
  60. void setBlink(uint8_t state);
  61. /*
  62. * Set date. The third digit seems to be broken in hardware?
  63. */
  64. void setDate(uint8_t dd, uint8_t mm, uint8_t yy);
  65. /*
  66. * Set time. There seems to be a problem with time offsets
  67. * and the 12h/24h time format conflicting...?
  68. */
  69. void setTime(uint8_t h, uint8_t m);
  70. void setTimeOffset(uint8_t cl, int16_t offset);
  71. private:
  72. uint8_t sendCommand(uint16_t command, uint16_t val);
  73. USB* usb;
  74. USBHID* hid;
  75. uint8_t ready;
  76. };
  77. extern X52 x52;
  78. #endif // __X52_H__