-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadgs_api.cpp
More file actions
81 lines (71 loc) · 2.5 KB
/
Copy pathadgs_api.cpp
File metadata and controls
81 lines (71 loc) · 2.5 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
//
// AutoDGS: Show Marshaller or VDGS at default airports
//
// Copyright (C) 2006-2013 Jonathan Harris
// Copyright (C) 2023, 2025 Holger Teutsch
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
// USA
//
//
#include "opensam.h"
#include "autodgs_airport.h"
#include "my_plane.h"
#include "log_msg.h"
enum {
kApiOperationMode,
kApiOnGround,
};
// API accessor routines
static int
api_getint(XPLMDataRef ref)
{
switch ((long long)ref) {
case kApiOperationMode:
return operation_mode;
case kApiOnGround:
return my_plane->on_ground() ? 1 : 0;
}
return 0;
}
static void
api_setint(XPLMDataRef ref, int val)
{
switch ((long long)ref) {
case kApiOperationMode:
; // required by some gcc versions
OperationMode mode = static_cast<OperationMode>(val);
if (mode != kAuto && mode != kManual) {
LogMsg("API: trying to set invalid operation_mode %d, ignored", val);
return;
}
if (mode == operation_mode) // Lua hammers writeable drefs in a frame loop
return;
LogMsg("API: operation_mode set to %s", opmode_str[mode]);
operation_mode = mode;
break;
}
}
void
create_api_drefs()
{
// API datarefs
XPLMRegisterDataAccessor("AutoDGS/operation_mode", xplmType_Int, 1, api_getint, api_setint, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
(void *)kApiOperationMode, (void *)kApiOperationMode);
XPLMRegisterDataAccessor("AutoDGS/on_ground", xplmType_Int, 0, api_getint, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
(void *)kApiOnGround, NULL);
}