Browse Source

Work on LCD menu

Thomas Buck 8 years ago
parent
commit
a5bdc67441
4 changed files with 115 additions and 11 deletions
  1. 5
    0
      events.h
  2. 92
    3
      events_buttons.cpp
  3. 5
    4
      events_cppm.cpp
  4. 13
    4
      events_deadzone.cpp

+ 5
- 0
events.h View File

@@ -64,6 +64,10 @@ class JoystickEventsButtons : public JoystickEvents {
64 64
     enum MenuState {
65 65
         NONE = 0,
66 66
         MAINMENU,
67
+        CPPMMENU,
68
+        TRIMAXISMENU,
69
+        TRIMENDPOINTMENU,
70
+        INVERTAXISMENU,
67 71
 
68 72
         STATES_EDIT,
69 73
         EDIT_CHANNELS,
@@ -82,6 +86,7 @@ class JoystickEventsButtons : public JoystickEvents {
82 86
     MenuState state;
83 87
     uint8_t index;
84 88
     uint16_t value;
89
+    unsigned long menuTime;
85 90
 };
86 91
 
87 92
 #endif // __JOYSTICK_EVENTS_H__

+ 92
- 3
events_buttons.cpp View File

@@ -29,7 +29,7 @@
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) { }
32
+        : JoystickEvents(client), x52(x), state(NONE), index(0), value(0), menuTime(0) { }
33 33
 
34 34
 void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const char* title) {
35 35
     if (index >= count) {
@@ -40,19 +40,23 @@ void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const c
40 40
     if (index > 1) {
41 41
         start = index - 1;
42 42
     }
43
+
43 44
     uint8_t end = start + 2;
44 45
     if (index == 0) {
45 46
         x52->setMFDText(0, title);
46 47
         line = 1;
47 48
         end = start + 1;
48 49
     }
50
+
49 51
     if (end >= count) {
50 52
         end = count - 1;
51 53
     }
54
+
52 55
     for (uint8_t i = start; i <= end; i++) {
53 56
         String tmp = (index == i) ? "-> " : "   ";
54 57
         x52->setMFDText(line++, (tmp + menu[i]).c_str());
55 58
     }
59
+
56 60
     if (line == 2) {
57 61
         x52->setMFDText(2);
58 62
     }
@@ -71,13 +75,37 @@ void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const c
71 75
 
72 76
 void JoystickEventsButtons::printMenu() {
73 77
     static const char* mainMenu[] = {
74
-        "Channels", "Frame Length",
75
-        "Pulse Length", "Invert"
78
+        "Status", "Trim Axis", "Trim Endpoint", "Invert Axis", "CPPM Config"
76 79
     };
77 80
     static const uint8_t mainMenuCount = sizeof(mainMenu) / sizeof(mainMenu[0]);
78 81
 
82
+    static const char* cppmMenu[] = {
83
+        "Channels", "Frame Length", "Pulse Length", "Invert", "Main Menu"
84
+    };
85
+    static const uint8_t cppmMenuCount = sizeof(cppmMenu) / sizeof(cppmMenu[0]);
86
+
87
+    static const char* axisMenu[] = {
88
+        "Roll", "Pitch", "Yaw", "Throttle", "Aux1", "Aux2", "Main Menu"
89
+    };
90
+    static const uint8_t axisMenuCount = sizeof(axisMenu) / sizeof(axisMenu[0]);
91
+
92
+    static const char* endpointMenu[] = {
93
+        "Roll Min", "Roll Max", "Pitch Min", "Pitch Max", "Yaw Min", "Yaw Max",
94
+        "Throttle Min", "Throttle Max", "Aux1 Min", "Aux1 Max", "Aux2 Min",
95
+        "Aux2 Max", "Main Menu"
96
+    };
97
+    static const uint8_t endpointMenuCount = sizeof(endpointMenu) / sizeof(endpointMenu[0]);
98
+
79 99
     if (state == MAINMENU) {
80 100
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
101
+    } else if (state == CPPMMENU) {
102
+        menuHelper(cppmMenuCount, cppmMenu, "CPPM Config Menu");
103
+    } else if (state == TRIMAXISMENU) {
104
+        menuHelper(axisMenuCount, axisMenu, "Trim Axis Menu");
105
+    } else if (state == TRIMENDPOINTMENU) {
106
+        menuHelper(endpointMenuCount, endpointMenu, "Trim Endpoints");
107
+    } else if (state == INVERTAXISMENU) {
108
+        menuHelper(axisMenuCount, axisMenu, "Invert Axis Menu");
81 109
     } else if (state == EDIT_CHANNELS) {
82 110
         printValue(4, CHANNELS_MAX, mainMenu[0]);
83 111
     } else if (state == EDIT_FRAME_LENGTH) {
@@ -87,6 +115,8 @@ void JoystickEventsButtons::printMenu() {
87 115
     } else if (state == EDIT_INVERT) {
88 116
         printValue(0, 1, mainMenu[3]);
89 117
     }
118
+
119
+    menuTime = millis();
90 120
 }
91 121
 
92 122
 void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* title) {
@@ -131,8 +161,64 @@ void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
131 161
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
132 162
         if (state == NONE) {
133 163
             state = MAINMENU;
164
+            index = 0;
134 165
         } else if (state == MAINMENU) {
135 166
             if (index == 0) {
167
+                state = NONE;
168
+            } else if (index == 1) {
169
+                //state = TRIMAXISMENU;
170
+                //index = 0;
171
+            } else if (index == 2) {
172
+                //state = TRIMENDPOINTMENU;
173
+                //index = 0;
174
+            } else if (index == 3) {
175
+                //state = INVERTAXISMENU;
176
+                //index = 0;
177
+            } else if (index == 4) {
178
+                state = CPPMMENU;
179
+                index = 0;
180
+            }
181
+        } else if (state == TRIMAXISMENU) {
182
+            if (index == 0) {
183
+            } else if (index == 1) {
184
+            } else if (index == 2) {
185
+            } else if (index == 3) {
186
+            } else if (index == 4) {
187
+            } else if (index == 5) {
188
+            } else if (index == 6) {
189
+                state = MAINMENU;
190
+                index = 0;
191
+            }
192
+        } else if (state == TRIMENDPOINTMENU) {
193
+            if (index == 0) {
194
+            } else if (index == 1) {
195
+            } else if (index == 2) {
196
+            } else if (index == 3) {
197
+            } else if (index == 4) {
198
+            } else if (index == 5) {
199
+            } else if (index == 6) {
200
+            } else if (index == 7) {
201
+            } else if (index == 8) {
202
+            } else if (index == 9) {
203
+            } else if (index == 10) {
204
+            } else if (index == 11) {
205
+            } else if (index == 12) {
206
+                state = MAINMENU;
207
+                index = 0;
208
+            }
209
+        } else if (state == INVERTAXISMENU) {
210
+            if (index == 0) {
211
+            } else if (index == 1) {
212
+            } else if (index == 2) {
213
+            } else if (index == 3) {
214
+            } else if (index == 4) {
215
+            } else if (index == 5) {
216
+            } else if (index == 6) {
217
+                state = MAINMENU;
218
+                index = 0;
219
+            }
220
+        } else if (state == CPPMMENU) {
221
+            if (index == 0) {
136 222
                 state = EDIT_CHANNELS;
137 223
                 value = CPPM::instance().getChannels();
138 224
             } else if (index == 1) {
@@ -144,6 +230,9 @@ void JoystickEventsButtons::OnButtonDown(uint8_t but_id) {
144 230
             } else if (index == 3) {
145 231
                 state = EDIT_INVERT;
146 232
                 value = CPPM::instance().getInvert();
233
+            } else if (index == 4) {
234
+                state = MAINMENU;
235
+                index = 0;
147 236
             }
148 237
         } else if (state == EDIT_CHANNELS) {
149 238
             CPPM::instance().setChannels(value);

+ 5
- 4
events_cppm.cpp View File

@@ -15,9 +15,9 @@
15 15
 #include "cppm.h"
16 16
 #include "events.h"
17 17
 
18
-#define CHANNEL_THROTTLE 2
19
-#define CHANNEL_PITCH 1
20 18
 #define CHANNEL_ROLL 0
19
+#define CHANNEL_PITCH 1
20
+#define CHANNEL_THROTTLE 2
21 21
 #define CHANNEL_YAW 3
22 22
 #define CHANNEL_AUX1 4
23 23
 #define CHANNEL_AUX2 5
@@ -34,12 +34,13 @@ JoystickEventsCPPM::JoystickEventsCPPM(JoystickEvents* client) : JoystickEvents(
34 34
 }
35 35
 
36 36
 void JoystickEventsCPPM::OnGamePadChanged(const GamePadEventData& evt) {
37
-    values[CHANNEL_THROTTLE] = map(evt.Z, 0, 0xFF, 2000, 1000);
38
-    values[CHANNEL_PITCH] = map(evt.Y, 0, 0x7FF, 1000, 2000);
39 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 40
     values[CHANNEL_YAW] = map(evt.Rz, 0, 0x3FF, 1000, 2000);
41 41
     values[CHANNEL_AUX1] = map(evt.Ry, 0, 0xFF, 1000, 2000);
42 42
     values[CHANNEL_AUX2] = map(evt.Slider, 0, 0xFF, 1000, 2000);
43
+    values[CHANNEL_AUX2 + 1] = map(evt.Rx, 0, 0xFF, 1000, 2000);
43 44
 
44 45
     CPPM::instance().copy(values);
45 46
 

+ 13
- 4
events_deadzone.cpp View File

@@ -18,14 +18,23 @@
18 18
 //#define DEBUG_OUTPUT_RAW
19 19
 //#define DEBUG_OUTPUT
20 20
 
21
-// X, Y, Z, Rx, Ry, Rz, Slider
21
+/*
22
+ * Deadzone around the axis center, in both directions.
23
+ * You can try to counteract a faulty Yaw-Potentiometer
24
+ * with this, but it won't be enough in extreme cases.
25
+ * X, Y, Z, Rx, Ry, Rz, Slider
26
+ */
22 27
 const GamePadEventData JoystickEventsDeadZone::deadZone(
23 28
     4, 4, 2, 2, 5, 25, 2
24 29
 );
25 30
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
26 31
 const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
27 32
 
28
-// X, Y, Z, Rx, Ry, Rz, Slider
33
+/*
34
+ * Absolute values of the axis center. Deadzone will be applied
35
+ * in both directions around these values.
36
+ * X 11bit, Y 11bit, Z 8bit, Rx 8bit, Ry 8bit, Rz 10bit, Slider 8bit
37
+ */
29 38
 const GamePadEventData JoystickEventsDeadZone::centerValue(
30 39
     0x3FF, 0x3FF, 0x7F, 0x7F, 0x7F, 0x1FF, 0x7F
31 40
 );
@@ -34,7 +43,7 @@ const uint8_t JoystickEventsDeadZone::centerMouseY = 0x07;
34 43
 
35 44
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
36 45
 #ifdef DEBUG_OUTPUT_RAW
37
-    Serial.print("X: ");
46
+    Serial.print("Raw X: ");
38 47
     PrintHex<uint16_t > (evt.X, 0x80);
39 48
     Serial.print(" Y: ");
40 49
     PrintHex<uint16_t > (evt.Y, 0x80);
@@ -147,7 +156,7 @@ void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
147 156
 
148 157
 void JoystickEventsDeadZone::OnMouseMoved(uint8_t x, uint8_t y) {
149 158
 #ifdef DEBUG_OUTPUT_RAW
150
-    Serial.print("Mouse X: ");
159
+    Serial.print("Raw Mouse X: ");
151 160
     PrintHex<uint8_t >(x, 0x80);
152 161
     Serial.print("\tY: ");
153 162
     PrintHex<uint8_t >(y, 0x80);

Loading…
Cancel
Save