Control drones with a proper joystick
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

frsky.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * FrSky Telemetry Protocol Host implementation.
  3. * Copyright 2016 by Thomas Buck <xythobuz@xythobuz.de>
  4. *
  5. * Based on the FrSky Telemetry Protocol documentation:
  6. * http://www.frsky-rc.com/download/down.php?id=128
  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 __FRSKY_H__
  13. #define __FRSKY_H__
  14. #include <Arduino.h>
  15. class FrSky {
  16. public:
  17. enum AnalogValue {
  18. analog1_1 = 0,
  19. analog1_2 = 1,
  20. analog2_1 = 2,
  21. analog2_2 = 3
  22. };
  23. enum GreaterLessThan {
  24. less = 0,
  25. greater = 1
  26. };
  27. enum AlarmLevel {
  28. disable = 0,
  29. yellow = 1,
  30. orange = 2,
  31. red = 3
  32. };
  33. struct AlarmThreshold {
  34. AlarmThreshold(AnalogValue i, GreaterLessThan d, AlarmLevel l, uint8_t v)
  35. : id(i), dir(d), level(l), value(v) { }
  36. AnalogValue id;
  37. GreaterLessThan dir;
  38. AlarmLevel level;
  39. uint8_t value;
  40. };
  41. typedef void (*DataHandler)(uint8_t a1, uint8_t a2, uint8_t q1, uint8_t q2);
  42. typedef void (*AlarmThresholdHandler)(AlarmThreshold alarm);
  43. typedef void (*UserDataHandler)(const uint8_t* buf, uint8_t len);
  44. // -------------------------------------------------------------------------------
  45. FrSky(Stream* s);
  46. void poll();
  47. void pollAlarms();
  48. void setAlarm(AlarmThreshold alarm);
  49. void setDataHandler(DataHandler h) { dataHandler = h; }
  50. void setAlarmThresholdHandler(AlarmThresholdHandler h) { alarmThresholdHandler = h; }
  51. void setUserDataHandler(UserDataHandler h) { userDataHandler = h; }
  52. private:
  53. void handleMessage();
  54. void writeEscaped(uint8_t v);
  55. const static uint8_t bufferSize = 19;
  56. const static uint8_t userDataSize = 6;
  57. const static uint8_t minPacketSize = 11;
  58. const static uint8_t delimiter = 0x7E;
  59. const static uint8_t escape = 0x7D;
  60. const static uint8_t key = 0x20;
  61. const static uint8_t alarms = 4;
  62. const static uint8_t idVoltageQuality = 0xFE;
  63. const static uint8_t idUserData = 0xFD;
  64. const static uint8_t idAlarm0 = 0xFC;
  65. const static uint8_t idAlarm1 = 0xFB;
  66. const static uint8_t idAlarm2 = 0xFA;
  67. const static uint8_t idAlarm3 = 0xF9;
  68. const static uint8_t idGetAlarms = 0xF8;
  69. Stream* serial;
  70. DataHandler dataHandler;
  71. AlarmThresholdHandler alarmThresholdHandler;
  72. UserDataHandler userDataHandler;
  73. uint8_t userData[userDataSize];
  74. uint8_t buffer[bufferSize];
  75. uint8_t bufferIndex;
  76. };
  77. #endif // __FRSKY_H__