| 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 |
# Fuel Publisher, providing information about fuel tank contents |
| 18 |
var GenericFuelPublisher = |
| 19 |
{ |
| 20 |
|
| 21 |
new : func (period=1.0) { |
| 22 |
var obj = { |
| 23 |
parents : [ |
| 24 |
GenericFuelPublisher, |
| 25 |
PeriodicPropertyPublisher.new(notifications.PFDEventNotification.FuelData, period) |
| 26 |
], |
| 27 |
}; |
| 28 |
|
| 29 |
obj.deltaT = period; |
| 30 |
|
| 31 |
|
| 32 |
# Hack to handle most aircraft not having proper engine hours |
| 33 |
if (getprop("/engines/engine[0]/hours") == nil) setprop("/engines/engine[0]/hours", 157.0); |
| 34 |
|
| 35 |
# Assume pilot has correct fuel quantities entered at Start of Day |
| 36 |
var tanks = props.getNode("/consumables/fuel",1).getChildren("tank"); |
| 37 |
|
| 38 |
foreach(var tank; tanks) { |
| 39 |
var actual = tank.getNode("level-gal_us", 1).getValue(); |
| 40 |
if ((actual == nil) or (! isnum(actual))) actual = 0; |
| 41 |
var indicatedNode = tank.getNode("fg1000-indicated-level-gal_us", 1); |
| 42 |
if (indicatedNode.getValue() == nil) indicatedNode.setValue(actual); |
| 43 |
} |
| 44 |
|
| 45 |
return obj; |
| 46 |
}, |
| 47 |
|
| 48 |
# Custom publish method as we package the values into an array of fuel tanks, |
| 49 |
# assuming that fuel is drawn evenly from both tanks. |
| 50 |
publish : func() { |
| 51 |
var tank_data = []; |
| 52 |
var tanks = props.getNode("/consumables/fuel",1).getChildren("tank"); |
| 53 |
|
| 54 |
foreach(var tank; tanks) { |
| 55 |
var indicatedNode = tank.getNode("fg1000-indicated-level-gal_us", 1); |
| 56 |
var fuel = indicatedNode.getValue(); |
| 57 |
if ((fuel == nil) or (! isnum(fuel))) fuel = 0; |
| 58 |
var fuel_flow = getprop("/engines/engine[0]/fuel-flow-gph"); |
| 59 |
if ((fuel_flow == nil) or (! isnum(fuel_flow))) fuel_flow = 0; |
| 60 |
fuel = fuel - fuel_flow*me.deltaT/3600.0/2; |
| 61 |
indicatedNode.setValue(fuel); |
| 62 |
append(tank_data, {"FuelUSGal": fuel}); |
| 63 |
} |
| 64 |
|
| 65 |
var notification = notifications.PFDEventNotification.new( |
| 66 |
"MFD", |
| 67 |
1, |
| 68 |
notifications.PFDEventNotification.FuelData, |
| 69 |
{ Id : "FuelData", Value : tank_data} ); |
| 70 |
|
| 71 |
me._transmitter.NotifyAll(notification); |
| 72 |
}, |
| 73 |
}; |