|
@@ -13,6 +13,7 @@
|
13
|
13
|
#include <hid.h>
|
14
|
14
|
#include <hiduniversal.h>
|
15
|
15
|
#include <usbhub.h>
|
|
16
|
+#include <avr/wdt.h>
|
16
|
17
|
|
17
|
18
|
#include "events.h"
|
18
|
19
|
#include "parser.h"
|
|
@@ -34,6 +35,33 @@ JoystickEventsDeadZone joyDeadZone((JoystickEvents*)&joyButtons);
|
34
|
35
|
JoystickReportParser joy(&joyDeadZone);
|
35
|
36
|
FrSky frsky(&Serial);
|
36
|
37
|
|
|
38
|
+static void stringHelper(String& a, String& b, char delim, uint8_t line) {
|
|
39
|
+ String s = a + delim;
|
|
40
|
+ for (uint8_t i = 0; i < (14 - a.length() - b.length()); i++) {
|
|
41
|
+ s += ' ';
|
|
42
|
+ }
|
|
43
|
+ s += b + delim;
|
|
44
|
+ x52.setMFDText(line, s.c_str());
|
|
45
|
+}
|
|
46
|
+
|
|
47
|
+void statusCallback(uint8_t a1, uint8_t a2, uint8_t q1, uint8_t q2) {
|
|
48
|
+ x52.setMFDText(0, "Telemetry Status");
|
|
49
|
+
|
|
50
|
+ uint16_t l1 = q1 * 100 / 255, l2 = q2 * 100 / 255;
|
|
51
|
+ String link1(l1), link2(l2);
|
|
52
|
+ stringHelper(link1, link2, '%', 1);
|
|
53
|
+
|
|
54
|
+ uint32_t v1 = a1 * 330 / 255;
|
|
55
|
+ uint32_t v1hundred = v1 / 100;
|
|
56
|
+ uint32_t v1ten = v1 % 100;
|
|
57
|
+ String volt1 = String(v1hundred) + '.' + (v1ten);
|
|
58
|
+ uint32_t v2 = a2 * 330 / 255;
|
|
59
|
+ uint32_t v2hundred = v2 / 100;
|
|
60
|
+ uint32_t v2ten = v2 % 100;
|
|
61
|
+ String volt2 = String(v2hundred) + '.' + (v2ten);
|
|
62
|
+ stringHelper(volt1, volt2, 'V', 2);
|
|
63
|
+}
|
|
64
|
+
|
37
|
65
|
void setup() {
|
38
|
66
|
#ifdef ENABLE_SERIAL_PORT
|
39
|
67
|
Serial.begin(115200);
|
|
@@ -61,13 +89,13 @@ void setup() {
|
61
|
89
|
}
|
62
|
90
|
|
63
|
91
|
CPPM::instance().init();
|
|
92
|
+ frsky.setDataHandler(&statusCallback);
|
|
93
|
+ wdt_enable(WDTO_500MS);
|
64
|
94
|
}
|
65
|
95
|
|
66
|
96
|
void init_joystick() {
|
67
|
97
|
x52.initialize();
|
68
|
|
- x52.setMFDText(0, "Arduino X52 Host");
|
69
|
|
- x52.setMFDText(1, "should be ready!");
|
70
|
|
- x52.setMFDText(2, " OK for options ");
|
|
98
|
+ statusCallback(0, 0, 0, 0);
|
71
|
99
|
|
72
|
100
|
// Sometimes the first message is lost, so send again
|
73
|
101
|
if (joyButtons.getCurrentMode() == 1) {
|
|
@@ -83,6 +111,7 @@ void init_joystick() {
|
83
|
111
|
}
|
84
|
112
|
|
85
|
113
|
void loop() {
|
|
114
|
+ wdt_reset();
|
86
|
115
|
usb.Task();
|
87
|
116
|
frsky.poll();
|
88
|
117
|
|