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
     enum MenuState {
64
     enum MenuState {
65
         NONE = 0,
65
         NONE = 0,
66
         MAINMENU,
66
         MAINMENU,
67
+        CPPMMENU,
68
+        TRIMAXISMENU,
69
+        TRIMENDPOINTMENU,
70
+        INVERTAXISMENU,
67
 
71
 
68
         STATES_EDIT,
72
         STATES_EDIT,
69
         EDIT_CHANNELS,
73
         EDIT_CHANNELS,
82
     MenuState state;
86
     MenuState state;
83
     uint8_t index;
87
     uint8_t index;
84
     uint16_t value;
88
     uint16_t value;
89
+    unsigned long menuTime;
85
 };
90
 };
86
 
91
 
87
 #endif // __JOYSTICK_EVENTS_H__
92
 #endif // __JOYSTICK_EVENTS_H__

+ 92
- 3
events_buttons.cpp View File

29
 #define MODE_BUTTON_RED 25
29
 #define MODE_BUTTON_RED 25
30
 
30
 
31
 JoystickEventsButtons::JoystickEventsButtons(X52* x, JoystickEvents* client)
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
 void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const char* title) {
34
 void JoystickEventsButtons::menuHelper(uint8_t count, const char** menu, const char* title) {
35
     if (index >= count) {
35
     if (index >= count) {
40
     if (index > 1) {
40
     if (index > 1) {
41
         start = index - 1;
41
         start = index - 1;
42
     }
42
     }
43
+
43
     uint8_t end = start + 2;
44
     uint8_t end = start + 2;
44
     if (index == 0) {
45
     if (index == 0) {
45
         x52->setMFDText(0, title);
46
         x52->setMFDText(0, title);
46
         line = 1;
47
         line = 1;
47
         end = start + 1;
48
         end = start + 1;
48
     }
49
     }
50
+
49
     if (end >= count) {
51
     if (end >= count) {
50
         end = count - 1;
52
         end = count - 1;
51
     }
53
     }
54
+
52
     for (uint8_t i = start; i <= end; i++) {
55
     for (uint8_t i = start; i <= end; i++) {
53
         String tmp = (index == i) ? "-> " : "   ";
56
         String tmp = (index == i) ? "-> " : "   ";
54
         x52->setMFDText(line++, (tmp + menu[i]).c_str());
57
         x52->setMFDText(line++, (tmp + menu[i]).c_str());
55
     }
58
     }
59
+
56
     if (line == 2) {
60
     if (line == 2) {
57
         x52->setMFDText(2);
61
         x52->setMFDText(2);
58
     }
62
     }
71
 
75
 
72
 void JoystickEventsButtons::printMenu() {
76
 void JoystickEventsButtons::printMenu() {
73
     static const char* mainMenu[] = {
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
     static const uint8_t mainMenuCount = sizeof(mainMenu) / sizeof(mainMenu[0]);
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
     if (state == MAINMENU) {
99
     if (state == MAINMENU) {
80
         menuHelper(mainMenuCount, mainMenu, "Main Menu");
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
     } else if (state == EDIT_CHANNELS) {
109
     } else if (state == EDIT_CHANNELS) {
82
         printValue(4, CHANNELS_MAX, mainMenu[0]);
110
         printValue(4, CHANNELS_MAX, mainMenu[0]);
83
     } else if (state == EDIT_FRAME_LENGTH) {
111
     } else if (state == EDIT_FRAME_LENGTH) {
87
     } else if (state == EDIT_INVERT) {
115
     } else if (state == EDIT_INVERT) {
88
         printValue(0, 1, mainMenu[3]);
116
         printValue(0, 1, mainMenu[3]);
89
     }
117
     }
118
+
119
+    menuTime = millis();
90
 }
120
 }
91
 
121
 
92
 void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* title) {
122
 void JoystickEventsButtons::printValue(uint16_t min, uint16_t max, const char* title) {
131
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
161
     } else if ((but_id == MENU_BUTTON_ENTER_1) || (but_id == MENU_BUTTON_ENTER_2)) {
132
         if (state == NONE) {
162
         if (state == NONE) {
133
             state = MAINMENU;
163
             state = MAINMENU;
164
+            index = 0;
134
         } else if (state == MAINMENU) {
165
         } else if (state == MAINMENU) {
135
             if (index == 0) {
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
                 state = EDIT_CHANNELS;
222
                 state = EDIT_CHANNELS;
137
                 value = CPPM::instance().getChannels();
223
                 value = CPPM::instance().getChannels();
138
             } else if (index == 1) {
224
             } else if (index == 1) {
144
             } else if (index == 3) {
230
             } else if (index == 3) {
145
                 state = EDIT_INVERT;
231
                 state = EDIT_INVERT;
146
                 value = CPPM::instance().getInvert();
232
                 value = CPPM::instance().getInvert();
233
+            } else if (index == 4) {
234
+                state = MAINMENU;
235
+                index = 0;
147
             }
236
             }
148
         } else if (state == EDIT_CHANNELS) {
237
         } else if (state == EDIT_CHANNELS) {
149
             CPPM::instance().setChannels(value);
238
             CPPM::instance().setChannels(value);

+ 5
- 4
events_cppm.cpp View File

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

+ 13
- 4
events_deadzone.cpp View File

18
 //#define DEBUG_OUTPUT_RAW
18
 //#define DEBUG_OUTPUT_RAW
19
 //#define DEBUG_OUTPUT
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
 const GamePadEventData JoystickEventsDeadZone::deadZone(
27
 const GamePadEventData JoystickEventsDeadZone::deadZone(
23
     4, 4, 2, 2, 5, 25, 2
28
     4, 4, 2, 2, 5, 25, 2
24
 );
29
 );
25
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
30
 const uint8_t JoystickEventsDeadZone::deadZoneMouseX = 1;
26
 const uint8_t JoystickEventsDeadZone::deadZoneMouseY = 1;
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
 const GamePadEventData JoystickEventsDeadZone::centerValue(
38
 const GamePadEventData JoystickEventsDeadZone::centerValue(
30
     0x3FF, 0x3FF, 0x7F, 0x7F, 0x7F, 0x1FF, 0x7F
39
     0x3FF, 0x3FF, 0x7F, 0x7F, 0x7F, 0x1FF, 0x7F
31
 );
40
 );
34
 
43
 
35
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
44
 void JoystickEventsDeadZone::OnGamePadChanged(const GamePadEventData& evt) {
36
 #ifdef DEBUG_OUTPUT_RAW
45
 #ifdef DEBUG_OUTPUT_RAW
37
-    Serial.print("X: ");
46
+    Serial.print("Raw X: ");
38
     PrintHex<uint16_t > (evt.X, 0x80);
47
     PrintHex<uint16_t > (evt.X, 0x80);
39
     Serial.print(" Y: ");
48
     Serial.print(" Y: ");
40
     PrintHex<uint16_t > (evt.Y, 0x80);
49
     PrintHex<uint16_t > (evt.Y, 0x80);
147
 
156
 
148
 void JoystickEventsDeadZone::OnMouseMoved(uint8_t x, uint8_t y) {
157
 void JoystickEventsDeadZone::OnMouseMoved(uint8_t x, uint8_t y) {
149
 #ifdef DEBUG_OUTPUT_RAW
158
 #ifdef DEBUG_OUTPUT_RAW
150
-    Serial.print("Mouse X: ");
159
+    Serial.print("Raw Mouse X: ");
151
     PrintHex<uint8_t >(x, 0x80);
160
     PrintHex<uint8_t >(x, 0x80);
152
     Serial.print("\tY: ");
161
     Serial.print("\tY: ");
153
     PrintHex<uint8_t >(y, 0x80);
162
     PrintHex<uint8_t >(y, 0x80);

Loading…
Cancel
Save