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-01-03 20:24:41 +00:00
|
|
|
# EIS Controller
|
|
|
|
var EISController =
|
|
|
|
{
|
|
|
|
new : func (page, svg)
|
|
|
|
{
|
|
|
|
var obj = {
|
|
|
|
parents : [ EISController ],
|
|
|
|
_crsrToggle : 0,
|
|
|
|
_recipient : nil,
|
|
|
|
_page : page,
|
|
|
|
};
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
# Function to handle the data provided from the EngineData Emesary Notification.
|
|
|
|
# This implementation assumes a vector containing a single engine.
|
|
|
|
handleEngineData : func (engineData) {
|
|
|
|
assert(size(engineData) > 0, "handleEngineData expects vector of hash");
|
|
|
|
var data = engineData[0];
|
|
|
|
|
|
|
|
# Sanitize data
|
|
|
|
var elements = [
|
|
|
|
"RPM",
|
2018-04-07 12:22:01 +00:00
|
|
|
"Man",
|
2018-01-03 20:24:41 +00:00
|
|
|
"MBusVolts",
|
|
|
|
"EngineHours",
|
|
|
|
"FuelFlowGPH",
|
|
|
|
"OilPressurePSI",
|
|
|
|
"OilTemperatureF",
|
|
|
|
"EGTNorm",
|
2019-01-11 20:19:09 +00:00
|
|
|
"VacuumSuctionInHG"];
|
2018-01-03 20:24:41 +00:00
|
|
|
|
|
|
|
foreach (var val; elements) {
|
|
|
|
if (data[val] == nil) data[val] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display it
|
2019-01-11 20:19:09 +00:00
|
|
|
me._page.updateEngineData(data);
|
|
|
|
return emesary.Transmitter.ReceiptStatus_OK;
|
|
|
|
},
|
|
|
|
|
|
|
|
# Function to handle the data provided from the FuelData Emesary Notification.
|
|
|
|
# This implementation assumes a vector containing hashes of "FuelUSGal" entries
|
|
|
|
handleFuelData : func (fuelData) {
|
|
|
|
assert(size(fuelData) > 1, "handleEngineData expects vector of size > 1");
|
|
|
|
var data = {};
|
|
|
|
data["LeftFuelUSGal"] = (fuelData[0]["FuelUSGal"] or 0);
|
|
|
|
data["RightFuelUSGal"] = (fuelData[1]["FuelUSGal"] or 0);
|
|
|
|
|
|
|
|
# Display it
|
|
|
|
me._page.updateFuelData(data);
|
2018-01-05 16:37:39 +00:00
|
|
|
return emesary.Transmitter.ReceiptStatus_OK;
|
2018-01-03 20:24:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
RegisterWithEmesary : func(transmitter = nil){
|
|
|
|
if (transmitter == nil)
|
|
|
|
transmitter = emesary.GlobalTransmitter;
|
|
|
|
|
|
|
|
if (me._recipient == nil){
|
2018-02-26 21:24:21 +00:00
|
|
|
me._recipient = emesary.Recipient.new("EISController_" ~ me._page.device.designation);
|
2018-01-03 20:24:41 +00:00
|
|
|
var pfd_obj = me._page.device;
|
|
|
|
var controller = me;
|
|
|
|
me._recipient.Receive = func(notification)
|
|
|
|
{
|
2018-02-04 21:40:37 +00:00
|
|
|
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
|
|
|
|
notification.Event_Id == notifications.PFDEventNotification.EngineData and
|
2019-01-11 20:19:09 +00:00
|
|
|
notification.EventParameter.Id == "EngineData")
|
|
|
|
{
|
|
|
|
return controller.handleEngineData(notification.EventParameter.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
|
|
|
|
notification.Event_Id == notifications.PFDEventNotification.FuelData and
|
|
|
|
notification.EventParameter.Id == "FuelData")
|
2018-02-04 21:40:37 +00:00
|
|
|
{
|
2019-01-11 20:19:09 +00:00
|
|
|
return controller.handleFuelData(notification.EventParameter.Value);
|
2018-01-03 20:24:41 +00:00
|
|
|
}
|
2019-01-11 20:19:09 +00:00
|
|
|
|
2018-01-03 20:24:41 +00:00
|
|
|
return emesary.Transmitter.ReceiptStatus_NotProcessed;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
transmitter.Register(me._recipient);
|
|
|
|
me.transmitter = transmitter;
|
|
|
|
},
|
|
|
|
DeRegisterWithEmesary : func(transmitter = nil){
|
|
|
|
# remove registration from transmitter; but keep the recipient once it is created.
|
|
|
|
if (me.transmitter != nil)
|
|
|
|
me.transmitter.DeRegister(me._recipient);
|
|
|
|
me.transmitter = nil;
|
|
|
|
},
|
|
|
|
|
|
|
|
# Reset controller if required when the page is displayed or hidden
|
|
|
|
ondisplay : func() {
|
|
|
|
me.RegisterWithEmesary();
|
|
|
|
},
|
|
|
|
offdisplay : func() {
|
|
|
|
me.DeRegisterWithEmesary();
|
|
|
|
},
|
|
|
|
|
2019-01-11 20:19:09 +00:00
|
|
|
setFuelQuantity : func(val) {
|
|
|
|
me.sendFuelUpdateNotification("SetFuelQuantity", val);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateFuelQuantity : func(val) {
|
|
|
|
me.sendFuelUpdateNotification("UpdateFuelQuantity", val);
|
|
|
|
},
|
|
|
|
|
|
|
|
# Send an update to fuel quantities
|
|
|
|
sendFuelUpdateNotification : func(type, val)
|
|
|
|
{
|
|
|
|
# Use Emesary to set the default DTO waypoint
|
|
|
|
var notification = notifications.PFDEventNotification.new(
|
|
|
|
"MFD",
|
|
|
|
me._page.mfd.getDeviceID(),
|
|
|
|
notifications.PFDEventNotification.FuelData,
|
|
|
|
{Id: type, Value: val});
|
|
|
|
|
|
|
|
var response = me.transmitter.NotifyAll(notification);
|
|
|
|
if (me.transmitter.IsFailed(response)) print("Failed to set Fuel Data notification " ~ type ~ " " ~ val);
|
|
|
|
},
|
|
|
|
|
2018-01-03 20:24:41 +00:00
|
|
|
};
|