-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (62 loc) · 1.6 KB
/
Copy pathmain.cpp
File metadata and controls
72 lines (62 loc) · 1.6 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
#include <XPLMPlugin.h>
#include <XPLMMenus.h>
#include <XPLMUtilities.h>
#include <XPLMProcessing.h>
#include <XPLMDisplay.h>
#include <XPLMGraphics.h>
#include <XPWidgets.h>
#include <XPStandardWidgets.h>
#include "main.hpp"
#include "serial.hpp"
#include "ui.hpp"
#include "telemetry.hpp"
#include "calibration.hpp"
#include "remote.hpp"
PLUGIN_API int XPluginStart(
char *outName,
char *outSig,
char *outDesc) {
strcpy(outName, "Ardupilot HITL");
strcpy(outSig, "https://github.com/qgerman2/xplane-HITL");
strcpy(outDesc, "A plugin to enable simple HITL testing with Ardupilot");
UI::Menu::Create();
UI::Window::Create();
XPLMRegisterFlightLoopCallback(Loop, -1, NULL);
return 1;
}
PLUGIN_API void XPluginStop(void) {
Serial::Disconnect();
Serial::StopScan();
}
PLUGIN_API int XPluginEnable(void) {
return 1;
}
PLUGIN_API void XPluginDisable(void) {
Serial::Disconnect();
Serial::StopScan();
}
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, int inMsg, void *inParam) {
if (inFrom == XPLM_PLUGIN_XPLANE) {
switch (inMsg) {
case XPLM_MSG_PLANE_LOADED:
case XPLM_MSG_AIRPORT_LOADED:
Telemetry::RestartArdupilot();
Serial::Disconnect();
break;
}
}
}
float Loop(float dt, float, int, void *) {
// cap deltatime in case of a long freeze
dt = std::min(dt, 0.1f);
if (Calibration::IsEnabled()) {
Calibration::Loop(dt);
}
if (Serial::IsOpen()) {
Remote::Update();
Telemetry::Send();
} else {
Serial::Scan();
}
return -1.0;
}