Debian Codegraph @

Aircraft/c172p/Nasal/Interfaces/SelectableEISPublisher.nas

raw
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 # EIS Driver using Emesary for selectable single engine aircraft, e.g. Cessna 172.
18 var SelectableEISPublisher =
19 {
20
21 new : func (period=0.25) {
22 var obj = {
23 parents : [
24 SelectableEISPublisher,
25 PeriodicPropertyPublisher.new(notifications.PFDEventNotification.EngineData, period)
26 ],
27 };
28
29 # Hack to handle most aircraft not having proper engine hours
30 if (getprop("/engines/engine[0]/hours") == nil) setprop("/engines/engine[0]/hours", 157.0);
31
32 obj.addPropMap("RPM", "/engines/active-engine/rpm");
33 obj.addPropMap("Man", "/engines/active-engine/mp-osi");
34 obj.addPropMap("MBusVolts", "/systems/electrical/volts");
35 obj.addPropMap("EBusVolts", "/systems/electrical/evolts");
36 obj.addPropMap("MBattAmps", "/systems/electrical/amps");
37 obj.addPropMap("SBattAmps", "/systems/electrical/eamps");
38 obj.addPropMap("EngineHours", "/engines/engine[0]/hours");
39 obj.addPropMap("FuelFlowGPH", "/engines/active-engine/fuel-flow-gph");
40 obj.addPropMap("OilPressurePSI", "/engines/active-engine/oil-pressure-psi");
41 obj.addPropMap("OilTemperatureF", "/engines/active-engine/oil-temperature-degf");
42 obj.addPropMap("EGTNorm", "/engines/active-engine/egt-norm");
43 obj.addPropMap("CHTDegF", "/engines/engine/cht-degf");
44 obj.addPropMap("VacuumSuctionInHG", "/systems/vacuum/suction-inhg");
45
46 return obj;
47 },
48
49 # Custom publish method as we package the values into an array of engines,
50 # in this case, only one!
51 publish : func() {
52 var engineData1 = {};
53
54 foreach (var propmap; me._propmaps) {
55 var name = propmap.getName();
56 engineData1[name] = propmap.getValue();
57 }
58
59 var engineData = [];
60 append(engineData, engineData1);
61
62 var notification = notifications.PFDEventNotification.new(
63 "MFD",
64 1,
65 notifications.PFDEventNotification.EngineData,
66 { Id: "EngineData", Value: engineData } );
67
68 me._transmitter.NotifyAll(notification);
69 },
70 };