| 1 |
# Copyright 2018 Stuart Buchanan |
| 2 |
# This file is part of FlightGear. |
| 3 |
# |
| 4 |
# FlightGear is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# FlightGear is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# Selectable Interface controller. |
| 18 |
|
| 19 |
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/"; |
| 20 |
var aircraft_dir = getprop("/sim/aircraft-dir"); |
| 21 |
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyPublisher.nas', "fg1000"); |
| 22 |
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyUpdater.nas', "fg1000"); |
| 23 |
io.load_nasal(nasal_dir ~ 'Interfaces/NavDataInterface.nas', "fg1000"); |
| 24 |
io.load_nasal(aircraft_dir ~ '/Nasal/Interfaces/SelectableEISPublisher.nas', "fg1000"); |
| 25 |
io.load_nasal(nasal_dir ~ 'Interfaces/GenericNavComPublisher.nas', "fg1000"); |
| 26 |
io.load_nasal(nasal_dir ~ 'Interfaces/GenericNavComUpdater.nas', "fg1000"); |
| 27 |
io.load_nasal(nasal_dir ~ 'Interfaces/GenericFMSPublisher.nas', "fg1000"); |
| 28 |
io.load_nasal(nasal_dir ~ 'Interfaces/GenericFMSUpdater.nas', "fg1000"); |
| 29 |
io.load_nasal(nasal_dir ~ 'Interfaces/GenericADCPublisher.nas', "fg1000"); |
| 30 |
io.load_nasal(aircraft_dir ~ '/Nasal/Interfaces/SelectableFuelInterface.nas', "fg1000"); |
| 31 |
io.load_nasal(aircraft_dir ~ '/Nasal/Interfaces/SelectableFuelPublisher.nas', "fg1000"); |
| 32 |
io.load_nasal(nasal_dir ~ 'Interfaces/GFC700Publisher.nas', "fg1000"); |
| 33 |
io.load_nasal(nasal_dir ~ 'Interfaces/GFC700Interface.nas', "fg1000"); |
| 34 |
|
| 35 |
var SelectableInterfaceController = { |
| 36 |
|
| 37 |
_instance : nil, |
| 38 |
|
| 39 |
INTERFACE_LIST : [ |
| 40 |
"NavDataInterface", |
| 41 |
"SelectableEISPublisher", |
| 42 |
"GenericNavComPublisher", |
| 43 |
"GenericNavComUpdater", |
| 44 |
"GenericFMSPublisher", |
| 45 |
"GenericFMSUpdater", |
| 46 |
"GenericADCPublisher", |
| 47 |
"SelectableFuelInterface", |
| 48 |
"SelectableFuelPublisher", |
| 49 |
"GFC700Publisher", |
| 50 |
"GFC700Interface", |
| 51 |
], |
| 52 |
|
| 53 |
# Factory method |
| 54 |
getOrCreateInstance : func() { |
| 55 |
if (SelectableInterfaceController._instance == nil) { |
| 56 |
SelectableInterfaceController._instance = SelectableInterfaceController.new(); |
| 57 |
} |
| 58 |
|
| 59 |
return SelectableInterfaceController._instance; |
| 60 |
}, |
| 61 |
|
| 62 |
new : func() { |
| 63 |
var obj = { |
| 64 |
parents : [SelectableInterfaceController], |
| 65 |
running : 0, |
| 66 |
}; |
| 67 |
|
| 68 |
return obj; |
| 69 |
}, |
| 70 |
|
| 71 |
start : func() { |
| 72 |
if (me.running) return; |
| 73 |
|
| 74 |
foreach (var interface; SelectableInterfaceController.INTERFACE_LIST) { |
| 75 |
var code = sprintf("me.%sInstance = fg1000.%s.new();", interface, interface); |
| 76 |
var instantiate = compile(code); |
| 77 |
instantiate(); |
| 78 |
} |
| 79 |
|
| 80 |
foreach (var interface; SelectableInterfaceController.INTERFACE_LIST) { |
| 81 |
var code = 'me.' ~ interface ~ 'Instance.start();'; |
| 82 |
var start_interface = compile(code); |
| 83 |
start_interface(); |
| 84 |
} |
| 85 |
|
| 86 |
me.running = 1; |
| 87 |
}, |
| 88 |
|
| 89 |
stop : func() { |
| 90 |
if (me.running == 0) return; |
| 91 |
|
| 92 |
foreach (var interface; SelectableInterfaceController.INTERFACE_LIST) { |
| 93 |
var code = 'me.' ~ interface ~ 'Instance.stop();'; |
| 94 |
var stop_interface = compile(code); |
| 95 |
stop_interface(); |
| 96 |
} |
| 97 |
}, |
| 98 |
|
| 99 |
restart : func() { |
| 100 |
me.stop(); |
| 101 |
me.start(); |
| 102 |
} |
| 103 |
}; |