-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.cpp
More file actions
264 lines (249 loc) · 8.1 KB
/
Copy pathui.cpp
File metadata and controls
264 lines (249 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <XPLMMenus.h>
#include <XPLMDisplay.h>
#include <XPLMGraphics.h>
#include <XPLMUtilities.h>
#include <XPWidgets.h>
#include <XPStandardWidgets.h>
#include <XPWidgetsEx.h>
#include <format>
#include <numeric>
#include <string>
#include "ui.hpp"
#include "main.hpp"
#include "serial.hpp"
#include "calibration.hpp"
#include "remote.hpp"
// X-Plane top menu plugin definitions
namespace UI::Menu {
XPLMMenuID id;
void OnEvent(void *mRef, void *iRef);
}
// Main window definitions
namespace UI::Window {
XPWidgetID id;
int width = 260;
int height = 125;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
namespace LabelSerialPort {
XPWidgetID id;
void SetText(std::string text) { XPSetWidgetDescriptor(id, text.c_str()); };
}
namespace ButtonCalibration {
XPWidgetID id;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
}
namespace LabelCalibration {
XPWidgetID id;
void SetText(std::string text) { XPSetWidgetDescriptor(id, text.c_str()); };
}
namespace ButtonCalibrationNextStep {
XPWidgetID id;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
}
namespace ButtonCalibrationPrevStep {
XPWidgetID id;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
}
namespace ButtonCalibrationCompass {
XPWidgetID id;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
}
namespace ButtonRemoteOverride {
XPWidgetID id;
int OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
}
namespace LabelRemoteArmed {
XPWidgetID id;
void SetText(std::string text) { XPSetWidgetDescriptor(id, text.c_str()); };
}
namespace LabelAHRSCount {
XPWidgetID id;
void SetText(std::string text) { XPSetWidgetDescriptor(id, text.c_str()); };
}
}
// Top menu methods
void UI::Menu::Create() {
int index = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "HITL", NULL, 1);
id = XPLMCreateMenu("HITL", XPLMFindPluginsMenu(), index, OnEvent, NULL);
XPLMAppendMenuItem(id, "Settings", (void *)"Settings", 1);
}
void UI::Menu::OnEvent(void *mRef, void *iRef) {
XPShowWidget(UI::Window::id);
}
// Main window methods
void UI::Window::Create() {
id = XPCreateWidget(0, height, width, 0, 1, "HITL Settings", 1, 0, xpWidgetClass_MainWindow);
XPHideWidget(id);
XPSetWidgetProperty(id, xpProperty_MainWindowHasCloseBoxes, 1);
XPAddWidgetCallback(id, OnEvent);
// -- Serial Widgets --
XPCreateWidget(
10 - 2,
height - 20 - 2,
80,
height - 35,
1, "Serial", 0, id, xpWidgetClass_Caption);
LabelSerialPort::id = XPCreateWidget(
10 - 2,
height - 40,
80,
height - 55,
1, "Disconnect", 0, id, xpWidgetClass_Caption);
// -- Calibration Widgets --
XPCreateWidget(
95 - 2,
height - 20 - 2,
165,
height - 35,
1, "Calibration", 0, id, xpWidgetClass_Caption);
ButtonCalibration::id = XPCreateWidget(
95,
height - 40,
165,
height - 55,
1, "Begin", 0, id, xpWidgetClass_Button);
XPAddWidgetCallback(ButtonCalibration::id, ButtonCalibration::OnEvent);
LabelCalibration::id = XPCreateWidget(
95,
height - 60 + 3,
165,
height - 75,
1, "None", 0, id, xpWidgetClass_Caption);
ButtonCalibrationPrevStep::id = XPCreateWidget(
95,
height - 80,
95 + 30,
height - 95,
1, "<<", 0, id, xpWidgetClass_Button);
XPAddWidgetCallback(ButtonCalibrationPrevStep::id, ButtonCalibrationPrevStep::OnEvent);
ButtonCalibrationNextStep::id = XPCreateWidget(
165 - 30,
height - 80,
165,
height - 95,
1, ">>", 0, id, xpWidgetClass_Button);
XPAddWidgetCallback(ButtonCalibrationNextStep::id, ButtonCalibrationNextStep::OnEvent);
ButtonCalibrationCompass::id = XPCreateWidget(
95,
height - 100,
165,
height - 115,
1, "Rotate", 0, id, xpWidgetClass_Button);
XPAddWidgetCallback(ButtonCalibrationCompass::id, ButtonCalibrationCompass::OnEvent);
// -- Remote control Widgets --
XPCreateWidget(
180 - 2,
height - 20 - 2,
250,
height - 35,
1, "Remote", 0, id, xpWidgetClass_Caption);
ButtonRemoteOverride::id = XPCreateWidget(
180,
height - 40,
195,
height - 55,
1, "", 0, id, xpWidgetClass_Button);
XPCreateWidget(
195 - 2,
height - 40 + 3,
250,
height - 55,
1, "Override", 0, id, xpWidgetClass_Caption);
LabelRemoteArmed::id = XPCreateWidget(
180 - 2,
height - 60 + 3,
250,
height - 75,
1, "None", 0, id, xpWidgetClass_Caption);
LabelAHRSCount::id = XPCreateWidget(
180 - 2,
height - 80 + 3,
250,
height - 95,
1, "AHRS: 0 Hz", 0, id, xpWidgetClass_Caption);
XPSetWidgetProperty(ButtonRemoteOverride::id, xpProperty_ButtonType, xpRadioButton);
XPSetWidgetProperty(ButtonRemoteOverride::id, xpProperty_ButtonBehavior, xpButtonBehaviorCheckBox);
XPSetWidgetProperty(ButtonRemoteOverride::id, xpProperty_ButtonState, true);
XPAddWidgetCallback(ButtonRemoteOverride::id, ButtonRemoteOverride::OnEvent);
int screenWidth;
int screenHeight;
XPLMGetScreenSize(&screenWidth, &screenHeight);
XPSetWidgetGeometry(id,
screenWidth / 2 - width / 2,
screenHeight / 2 + height / 2,
screenWidth / 2 + width / 2,
screenHeight / 2 - height / 2);
}
int UI::Window::OnEvent(
XPWidgetMessage inMessage,
XPWidgetID inWidget,
intptr_t inParam1,
intptr_t inParam2) {
if (inMessage == xpMessage_CloseButtonPushed) {
XPHideWidget(id);
return 1;
}
return 0;
}
void UI::OnSerialConnect(std::string port) {
UI::Window::LabelSerialPort::SetText(port.c_str());
}
void UI::OnSerialDisconnect() {
UI::Window::LabelSerialPort::SetText("Disconnected");
UI::Window::LabelRemoteArmed::SetText("None");
UI::Window::LabelAHRSCount::SetText("AHRS: 0 Hz");
}
int UI::Window::ButtonCalibration::OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2) {
if (inWidget != id) { return 0; }
switch (inMessage) {
case xpMsg_PushButtonPressed:
if (Calibration::Toggle()) {
XPSetWidgetDescriptor(id, "End");
} else {
XPSetWidgetDescriptor(id, "Begin");
}
return 1;
default:
return 0;
}
}
int UI::Window::ButtonCalibrationNextStep::OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2) {
if (inWidget != id) { return 0; }
switch (inMessage) {
case xpMsg_PushButtonPressed:
Calibration::NextCalibrationStep();
return 1;
default:
return 0;
}
}
int UI::Window::ButtonCalibrationPrevStep::OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2) {
if (inWidget != id) { return 0; }
switch (inMessage) {
case xpMsg_PushButtonPressed:
Calibration::PreviousCalibrationStep();
return 1;
default:
return 0;
}
}
int UI::Window::ButtonCalibrationCompass::OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2) {
if (inWidget != id) { return 0; }
switch (inMessage) {
case xpMsg_PushButtonPressed:
Calibration::ToggleRotation();
return 1;
default:
return 0;
}
}
int UI::Window::ButtonRemoteOverride::OnEvent(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2) {
if (inWidget != id) { return 0; }
switch (inMessage) {
case xpMsg_ButtonStateChanged:
Remote::SetOverride(inParam2);
return 1;
default:
return 0;
}
}