Procházet zdrojové kódy

Add Watchdog, Telemetry Status Callback

Thomas Buck před 8 roky
rodič
revize
757e9c85cb
2 změnil soubory, kde provedl 35 přidání a 6 odebrání
  1. 32
    3
      Saitek-X52-PPM.ino
  2. 3
    3
      events_buttons.cpp

+ 32
- 3
Saitek-X52-PPM.ino Zobrazit soubor

@@ -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
 

+ 3
- 3
events_buttons.cpp Zobrazit soubor

@@ -28,6 +28,8 @@
28 28
 #define MODE_BUTTON_YELLOW 24
29 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 33
 JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
32 34
         : JoystickEvents(client), x52(x), state(NONE), index(0),
33 35
         value(0), signedValue(0), currentMode(0) { }
@@ -56,9 +58,7 @@ void JoystickEventsButtons::printMenu() {
56 58
     static const uint8_t endpointMenuCount = sizeof(endpointMenu) / sizeof(endpointMenu[0]);
57 59
 
58 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 62
     } else if (state == MAINMENU) {
63 63
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
64 64
     } else if (state == CPPMMENU) {

Loading…
Zrušit
Uložit