-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathff.c
93 lines (84 loc) · 2.44 KB
/
ff.c
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
/**
* A320UE - X-Plane 11 Plugin
*
* A plugin for the FlightFactor A320 Ultimate that adds a couple of new
* commands for operating the thrust levers more comfortably as well as a
* bunch of other little workarounds and/or features.
*
* Copyright 2019 Torben Könke.
*/
#include "plugin.h"
static int ff_plugin_id = XPLM_NO_PLUGIN_ID;
static int ff_loop_reg = 0;
static ff_api_t ff_api = { 0 };
static ff_init_done_cb ff_on_done_init = NULL;
int ff_init(ff_init_done_cb cb) {
ff_on_done_init = cb;
ff_plugin_id = XPLMFindPluginBySignature(XPLM_FF_SIGNATURE);
if (ff_plugin_id == XPLM_NO_PLUGIN_ID) {
_log("Could not find FF A320 plugin (%s)", XPLM_FF_SIGNATURE);
return 0;
} else {
/* Try to get reference to api now. */
XPLMSendMessageToPlugin(ff_plugin_id, XPLM_FF_MSG_GET_SHARED_INTERFACE,
&ff_api);
if (ff_api.ValuesCount == NULL) {
ff_loop_reg = 1;
XPLMRegisterFlightLoopCallback(ff_loop_cb, 1, NULL);
} else {
ff_on_done_init();
}
}
return 1;
}
float ff_loop_cb(float last_call, float last_loop, int count, void *data) {
if (ff_plugin_id < 0)
return 0;
XPLMSendMessageToPlugin(ff_plugin_id, XPLM_FF_MSG_GET_SHARED_INTERFACE,
&ff_api);
/* Keep trying until FF A320 has finished loading and returns a valid
data... */
if (ff_api.ValuesCount == NULL)
return 1;
/* Once we got the stupid FF interface we can continue with init'ing. */
ff_on_done_init();
/* No need to schedule loop again once we're here. */
return 0;
}
void ff_deinit() {
if (ff_loop_reg)
XPLMUnregisterFlightLoopCallback(ff_loop_cb, NULL);
ff_loop_reg = 0;
ff_plugin_id = XPLM_NO_PLUGIN_ID;
memset(&ff_api, 0, sizeof(ff_api_t));
ff_on_done_init = NULL;
}
int ff_get_id(const char *name) {
if (!ff_api.ValueIdByName)
return -1;
return ff_api.ValueIdByName(name);
}
int ff_get_int(int id) {
if (!ff_api.ValueGet)
return 0;
int retval;
ff_api.ValueGet(id, &retval);
return retval;
}
void ff_set_int(int id, int val) {
if (!ff_api.ValueSet)
return;
ff_api.ValueSet(id, &val);
}
float ff_get_float(int id) {
if (!ff_api.ValueGet)
return 0;
float retval;
ff_api.ValueGet(id, &retval);
return retval;
}
void ff_set_float(int id, float val) {
if (!ff_api.ValueSet)
return;
ff_api.ValueSet(id, &val);
}