1
0
Fork 0
fgdata/Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/PFDInstruments/PFDInstrumentsController.nas

265 lines
9 KiB
Text
Raw Normal View History

2018-02-26 21:24:21 +00:00
# Copyright 2018 Stuart Buchanan
# This file is part of FlightGear.
#
# Foobar is free software: you can redistribute it and/or modify
# 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/>.
#
# PFDInstruments Controller
var PFDInstrumentsController =
{
new : func (page, svg)
{
var obj = {
parents : [ PFDInstrumentsController, MFDPageController.new(page) ],
_crsrToggle : 0,
_pfdrecipient : nil,
page : page,
_last_ias_kt : 0,
_last_alt_ft : 0,
_last_trend : systime(),
_selected_alt_ft : 0,
_heading : 0,
_source : "GPS",
_from :0,
_leg_id : "",
_leg_bearing : 0,
_leg_distance_nm : 0,
_leg_deviation_deg : 0,
_deflection_dots :0,
_leg_xtrk_nm : 0,
2018-02-26 21:24:21 +00:00
};
return obj;
},
# Input Handling
handleCRSR : func() {
me._crsrToggle = (! me._crsrToggle);
if (me._crsrToggle) {
} else {
me.page.hideCRSR();
}
return emesary.Transmitter.ReceiptStatus_Finished;
},
handleFMSInner : func(value) {
if (me._crsrToggle == 1) {
# Scroll through whatever is the current list
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
# Pass to the page group controller to display and scroll through the page group menu
#return me.page.mfd.SurroundController.handleFMSInner(value);
}
},
handleFMSOuter : func(value) {
if (me._crsrToggle == 1) {
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
# Pass to the page group controller to display and scroll through the page group menu
#return me.page.mfd.SurroundController.handleFMSOuter(value);
}
},
handleEnter : func(value) {
if (me._crsrToggle == 1) {
return emesary.Transmitter.ReceiptStatus_Finished;
} else {
return emesary.Transmitter.ReceiptStatus_NotProcessed;
}
},
handleRange : func(val)
{
var incr_or_decr = (val > 0) ? me.page.insetMap.zoomIn() : me.page.insetMap.zoomOut();
},
# Set the STD BARO to 29.92 in Hg
setStdBaro : func() {
var data = {};
data["FMSPressureSettingInHG"] = 29.92;
var notification = notifications.PFDEventNotification.new(
"MFD",
me._page.mfd.getDeviceID(),
notifications.PFDEventNotification.FMSData,
data);
me.transmitter.NotifyAll(notification);
},
2018-02-26 21:24:21 +00:00
# Handle update of the airdata information.
# ADC data is produced periodically as an entire set
handleADCData : func(data) {
var ias = data["ADCIndicatedAirspeed"];
var alt = data["ADCAltitudeFT"];
# estimated speed and altitude in 6s
var now = systime();
var lookahead_ias_6sec = 6 * (ias - me._last_ias_kt) / (now - me._last_trend);
var lookahead_alt_6sec = .3 * (alt - me._last_alt_ft) / (now - me._last_trend); # scale = 1/20ft
me.page.updateIAS(ias, lookahead_ias_6sec);
me.page.updateALT(alt, lookahead_alt_6sec, me._selected_alt_ft);
me._last_ias_kt = ias;
me._last_alt_ft = alt;
me._last_trend = now;
var pitch = data["ADCPitchDeg"];
var roll = data["ADCRollDeg"];
var slip = data["ADCSlipSkid"];
me.page.updateAI(pitch, roll, slip);
me.page.updateVSI(data["ADCVerticalSpeedFPM"]);
me.page.updateTAS(data["ADCTrueAirspeed"]);
me.page.updateBARO(data["ADCPressureSettingInHG"]);
2018-02-26 21:24:21 +00:00
me.page.updateOAT(data["ADCOutsideAirTemperatureC"]);
me.page.updateHSI(data["ADCHeadingDeg"]);
me._heading = data["ADCHeadingDeg"];
2018-02-27 19:57:45 +00:00
# If we're "flying" at < 10kts, then we won't have sufficient delta between
# airspeed and groundspeed to determine wind
2018-02-26 21:24:21 +00:00
me.page.updateWindData(
hdg : data["ADCHeadingDeg"],
wind_hdg : data["ADCWindHeadingDeg"],
2018-02-27 19:57:45 +00:00
wind_spd : data ["ADCWindSpeedKt"],
no_data: (data["ADCIndicatedAirspeed"] < 1.0)
2018-02-26 21:24:21 +00:00
);
return emesary.Transmitter.ReceiptStatus_OK;
},
# Handle update to the FMS information. Note that there is no guarantee
# that the entire set of FMS data will be available.
2018-02-26 21:24:21 +00:00
handleFMSData : func(data) {
if (data["FMSHeadingBug"] != nil) me.page.updateHDG(data["FMSHeadingBug"]);
if (data["FMSSelectedAlt"] != nil) {
me.page.updateSelectedALT(data["FMSSelectedAlt"]);
me._selected_alt_ft = data["FMSSelectedAlt"];
}
2018-02-26 21:24:21 +00:00
if (data["FMSLegValid"] == "false") {
# No valid leg data, likely because there's no GPS course set
me.page.updateCRS(0);
me.page.updateCDI(
heading: me._heading,
course: 0,
waypoint_valid: 0,
course_deviation_deg : 0,
deflection_dots : 0,
xtrk_nm : 0,
from: 0,
);
# Update the bearing indicators with GPS data if that's what we're displaying.
if (me.page.getBRG1() == "GPS") me.page.setBRG1("NONE", 0);
if (me.page.getBRG2() == "GPS") me.page.setBRG2("NONE", 0);
2018-02-26 21:24:21 +00:00
} else {
if (data["FMSLegBearing"] != nil) me.page.updateCRS(data["FMSLegBearing"]);
if (me._navSelected == 1) {
if (data["FMSNav1From"] != nil) me._from = data["FMSNav1From"];
} else {
if (data["FMSNav2From"] != nil) me._from = data["FMSNav2From"];
}
if (data["FMSLegID"] != nil) me._leg_id = data["FMSLegID"];
if (data["FMSLegBearing"] != nil) me._leg_bearing = data["FMSLegBearing"];
if (data["FMSLegTrackErrorAngle"] != nil) me._leg_deviation_deg = data["FMSLegTrackErrorAngle"];
# TODO: Proper cross-track error based on source and flight phase.
if (data["FMSLegCourseError"] != nil) me.deflection_dots = data["FMSLegCourseError"];
if (data["FMSLegCourseError"] != nil) me._leg_xtrk_nm = data["FMSLegCourseError"];
me.page.updateCDI(
heading: me._heading,
course: me._leg_bearing,
waypoint_valid: (data["FMSLegValid"] == "true"),
course_deviation_deg : me._leg_deviation_deg,
deflection_dots : me._deflection_dots,
xtrk_nm : me._leg_xtrk_nm,
from: me._from,
annun: "ENR"
);
# Update the bearing indicators with GPS data if that's what we're displaying.
if (me.page.getBRG1() == "GPS") me.page.setBRG1(me._leg_id, me._leg_bearing);
if (me.page.getBRG2() == "GPS") me.page.setBRG2(me._leg_id, me._leg_bearing);
}
2018-02-26 21:24:21 +00:00
return emesary.Transmitter.ReceiptStatus_OK;
},
# Handle update of the NavCom data.
# Note that this updated on a property by property basis, so we need to check
# that the data we want exists in this notification, unlike the periodic
# publishers
handleNavComData : func(data) {
if (data["NavSelected"] != nil) {
me._navSelected = data["NavSelected"];
}
},
PFDRegisterWithEmesary : func(transmitter = nil){
if (transmitter == nil)
transmitter = emesary.GlobalTransmitter;
if (me._pfdrecipient == nil){
me._pfdrecipient = emesary.Recipient.new("PFDInstrumentsController_" ~ me._page.device.designation);
var pfd_obj = me._page.device;
var controller = me;
me._pfdrecipient.Receive = func(notification)
{
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
notification.Event_Id == notifications.PFDEventNotification.ADCData and
notification.EventParameter != nil)
{
return controller.handleADCData(notification.EventParameter);
}
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
notification.Event_Id == notifications.PFDEventNotification.FMSData and
notification.EventParameter != nil)
{
return controller.handleFMSData(notification.EventParameter);
}
if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
notification.Event_Id == notifications.PFDEventNotification.NavComData and
notification.EventParameter != nil)
{
return controller.handleNavComData(notification.EventParameter);
}
return emesary.Transmitter.ReceiptStatus_NotProcessed;
};
}
transmitter.Register(me._pfdrecipient);
me.transmitter = transmitter;
},
PFDDeRegisterWithEmesary : func(transmitter = nil){
# remove registration from transmitter; but keep the recipient once it is created.
if (me.transmitter != nil)
me.transmitter.DeRegister(me._pfdrecipient);
me.transmitter = nil;
},
# Reset controller if required when the page is displayed or hidden
ondisplay : func() {
me.RegisterWithEmesary();
me.PFDRegisterWithEmesary();
},
offdisplay : func() {
me.DeRegisterWithEmesary();
me.PFDDeRegisterWithEmesary();
},
};