Ver código fonte

Implemented missing channel invert, trim and endpoint menus

Thomas Buck 8 anos atrás
pai
commit
4999e4178a
4 arquivos alterados com 389 adições e 100 exclusões
  1. 2
    2
      Saitek-X52-PPM.ino
  2. 82
    0
      events.h
  3. 255
    84
      events_buttons.cpp
  4. 50
    14
      events_cppm.cpp

+ 2
- 2
Saitek-X52-PPM.ino Ver arquivo

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

+ 82
- 0
events.h Ver arquivo

@@ -45,14 +45,64 @@ class JoystickEventsDeadZone : public JoystickEvents {
45 45
     const static uint8_t centerMouseX, centerMouseY;
46 46
 };
47 47
 
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
+
48 55
 class JoystickEventsCPPM : public JoystickEvents {
49 56
   public:
50 57
     JoystickEventsCPPM(JoystickEvents* client = 0);
51 58
     virtual void OnGamePadChanged(const GamePadEventData& evt);
52 59
 
60
+    uint8_t getInvert(uint8_t ch) {
61
+        if (ch < channels) return invert[ch];
62
+        else return 0;
63
+    }
64
+
65
+    void setInvert(uint8_t ch, uint8_t i) {
66
+        if (ch < channels) invert[ch] = i;
67
+    }
68
+
69
+    uint16_t getMinimum(uint8_t ch) {
70
+        if (ch < channels) return minimum[ch];
71
+        else return 0;
72
+    }
73
+
74
+    void setMinimum(uint8_t ch, uint16_t i) {
75
+        if (ch < channels) minimum[ch] = i;
76
+    }
77
+
78
+    uint16_t getMaximum(uint8_t ch) {
79
+        if (ch < channels) return maximum[ch];
80
+        else return 0;
81
+    }
82
+
83
+    void setMaximum(uint8_t ch, uint16_t i) {
84
+        if (ch < channels) maximum[ch] = i;
85
+    }
86
+
87
+    int16_t getTrim(uint8_t ch) {
88
+        if (ch < channels) return trim[ch];
89
+        else return 0;
90
+    }
91
+
92
+    void setTrim(uint8_t ch, int16_t i) {
93
+        if (ch < channels) trim[ch] = i;
94
+    }
95
+
53 96
   private:
97
+    uint16_t getJoystickAxis(const GamePadEventData& evt, uint8_t ch);
98
+    uint16_t getJoystickMax(uint8_t ch);
99
+
54 100
     const static uint8_t channels = 12;
55 101
     uint16_t values[channels];
102
+    uint8_t invert[channels];
103
+    uint16_t minimum[channels];
104
+    uint16_t maximum[channels];
105
+    int16_t trim[channels];
56 106
 };
57 107
 
58 108
 class JoystickEventsButtons : public JoystickEvents {
@@ -74,6 +124,32 @@ class JoystickEventsButtons : public JoystickEvents {
74 124
         EDIT_FRAME_LENGTH,
75 125
         EDIT_PULSE_LENGTH,
76 126
         EDIT_INVERT,
127
+        EDIT_MIN_ROLL,
128
+        EDIT_MAX_ROLL,
129
+        EDIT_MIN_PITCH,
130
+        EDIT_MAX_PITCH,
131
+        EDIT_MIN_YAW,
132
+        EDIT_MAX_YAW,
133
+        EDIT_MIN_THROTTLE,
134
+        EDIT_MAX_THROTTLE,
135
+        EDIT_MIN_AUX1,
136
+        EDIT_MAX_AUX1,
137
+        EDIT_MIN_AUX2,
138
+        EDIT_MAX_AUX2,
139
+        EDIT_INVERT_ROLL,
140
+        EDIT_INVERT_PITCH,
141
+        EDIT_INVERT_YAW,
142
+        EDIT_INVERT_THROTTLE,
143
+        EDIT_INVERT_AUX1,
144
+        EDIT_INVERT_AUX2,
145
+
146
+        STATES_EDIT_SIGNED,
147
+        EDIT_TRIM_ROLL,
148
+        EDIT_TRIM_PITCH,
149
+        EDIT_TRIM_YAW,
150
+        EDIT_TRIM_THROTTLE,
151
+        EDIT_TRIM_AUX1,
152
+        EDIT_TRIM_AUX2,
77 153
 
78 154
         STATES_MAX
79 155
     };
@@ -81,13 +157,19 @@ class JoystickEventsButtons : public JoystickEvents {
81 157
     void printMenu();
82 158
     void menuHelper(uint8_t count, const char** menu, const char* title);
83 159
     void printValue(uint16_t min, uint16_t max, const char* title);
160
+    void printSignedValue(int16_t min, int16_t max, const char* title);
84 161
 
85 162
     X52* x52;
86 163
     MenuState state;
87 164
     uint8_t index;
88 165
     uint16_t value;
166
+    int16_t signedValue;
89 167
     unsigned long menuTime;
90 168
 };
91 169
 
170
+extern JoystickEventsCPPM joyCPPM;
171
+extern JoystickEventsButtons joyButtons;
172
+extern JoystickEventsDeadZone joyDeadZone;
173
+
92 174
 #endif // __JOYSTICK_EVENTS_H__
93 175
 

+ 255
- 84
events_buttons.cpp Ver arquivo

@@ -29,49 +29,8 @@
29 29
 #define MODE_BUTTON_RED 25
30 30
 
31 31
 JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
32
-        : JoystickEvents(client), x52(x), state(NONE), index(0), value(0), menuTime(0) { }
33
-
34
-void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const char* title) {
35
-    if (index >= count) {
36
-        index = count - 1;
37
-    }
38
-
39
-    uint8_t start = 0, line = 0;
40
-    if (index > 1) {
41
-        start = index - 1;
42
-    }
43
-
44
-    uint8_t end = start + 2;
45
-    if (index == 0) {
46
-        x52->setMFDText(0, title);
47
-        line = 1;
48
-        end = start + 1;
49
-    }
50
-
51
-    if (end >= count) {
52
-        end = count - 1;
53
-    }
54
-
55
-    for (uint8_t i = start; i <= end; i++) {
56
-        String tmp = (index == i) ? "-> " : "   ";
57
-        x52->setMFDText(line++, (tmp + menu[i]).c_str());
58
-    }
59
-
60
-    if (line == 2) {
61
-        x52->setMFDText(2);
62
-    }
63
-
64
-#ifdef DEBUG_OUTPUT
65
-    Serial.print("menuHelper() state=");
66
-    Serial.print(state);
67
-    Serial.print(" index=");
68
-    Serial.print(index);
69
-    Serial.print(" start=");
70
-    Serial.print(start);
71
-    Serial.print(" end=");
72
-    Serial.println(end);
73
-#endif
74
-}
32
+        : JoystickEvents(client), x52(x), state(NONE), index(0),
33
+        value(0), signedValue(0), menuTime(0) { }
75 34
 
76 35
 void JoystickEventsButtons::printMenu() {
77 36
     static const char* mainMenu[] = {
@@ -96,7 +55,11 @@ void JoystickEventsButtons::printMenu() {
96 55
     };
97 56
     static const uint8_t endpointMenuCount = sizeof(endpointMenu) / sizeof(endpointMenu[0]);
98 57
 
99
-    if (state == MAINMENU) {
58
+    if (state == NONE) {
59
+        x52->setMFDText(0, "Telemetry Status");
60
+        x52->setMFDText(1, "???%        ???%");
61
+        x52->setMFDText(2, "??.?V      ??.?V");
62
+    } else if (state == MAINMENU) {
100 63
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
101 64
     } else if (state == CPPMMENU) {
102 65
         menuHelper(cppmMenuCount, cppmMenu, "CPPM Config Menu");
@@ -107,42 +70,31 @@ void JoystickEventsButtons::printMenu() {
107 70
     } else if (state == INVERTAXISMENU) {
108 71
         menuHelper(axisMenuCount, axisMenu, "Invert Axis Menu");
109 72
     } else if (state == EDIT_CHANNELS) {
110
-        printValue(4, CHANNELS_MAX, mainMenu[0]);
73
+        printValue(4, CHANNELS_MAX, cppmMenu[0]);
111 74
     } else if (state == EDIT_FRAME_LENGTH) {
112
-        printValue(10000, 30000, mainMenu[1]);
75
+        printValue(10000, 30000, cppmMenu[1]);
113 76
     } else if (state == EDIT_PULSE_LENGTH) {
114
-        printValue(100, 1000, mainMenu[2]);
77
+        printValue(100, 1000, cppmMenu[2]);
115 78
     } else if (state == EDIT_INVERT) {
116
-        printValue(0, 1, mainMenu[3]);
79
+        printValue(0, 1, cppmMenu[3]);
80
+    } else if ((state >= EDIT_INVERT_ROLL) && (state <= EDIT_INVERT_AUX2)) {
81
+        uint8_t index = state - EDIT_INVERT_ROLL;
82
+        printValue(0, 1, (String("Invert ") + axisMenu[index]).c_str());
83
+    } else if ((state >= EDIT_MIN_ROLL) && (state <= EDIT_MAX_AUX2)) {
84
+        uint8_t index = state - EDIT_MIN_ROLL;
85
+        if (index & 0x01) {
86
+            printValue(1500, 2500, endpointMenu[index]);
87
+        } else {
88
+            printValue(500, 1500, endpointMenu[index]);
89
+        }
90
+    } else if ((state >= EDIT_TRIM_ROLL) && (state <= EDIT_TRIM_AUX2)) {
91
+        uint8_t index = state - EDIT_TRIM_ROLL;
92
+        printSignedValue(-100, 100, (String("Trim ") + axisMenu[index]).c_str());
117 93
     }
118 94
 
119 95
     menuTime = millis();
120 96
 }
121 97
 
122
-void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* title) {
123
-#ifdef DEBUG_OUTPUT
124
-    Serial.print("printValue() state=");
125
-    Serial.print(state);
126
-    Serial.print(" index=");
127
-    Serial.print(index);
128
-    Serial.print(" min=");
129
-    Serial.print(min);
130
-    Serial.print(" max=");
131
-    Serial.println(max);
132
-#endif
133
-
134
-    if (value < min) {
135
-        value = min;
136
-    }
137
-    if (value > max) {
138
-        value = max;
139
-    }
140
-
141
-    x52->setMFDText(0, (String(title) + ":").c_str());
142
-    x52->setMFDText(1, String(value).c_str());
143
-    x52->setMFDText(2, "Press OK to save");
144
-}
145
-
146 98
 void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
147 99
 #ifdef DEBUG_BUTTON_MFD
148 100
     String text = "Button " + String(but_id) + " down";
@@ -166,53 +118,102 @@ void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
166 118
             if (index == 0) {
167 119
                 state = NONE;
168 120
             } else if (index == 1) {
169
-                //state = TRIMAXISMENU;
170
-                //index = 0;
121
+                state = TRIMAXISMENU;
122
+                index = 0;
171 123
             } else if (index == 2) {
172
-                //state = TRIMENDPOINTMENU;
173
-                //index = 0;
124
+                state = TRIMENDPOINTMENU;
125
+                index = 0;
174 126
             } else if (index == 3) {
175
-                //state = INVERTAXISMENU;
176
-                //index = 0;
127
+                state = INVERTAXISMENU;
128
+                index = 0;
177 129
             } else if (index == 4) {
178 130
                 state = CPPMMENU;
179 131
                 index = 0;
180 132
             }
181 133
         } else if (state == TRIMAXISMENU) {
182 134
             if (index == 0) {
135
+                state = EDIT_TRIM_ROLL;
136
+                signedValue = joyCPPM.getTrim(CHANNEL_ROLL);
183 137
             } else if (index == 1) {
138
+                state = EDIT_TRIM_PITCH;
139
+                signedValue = joyCPPM.getTrim(CHANNEL_PITCH);
184 140
             } else if (index == 2) {
141
+                state = EDIT_TRIM_YAW;
142
+                signedValue = joyCPPM.getTrim(CHANNEL_YAW);
185 143
             } else if (index == 3) {
144
+                state = EDIT_TRIM_THROTTLE;
145
+                signedValue = joyCPPM.getTrim(CHANNEL_THROTTLE);
186 146
             } else if (index == 4) {
147
+                state = EDIT_TRIM_AUX1;
148
+                signedValue = joyCPPM.getTrim(CHANNEL_AUX1);
187 149
             } else if (index == 5) {
150
+                state = EDIT_TRIM_AUX2;
151
+                signedValue = joyCPPM.getTrim(CHANNEL_AUX2);
188 152
             } else if (index == 6) {
189 153
                 state = MAINMENU;
190 154
                 index = 0;
191 155
             }
192 156
         } else if (state == TRIMENDPOINTMENU) {
193 157
             if (index == 0) {
158
+                state = EDIT_MIN_ROLL;
159
+                value = joyCPPM.getMinimum(CHANNEL_ROLL);
194 160
             } else if (index == 1) {
161
+                state = EDIT_MAX_ROLL;
162
+                value = joyCPPM.getMaximum(CHANNEL_ROLL);
195 163
             } else if (index == 2) {
164
+                state = EDIT_MIN_PITCH;
165
+                value = joyCPPM.getMinimum(CHANNEL_PITCH);
196 166
             } else if (index == 3) {
167
+                state = EDIT_MAX_PITCH;
168
+                value = joyCPPM.getMaximum(CHANNEL_PITCH);
197 169
             } else if (index == 4) {
170
+                state = EDIT_MIN_YAW;
171
+                value = joyCPPM.getMinimum(CHANNEL_YAW);
198 172
             } else if (index == 5) {
173
+                state = EDIT_MAX_YAW;
174
+                value = joyCPPM.getMaximum(CHANNEL_YAW);
199 175
             } else if (index == 6) {
176
+                state = EDIT_MIN_THROTTLE;
177
+                value = joyCPPM.getMinimum(CHANNEL_THROTTLE);
200 178
             } else if (index == 7) {
179
+                state = EDIT_MAX_THROTTLE;
180
+                value = joyCPPM.getMaximum(CHANNEL_THROTTLE);
201 181
             } else if (index == 8) {
182
+                state = EDIT_MIN_AUX1;
183
+                value = joyCPPM.getMinimum(CHANNEL_AUX1);
202 184
             } else if (index == 9) {
185
+                state = EDIT_MAX_AUX1;
186
+                value = joyCPPM.getMaximum(CHANNEL_AUX1);
203 187
             } else if (index == 10) {
188
+                state = EDIT_MIN_AUX2;
189
+                value = joyCPPM.getMinimum(CHANNEL_AUX2);
204 190
             } else if (index == 11) {
191
+                state = EDIT_MAX_AUX2;
192
+                value = joyCPPM.getMaximum(CHANNEL_AUX2);
205 193
             } else if (index == 12) {
194
+                state = EDIT_MIN_ROLL;
206 195
                 state = MAINMENU;
207 196
                 index = 0;
208 197
             }
209 198
         } else if (state == INVERTAXISMENU) {
210 199
             if (index == 0) {
200
+                state = EDIT_INVERT_ROLL;
201
+                value = joyCPPM.getInvert(CHANNEL_ROLL);
211 202
             } else if (index == 1) {
203
+                state = EDIT_INVERT_PITCH;
204
+                value = joyCPPM.getInvert(CHANNEL_PITCH);
212 205
             } else if (index == 2) {
206
+                state = EDIT_INVERT_YAW;
207
+                value = joyCPPM.getInvert(CHANNEL_YAW);
213 208
             } else if (index == 3) {
209
+                state = EDIT_INVERT_THROTTLE;
210
+                value = joyCPPM.getInvert(CHANNEL_THROTTLE);
214 211
             } else if (index == 4) {
212
+                state = EDIT_INVERT_AUX1;
213
+                value = joyCPPM.getInvert(CHANNEL_AUX1);
215 214
             } else if (index == 5) {
215
+                state = EDIT_INVERT_AUX2;
216
+                value = joyCPPM.getInvert(CHANNEL_AUX2);
216 217
             } else if (index == 6) {
217 218
                 state = MAINMENU;
218 219
                 index = 0;
@@ -236,32 +237,112 @@ void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
236 237
             }
237 238
         } else if (state == EDIT_CHANNELS) {
238 239
             CPPM::instance().setChannels(value);
239
-            state = MAINMENU;
240
+            state = CPPMMENU;
240 241
         } else if (state == EDIT_FRAME_LENGTH) {
241 242
             CPPM::instance().setFrameLength(value);
242
-            state = MAINMENU;
243
+            state = CPPMMENU;
243 244
         } else if (state == EDIT_PULSE_LENGTH) {
244 245
             CPPM::instance().setPulseLength(value);
245
-            state = MAINMENU;
246
+            state = CPPMMENU;
246 247
         } else if (state == EDIT_INVERT) {
247 248
             CPPM::instance().setInvert(value);
248
-            state = MAINMENU;
249
+            state = CPPMMENU;
250
+        } else if (state == EDIT_INVERT_ROLL) {
251
+            joyCPPM.setInvert(CHANNEL_ROLL, value);
252
+            state = INVERTAXISMENU;
253
+        } else if (state == EDIT_INVERT_PITCH) {
254
+            joyCPPM.setInvert(CHANNEL_PITCH, value);
255
+            state = INVERTAXISMENU;
256
+        } else if (state == EDIT_INVERT_YAW) {
257
+            joyCPPM.setInvert(CHANNEL_YAW, value);
258
+            state = INVERTAXISMENU;
259
+        } else if (state == EDIT_INVERT_THROTTLE) {
260
+            joyCPPM.setInvert(CHANNEL_THROTTLE, value);
261
+            state = INVERTAXISMENU;
262
+        } else if (state == EDIT_INVERT_AUX1) {
263
+            joyCPPM.setInvert(CHANNEL_AUX1, value);
264
+            state = INVERTAXISMENU;
265
+        } else if (state == EDIT_INVERT_AUX2) {
266
+            joyCPPM.setInvert(CHANNEL_AUX2, value);
267
+            state = INVERTAXISMENU;
268
+        } else if (state == EDIT_MIN_ROLL) {
269
+            joyCPPM.setMinimum(CHANNEL_ROLL, value);
270
+            state = TRIMENDPOINTMENU;
271
+        } else if (state == EDIT_MAX_ROLL) {
272
+            joyCPPM.setMaximum(CHANNEL_ROLL, value);
273
+            state = TRIMENDPOINTMENU;
274
+        } else if (state == EDIT_MIN_PITCH) {
275
+            joyCPPM.setMinimum(CHANNEL_PITCH, value);
276
+            state = TRIMENDPOINTMENU;
277
+        } else if (state == EDIT_MAX_PITCH) {
278
+            joyCPPM.setMaximum(CHANNEL_PITCH, value);
279
+            state = TRIMENDPOINTMENU;
280
+        } else if (state == EDIT_MIN_YAW) {
281
+            joyCPPM.setMinimum(CHANNEL_YAW, value);
282
+            state = TRIMENDPOINTMENU;
283
+        } else if (state == EDIT_MAX_YAW) {
284
+            joyCPPM.setMaximum(CHANNEL_YAW, value);
285
+            state = TRIMENDPOINTMENU;
286
+        } else if (state == EDIT_MIN_THROTTLE) {
287
+            joyCPPM.setMinimum(CHANNEL_THROTTLE, value);
288
+            state = TRIMENDPOINTMENU;
289
+        } else if (state == EDIT_MAX_THROTTLE) {
290
+            joyCPPM.setMaximum(CHANNEL_THROTTLE, value);
291
+            state = TRIMENDPOINTMENU;
292
+        } else if (state == EDIT_MIN_AUX1) {
293
+            joyCPPM.setMinimum(CHANNEL_AUX1, value);
294
+            state = TRIMENDPOINTMENU;
295
+        } else if (state == EDIT_MAX_AUX1) {
296
+            joyCPPM.setMaximum(CHANNEL_AUX1, value);
297
+            state = TRIMENDPOINTMENU;
298
+        } else if (state == EDIT_MIN_AUX2) {
299
+            joyCPPM.setMinimum(CHANNEL_AUX2, value);
300
+            state = TRIMENDPOINTMENU;
301
+        } else if (state == EDIT_MAX_AUX2) {
302
+            joyCPPM.setMaximum(CHANNEL_AUX2, value);
303
+            state = TRIMENDPOINTMENU;
304
+        } else if (state == EDIT_TRIM_ROLL) {
305
+            joyCPPM.setTrim(CHANNEL_ROLL, signedValue);
306
+            state = TRIMAXISMENU;
307
+        } else if (state == EDIT_TRIM_PITCH) {
308
+            joyCPPM.setTrim(CHANNEL_PITCH, signedValue);
309
+            state = TRIMAXISMENU;
310
+        } else if (state == EDIT_TRIM_YAW) {
311
+            joyCPPM.setTrim(CHANNEL_YAW, signedValue);
312
+            state = TRIMAXISMENU;
313
+        } else if (state == EDIT_TRIM_THROTTLE) {
314
+            joyCPPM.setTrim(CHANNEL_THROTTLE, signedValue);
315
+            state = TRIMAXISMENU;
316
+        } else if (state == EDIT_TRIM_AUX1) {
317
+            joyCPPM.setTrim(CHANNEL_AUX1, signedValue);
318
+            state = TRIMAXISMENU;
319
+        } else if (state == EDIT_TRIM_AUX2) {
320
+            joyCPPM.setTrim(CHANNEL_AUX2, signedValue);
321
+            state = TRIMAXISMENU;
249 322
         }
250 323
         printMenu();
251 324
     } else if (but_id == MENU_BUTTON_DOWN) {
252
-        if (state > STATES_EDIT) {
325
+        if ((state > STATES_EDIT) && (state < STATES_EDIT_SIGNED)) {
253 326
             if (value > 0) {
254 327
                 value--;
255 328
             }
329
+        } else if (state > STATES_EDIT_SIGNED) {
330
+            if (signedValue > -32767) {
331
+                signedValue--;
332
+            }
256 333
         } else if (state != NONE) {
257 334
             index++;
258 335
         }
259 336
         printMenu();
260 337
     } else if (but_id == MENU_BUTTON_UP) {
261
-        if (state > STATES_EDIT) {
338
+        if ((state > STATES_EDIT) && (state < STATES_EDIT_SIGNED)) {
262 339
             if (value < 0xFFFF) {
263 340
                 value++;
264 341
             }
342
+        } else if (state > STATES_EDIT_SIGNED) {
343
+            if (signedValue < 32767) {
344
+                signedValue++;
345
+            }
265 346
         } else if (state != NONE) {
266 347
             if (index > 0) {
267 348
                 index--;
@@ -275,3 +356,93 @@ void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
275 356
     }
276 357
 }
277 358
 
359
+void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const char* title) {
360
+    if (index >= count) {
361
+        index = count - 1;
362
+    }
363
+
364
+    uint8_t start = 0, line = 0;
365
+    if (index > 1) {
366
+        start = index - 1;
367
+    }
368
+
369
+    uint8_t end = start + 2;
370
+    if (index == 0) {
371
+        x52->setMFDText(0, title);
372
+        line = 1;
373
+        end = start + 1;
374
+    }
375
+
376
+    if (end >= count) {
377
+        end = count - 1;
378
+    }
379
+
380
+    for (uint8_t i = start; i <= end; i++) {
381
+        String tmp = (index == i) ? "-> " : "   ";
382
+        x52->setMFDText(line++, (tmp + menu[i]).c_str());
383
+    }
384
+
385
+    if (line == 2) {
386
+        x52->setMFDText(2);
387
+    }
388
+
389
+#ifdef DEBUG_OUTPUT
390
+    Serial.print("menuHelper() state=");
391
+    Serial.print(state);
392
+    Serial.print(" index=");
393
+    Serial.print(index);
394
+    Serial.print(" start=");
395
+    Serial.print(start);
396
+    Serial.print(" end=");
397
+    Serial.println(end);
398
+#endif
399
+}
400
+
401
+void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* title) {
402
+#ifdef DEBUG_OUTPUT
403
+    Serial.print("printValue() state=");
404
+    Serial.print(state);
405
+    Serial.print(" index=");
406
+    Serial.print(index);
407
+    Serial.print(" min=");
408
+    Serial.print(min);
409
+    Serial.print(" max=");
410
+    Serial.println(max);
411
+#endif
412
+
413
+    if (value < min) {
414
+        value = min;
415
+    }
416
+    if (value > max) {
417
+        value = max;
418
+    }
419
+
420
+    x52->setMFDText(0, (String(title) + ":").c_str());
421
+    x52->setMFDText(1, String(value).c_str());
422
+    x52->setMFDText(2, "Press OK to save");
423
+}
424
+
425
+void JoystickEventsButtons::printSignedValue(int16_t min, int16_t max, const char* title) {
426
+#ifdef DEBUG_OUTPUT
427
+    Serial.print("printSignedValue() state=");
428
+    Serial.print(state);
429
+    Serial.print(" index=");
430
+    Serial.print(index);
431
+    Serial.print(" min=");
432
+    Serial.print(min);
433
+    Serial.print(" max=");
434
+    Serial.println(max);
435
+#endif
436
+
437
+    if (signedValue < min) {
438
+        signedValue = min;
439
+    }
440
+    if (signedValue > max) {
441
+        signedValue = max;
442
+    }
443
+
444
+    x52->setMFDText(0, (String(title) + ":").c_str());
445
+    x52->setMFDText(1, String(signedValue).c_str());
446
+    x52->setMFDText(2, "Press OK to save");
447
+}
448
+

+ 50
- 14
events_cppm.cpp Ver arquivo

@@ -15,32 +15,28 @@
15 15
 #include "cppm.h"
16 16
 #include "events.h"
17 17
 
18
-#define CHANNEL_ROLL 0
19
-#define CHANNEL_PITCH 1
20
-#define CHANNEL_THROTTLE 2
21
-#define CHANNEL_YAW 3
22
-#define CHANNEL_AUX1 4
23
-#define CHANNEL_AUX2 5
24
-
25 18
 JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(client) {
26 19
     for (uint8_t i = 0; i < channels; i++) {
27 20
         values[i] = 1500;
21
+        invert[i] = 0;
22
+        minimum[i] = 1000;
23
+        maximum[i] = 2000;
24
+        trim[i] = 0;
28 25
     }
29 26
 
30 27
     values[CHANNEL_AUX1] = 1000;
31 28
     values[CHANNEL_AUX2] = 1000;
29
+    invert[CHANNEL_THROTTLE] = 1;
32 30
 
33 31
     CPPM::instance().copy(values);
34 32
 }
35 33
 
36 34
 void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
37
-    values[CHANNEL_ROLL] = map(evt.X, 0, 0x7FF, 1000, 2000);
38
-    values[CHANNEL_PITCH] = map(evt.Y, 0, 0x7FF, 1000, 2000);
39
-    values[CHANNEL_THROTTLE] = map(evt.Z, 0, 0xFF, 2000, 1000);
40
-    values[CHANNEL_YAW] = map(evt.Rz, 0, 0x3FF, 1000, 2000);
41
-    values[CHANNEL_AUX1] = map(evt.Ry, 0, 0xFF, 1000, 2000);
42
-    values[CHANNEL_AUX2] = map(evt.Slider, 0, 0xFF, 1000, 2000);
43
-    values[CHANNEL_AUX2 + 1] = map(evt.Rx, 0, 0xFF, 1000, 2000);
35
+    for (uint8_t i = 0; i < (CHANNEL_AUX2 + 1); i++) {
36
+        uint16_t value = ((int32_t)getJoystickAxis(evt, i)) + trim[i];
37
+        values[i] = map(value, 0, getJoystickMax(i),
38
+                invert[i] ? maximum[i] : minimum[i], invert[i] ? minimum[i] : maximum[i]);
39
+    }
44 40
 
45 41
     CPPM::instance().copy(values);
46 42
 
@@ -49,3 +45,43 @@ void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
49 45
     }
50 46
 }
51 47
 
48
+uint16_t JoystickEventsCPPM::getJoystickAxis(const GamePadEventData& evt, uint8_t ch) {
49
+    if (ch == CHANNEL_ROLL) {
50
+        return evt.X;
51
+    } else if (ch == CHANNEL_PITCH) {
52
+        return evt.Y;
53
+    } else if (ch == CHANNEL_THROTTLE) {
54
+        return evt.Z;
55
+    } else if (ch == CHANNEL_YAW) {
56
+        return evt.Rz;
57
+    } else if (ch == CHANNEL_AUX1) {
58
+        return evt.Ry;
59
+    } else if (ch == CHANNEL_AUX2) {
60
+        return evt.Slider;
61
+    } else if (ch == (CHANNEL_AUX2 + 1)) {
62
+        return evt.Rx;
63
+    } else {
64
+        return 0;
65
+    }
66
+}
67
+
68
+uint16_t JoystickEventsCPPM::getJoystickMax(uint8_t ch) {
69
+    if (ch == CHANNEL_ROLL) {
70
+        return 0x7FF;
71
+    } else if (ch == CHANNEL_PITCH) {
72
+        return 0x7FF;
73
+    } else if (ch == CHANNEL_THROTTLE) {
74
+        return 0xFF;
75
+    } else if (ch == CHANNEL_YAW) {
76
+        return 0x3FF;
77
+    } else if (ch == CHANNEL_AUX1) {
78
+        return 0xFF;
79
+    } else if (ch == CHANNEL_AUX2) {
80
+        return 0xFF;
81
+    } else if (ch == (CHANNEL_AUX2 + 1)) {
82
+        return 0xFF;
83
+    } else {
84
+        return 0xFF;
85
+    }
86
+}
87
+

Carregando…
Cancelar
Salvar