SR22TInterfaceController.nas 3.6 KB

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