Browse Source

Add Watchdog, Telemetry Status Callback

Thomas Buck 7 years ago
parent
commit
757e9c85cb
2 changed files with 35 additions and 6 deletions
  1. 32
    3
      Saitek-X52-PPM.ino
  2. 3
    3
      events_buttons.cpp

+ 32
- 3
Saitek-X52-PPM.ino View File

13
 #include <hid.h>
13
 #include <hid.h>
14
 #include <hiduniversal.h>
14
 #include <hiduniversal.h>
15
 #include <usbhub.h>
15
 #include <usbhub.h>
16
+#include <avr/wdt.h>
16
 
17
 
17
 #include "events.h"
18
 #include "events.h"
18
 #include "parser.h"
19
 #include "parser.h"
34
 JoystickReportParser joy(&joyDeadZone);
35
 JoystickReportParser joy(&joyDeadZone);
35
 FrSky frsky(&Serial);
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
 void setup() {
65
 void setup() {
38
 #ifdef ENABLE_SERIAL_PORT
66
 #ifdef ENABLE_SERIAL_PORT
39
     Serial.begin(115200);
67
     Serial.begin(115200);
61
     }
89
     }
62
 
90
 
63
     CPPM::instance().init();
91
     CPPM::instance().init();
92
+    frsky.setDataHandler(&statusCallback);
93
+    wdt_enable(WDTO_500MS);
64
 }
94
 }
65
 
95
 
66
 void init_joystick() {
96
 void init_joystick() {
67
     x52.initialize();
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
     // Sometimes the first message is lost, so send again
100
     // Sometimes the first message is lost, so send again
73
     if (joyButtons.getCurrentMode() == 1) {
101
     if (joyButtons.getCurrentMode() == 1) {
83
 }
111
 }
84
 
112
 
85
 void loop() {
113
 void loop() {
114
+    wdt_reset();
86
     usb.Task();
115
     usb.Task();
87
     frsky.poll();
116
     frsky.poll();
88
 
117
 

+ 3
- 3
events_buttons.cpp View File

28
 #define MODE_BUTTON_YELLOW 24
28
 #define MODE_BUTTON_YELLOW 24
29
 #define MODE_BUTTON_RED 25
29
 #define MODE_BUTTON_RED 25
30
 
30
 
31
+void statusCallback(uint8_t a1, uint8_t a2, uint8_t q1, uint8_t q2);
32
+
31
 JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
33
 JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
32
         : JoystickEvents(client), x52(x), state(NONE), index(0),
34
         : JoystickEvents(client), x52(x), state(NONE), index(0),
33
         value(0), signedValue(0), currentMode(0) { }
35
         value(0), signedValue(0), currentMode(0) { }
56
     static const uint8_t endpointMenuCount = sizeof(endpointMenu) / sizeof(endpointMenu[0]);
58
     static const uint8_t endpointMenuCount = sizeof(endpointMenu) / sizeof(endpointMenu[0]);
57
 
59
 
58
     if (state == NONE) {
60
     if (state == NONE) {
59
-        x52->setMFDText(0, "Telemetry Status");
60
-        x52->setMFDText(1, "???%        ???%");
61
-        x52->setMFDText(2, "??.?V      ??.?V");
61
+        statusCallback(0, 0, 0, 0);
62
     } else if (state == MAINMENU) {
62
     } else if (state == MAINMENU) {
63
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
63
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
64
     } else if (state == CPPMMENU) {
64
     } else if (state == CPPMMENU) {

Loading…
Cancel
Save