Kaynağa Gözat

Some 'beauty' fixes and default values

Thomas Buck 8 yıl önce
ebeveyn
işleme
31777b3fed
5 değiştirilmiş dosya ile 68 ekleme ve 34 silme
  1. 1
    1
      Saitek-X52-PPM.ino
  2. 10
    10
      events.h
  3. 34
    23
      events_buttons.cpp
  4. 21
    0
      events_cppm.cpp
  5. 2
    0
      x52.h

+ 1
- 1
Saitek-X52-PPM.ino Dosyayı Görüntüle

@@ -30,7 +30,7 @@ USBHub hub(&usb);
30 30
 HIDUniversal hid(&usb);
31 31
 X52 x52(&usb, &hid);
32 32
 JoystickEventsCPPM joyCPPM;
33
-JoystickEventsButtons joyButtons(&x52, (JoystickEvents*)&joyCPPM);
33
+JoystickEventsButtons joyButtons((JoystickEvents*)&joyCPPM);
34 34
 JoystickEventsDeadZone joyDeadZone((JoystickEvents*)&joyButtons);
35 35
 JoystickReportParser joy(&joyDeadZone);
36 36
 FrSky frsky(&Serial);

+ 10
- 10
events.h Dosyayı Görüntüle

@@ -16,7 +16,15 @@
16 16
 #include <stdint.h>
17 17
 
18 18
 class GamePadEventData;
19
-class X52;
19
+
20
+enum RxChannels {
21
+    CHANNEL_ROLL = 0,
22
+    CHANNEL_PITCH = 1,
23
+    CHANNEL_THROTTLE = 2,
24
+    CHANNEL_YAW = 3,
25
+    CHANNEL_AUX1 = 4,
26
+    CHANNEL_AUX2 = 5
27
+};
20 28
 
21 29
 class JoystickEvents {
22 30
   public:
@@ -45,13 +53,6 @@ class JoystickEventsDeadZone : public JoystickEvents {
45 53
     const static uint8_t centerMouseX, centerMouseY;
46 54
 };
47 55
 
48
-#define CHANNEL_ROLL 0
49
-#define CHANNEL_PITCH 1
50
-#define CHANNEL_THROTTLE 2
51
-#define CHANNEL_YAW 3
52
-#define CHANNEL_AUX1 4
53
-#define CHANNEL_AUX2 5
54
-
55 56
 class JoystickEventsCPPM : public JoystickEvents {
56 57
   public:
57 58
     JoystickEventsCPPM(JoystickEvents* client = 0);
@@ -107,7 +108,7 @@ class JoystickEventsCPPM : public JoystickEvents {
107 108
 
108 109
 class JoystickEventsButtons : public JoystickEvents {
109 110
   public:
110
-    JoystickEventsButtons(X52* x = 0, JoystickEvents* client = 0);
111
+    JoystickEventsButtons(JoystickEvents* client = 0);
111 112
     virtual void OnButtonDown(uint8_t but_id);
112 113
 
113 114
     uint8_t getCurrentMode() { return currentMode; }
@@ -161,7 +162,6 @@ class JoystickEventsButtons : public JoystickEvents {
161 162
     void printValue(uint16_t min, uint16_t max, const char* title);
162 163
     void printSignedValue(int16_t min, int16_t max, const char* title);
163 164
 
164
-    X52* x52;
165 165
     MenuState state;
166 166
     uint8_t index;
167 167
     uint16_t value;

+ 34
- 23
events_buttons.cpp Dosyayı Görüntüle

@@ -28,10 +28,21 @@
28 28
 #define MODE_BUTTON_YELLOW 24
29 29
 #define MODE_BUTTON_RED 25
30 30
 
31
+#define MIN_FRAME_LENGTH 10000
32
+#define MAX_FRAME_LENGTH 30000
33
+#define MIN_PULSE_LENGTH 100
34
+#define MAX_PULSE_LENGTH 1000
35
+#define MIN_LOW_ENDPOINT 500
36
+#define MAX_LOW_ENDPOINT 1500
37
+#define MIN_HIGH_ENDPOINT 1500
38
+#define MAX_HIGH_ENDPOINT 2500
39
+#define MIN_TRIM -100
40
+#define MAX_TRIM 100
41
+
31 42
 void statusCallback(uint8_t a1, uint8_t a2, uint8_t q1, uint8_t q2);
32 43
 
33
-JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
34
-        : JoystickEvents(client), x52(x), state(NONE), index(0),
44
+JoystickEventsButtons::JoystickEventsButtons(JoystickEvents* client)
45
+        : JoystickEvents(client), state(NONE), index(0),
35 46
         value(0), signedValue(0), currentMode(0) { }
36 47
 
37 48
 void JoystickEventsButtons::printMenu() {
@@ -72,9 +83,9 @@ void JoystickEventsButtons::printMenu() {
72 83
     } else if (state == EDIT_CHANNELS) {
73 84
         printValue(4, CHANNELS_MAX, cppmMenu[0]);
74 85
     } else if (state == EDIT_FRAME_LENGTH) {
75
-        printValue(10000, 30000, cppmMenu[1]);
86
+        printValue(MIN_FRAME_LENGTH, MAX_FRAME_LENGTH, cppmMenu[1]);
76 87
     } else if (state == EDIT_PULSE_LENGTH) {
77
-        printValue(100, 1000, cppmMenu[2]);
88
+        printValue(MIN_PULSE_LENGTH, MAX_PULSE_LENGTH, cppmMenu[2]);
78 89
     } else if (state == EDIT_INVERT) {
79 90
         printValue(0, 1, cppmMenu[3]);
80 91
     } else if ((state >= EDIT_INVERT_ROLL) && (state <= EDIT_INVERT_AUX2)) {
@@ -83,33 +94,33 @@ void JoystickEventsButtons::printMenu() {
83 94
     } else if ((state >= EDIT_MIN_ROLL) && (state <= EDIT_MAX_AUX2)) {
84 95
         uint8_t index = state - EDIT_MIN_ROLL;
85 96
         if (index & 0x01) {
86
-            printValue(1500, 2500, endpointMenu[index]);
97
+            printValue(MIN_HIGH_ENDPOINT, MAX_HIGH_ENDPOINT, endpointMenu[index]);
87 98
         } else {
88
-            printValue(500, 1500, endpointMenu[index]);
99
+            printValue(MIN_LOW_ENDPOINT, MAX_LOW_ENDPOINT, endpointMenu[index]);
89 100
         }
90 101
     } else if ((state >= EDIT_TRIM_ROLL) && (state <= EDIT_TRIM_AUX2)) {
91 102
         uint8_t index = state - EDIT_TRIM_ROLL;
92
-        printSignedValue(-100, 100, (String("Trim ") + axisMenu[index]).c_str());
103
+        printSignedValue(MIN_TRIM, MAX_TRIM, (String("Trim ") + axisMenu[index]).c_str());
93 104
     }
94 105
 }
95 106
 
96 107
 void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
97 108
 #ifdef DEBUG_BUTTON_MFD
98 109
     String text = "Button " + String(but_id) + " down";
99
-    x52->setMFDText(1, text.c_str());
110
+    x52.setMFDText(1, text.c_str());
100 111
 #endif
101 112
 
102 113
     if (but_id == MODE_BUTTON_GREEN) {
103
-        x52->setLEDBrightness(2);
104
-        x52->setMFDBrightness(2);
114
+        x52.setLEDBrightness(2);
115
+        x52.setMFDBrightness(2);
105 116
         currentMode = 1;
106 117
     } else if (but_id == MODE_BUTTON_YELLOW) {
107
-        x52->setLEDBrightness(1);
108
-        x52->setMFDBrightness(1);
118
+        x52.setLEDBrightness(1);
119
+        x52.setMFDBrightness(1);
109 120
         currentMode = 2;
110 121
     } else if (but_id == MODE_BUTTON_RED) {
111
-        x52->setLEDBrightness(0);
112
-        x52->setMFDBrightness(0);
122
+        x52.setLEDBrightness(0);
123
+        x52.setMFDBrightness(0);
113 124
         currentMode = 3;
114 125
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
115 126
         if (state == NONE) {
@@ -369,7 +380,7 @@ void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const c
369 380
 
370 381
     uint8_t end = start + 2;
371 382
     if (index == 0) {
372
-        x52->setMFDText(0, title);
383
+        x52.setMFDText(0, title);
373 384
         line = 1;
374 385
         end = start + 1;
375 386
     }
@@ -380,11 +391,11 @@ void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const c
380 391
 
381 392
     for (uint8_t i = start; i <= end; i++) {
382 393
         String tmp = (index == i) ? "-> " : "   ";
383
-        x52->setMFDText(line++, (tmp + menu[i]).c_str());
394
+        x52.setMFDText(line++, (tmp + menu[i]).c_str());
384 395
     }
385 396
 
386 397
     if (line == 2) {
387
-        x52->setMFDText(2);
398
+        x52.setMFDText(2);
388 399
     }
389 400
 
390 401
 #ifdef DEBUG_OUTPUT
@@ -418,9 +429,9 @@ void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* t
418 429
         value = max;
419 430
     }
420 431
 
421
-    x52->setMFDText(0, (String(title) + ":").c_str());
422
-    x52->setMFDText(1, String(value).c_str());
423
-    x52->setMFDText(2, "Press OK to save");
432
+    x52.setMFDText(0, (String(title) + ":").c_str());
433
+    x52.setMFDText(1, String(value).c_str());
434
+    x52.setMFDText(2, "Press OK to save");
424 435
 }
425 436
 
426 437
 void JoystickEventsButtons::printSignedValue(int16_t min, int16_t max, const char* title) {
@@ -442,8 +453,8 @@ void JoystickEventsButtons::printSignedValue(int16_t min, int16_t max, const cha
442 453
         signedValue = max;
443 454
     }
444 455
 
445
-    x52->setMFDText(0, (String(title) + ":").c_str());
446
-    x52->setMFDText(1, String(signedValue).c_str());
447
-    x52->setMFDText(2, "Press OK to save");
456
+    x52.setMFDText(0, (String(title) + ":").c_str());
457
+    x52.setMFDText(1, String(signedValue).c_str());
458
+    x52.setMFDText(2, "Press OK to save");
448 459
 }
449 460
 

+ 21
- 0
events_cppm.cpp Dosyayı Görüntüle

@@ -24,9 +24,30 @@ JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(
24 24
         trim[i] = 0;
25 25
     }
26 26
 
27
+    /*
28
+     * Aux switches are commonly used for arming.
29
+     * Ensure we're not sending high values when
30
+     * no joystick has been connected...
31
+     */
27 32
     values[CHANNEL_AUX1] = 1000;
28 33
     values[CHANNEL_AUX2] = 1000;
34
+
35
+    /*
36
+     * Default values to match my personal setup.
37
+     * Can be changed using the on-screen menu.
38
+     */
29 39
     invert[CHANNEL_THROTTLE] = 1;
40
+    invert[CHANNEL_PITCH] = 1;
41
+    minimum[CHANNEL_THROTTLE] = 1010;
42
+    maximum[CHANNEL_THROTTLE] = 1950;
43
+    minimum[CHANNEL_ROLL] = 1050;
44
+    maximum[CHANNEL_ROLL] = 1950;
45
+    minimum[CHANNEL_PITCH] = 1080;
46
+    maximum[CHANNEL_PITCH] = 1890;
47
+    minimum[CHANNEL_AUX1] = 990;
48
+    maximum[CHANNEL_AUX1] = 2100;
49
+    minimum[CHANNEL_AUX2] = 990;
50
+    maximum[CHANNEL_AUX2] = 1990;
30 51
 
31 52
     CPPM::instance().copy(values);
32 53
 }

+ 2
- 0
x52.h Dosyayı Görüntüle

@@ -88,5 +88,7 @@ class X52 {
88 88
     uint8_t ready;
89 89
 };
90 90
 
91
+extern X52 x52;
92
+
91 93
 #endif // __X52_H__
92 94
 

Loading…
İptal
Kaydet