317 lines
11 KiB
Text
317 lines
11 KiB
Text
# MFD Surround
|
|
#
|
|
# Header fields at the top of the page
|
|
#
|
|
# PageGroup navigation, displayed in the bottom right of the
|
|
# FMS, and controlled by the FMS knob
|
|
|
|
# Set of pages, references by SVG ID
|
|
var PAGE_GROUPS = [
|
|
|
|
{ label: "MapPageGroupLabel",
|
|
group: "MapPageGroup",
|
|
pages: [ "NavigationMap", "TrafficMap", "Stormscope", "WeatherDataLink", "TAWSB"],
|
|
},
|
|
{ label: "WPTGroupLabel",
|
|
group: "WPTPageGroup",
|
|
pages: [ "AirportInfo", "IntersectionInfo", "NDBInfo", "VORInfo", "UserWPTInfo"],
|
|
},
|
|
|
|
{ label: "AuxGroupLabel",
|
|
group: "AuxPageGroup",
|
|
pages: [ "TripPlanning", "Utility", "GPSStatus", "XMRadio", "SystemStatus"],
|
|
},
|
|
|
|
{ label: "FPLGroupLabel",
|
|
group: "FPLPageGroup",
|
|
pages: [ "ActiveFlightPlanWide", "FlightPlanCatalog", "StoredFlightPlan"],
|
|
},
|
|
|
|
{ label: "LstGroupLabel",
|
|
group: "LstPageGroup",
|
|
pages: [ "Checklist1", "Checklist2", "Checklist3", "Checklist4", "Checklist5"],
|
|
},
|
|
|
|
{ label: "NrstGroupLabel",
|
|
group: "NrstPageGroup",
|
|
pages: [ "NearestAirports", "NearestIntersections", "NearestNDB", "NearestVOR", "NearestUserWaypoints", "NearestFrequencies", "NearestAirspaces"],
|
|
}
|
|
];
|
|
|
|
# Mapping for header labels to specific FMS or ADC messages, and sprintf formatting
|
|
# to use
|
|
var HEADER_MAPPING = {
|
|
"BRG" : { message : "FMSLegBearing", format : "%d"},
|
|
"XTK" : { message : "FMSLegCourseError", format : "%.1fnm"},
|
|
"DIS" : { message : "FMSDistance", format : "%.1fnm"},
|
|
"DTK" : { message : "FMSLegDesiredTrack", format : "%d"},
|
|
"END" : { message : "EnduranceHrs", format : "%.1fhrs"},
|
|
"ESA" : { message : "EnRouteSafeAltitude", format : "%dft"}, # TODO
|
|
"ETA" : { message : "FMSEstimatedTimeArrival", format : ""}, # TODO
|
|
"ETE" : { message : "FMSEstimatedTimeEnroute", format : ""},
|
|
"FOD" : { message : "FMSFuelOverDestination", format : "%dgal"},
|
|
"FOB" : { message : "FuelOnBoard", format : "%dgal"},
|
|
"GS" : { message : "FMSGroundspeed", format : "%dkts"},
|
|
"MSA" : { message : "MinimumSafeAltitude", format : "%dft"}, # TODO
|
|
"TAS" : { message : "ADCTrueAirspeed", format : "%dkts"},
|
|
"TKE" : { message : "FMSLegTrackErrorAngle", format : "%d"},
|
|
"TRK" : { message : "FMSLegTrack", format : "%d"},
|
|
"VSR" : { message : "FMSLegVerticalSpeedRequired", format : "%dfpm"}, # TODO
|
|
};
|
|
|
|
var Surround =
|
|
{
|
|
new : func (mfd, myCanvas, device, svg)
|
|
{
|
|
var obj = { parents : [
|
|
Surround,
|
|
MFDPage.new(mfd, myCanvas, device, svg, "Surround", ""),
|
|
] };
|
|
|
|
var textElements = [
|
|
"Comm1StandbyFreq", "Comm1SelectedFreq",
|
|
"Comm2StandbyFreq", "Comm2SelectedFreq",
|
|
"Nav1StandbyFreq", "Nav1SelectedFreq",
|
|
"Nav2StandbyFreq", "Nav2SelectedFreq",
|
|
"Nav1ID", "Nav2ID",
|
|
"Header1Label", "Header1Value",
|
|
"Header2Label", "Header2Value",
|
|
"Header3Label", "Header3Value",
|
|
"Header4Label", "Header4Value",
|
|
];
|
|
|
|
obj.addTextElements(textElements);
|
|
|
|
obj._comm1selected = PFD.HighlightElement.new(obj.pageName, svg, "Comm1Selected", "Comm1");
|
|
obj._comm2selected = PFD.HighlightElement.new(obj.pageName, svg, "Comm2Selected", "Comm2");
|
|
|
|
obj._nav1selected = PFD.HighlightElement.new(obj.pageName, svg, "Nav1Selected", "Nav1");
|
|
obj._nav2selected = PFD.HighlightElement.new(obj.pageName, svg, "Nav2Selected", "Nav2");
|
|
|
|
obj._comm1failed = PFD.HighlightElement.new(obj.pageName, svg, "Comm1Failed", "Comm1");
|
|
obj._comm2failed = PFD.HighlightElement.new(obj.pageName, svg, "Comm2Failed", "Comm2");
|
|
|
|
obj._nav1failed = PFD.HighlightElement.new(obj.pageName, svg, "Nav1Failed", "Nav1");
|
|
obj._nav2failed = PFD.HighlightElement.new(obj.pageName, svg, "Nav2Failed", "Nav2");
|
|
|
|
obj._canvas = myCanvas;
|
|
obj._menuVisible = 0;
|
|
obj._selectedPageGroup = 0;
|
|
obj._selectedPage = 0;
|
|
|
|
obj._elements = {};
|
|
|
|
foreach (var pageGroup; PAGE_GROUPS) {
|
|
var group = svg.getElementById(pageGroup.group);
|
|
var label = svg.getElementById(pageGroup.label);
|
|
assert(group != nil, "Unable to find element " ~ pageGroup.group);
|
|
assert(label != nil, "Unable to find element " ~ pageGroup.label);
|
|
obj._elements[pageGroup.group] = group;
|
|
obj._elements[pageGroup.label] = label;
|
|
|
|
foreach(var pg; pageGroup.pages) {
|
|
var page = svg.getElementById(pg);
|
|
assert(page != nil, "Unable to find element " ~ pg);
|
|
obj._elements[pg] = page;
|
|
}
|
|
}
|
|
|
|
# Timers to control when to hide the menu after inactivity, and when to load
|
|
# a new page.
|
|
obj._hideMenuTimer = maketimer(3, obj, obj.hideMenu);
|
|
obj._hideMenuTimer.singleShot = 1;
|
|
|
|
obj._loadPageTimer = maketimer(0.5, obj, obj.loadPage);
|
|
obj._loadPageTimer.singleShot = 1;
|
|
|
|
obj.hideMenu();
|
|
|
|
obj.setController(fg1000.SurroundController.new(obj, svg));
|
|
return obj;
|
|
},
|
|
|
|
handleNavComData : func(data) {
|
|
foreach(var name; keys(data)) {
|
|
var val = data[name];
|
|
|
|
if (name == "Comm1SelectedFreq") me.setTextElement("Comm1SelectedFreq", sprintf("%0.03f", val));
|
|
if (name == "Comm1StandbyFreq") me.setTextElement("Comm1StandbyFreq", sprintf("%0.03f", val));
|
|
if (name == "Comm1Serviceable") {
|
|
if (val == 1) {
|
|
me._comm1failed.unhighlightElement()
|
|
} else {
|
|
me._comm1failed.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "Comm2SelectedFreq") me.setTextElement("Comm2SelectedFreq", sprintf("%0.03f", val));
|
|
if (name == "Comm2StandbyFreq") me.setTextElement("Comm2StandbyFreq", sprintf("%0.03f", val));
|
|
if (name == "Comm2Serviceable") {
|
|
if (val == 1) {
|
|
me._comm2failed.unhighlightElement();
|
|
} else {
|
|
me._comm2failed.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "CommSelected") {
|
|
if (val == 1) {
|
|
me._comm1selected.highlightElement();
|
|
me._comm2selected.unhighlightElement();
|
|
} else {
|
|
me._comm1selected.unhighlightElement();
|
|
me._comm2selected.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "Nav1SelectedFreq") me.setTextElement("Nav1SelectedFreq", sprintf("%0.03f", val));
|
|
if (name == "Nav1StandbyFreq") me.setTextElement("Nav1StandbyFreq", sprintf("%0.03f", val));
|
|
if (name == "Nav1Serviceable") {
|
|
if (val == 1) {
|
|
me._nav1failed.unhighlightElement();
|
|
} else {
|
|
me._nav1failed.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "Nav2SelectedFreq") me.setTextElement("Nav2SelectedFreq", sprintf("%0.03f", val));
|
|
if (name == "Nav2StandbyFreq") me.setTextElement("Nav2StandbyFreq", sprintf("%0.03f", val));
|
|
if (name == "Nav2Serviceable") {
|
|
if (val == 1) {
|
|
me._nav2failed.unhighlightElement();
|
|
} else {
|
|
me._nav2failed.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "NavSelected") {
|
|
if (val == 1) {
|
|
me._nav1selected.highlightElement();
|
|
me._nav2selected.unhighlightElement();
|
|
} else {
|
|
me._nav1selected.unhighlightElement();
|
|
me._nav2selected.highlightElement();
|
|
}
|
|
}
|
|
|
|
if (name == "Nav1ID") me.setTextElement("Nav1ID", val);
|
|
if (name == "Nav2ID") me.setTextElement("Nav2ID", val);
|
|
|
|
# TODO - COM Volume - display the current volume for 2 seconds in place of the
|
|
# standby frequency.
|
|
|
|
|
|
}
|
|
},
|
|
|
|
# Update Header data with FMS or ADC data.
|
|
updateHeaderData : func(data) {
|
|
var headers = ["Header1", "Header2", "Header3", "Header4"];
|
|
foreach (var header; headers) {
|
|
|
|
# Get the currently configured heading and set the surround to display it.
|
|
var label = me.mfd.ConfigStore.get("MFD" ~ header);
|
|
assert(label != nil, "No header configured in ConfigStore for " ~ header);
|
|
me.setTextElement(header ~ "Label", label);
|
|
|
|
# Determine how it maps to Emesary data notifications
|
|
var mapping = HEADER_MAPPING[label];
|
|
assert(mapping != nil, "No header mapping for " ~ label);
|
|
|
|
if (data[mapping.message] != nil) {
|
|
# Format and display the value
|
|
var value = sprintf(mapping.format, data[mapping.message]);
|
|
|
|
if (mapping.message == "FMSEstimatedTimeEnroute") {
|
|
# Special case to format time strings.
|
|
var hrs = int(data[mapping.message]);
|
|
var mins = int(60*(data[mapping.message] - hrs));
|
|
var secs = int(3600*(data[mapping.message] - hrs - mins/60));
|
|
|
|
if (hrs == 0) {
|
|
value = sprintf("%d:%02d", mins, secs);
|
|
} else {
|
|
value = sprintf("%d:%02d", hrs, mins);
|
|
}
|
|
}
|
|
me.setTextElement(header ~ "Value", value);
|
|
}
|
|
}
|
|
},
|
|
|
|
getCurrentPage : func()
|
|
{
|
|
var currentpage = PAGE_GROUPS[me._selectedPageGroup].pages[me._selectedPage];
|
|
return me.getMFD().getPage(currentpage);
|
|
},
|
|
|
|
# Function to change a page based on the selection
|
|
loadPage : func()
|
|
{
|
|
var pageToLoad = PAGE_GROUPS[me._selectedPageGroup].pages[me._selectedPage];
|
|
var page = me.getMFD().getPage(pageToLoad);
|
|
|
|
assert(page != nil, "Unable to find page " ~ pageToLoad);
|
|
me.device.selectPage(page);
|
|
},
|
|
incrPageGroup : func(val) {
|
|
var incr_or_decr = (val > 0) ? 1 : -1;
|
|
me._selectedPageGroup = math.mod(me._selectedPageGroup + incr_or_decr, size(PAGE_GROUPS));
|
|
me._selectedPage = 0;
|
|
},
|
|
incrPage : func(val) {
|
|
var incr_or_decr = (val > 0) ? 1 : -1;
|
|
me._selectedPage = math.mod(me._selectedPage + incr_or_decr, size(PAGE_GROUPS[me._selectedPageGroup].pages));
|
|
},
|
|
showMenu : func()
|
|
{
|
|
foreach(var pageGroup; PAGE_GROUPS)
|
|
{
|
|
if (PAGE_GROUPS[me._selectedPageGroup].label == pageGroup.label)
|
|
{
|
|
# Display the page group and highlight the label
|
|
me._elements[pageGroup.group].setVisible(1);
|
|
me._elements[pageGroup.label].setVisible(1);
|
|
me._elements[pageGroup.label].setColor(0.7,0.7,1.0);
|
|
|
|
foreach (var page; pageGroup.pages)
|
|
{
|
|
# Highlight the current page.
|
|
if (pageGroup.pages[me._selectedPage] == page) {
|
|
me._elements[page].setColor(0.7,0.7,1.0);
|
|
} else {
|
|
me._elements[page].setColor(0.7,0.7,0.7);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
# Hide the pagegroup and unhighlight the label on the bottom
|
|
me._elements[pageGroup.group].setVisible(0);
|
|
me._elements[pageGroup.label].setVisible(1);
|
|
me._elements[pageGroup.label].setColor(0.7,0.7,0.7);
|
|
}
|
|
}
|
|
me._menuVisible = 1;
|
|
me._hideMenuTimer.stop();
|
|
me._hideMenuTimer.restart(3);
|
|
me._loadPageTimer.stop();
|
|
me._loadPageTimer.restart(0.5);
|
|
|
|
},
|
|
hideMenu : func()
|
|
{
|
|
foreach(var pageGroup; PAGE_GROUPS)
|
|
{
|
|
me._elements[pageGroup.group].setVisible(0);
|
|
me._elements[pageGroup.label].setVisible(0);
|
|
}
|
|
me._menuVisible = 0;
|
|
},
|
|
isMenuVisible : func()
|
|
{
|
|
return me._menuVisible;
|
|
},
|
|
|
|
|
|
};
|