-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.cpp
More file actions
77 lines (67 loc) · 2.4 KB
/
api.cpp
File metadata and controls
77 lines (67 loc) · 2.4 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
//
// 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 "autodgs.h"
enum {
API_OPERATION_MODE,
API_ON_GROUND,
};
// API accessor routines
static int
api_getint(XPLMDataRef ref)
{
switch ((long long)ref) {
case API_OPERATION_MODE:
return operation_mode;
case API_ON_GROUND:
return on_ground;
}
return 0;
}
static void
api_setint(XPLMDataRef ref, int val)
{
switch ((long long)ref) {
case API_OPERATION_MODE:
; // required by some gcc versions
opmode_t mode = (opmode_t)val;
if (mode != MODE_AUTO && mode != MODE_MANUAL) {
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 *)API_OPERATION_MODE, (void *)API_OPERATION_MODE);
XPLMRegisterDataAccessor("AutoDGS/on_ground", xplmType_Int, 0, api_getint, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
(void *)API_ON_GROUND, NULL);
}