2018-02-09 18:55:53 +00:00
|
|
|
# Copyright 2018 Stuart Buchanan
|
|
|
|
# This file is part of FlightGear.
|
|
|
|
#
|
2018-05-28 19:15:57 +00:00
|
|
|
# FlightGear is free software: you can redistribute it and/or modify
|
2018-02-09 18:55:53 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# FlightGear 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 General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2018-02-09 15:01:33 +00:00
|
|
|
# Generic Interface controller.
|
|
|
|
|
|
|
|
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
|
|
|
|
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyPublisher.nas', "fg1000");
|
|
|
|
io.load_nasal(nasal_dir ~ 'Interfaces/PropertyUpdater.nas', "fg1000");
|
|
|
|
|
|
|
|
var GenericInterfaceController = {
|
|
|
|
|
2018-02-09 17:26:57 +00:00
|
|
|
_instance : nil,
|
|
|
|
|
2019-02-10 22:06:31 +00:00
|
|
|
INTERFACE_LIST : [
|
2020-12-17 22:44:08 +00:00
|
|
|
{ id:"NavDataInterface", path: nasal_dir ~ 'Interfaces/NavDataInterface.nas' },
|
|
|
|
{ id:"GenericEISPublisher", path: nasal_dir ~ 'Interfaces/GenericEISPublisher.nas' },
|
|
|
|
{ id:"GenericNavComPublisher", path: nasal_dir ~ 'Interfaces/GenericNavComPublisher.nas' },
|
|
|
|
{ id:"GenericNavComUpdater", path: nasal_dir ~ 'Interfaces/GenericNavComUpdater.nas' },
|
|
|
|
{ id:"GenericFMSPublisher", path: nasal_dir ~ 'Interfaces/GenericFMSPublisher.nas' },
|
|
|
|
{ id:"GenericFMSUpdater", path: nasal_dir ~ 'Interfaces/GenericFMSUpdater.nas' },
|
|
|
|
{ id:"GenericADCPublisher", path: nasal_dir ~ 'Interfaces/GenericADCPublisher.nas' },
|
|
|
|
{ id:"GenericFuelInterface", path: nasal_dir ~ 'Interfaces/GenericFuelInterface.nas' },
|
|
|
|
{ id:"GenericFuelPublisher", path: nasal_dir ~ 'Interfaces/GenericFuelPublisher.nas' },
|
|
|
|
{ id:"GFC700Interface", path: nasal_dir ~ 'Interfaces/GFC700Interface.nas' },
|
2021-08-18 19:18:57 +00:00
|
|
|
{ id:"GFC700Publisher", path: nasal_dir ~ 'Interfaces/GFC700Publisher.nas' },
|
|
|
|
{ id:"GMA1347Interface", path: nasal_dir ~ 'Interfaces/GMA1347Interface.nas' },
|
|
|
|
|
2019-02-10 22:06:31 +00:00
|
|
|
],
|
|
|
|
|
2018-02-09 17:26:57 +00:00
|
|
|
# Factory method
|
2018-02-18 21:41:17 +00:00
|
|
|
getOrCreateInstance : func() {
|
2018-02-09 17:26:57 +00:00
|
|
|
if (GenericInterfaceController._instance == nil) {
|
|
|
|
GenericInterfaceController._instance = GenericInterfaceController.new();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GenericInterfaceController._instance;
|
|
|
|
},
|
|
|
|
|
2018-02-09 15:01:33 +00:00
|
|
|
new : func() {
|
|
|
|
var obj = {
|
|
|
|
parents : [GenericInterfaceController],
|
|
|
|
running : 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
start : func() {
|
|
|
|
if (me.running) return;
|
2019-02-10 22:06:31 +00:00
|
|
|
|
|
|
|
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) {
|
2020-12-17 22:44:08 +00:00
|
|
|
io.load_nasal(interface.path, "fg1000");
|
|
|
|
var code = sprintf("me.%sInstance = fg1000.%s.new();", interface.id, interface.id);
|
2019-02-10 22:06:31 +00:00
|
|
|
var instantiate = compile(code);
|
|
|
|
instantiate();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) {
|
2020-12-17 22:44:08 +00:00
|
|
|
var code = 'me.' ~ interface.id ~ 'Instance.start();';
|
2019-02-10 22:06:31 +00:00
|
|
|
var start_interface = compile(code);
|
|
|
|
start_interface();
|
|
|
|
}
|
|
|
|
|
|
|
|
me.running = 1;
|
2018-02-09 15:01:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
stop : func() {
|
|
|
|
if (me.running == 0) return;
|
2019-09-25 19:52:54 +00:00
|
|
|
|
2019-02-10 22:06:31 +00:00
|
|
|
foreach (var interface; GenericInterfaceController.INTERFACE_LIST) {
|
2020-12-17 22:44:08 +00:00
|
|
|
io.load_nasal(interface.path, "fg1000");
|
|
|
|
var code = 'me.' ~ interface.id ~ 'Instance.stop();';
|
2019-02-10 22:06:31 +00:00
|
|
|
var stop_interface = compile(code);
|
|
|
|
stop_interface();
|
|
|
|
}
|
2020-12-17 22:44:08 +00:00
|
|
|
|
|
|
|
me.running = 0;
|
2018-02-09 15:01:33 +00:00
|
|
|
},
|
2019-02-10 22:06:31 +00:00
|
|
|
|
|
|
|
restart : func() {
|
|
|
|
me.stop();
|
|
|
|
me.start();
|
|
|
|
}
|
2018-02-09 15:01:33 +00:00
|
|
|
};
|