Browse Source

Some 'beauty' fixes and default values

Thomas Buck 8 years ago
parent
commit
31777b3fed
5 changed files with 68 additions and 34 deletions
  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 View File

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

+ 10
- 10
events.h View File

16
 #include <stdint.h>
16
 #include <stdint.h>
17
 
17
 
18
 class GamePadEventData;
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
 class JoystickEvents {
29
 class JoystickEvents {
22
   public:
30
   public:
45
     const static uint8_t centerMouseX, centerMouseY;
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
 class JoystickEventsCPPM : public JoystickEvents {
56
 class JoystickEventsCPPM : public JoystickEvents {
56
   public:
57
   public:
57
     JoystickEventsCPPM(JoystickEvents* client = 0);
58
     JoystickEventsCPPM(JoystickEvents* client = 0);
107
 
108
 
108
 class JoystickEventsButtons : public JoystickEvents {
109
 class JoystickEventsButtons : public JoystickEvents {
109
   public:
110
   public:
110
-    JoystickEventsButtons(X52* x = 0, JoystickEvents* client = 0);
111
+    JoystickEventsButtons(JoystickEvents* client = 0);
111
     virtual void OnButtonDown(uint8_t but_id);
112
     virtual void OnButtonDown(uint8_t but_id);
112
 
113
 
113
     uint8_t getCurrentMode() { return currentMode; }
114
     uint8_t getCurrentMode() { return currentMode; }
161
     void printValue(uint16_t min, uint16_t max, const char* title);
162
     void printValue(uint16_t min, uint16_t max, const char* title);
162
     void printSignedValue(int16_t min, int16_t max, const char* title);
163
     void printSignedValue(int16_t min, int16_t max, const char* title);
163
 
164
 
164
-    X52* x52;
165
     MenuState state;
165
     MenuState state;
166
     uint8_t index;
166
     uint8_t index;
167
     uint16_t value;
167
     uint16_t value;

+ 34
- 23
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
+#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
 void statusCallback(uint8_t a1, uint8_t a2, uint8_t q1, uint8_t q2);
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
         value(0), signedValue(0), currentMode(0) { }
46
         value(0), signedValue(0), currentMode(0) { }
36
 
47
 
37
 void JoystickEventsButtons::printMenu() {
48
 void JoystickEventsButtons::printMenu() {
72
     } else if (state == EDIT_CHANNELS) {
83
     } else if (state == EDIT_CHANNELS) {
73
         printValue(4, CHANNELS_MAX, cppmMenu[0]);
84
         printValue(4, CHANNELS_MAX, cppmMenu[0]);
74
     } else if (state == EDIT_FRAME_LENGTH) {
85
     } else if (state == EDIT_FRAME_LENGTH) {
75
-        printValue(10000, 30000, cppmMenu[1]);
86
+        printValue(MIN_FRAME_LENGTH, MAX_FRAME_LENGTH, cppmMenu[1]);
76
     } else if (state == EDIT_PULSE_LENGTH) {
87
     } else if (state == EDIT_PULSE_LENGTH) {
77
-        printValue(100, 1000, cppmMenu[2]);
88
+        printValue(MIN_PULSE_LENGTH, MAX_PULSE_LENGTH, cppmMenu[2]);
78
     } else if (state == EDIT_INVERT) {
89
     } else if (state == EDIT_INVERT) {
79
         printValue(0, 1, cppmMenu[3]);
90
         printValue(0, 1, cppmMenu[3]);
80
     } else if ((state >= EDIT_INVERT_ROLL) && (state <= EDIT_INVERT_AUX2)) {
91
     } else if ((state >= EDIT_INVERT_ROLL) && (state <= EDIT_INVERT_AUX2)) {
83
     } else if ((state >= EDIT_MIN_ROLL) && (state <= EDIT_MAX_AUX2)) {
94
     } else if ((state >= EDIT_MIN_ROLL) && (state <= EDIT_MAX_AUX2)) {
84
         uint8_t index = state - EDIT_MIN_ROLL;
95
         uint8_t index = state - EDIT_MIN_ROLL;
85
         if (index & 0x01) {
96
         if (index & 0x01) {
86
-            printValue(1500, 2500, endpointMenu[index]);
97
+            printValue(MIN_HIGH_ENDPOINT, MAX_HIGH_ENDPOINT, endpointMenu[index]);
87
         } else {
98
         } else {
88
-            printValue(500, 1500, endpointMenu[index]);
99
+            printValue(MIN_LOW_ENDPOINT, MAX_LOW_ENDPOINT, endpointMenu[index]);
89
         }
100
         }
90
     } else if ((state >= EDIT_TRIM_ROLL) && (state <= EDIT_TRIM_AUX2)) {
101
     } else if ((state >= EDIT_TRIM_ROLL) && (state <= EDIT_TRIM_AUX2)) {
91
         uint8_t index = state - EDIT_TRIM_ROLL;
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
 void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
107
 void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
97
 #ifdef DEBUG_BUTTON_MFD
108
 #ifdef DEBUG_BUTTON_MFD
98
     String text = "Button " + String(but_id) + " down";
109
     String text = "Button " + String(but_id) + " down";
99
-    x52->setMFDText(1, text.c_str());
110
+    x52.setMFDText(1, text.c_str());
100
 #endif
111
 #endif
101
 
112
 
102
     if (but_id == MODE_BUTTON_GREEN) {
113
     if (but_id == MODE_BUTTON_GREEN) {
103
-        x52->setLEDBrightness(2);
104
-        x52->setMFDBrightness(2);
114
+        x52.setLEDBrightness(2);
115
+        x52.setMFDBrightness(2);
105
         currentMode = 1;
116
         currentMode = 1;
106
     } else if (but_id == MODE_BUTTON_YELLOW) {
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
         currentMode = 2;
120
         currentMode = 2;
110
     } else if (but_id == MODE_BUTTON_RED) {
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
         currentMode = 3;
124
         currentMode = 3;
114
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
125
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
115
         if (state == NONE) {
126
         if (state == NONE) {
369
 
380
 
370
     uint8_t end = start + 2;
381
     uint8_t end = start + 2;
371
     if (index == 0) {
382
     if (index == 0) {
372
-        x52->setMFDText(0, title);
383
+        x52.setMFDText(0, title);
373
         line = 1;
384
         line = 1;
374
         end = start + 1;
385
         end = start + 1;
375
     }
386
     }
380
 
391
 
381
     for (uint8_t i = start; i <= end; i++) {
392
     for (uint8_t i = start; i <= end; i++) {
382
         String tmp = (index == i) ? "-> " : "   ";
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
     if (line == 2) {
397
     if (line == 2) {
387
-        x52->setMFDText(2);
398
+        x52.setMFDText(2);
388
     }
399
     }
389
 
400
 
390
 #ifdef DEBUG_OUTPUT
401
 #ifdef DEBUG_OUTPUT
418
         value = max;
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
 void JoystickEventsButtons::printSignedValue(int16_t min, int16_t max, const char* title) {
437
 void JoystickEventsButtons::printSignedValue(int16_t min, int16_t max, const char* title) {
442
         signedValue = max;
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 View File

24
         trim[i] = 0;
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
     values[CHANNEL_AUX1] = 1000;
32
     values[CHANNEL_AUX1] = 1000;
28
     values[CHANNEL_AUX2] = 1000;
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
     invert[CHANNEL_THROTTLE] = 1;
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
     CPPM::instance().copy(values);
52
     CPPM::instance().copy(values);
32
 }
53
 }

+ 2
- 0
x52.h View File

88
     uint8_t ready;
88
     uint8_t ready;
89
 };
89
 };
90
 
90
 
91
+extern X52 x52;
92
+
91
 #endif // __X52_H__
93
 #endif // __X52_H__
92
 
94
 

Loading…
Cancel
Save