-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputproxy.lua
More file actions
711 lines (621 loc) · 22.8 KB
/
inputproxy.lua
File metadata and controls
711 lines (621 loc) · 22.8 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
-- Input Proxy
--
-- Unifies commonly used but non-standardized button/key commands for cleaner control profiles.
-- == START OF CONFIGURATION ==
local proxied_commands = {
["addon_control"] = "Toggle Addon Control Panel",
["control_fd"] = "FD Control Input (CWS, TCS, FD Sync, ...)",
["disconnect_ap"] = "AP Disconnect Soft (button on yoke/flightstick)",
["disconnect_at"] = "AT Disconnect Soft (button on thrust lever)",
["pitch_trim_down_a"] = "Pitch Trim Down, Channel A",
["pitch_trim_down_b"] = "Pitch Trim Down, Channel B",
["pitch_trim_up_a"] = "Pitch Trim Up, Channel A",
["pitch_trim_up_b"] = "Pitch Trim Up, Channel B",
["to_ga"] = "TO/GA"
}
local aircraft_aliases = {
-- alias => list of possible search strings in path or aircraft file name (first found will match)
-- note that these are actually pattern strings which also means that some characters,
-- such as a hyphen, need to be escaped properly; see https://www.lua.org/pil/20.2.html
["FelisB742"] = { "747 Felis" },
["FFA320U"] = { "FlightFactor A320" },
["FJSQ4XP"] = { "FlyJSim_Q4XP" },
["HSCL650"] = { "CL650" },
["IXEG733"] = { "IXEG 737 Classic" },
["iniA300"] = { "iniSimulations A300", "iniSimulations_A310" },
["RotateMD11"] = { "Rotate%-MD%-11" },
["RotateMD80"] = { "Rotate%-MD%-80" },
["ToLissA319"] = { "ToLiss319", "ToLissA319", "ToLissA346" },
["Zibo738"] = { "B737%-800X" },
}
local aircraft_commands = {
-- aircraft alias => configuration by command alias:
-- command => actual command (hover list of commands in X-Plane joystick configuration to reveal)
-- repeat => should command trigger repeatedly? (called "once" in API although it is triggered many times)
["default"] = {
-- TODO: find reasonable defaults
["addon_control"] = {
["command"] = "",
["repeat"] = false,
},
["control_fd"] = {
["command"] = "",
["repeat"] = false,
},
["disconnect_ap"] = {
["command"] = "sim/autopilot/servos_fdir_off",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "sim/autopilot/autothrottle_off",
["repeat"] = false,
},
["pitch_trim_down_a"] = {
["command"] = "sim/flight_controls/pitch_trimA_down",
["repeat"] = false,
},
["pitch_trim_down_b"] = {
["command"] = "sim/flight_controls/pitch_trimB_down",
["repeat"] = false,
},
["pitch_trim_up_a"] = {
["command"] = "sim/flight_controls/pitch_trimA_up",
["repeat"] = false,
},
["pitch_trim_up_b"] = {
["command"] = "sim/flight_controls/pitch_trimB_up",
["repeat"] = false,
},
["to_ga"] = {
-- This command refers to the TO/GA button usually found on thrust levers.
-- As every aircraft appears to do this differently and issuing the wrong command
-- for TO/GA may have severe effects this is left INOP by default and should be
-- configured for every aircraft individually.
["command"] = "",
["repeat"] = false
},
},
["FelisB742"] = {
["disconnect_ap"] = {
["command"] = "sim/autopilot/fdir_toggle",
["repeat"] = false,
},
-- B742 does not appear to have any disconnect buttons on throttles, set INOP
["disconnect_at"] = {
["command"] = "",
["repeat"] = false,
},
-- B742 also has no TO/GA button (only mode selector)
},
["FFA320U"] = {
["disconnect_ap"] = {
["command"] = "sim/autopilot/fdir_servos_up_one",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "a320/Pedestal/EngineDisconnect1_button",
["repeat"] = false,
},
-- A320 has no TO/GA button (it's a thrust detent instead)
},
["FJSQ4XP"] = {
-- TODO: find command for GA button on throttles
["control_fd"] = {
["command"] = "FJS/Q4XP/Autopilot/TCS_Engage",
["repeat"] = false,
},
["disconnect_ap"] = {
["command"] = "FJS/Q4XP/Autopilot/AUTOPILOT_DISCONNECT",
["repeat"] = false,
},
["disconnect_at"] = {
-- Q4 has no auto-thrust, set INOP
["command"] = "",
["repeat"] = false,
},
["to_ga"] = {
["command"] = "sim/autopilot/take_off_go_around",
["repeat"] = false
},
},
["HSCL650"] = {
-- there also is a stab trim disconnect button on yokes: CL650/contwheel/0/trim_disc
["control_fd"] = {
["command"] = "CL650/contwheel/0/fd_sync",
["repeat"] = false,
},
["disconnect_ap"] = {
["command"] = "CL650/contwheel/0/ap_disc",
["repeat"] = false,
},
["disconnect_at"] = {
-- only one button supported for now but both exist:
-- CL650/pedestal/throttle/at_disc_L
-- CL650/pedestal/throttle/at_disc_R
["command"] = "CL650/pedestal/throttle/at_disc_L",
["repeat"] = false,
},
["to_ga"] = {
["command"] = "CL650/pedestal/throttle/toga_L",
["repeat"] = false
},
},
["iniA300"] = {
-- TODO: check if there is a CWS button on yokes (A300/MCDU/cws_toggle appears to be FCP)
["disconnect_ap"] = {
["command"] = "A300/MCDU/yoke_ap_disconnect_captain",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "A300/MCDU/disconnect_at",
["repeat"] = false,
},
-- TODO: check if realistic - I'm not sure if there really is a TO/GA button
-- on A300/A310 throttles or if that's just triggering the "magic screw"
-- provided by iniSimulations for convenience?
["to_ga"] = {
["command"] = "A300/MCDU/takeoff_goaround_trigger",
["repeat"] = false
},
},
["IXEG733"] = {
-- TODO: find command for TO/GA
["disconnect_ap"] = {
["command"] = "ixeg/733/autopilot/AP_disengage",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "ixeg/733/autopilot/at_disengage",
["repeat"] = false,
},
-- 737 does not appear to have a CWS button on yokes
},
["RotateMD11"] = {
["addon_control"] = {
["command"] = "Rotate/aircraft/ui_c/toggle_aircraft_menu",
["repeat"] = false,
},
["disconnect_ap"] = {
["command"] = "Rotate/aircraft/controls_c/ap_disc_l",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "Rotate/aircraft/controls_c/ats_disc_l",
["repeat"] = false,
},
-- Rotate MD11 does not support 2-channel pitch/stab trim
-- channels need to be replaced by single trim command issued by one side only
["pitch_trim_down_a"] = {
["command"] = "sim/flight_controls/pitch_trim_down",
["repeat"] = false,
},
["pitch_trim_down_b"] = {
["command"] = "",
["repeat"] = false,
},
["pitch_trim_up_a"] = {
["command"] = "sim/flight_controls/pitch_trim_up",
["repeat"] = false,
},
["pitch_trim_up_b"] = {
["command"] = "",
["repeat"] = false,
},
["to_ga"] = {
["command"] = "Rotate/aircraft/controls_c/to_ga",
["repeat"] = false
}
},
["RotateMD80"] = {
["disconnect_ap"] = {
["command"] = "Rotate/md80/autopilot/ap_disc",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "Rotate/md80/autopilot/at_disc",
["repeat"] = false,
},
-- The command appears to be correct (changes EPR if not already a TO/GA mode) but A/T cannot be armed, it's only either on or off.
-- As it's not possible to just arm A/T and activate it via TO/GA, unless doing a GA (and with EPR already set for TO) this probably has no use.
-- A/T switch needs to be pressed on MCP anyway; it's not activated by pressing TO/GA.
["to_ga"] = {
["command"] = "Rotate/md80/autopilot/to_ga_button",
["repeat"] = false
}
},
["ToLissA319"] = {
["disconnect_ap"] = {
["command"] = "sim/autopilot/fdir_servos_down_one",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "sim/autopilot/autothrottle_off",
["repeat"] = false,
},
-- A319 has no TO/GA button (it's a thrust detent instead), set INOP
},
["Zibo738"] = {
["disconnect_ap"] = {
--["command"] = "laminar/B738/autopilot/disconnect_toggle",
["command"] = "laminar/B738/autopilot/disconnect_button",
["repeat"] = false,
},
["disconnect_at"] = {
["command"] = "laminar/B738/autopilot/right_at_dis_press",
["repeat"] = false,
},
["to_ga"] = {
["command"] = "laminar/B738/autopilot/left_toga_press",
["repeat"] = false
},
-- there does not appear to be any CWS button on the yoke, only on MCP (laminar/B738/autopilot/cws_a_press)
-- control_fd command refers to yoke, not MCP button, so leave INOP
},
}
local command_protection = {
-- protection against accidental triggering
-- required_num_triggers => number of required proxy command triggers before command is proxied (only values above 1 make sense)
-- retrigger_time_interval_ms => maximum milliseconds between proxy command triggers before request gets ignored and command re-locked
-- keep_unlocked_until_expired => if true, any triggers after unlocking will be instantly allowed within retrigger time interval
-- if false, command will be locked after a single invocation
--
-- example: 3 triggers needed within 750ms to unlock
--
-- if true: first and second triggers get "ignored" (command still locked)
-- third trigger is allowed (command unlocked)
-- fourth, fifth, ... trigger is allowed as well (command remains unlocked)
-- ... unless last trigger was more than 750ms ago (counter gets reset)
--
-- if false: first and second triggers get "ignored" (command still locked)
-- third trigger is allowed (command unlocked)
-- command gets locked again immediately after that trigger (not just after 750ms)
-- fourth and fifth triggers get "ignored" (command locked again; seen as first and second)
-- sixth trigger is allowed again (seen as third trigger)
["to_ga"] = {
["required_num_triggers"] = 3,
["retrigger_time_interval_ms"] = 750,
["keep_unlocked_until_expired"] = true
}
}
-- == END OF CONFIGURATION ==
local version = '0.2dev'
local LOG_PREFIX = "[Input Proxy] "
print(LOG_PREFIX .. "Initializing Input Proxy version " .. version)
-- script globals
local system_path = nil
local dir_sep = nil
local loaded_aircraft_path = ""
local commands = {}
local inputproxy_protection = {}
local inputproxy_allow_release = {}
-- register commands (button/key mappings) before we do anything else
function register_proxied_commands(proxied_commands)
for alias, description in pairs(proxied_commands) do
local command = "FlyWithLua/inputproxy/" .. alias
create_command(
command,
description,
"inputproxy_command_begin('" .. alias .. "')",
"inputproxy_command_once('" .. alias .. "')",
"inputproxy_command_end('" .. alias .. "')"
)
print(LOG_PREFIX .. "Registered command " .. command)
end
end
register_proxied_commands(proxied_commands)
-- prepare native calls using ffi and XPLM
--
-- see https://developer.x-plane.com/sdk/XPLMUtilities/
--
-- XPLM loading and a quick start on how to access X-Plane aircraft data thanks to:
--
-- jörn-jören jörensön (jjj/3j) https://forums.x-plane.org/index.php?/forums/topic/123390-xplm-library-how-to-load-and-use/
-- Speedy JTAC 3.1 by XPJavelin https://forums.x-plane.org/index.php?/files/file/50956-speedy-jtac/
local ffi = require("ffi")
function inputproxy_load_xplm()
-- find the right lib to load
local XPLMlib = ""
if SYSTEM == "IBM" then
-- Windows OS (no path and file extension needed)
if SYSTEM_ARCHITECTURE == 64 then
XPLMlib = "XPLM_64" -- 64bit
else
XPLMlib = "XPLM" -- 32bit
end
elseif SYSTEM == "LIN" then
-- Linux OS (we need the path "Resources/plugins/" here for some reason)
if SYSTEM_ARCHITECTURE == 64 then
XPLMlib = "Resources/plugins/XPLM_64.so" -- 64bit
else
XPLMlib = "Resources/plugins/XPLM.so" -- 32bit
end
elseif SYSTEM == "APL" then
-- Mac OS (we need the path "Resources/plugins/" here for some reason)
XPLMlib = "Resources/plugins/XPLM.framework/XPLM" -- 64bit and 32 bit
else
return nil -- this should not happen
end
-- load the lib
return ffi.load(XPLMlib)
end
local XPLM = inputproxy_load_xplm()
function inputproxy_find_system_path()
local ffi_system_path = ffi.new("char[4096]")
XPLM.XPLMGetSystemPath(ffi_system_path)
return ffi.string(ffi_system_path)
end
function inputproxy_get_directory_separator()
local xp_const_dir_sep = XPLM.XPLMGetDirectorySeparator()
return ffi.string(xp_const_dir_sep, 1)
end
function inputproxy_get_aircraft()
local ffi_aircraft_name = ffi.new("char[1024]")
local ffi_aircraft_path = ffi.new("char[4096]")
XPLM.XPLMGetNthAircraftModel(0, ffi_aircraft_name, ffi_aircraft_path)
local name = ffi.string(ffi_aircraft_name)
local path = ffi.string(ffi_aircraft_path)
return {name, path}
end
-- that was enough native API binding, back to our script now...
function inputproxy_check_aircraft()
local aircraft_info = inputproxy_get_aircraft()
local aircraft_path = aircraft_info[2]
if aircraft_path ~= loaded_aircraft_path then
print(LOG_PREFIX .. "Aircraft change detected, was '" .. loaded_aircraft_path .. "', now '" .. aircraft_path .. "'")
inputproxy_load_aircraft_config(aircraft_path)
end
end
function inputproxy_string_split(haystack, needle)
local last_pos = 0
local next_pos = 1
local result = {}
repeat
next_pos = string.find(haystack, needle, last_pos + 1)
if next_pos ~= nil then
item = string.sub(haystack, last_pos + 1, next_pos - 1)
if item ~= "" then
table.insert(result, item)
end
last_pos = next_pos
end
until next_pos == nil
table.insert(result, string.sub(haystack, last_pos + 1))
return result
end
function inputproxy_match_aircraft_path(aircraft_path)
local pos = string.len(system_path) + 1
local subpath = string.sub(aircraft_path, pos)
local split = inputproxy_string_split(subpath, dir_sep)
for i, part in ipairs(split) do
for alias, needles in pairs(aircraft_aliases) do
for i, needle in ipairs(needles) do
if string.find(part, needle) ~= nil then
return alias
end
end
end
end
return nil
end
function inputproxy_load_aircraft_config(aircraft_path)
loaded_aircraft_path = ""
print(LOG_PREFIX .. "Configuring for " .. aircraft_path)
aircraft_alias = inputproxy_match_aircraft_path(aircraft_path)
if aircraft_alias ~= nil then
print(LOG_PREFIX .. "matched configuration alias '" .. aircraft_alias .. "'")
else
print(LOG_PREFIX .. "aircraft path " .. aircraft_path .. " did not match any configured alias; falling back to default configuration")
aircraft_alias = "default"
end
commands = aircraft_commands[aircraft_alias]
if commands == nil then
-- fall back to default if no such configuration exists
print(LOG_PREFIX .. "WARNING: no configuration found for " .. aircraft_alias .. "; falling back to default configuration")
commands = aircraft_commands["default"]
else
-- complete missing aliases with defaults if available
for alias, default_command_config in pairs(aircraft_commands["default"]) do
if commands[alias] == nil then
print(LOG_PREFIX .. "Command alias " .. alias .. " has not been configured for " .. aircraft_alias .. ", using default configuration")
commands[alias] = default_command_config
end
end
end
-- warn if any aliases are still missing
for alias, _ in pairs(proxied_commands) do
if commands[alias] == nil then
print(LOG_PREFIX .. "WARNING: Command alias " .. alias .. " has not been configured for " .. aircraft_alias .. " (also no default has been configured)")
end
end
loaded_aircraft_path = aircraft_path
end
function inputproxy_check_cached_command_available(command_config)
local found = command_config["found"] or false
if not found then
found = (XPLMFindCommand(command_config["command"]) ~= nil)
command_config["found"] = found
end
return found
end
function inputproxy_run_command(fn, command_config)
local available = inputproxy_check_cached_command_available(command_config)
if not available then
print(LOG_PREFIX .. "command unavailable: " .. command)
else
fn(command_config["command"])
end
end
function inputproxy_protection_trigger(proxy_alias)
-- registers trigger and checks conditions
-- returns true if command is allowed to be proxied, false if not
local config = command_protection[proxy_alias]
if config == nil then
-- protection is not configured for this command, always allow it to be proxied
return true
end
-- check for bad configuration
if config["required_num_triggers"] < 2 then
print(LOG_PREFIX .. "Command protection number of triggers is implausible (" .. config["required_num_triggers"] .. " ), check configuration: " .. proxy_alias)
elseif config["retrigger_time_interval_ms"] < 50 then
print(LOG_PREFIX .. "Command protection retrigger interval is implausible (" .. config["retrigger_time_interval_ms"] .. " ms), check configuration: " .. proxy_alias)
end
local protection = inputproxy_protection[proxy_alias]
if protection ~= nil then
-- count this trigger event
protection["trigger_count"] = protection["trigger_count"] + 1
else
-- initialize record if not tracked before
protection = {
["last_triggered"] = 0,
["trigger_count"] = 1,
["unlocked"] = false
}
end
local now = os.clock()
local was_unlocked = protection["unlocked"]
local is_allowed = was_unlocked
local should_reset = false
-- we only have to check for unlocking if the command was still locked before this event
if not was_unlocked then
local minimum_last_triggered = now - (config["retrigger_time_interval_ms"] / 1000.0)
if protection["last_triggered"] < minimum_last_triggered then
-- time expired (or protection was not triggered since last lock)
print(LOG_PREFIX .. "Command protection will be reset (trigger time): " .. proxy_alias)
should_reset = true
elseif protection["trigger_count"] >= config["required_num_triggers"] then
-- number of triggers reached
print(LOG_PREFIX .. "Command protection unlocks: " .. proxy_alias)
is_allowed = true
else
print(LOG_PREFIX .. "Command protection remains locked (trigger " .. protection["trigger_count"] .. " of " .. config["required_num_triggers"] .. "): " .. proxy_alias)
end
end
if should_reset then
protection["trigger_count"] = 1
protection["unlocked"] = false
is_allowed = false
end
protection["last_triggered"] = now
inputproxy_protection[proxy_alias] = protection
if not is_allowed then
print(LOG_PREFIX .. "Command is protected and locked: " .. proxy_alias)
else
protection["unlocked"] = true
end
return is_allowed
end
function inputproxy_protection_unlocked(proxy_alias)
-- only checks if command was previously unlocked (or is unprotected)
-- in contrast to inputproxy_protection_trigger this function does not work towards an unlock (useful for command repetitions)
-- returns true if command is allowed to be proxied, false if not
local config = command_protection[proxy_alias]
if config == nil then
-- protection is not configured for this command, always allow it to be proxied
return true
end
local protection = inputproxy_protection[proxy_alias]
local is_allowed = protection ~= nil and protection["unlocked"]
if not is_allowed then
print(LOG_PREFIX .. "Command is protected and locked: " .. proxy_alias)
end
return is_allowed
end
function inputproxy_protection_lock_again(proxy_alias)
-- lock command but only if protection was previously unlocked
local config = command_protection[proxy_alias]
if config == nil then
-- unprotected commands cannot and should not be locked
return
end
local protection = inputproxy_protection[proxy_alias]
local was_unlocked = protection ~= nil and protection["unlocked"]
if was_unlocked then
if config["keep_unlocked_until_expired"] then
print(LOG_PREFIX .. "Locking command (instant retriggering allowed): " .. proxy_alias)
-- only resetting "unlocked" will trigger re-evaluation of unlock criteria
inputproxy_protection[proxy_alias]["unlocked"] = false
else
print(LOG_PREFIX .. "Locking command (full cycle): " .. proxy_alias)
-- removing whole protection info will restart unlock sequence
inputproxy_protection[proxy_alias] = nil
end
end
end
function inputproxy_command_begin(proxy_alias)
print(LOG_PREFIX .. "Pressed: " .. proxy_alias)
local command_config = commands[proxy_alias]
if command_config == nil then
print(LOG_PREFIX .. "Proxy command alias not configured: " .. proxy_alias)
return
elseif command_config["command"] == "" then
print(LOG_PREFIX .. "Proxy command has been disabled: " .. proxy_alias)
return
end
local is_allowed = inputproxy_protection_trigger(proxy_alias)
if not is_allowed then
return
end
inputproxy_allow_release[proxy_alias] = true
inputproxy_run_command(command_begin, command_config)
end
function inputproxy_command_once(proxy_alias)
local command_config = commands[proxy_alias] or {}
local allowed_to_repeat = command_config["repeat"]
if allowed_to_repeat ~= nil and not allowed_to_repeat then
return
end
print(LOG_PREFIX .. "Repeat: " .. proxy_alias)
if command_config["command"] == "" then
print(LOG_PREFIX .. "Proxy command has been disabled: " .. proxy_alias)
return
end
local is_allowed = inputproxy_protection_unlocked(proxy_alias)
if not is_allowed then
return
end
inputproxy_run_command(command_once, command_config)
end
function inputproxy_command_end(proxy_alias)
local command_config = commands[proxy_alias] or {}
print(LOG_PREFIX .. "Released: " .. proxy_alias)
if command_config["command"] == "" then
-- avoid releasing an empty command when disabled
return
end
inputproxy_protection_lock_again(proxy_alias)
-- prevent release event if there's no open unreleased command event
-- if not prevented, this appears to randomly cause some general input freezes
-- NOTE: this only has to be checked if protection is configured
if command_protection[proxy_alias] ~= nil then
local allow_release = (inputproxy_allow_release[proxy_alias] ~= nil)
inputproxy_allow_release[proxy_alias] = nil
if not allow_release then
print(LOG_PREFIX .. "Release is not allowed (protection configured without open event): " .. proxy_alias)
return
end
end
inputproxy_run_command(command_end, command_config)
end
-- restore empty default in case it was omitted
if aircraft_commands["default"] == nil then
aircraft_commands["default"] = {}
end
-- initialize only if XPLM is available
if XPLM == nil then
print(LOG_PREFIX .. "XPLM not found, we are incompatible... Did X-Plane API change?")
else
print(LOG_PREFIX .. "Defining native API functions")
ffi.cdef[[
void XPLMGetNthAircraftModel(int inIndex, char *outFileName, char *outPath);
void XPLMGetSystemPath(char *outSystemPath);
const char *XPLMGetDirectorySeparator(void);
]]
print(LOG_PREFIX .. "Querying X-Plane API for constants")
system_path = inputproxy_find_system_path()
dir_sep = inputproxy_get_directory_separator()
print(LOG_PREFIX .. "Registering callbacks")
do_sometimes("inputproxy_check_aircraft()")
print(LOG_PREFIX .. "Performing first call")
inputproxy_check_aircraft()
print(LOG_PREFIX .. "Ready")
end