| 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 |
# Generic Interface controller. |
| 18 |
|
| 19 |
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/"; |
| 20 |
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyPublisher.nas', "fg1000"); |
| 21 |
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyUpdater.nas', "fg1000"); |
| 22 |
|
| 23 |
var GenericInterfaceController = { |
| 24 |
|
| 25 |
_instance : nil, |
| 26 |
|
| 27 |
INTERFACE_LIST : [ |
| 28 |
{ id:"NavDataInterface", path: nasal_dir ~ 'Interfaces/NavDataInterface.nas' }, |
| 29 |
{ id:"GenericEISPublisher", path: nasal_dir ~ 'Interfaces/GenericEISPublisher.nas' }, |
| 30 |
{ id:"GenericNavComPublisher", path: nasal_dir ~ 'Interfaces/GenericNavComPublisher.nas' }, |
| 31 |
{ id:"GenericNavComUpdater", path: nasal_dir ~ 'Interfaces/GenericNavComUpdater.nas' }, |
| 32 |
{ id:"GenericFMSPublisher", path: nasal_dir ~ 'Interfaces/GenericFMSPublisher.nas' }, |
| 33 |
{ id:"GenericFMSUpdater", path: nasal_dir ~ 'Interfaces/GenericFMSUpdater.nas' }, |
| 34 |
{ id:"GenericADCPublisher", path: nasal_dir ~ 'Interfaces/GenericADCPublisher.nas' }, |
| 35 |
{ id:"GenericFuelInterface", path: nasal_dir ~ 'Interfaces/GenericFuelInterface.nas' }, |
| 36 |
{ id:"GenericFuelPublisher", path: nasal_dir ~ 'Interfaces/GenericFuelPublisher.nas' }, |
| 37 |
{ id:"GFC700Interface", path: nasal_dir ~ 'Interfaces/GFC700Interface.nas' }, |
| 38 |
{ id:"GFC700Publisher", path: nasal_dir ~ 'Interfaces/GFC700Publisher.nas' }, |
| 39 |
{ id:"GMA1347Interface", path: nasal_dir ~ 'Interfaces/GMA1347Interface.nas' }, |
| 40 |
|
| 41 |
], |
| 42 |
|
| 43 |
# Factory method |
| 44 |
getOrCreateInstance : func() { |
| 45 |
if (GenericInterfaceController._instance == nil) { |
| 46 |
GenericInterfaceController._instance = GenericInterfaceController.new(); |
| 47 |
} |
| 48 |
|
| 49 |
return GenericInterfaceController._instance; |
| 50 |
}, |
| 51 |
|
| 52 |
new : func() { |
| 53 |
var obj = { |
| 54 |
parents : [GenericInterfaceController], |
| 55 |
running : 0, |
| 56 |
}; |
| 57 |
|
| 58 |
return obj; |
| 59 |
}, |
| 60 |
|
| 61 |
start : func() { |
| 62 |
if (me.running) return; |
| 63 |
|
| 64 |
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) { |
| 65 |
io.load_nasal(interface.path, "fg1000"); |
| 66 |
var code = sprintf("me.%sInstance = fg1000.%s.new();", interface.id, interface.id); |
| 67 |
var instantiate = compile(code); |
| 68 |
instantiate(); |
| 69 |
} |
| 70 |
|
| 71 |
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) { |
| 72 |
var code = 'me.' ~ interface.id ~ 'Instance.start();'; |
| 73 |
var start_interface = compile(code); |
| 74 |
start_interface(); |
| 75 |
} |
| 76 |
|
| 77 |
me.running = 1; |
| 78 |
}, |
| 79 |
|
| 80 |
stop : func() { |
| 81 |
if (me.running == 0) return; |
| 82 |
|
| 83 |
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) { |
| 84 |
io.load_nasal(interface.path, "fg1000"); |
| 85 |
var code = 'me.' ~ interface.id ~ 'Instance.stop();'; |
| 86 |
var stop_interface = compile(code); |
| 87 |
stop_interface(); |
| 88 |
} |
| 89 |
|
| 90 |
me.running = 0; |
| 91 |
}, |
| 92 |
|
| 93 |
restart : func() { |
| 94 |
me.stop(); |
| 95 |
me.start(); |
| 96 |
} |
| 97 |
}; |