| 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 |
# PFDInstruments |
| 18 |
var PFDInstruments = |
| 19 |
{ |
| 20 |
|
| 21 |
COLORS : { |
| 22 |
green : [0, 1, 0], |
| 23 |
white : [1, 1, 1], |
| 24 |
black : [0, 0, 0], |
| 25 |
lightblue : [0, 1, 1], |
| 26 |
darkblue : [0, 0, 1], |
| 27 |
red : [1, 0, 0], |
| 28 |
magenta : [1, 0, 1], |
| 29 |
}, |
| 30 |
|
| 31 |
new : func (mfd, myCanvas, device, svg) |
| 32 |
{ |
| 33 |
var obj = { |
| 34 |
parents : [ |
| 35 |
PFDInstruments, |
| 36 |
MFDPage.new(mfd, myCanvas, device, svg, "PFDInstruments", "PFD Instruments") |
| 37 |
], |
| 38 |
|
| 39 |
_ias_already_exceeded : 0, |
| 40 |
_windDataDisplay : 0, |
| 41 |
_BRG1 : "OFF", |
| 42 |
_BRG2 : "OFF", |
| 43 |
_DME : 0, |
| 44 |
_OMI : "", |
| 45 |
_Multiline : 0, |
| 46 |
_annunciation : 0, |
| 47 |
_fd_enabled : 1, # Mark the Flight Director as enabled, as it is visible in the SVG. |
| 48 |
_selected_spd : 0, |
| 49 |
_selected_spd_visible : 0, |
| 50 |
}; |
| 51 |
|
| 52 |
# Hide various elements for the moment. TODO - implement |
| 53 |
obj.device.svg.getElementById("PFDInstrumentsFailures").setVisible(0); |
| 54 |
obj.device.svg.getElementById("PFDInstrumentsGSPD").setVisible(0); |
| 55 |
|
| 56 |
obj.addTextElements([ |
| 57 |
"Speed110", |
| 58 |
"VSIText", |
| 59 |
"TAS-text", "GSPD-text", |
| 60 |
"Alt11100", |
| 61 |
"AltBigC", "AltSmallC", |
| 62 |
"BARO-text", "OAT-text", |
| 63 |
"HDG-text", |
| 64 |
"SelectedHDG-text", |
| 65 |
"SelectedALT-text", |
| 66 |
"SelectedSPD-text", |
| 67 |
"XPDR-DIGIT-3-text", "XPDR-DIGIT-2-text", "XPDR-DIGIT-1-text", "XPDR-DIGIT-0-text", |
| 68 |
"XPDR-MODE-text", |
| 69 |
"TIME-text", |
| 70 |
"GS-type", |
| 71 |
"MarkerText", |
| 72 |
]); |
| 73 |
|
| 74 |
# Set clipping for the various tapes |
| 75 |
var clips = { |
| 76 |
PitchScale : "rect(70,664,370,256)", |
| 77 |
SpeedLint1 : "rect(252,226,318,204)", |
| 78 |
SpeedTape : "rect(115,239,455,156)", |
| 79 |
LintAlt : "rect(115,808,455,704)", |
| 80 |
AltLint00011 : "rect(252,804,318,771)", |
| 81 |
}; |
| 82 |
|
| 83 |
foreach(var id; keys(clips)) { |
| 84 |
var clip = clips[id]; |
| 85 |
obj.device.svg.getElementById("PFDInstruments" ~ id).set("clip", clip); |
| 86 |
} |
| 87 |
|
| 88 |
obj._SVGGroup.setInt("z-index", 10); |
| 89 |
obj.insetMap = fg1000.NavMap.new(obj, obj.getElement("PFD-Map-Display"), [119,601], "rect(-109px, 109px, 109px, -109px)", 0, 2); |
| 90 |
|
| 91 |
# Flight Plan Window group |
| 92 |
obj.flightplanList = PFD.GroupElement.new( |
| 93 |
obj.pageName, |
| 94 |
svg, |
| 95 |
[ "FlightPlanArrow", "FlightPlanID", "FlightPlanType", "FlightPlanDTK", "FlightPlanDIS"], |
| 96 |
5, |
| 97 |
"FlightPlanArrow", |
| 98 |
1, |
| 99 |
"FlightPlanScrollTrough", |
| 100 |
"FlightPlanScrollThumb", |
| 101 |
120 |
| 102 |
); |
| 103 |
|
| 104 |
obj.setController(fg1000.PFDInstrumentsController.new(obj, svg)); |
| 105 |
|
| 106 |
obj.setWindDisplay(0); |
| 107 |
obj.setCDISource("GPS"); |
| 108 |
obj.setBRG1("OFF"); |
| 109 |
obj.setBRG2("OFF"); |
| 110 |
obj.setDME(0); |
| 111 |
obj.setMultiline(0); |
| 112 |
obj.setAnnunciation(0); |
| 113 |
obj.setOMI(""); |
| 114 |
obj.setInsetMapVisible(0); |
| 115 |
obj.updateHDG(0); |
| 116 |
obj.updateSelectedALT(0); |
| 117 |
obj.updateCRS(0); |
| 118 |
obj.setFlightPlanVisible(0); |
| 119 |
|
| 120 |
return obj; |
| 121 |
}, |
| 122 |
|
| 123 |
topMenu : func(device, pg, menuitem) { |
| 124 |
pg.clearMenu(); |
| 125 |
pg.resetMenuColors(); |
| 126 |
pg.addMenuItem(1, "INSET", pg, pg.mfd.PFDInstruments.insetMenu); |
| 127 |
pg.addMenuItem(3, "PFD", pg, pg.mfd.PFDInstruments.PFDMenu); |
| 128 |
pg.addMenuItem(4, "OBS", pg); # TODO |
| 129 |
pg.addMenuItem(5, "CDI", pg, func(dev, pg, mi) { pg.getController().incrCDISource(); } ); |
| 130 |
#pg.addMenuItem(6, "DME", pg, func(dev, pg, mi) { pg.toggleDME(); } ); # TODO |
| 131 |
pg.addMenuItem(7, "XPDR", pg, pg.mfd.PFDInstruments.transponderMenu); |
| 132 |
pg.addMenuItem(8, "IDENT", pg, pg.mfd.PFDInstruments.setIdent); # TODO |
| 133 |
pg.addMenuItem(9, "TMR/REF", pg); # TODO |
| 134 |
pg.addMenuItem(10, "NRST", pg, pg.mfd.PFDInstruments.toggleNRST, func(svg, mi) { pg.mfd.PFDInstruments.toggleNRSTDisplay(device, pg, svg, mi); } ); |
| 135 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 136 |
device.updateMenus(); |
| 137 |
}, |
| 138 |
|
| 139 |
toggleNRST : func (device, pg, mi) { |
| 140 |
pg.mfd.NearestAirports.toggleDisplay(); |
| 141 |
device.updateMenus(); |
| 142 |
}, |
| 143 |
|
| 144 |
toggleNRSTDisplay : func(device, pg, svg, mi) { |
| 145 |
var bg_name = sprintf("SoftKey%d-bg",mi.menu_id); |
| 146 |
if (pg.mfd.NearestAirports.visible()) { |
| 147 |
device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5); |
| 148 |
svg.setColor(0.0,0.0,0.0); |
| 149 |
} else { |
| 150 |
device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0); |
| 151 |
svg.setColor(1.0,1.0,1.0); |
| 152 |
} |
| 153 |
svg.setText(mi.title); |
| 154 |
svg.setVisible(1); # display function |
| 155 |
}, |
| 156 |
|
| 157 |
insetMenu : func(device, pg, menuitem) { |
| 158 |
# Switch on the inset Map |
| 159 |
pg.setInsetMapVisible(1); |
| 160 |
|
| 161 |
pg.clearMenu(); |
| 162 |
pg.resetMenuColors(); |
| 163 |
pg.addMenuItem(0, "OFF", pg, func(dev, pg, mi) { pg.setInsetMapVisible(0); pg.mfd.PFDInstruments.topMenu(dev, pg, mi); } ); |
| 164 |
pg.addMenuItem(1, "DCLTR", pg, |
| 165 |
func(dev, pg, mi) { pg.insetMap.incrDCLTR(dev, mi); device.updateMenus(); }, |
| 166 |
func(svg, mi) { pg.displayDCLTR(svg, mi); }, |
| 167 |
); |
| 168 |
#pg.addMenuItem(2, "WXLGND", pg); # Optional |
| 169 |
|
| 170 |
# TODO: Support TRFC-1 to add traffic layer, TRFC-2 to just display a traffic map |
| 171 |
pg.addMenuItem(3, "TRAFFIC", pg, |
| 172 |
func(dev, pg, mi) { pg.insetMap.toggleLayer("TFC"); device.updateMenus(); }, # callback |
| 173 |
func(svg, mi) { pg.display_toggle(device, svg, mi, "TFC"); } |
| 174 |
); |
| 175 |
|
| 176 |
pg.addMenuItem(4, "TOPO", pg, |
| 177 |
func(dev, pg, mi) { pg.insetMap.toggleLayer("OSM"); device.updateMenus(); }, # callback |
| 178 |
func(svg, mi) { pg.display_toggle(device, svg, mi, "OSM"); } |
| 179 |
); |
| 180 |
|
| 181 |
pg.addMenuItem(5, "TERRAIN", pg, |
| 182 |
func(dev, pg, mi) { pg.insetMap.toggleLayer("OSM"); device.updateMenus(); }, # callback |
| 183 |
func(svg, mi) { pg.display_toggle(device, svg, mi, "OSM"); } |
| 184 |
); |
| 185 |
#pg.addMenuItem(6, "STRMSCP", pg); # TODO |
| 186 |
#pg.addMenuItem(7, "NEXRAD", pg); # TODO |
| 187 |
#pg.addMenuItem(8, "XM LTNG", pg); # TODO |
| 188 |
#pg.addMenuItem(9, "METAR", pg); # TODO |
| 189 |
pg.addMenuItem(10, "BACK", pg, pg.mfd.PFDInstruments.topMenu); |
| 190 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 191 |
device.updateMenus(); |
| 192 |
}, |
| 193 |
|
| 194 |
displayDCLTR : func(svg, mi) { |
| 195 |
mi.title = me.insetMap.getDCLTRTitle(); |
| 196 |
svg.setText(mi.title); |
| 197 |
svg.setVisible(1); |
| 198 |
}, |
| 199 |
|
| 200 |
# Display map toggle softkeys which change color depending |
| 201 |
# on whether a particular layer is enabled or not. |
| 202 |
display_toggle : func(device, svg, mi, layer) { |
| 203 |
var bg_name = sprintf("SoftKey%d-bg",mi.menu_id); |
| 204 |
if (me.insetMap.isEnabled(layer)) { |
| 205 |
device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5); |
| 206 |
svg.setColor(0.0,0.0,0.0); |
| 207 |
} else { |
| 208 |
device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0); |
| 209 |
svg.setColor(1.0,1.0,1.0); |
| 210 |
} |
| 211 |
svg.setText(mi.title); |
| 212 |
svg.setVisible(1); # display function |
| 213 |
}, |
| 214 |
|
| 215 |
PFDMenu : func(device, pg, menuitem) { |
| 216 |
pg.clearMenu(); |
| 217 |
pg.resetMenuColors(); |
| 218 |
pg.addMenuItem(0, "SYN VIS", pg); # TODO |
| 219 |
pg.addMenuItem(1, "DFLTS", pg); |
| 220 |
pg.addMenuItem(2, "WIND", pg, pg.mfd.PFDInstruments.windMenu); |
| 221 |
#pg.addMenuItem(3, "DME", pg); # TODO |
| 222 |
pg.addMenuItem(4, "BRG1", pg, func(dev, pg, mi) { pg.getController().incrBRG1(); }); |
| 223 |
pg.addMenuItem(5, "HSI FRMT", pg); # TODO |
| 224 |
pg.addMenuItem(6, "BRG2", pg, func(dev, pg, mi) { pg.getController().incrBRG2(); }); |
| 225 |
pg.addMenuItem(8, "ALT UNIT ", pg); # TODO |
| 226 |
pg.addMenuItem(9, "STD BARO", pg, func(dev, pg, mi) { pg.getController().setStdBaro(); } ); |
| 227 |
pg.addMenuItem(10, "BACK", pg, pg.mfd.PFDInstruments.topMenu); |
| 228 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 229 |
device.updateMenus(); |
| 230 |
}, |
| 231 |
|
| 232 |
windMenu : func(device, pg, menuitem) { |
| 233 |
pg.clearMenu(); |
| 234 |
pg.resetMenuColors(); |
| 235 |
pg.addMenuItem(2, "OPTN1", pg, |
| 236 |
func(dev, pg, mi) { pg.mfd.PFDInstruments.setWindDisplay(1); device.updateMenus(); }, # Action callback |
| 237 |
func(svg, mi) { pg.mfd.PFDInstruments.toggleWindDisplay(device, svg, mi, 1); } # Display callback |
| 238 |
); |
| 239 |
pg.addMenuItem(3, "OPTN2", pg, |
| 240 |
func(dev, pg, mi) { pg.mfd.PFDInstruments.setWindDisplay(2); device.updateMenus(); }, # Action callback |
| 241 |
func(svg, mi) { pg.mfd.PFDInstruments.toggleWindDisplay(device, svg, mi, 2); } # Display callback |
| 242 |
); |
| 243 |
pg.addMenuItem(4, "OPTN3", pg, |
| 244 |
func(dev, pg, mi) { pg.mfd.PFDInstruments.setWindDisplay(3); device.updateMenus(); }, # Action callback |
| 245 |
func(svg, mi) { pg.mfd.PFDInstruments.toggleWindDisplay(device, svg, mi, 3); } # Display callback |
| 246 |
); |
| 247 |
pg.addMenuItem(5, "OFF", pg, |
| 248 |
func(dev, pg, mi) { pg.mfd.PFDInstruments.setWindDisplay(0); device.updateMenus(); }, # Action callback |
| 249 |
func(svg, mi) { pg.mfd.PFDInstruments.toggleWindDisplay(device, svg, mi, 0); } # Display callback |
| 250 |
); |
| 251 |
pg.addMenuItem(10, "BACK", pg, pg.mfd.PFDInstruments.topMenu); |
| 252 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 253 |
device.updateMenus(); |
| 254 |
}, |
| 255 |
|
| 256 |
toggleWindDisplay : func(device, svg, mi, wind_value) { |
| 257 |
var bg_name = sprintf("SoftKey%d-bg",mi.menu_id); |
| 258 |
if (me._windDataDisplay == wind_value) { |
| 259 |
device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5); |
| 260 |
svg.setColor(0.0,0.0,0.0); |
| 261 |
} else { |
| 262 |
device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0); |
| 263 |
svg.setColor(1.0,1.0,1.0); |
| 264 |
} |
| 265 |
svg.setText(mi.title); |
| 266 |
svg.setVisible(1); # display function |
| 267 |
}, |
| 268 |
|
| 269 |
transponderMenu : func(device, pg, menuitem) { |
| 270 |
pg.clearMenu(); |
| 271 |
pg.resetMenuColors(); |
| 272 |
pg.addMenuItem(2, "STBY", pg, pg.mfd.PFDInstruments.setTransponderMode); |
| 273 |
pg.addMenuItem(3, "ON", pg, pg.mfd.PFDInstruments.setTransponderMode); |
| 274 |
pg.addMenuItem(4, "ALT", pg, pg.mfd.PFDInstruments.setTransponderMode); |
| 275 |
pg.addMenuItem(5, "GND", pg, pg.mfd.PFDInstruments.setTransponderMode); |
| 276 |
pg.addMenuItem(6, "VFR", pg, pg.mfd.PFDInstruments.setVFR); |
| 277 |
pg.addMenuItem(7, "CODE", pg, pg.mfd.PFDInstruments.codeMenu); |
| 278 |
pg.addMenuItem(8, "IDENT", pg, pg.mfd.PFDInstruments.setIdent); |
| 279 |
pg.addMenuItem(10, "BACK", pg, pg.mfd.PFDInstruments.topMenu); |
| 280 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 281 |
device.updateMenus(); |
| 282 |
}, |
| 283 |
|
| 284 |
codeMenu : func(device, pg, menuitem) { |
| 285 |
pg.clearMenu(); |
| 286 |
pg.resetMenuColors(); |
| 287 |
pg.addMenuItem(0, "0", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 288 |
pg.addMenuItem(1, "1", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 289 |
pg.addMenuItem(2, "2", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 290 |
pg.addMenuItem(3, "3", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 291 |
pg.addMenuItem(4, "4", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 292 |
pg.addMenuItem(5, "5", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 293 |
pg.addMenuItem(6, "6", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 294 |
pg.addMenuItem(7, "7", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 295 |
pg.addMenuItem(8, "IDENT", pg, pg.mfd.PFDInstruments.setIdent); |
| 296 |
pg.addMenuItem(9, "BKSP", pg, pg.mfd.PFDInstruments.setTransponderDigit); |
| 297 |
pg.addMenuItem(10, "BACK", pg, pg.mfd.PFDInstruments.transponderMenu); |
| 298 |
pg.addMenuItem(11, "ALERTS", pg); # TODO |
| 299 |
device.updateMenus(); |
| 300 |
}, |
| 301 |
|
| 302 |
setTransponderMode : func(device, pg, menuitem) { |
| 303 |
# Get the transponder mode from the menuitem itself. |
| 304 |
pg.getController().setTransponderMode(menuitem.title); |
| 305 |
}, |
| 306 |
|
| 307 |
setVFR : func(device, pg, menuitem) { |
| 308 |
pg.getController().setVFRTransponderCode(); |
| 309 |
}, |
| 310 |
|
| 311 |
setIdent : func(device, pg, menuitem) { |
| 312 |
# Ident the transponder |
| 313 |
pg.getController().setTransponderIdent(1); |
| 314 |
}, |
| 315 |
|
| 316 |
setTransponderDigit: func(device, pg, menuitem) { |
| 317 |
# Set a transponder digit. Get digit from menu item. |
| 318 |
pg.getController().setTransponderDigit(menuitem.title); |
| 319 |
}, |
| 320 |
|
| 321 |
offdisplay : func() { |
| 322 |
me._group.setVisible(0); |
| 323 |
|
| 324 |
# Reset the menu colours. Shouldn't have to do this here, but |
| 325 |
# there's not currently an obvious other location to do so. |
| 326 |
for(var i = 0; i < 12; i +=1) { |
| 327 |
var name = sprintf("SoftKey%d",i); |
| 328 |
me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0); |
| 329 |
me.device.svg.getElementById(name).setColor(1.0,1.0,1.0); |
| 330 |
} |
| 331 |
me.getController().offdisplay(); |
| 332 |
}, |
| 333 |
ondisplay : func() { |
| 334 |
me._group.setVisible(1); |
| 335 |
me.getController().ondisplay(); |
| 336 |
}, |
| 337 |
|
| 338 |
updateAI: func(pitch, roll, slip) { |
| 339 |
if (pitch > 80) |
| 340 |
pitch = 80; |
| 341 |
elsif (pitch < -80) |
| 342 |
pitch = -80; |
| 343 |
me.getElement("Horizon") |
| 344 |
.setCenter(459, 282.8 - 6.849 * pitch) |
| 345 |
.setRotation(-roll * D2R) |
| 346 |
.setTranslation(0, pitch * 6.849); |
| 347 |
me.getElement("bankPointer") |
| 348 |
.setRotation(-roll * D2R); |
| 349 |
me.getElement("SlipSkid") |
| 350 |
.setTranslation(-20 * slip, 0); |
| 351 |
}, |
| 352 |
|
| 353 |
updateFD : func(enabled, pitch, roll, fd_pitch, fd_roll) { |
| 354 |
if (enabled) { |
| 355 |
me.getElement("FlightDirector") |
| 356 |
.setCenter(459,282.8) |
| 357 |
.setRotation(-(roll - fd_roll) * D2R) |
| 358 |
.setTranslation(0, -(fd_pitch - pitch) * 6.849) |
| 359 |
.setVisible(1); |
| 360 |
me._fd_enabled = 1; |
| 361 |
} else if (me._fd_enabled == 1) { |
| 362 |
me.getElement("FlightDirector").setVisible(0); |
| 363 |
me._fd_enabled = 0; |
| 364 |
} |
| 365 |
|
| 366 |
# Overrides - command bars disappear if pitch exceeeds -20/+30, roll 65 |
| 367 |
if ((pitch < -20.0) or (pitch > 30.0) or (roll < -65.0) or (roll > 65.0)) { |
| 368 |
me.getElement("FlightDirector").setVisible(0); |
| 369 |
} |
| 370 |
}, |
| 371 |
|
| 372 |
updateIAS: func (ias, ias_trend) { |
| 373 |
if (ias >= 10) { |
| 374 |
me.setTextElement("Speed110", sprintf("% 2u",num(math.floor(ias/10)))); |
| 375 |
} else { |
| 376 |
me.setTextElement("Speed110", ""); |
| 377 |
} |
| 378 |
|
| 379 |
me.getElement("SpeedLint1").setTranslation(0,(math.mod(ias,10) + (ias >= 10)*10) * 36); |
| 380 |
me.getElement("SpeedTape").setTranslation(0,ias * 5.711); |
| 381 |
|
| 382 |
ias_trend = math.clamp(ias_trend, -30, 30); |
| 383 |
me.getElement("Airspeed-Trend-Indicator") |
| 384 |
.setScale(1,ias_trend) |
| 385 |
.setTranslation(0, -284.5 * (ias_trend - 1)); |
| 386 |
|
| 387 |
var vne = me.mfd.ConfigStore.get("Vne"); |
| 388 |
|
| 389 |
if (ias > vne and ! me._ias_already_exceeded) { |
| 390 |
me._ias_already_exceeded = 1; |
| 391 |
me.getElement("IAS-bg").setColorFill(1,0,0); |
| 392 |
} elsif (ias < vne and me._ias_already_exceeded) { |
| 393 |
me._ias_already_exceeded = 0; |
| 394 |
me.getElement("IAS-bg").setColorFill(0,0,0); |
| 395 |
} |
| 396 |
|
| 397 |
foreach (var v; ["Vx", "Vy", "Vr", "Vglide"]) { |
| 398 |
var spd = me.mfd.ConfigStore.get(v); |
| 399 |
var visible = me.mfd.ConfigStore.get(v ~ "-visible"); |
| 400 |
if (visible and abs(spd - ias) < 30) { |
| 401 |
me.getElement("IAS-" ~ v) |
| 402 |
.setTranslation(0, (ias - spd) * 5.711) |
| 403 |
.show(); |
| 404 |
} else { |
| 405 |
me.getElement("IAS-" ~ v).hide(); |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
if ((me._selected_spd_visible) and ((me._selected_spd - ias) < 30)) { |
| 410 |
me.getElement("SelectedSPD-bug") |
| 411 |
.setTranslation(0, (ias - me._selected_spd) * 5.711) |
| 412 |
.show(); |
| 413 |
} else { |
| 414 |
me.getElement("SelectedSPD-bug").hide(); |
| 415 |
} |
| 416 |
}, |
| 417 |
|
| 418 |
updateVSI: func (vsi) { |
| 419 |
me.getElement("VSI").setTranslation(0, math.clamp(vsi, -4500, 4500) * -0.03465); |
| 420 |
me.setTextElement("VSIText", num(math.round(vsi, 10))); |
| 421 |
}, |
| 422 |
|
| 423 |
updateTAS: func (tas) { |
| 424 |
me.setTextElement("TAS-text", sprintf("%iKT", tas)); |
| 425 |
#me.getElement("GSPD-text").setText(sprintf("%iKT", tas)); |
| 426 |
}, |
| 427 |
|
| 428 |
updateGS : func (deflection_norm, type) { |
| 429 |
me.getElement("GS-ILS").setTranslation(0, - deflection_norm * 100); |
| 430 |
me.setTextElement("GS-type", type); |
| 431 |
}, |
| 432 |
|
| 433 |
updateALT: func (alt, alt_trend, selected_alt) { |
| 434 |
if (alt < 0) { |
| 435 |
me.setTextElement("Alt11100", sprintf("-% 3i",abs(math.ceil(alt/100)))); |
| 436 |
} elsif (alt < 100) { |
| 437 |
me.setTextElement("Alt11100", ""); |
| 438 |
} else { |
| 439 |
me.setTextElement("Alt11100", sprintf("% 3i",math.floor(alt/100))); |
| 440 |
} |
| 441 |
|
| 442 |
me.getElement("AltLint00011").setTranslation(0,math.fmod(alt,100) * 1.24); |
| 443 |
|
| 444 |
if (alt> -1000 and alt< 1000000) { |
| 445 |
var Offset10 = 0; |
| 446 |
var Offset100 = 0; |
| 447 |
var Offset1000 = 0; |
| 448 |
var Ne = 0; |
| 449 |
var Alt10 = math.mod(alt,100); |
| 450 |
var Alt100 = int(math.mod(alt/100,10)); |
| 451 |
var Alt1000 = int(math.mod(alt/1000,10)); |
| 452 |
var Alt10000 = int(math.mod(alt/10000,10)); |
| 453 |
var Alt20 = math.mod(Alt10,20)/20; |
| 454 |
|
| 455 |
|
| 456 |
if (alt< 0) { |
| 457 |
var Ne = 1; |
| 458 |
var alt= -alt; |
| 459 |
} |
| 460 |
|
| 461 |
if (Alt10 >= 80) Alt100 += Alt20; |
| 462 |
if (Alt10 >= 80 and Alt100 >= 9) Alt1000 += Alt20; |
| 463 |
if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9) Alt10000 += Alt20; |
| 464 |
if (alt> 100) Offset10 = 100; |
| 465 |
if (alt> 1000) Offset100 = 10; |
| 466 |
if (alt> 10000) Offset1000 = 10; |
| 467 |
|
| 468 |
if (Ne) { |
| 469 |
me.getElement("LintAlt").setTranslation(0,(math.mod(alt,100))*-0.57375); |
| 470 |
var altCentral = -(int(alt/100)*100); |
| 471 |
} else { |
| 472 |
me.getElement("LintAlt").setTranslation(0,(math.mod(alt,100))*0.57375); |
| 473 |
var altCentral = (int(alt/100)*100); |
| 474 |
} |
| 475 |
|
| 476 |
me.setTextElement("AltBigC", ""); |
| 477 |
me.setTextElement("AltSmallC", ""); |
| 478 |
for (var place = 1; place <= 6; place += 1) { |
| 479 |
var altUP = altCentral + (place*100); |
| 480 |
var altDOWN = altCentral - (place*100); |
| 481 |
var offset = -30.078; |
| 482 |
var prefix = ""; |
| 483 |
|
| 484 |
if (altUP < 0) { |
| 485 |
altUP = -altUP; |
| 486 |
prefix = "-"; |
| 487 |
offset += 15.039; |
| 488 |
} |
| 489 |
var AltBigUP = ""; |
| 490 |
var AltSmallUP = "0"; |
| 491 |
|
| 492 |
if (altUP == 0) { |
| 493 |
AltBigUP = ""; |
| 494 |
AltSmallUP = "0"; |
| 495 |
} elsif (math.mod(altUP,500) == 0 and altUP != 0) { |
| 496 |
AltBigUP = sprintf(prefix~"%1d", altUP); |
| 497 |
AltSmallUP = ""; |
| 498 |
} elsif (altUP < 1000 and (math.mod(altUP,500))) { |
| 499 |
AltBigUP = ""; |
| 500 |
AltSmallUP = sprintf(prefix~"%1d", int(math.mod(altUP,1000))); |
| 501 |
offset = -30.078; |
| 502 |
} elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) { |
| 503 |
AltBigUP = sprintf(prefix~"%1d", int(altUP/1000)); |
| 504 |
AltSmallUP = sprintf("%1d", int(math.mod(altUP,1000))); |
| 505 |
offset += 15.039; |
| 506 |
} else { |
| 507 |
AltBigUP = sprintf(prefix~"%1d", int(altUP/1000)); |
| 508 |
mod = int(math.mod(altUP,1000)); |
| 509 |
AltSmallUP = sprintf("%1d", mod); |
| 510 |
offset += 30.078; |
| 511 |
} |
| 512 |
|
| 513 |
me.getElement("AltBigU"~place).setText(AltBigUP); |
| 514 |
me.getElement("AltSmallU"~place).setText(AltSmallUP); |
| 515 |
me.getElement("AltSmallU"~place).setTranslation(offset,0); |
| 516 |
|
| 517 |
offset = -30.078; |
| 518 |
prefix = ""; |
| 519 |
if (altDOWN < 0) { |
| 520 |
altDOWN = -altDOWN; |
| 521 |
prefix = "-"; |
| 522 |
offset += 15.039; |
| 523 |
} |
| 524 |
|
| 525 |
if (altDOWN == 0) { |
| 526 |
AltBigDOWN = ""; |
| 527 |
AltSmallDOWN = "0"; |
| 528 |
} elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) { |
| 529 |
AltBigDOWN = sprintf(prefix~"%1d", altDOWN); |
| 530 |
AltSmallDOWN = ""; |
| 531 |
} elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) { |
| 532 |
AltBigDOWN = ""; |
| 533 |
AltSmallDOWN = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000))); |
| 534 |
offset = -30.078; |
| 535 |
} elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) { |
| 536 |
AltBigDOWN = sprintf(prefix~"%1d", int(altDOWN/1000)); |
| 537 |
AltSmallDOWN = sprintf("%1d", int(math.mod(altDOWN,1000))); |
| 538 |
offset += 15.039; |
| 539 |
} else { |
| 540 |
AltBigDOWN = sprintf(prefix~"%1d", int(altDOWN/1000)); |
| 541 |
AltSmallDOWN = sprintf("%1d", int(math.mod(altDOWN,1000))); |
| 542 |
offset += 30.078; |
| 543 |
} |
| 544 |
|
| 545 |
me.getElement("AltBigD"~place).setText(AltBigDOWN); |
| 546 |
me.getElement("AltSmallD"~place).setText(AltSmallDOWN); |
| 547 |
me.getElement("AltSmallD"~place).setTranslation(offset,0); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
alt_trend = math.clamp(alt_trend, -15, 15); |
| 552 |
me.getElement("Altitude-Trend-Indicator") |
| 553 |
.setScale(1,alt_trend) |
| 554 |
.setTranslation(0, -284.5 * (alt_trend - 1)); |
| 555 |
|
| 556 |
var delta_alt = alt - selected_alt; |
| 557 |
delta_alt = math.clamp(delta_alt, -300, 300); |
| 558 |
me.getElement("SelectedALT-bug").setTranslation(0, delta_alt * 0.567); # 170/300 = 0.567 |
| 559 |
}, |
| 560 |
|
| 561 |
updateBARO : func (baro) { |
| 562 |
# TODO: Support hPa and inhg |
| 563 |
#var fmt = me._baro_unit == "inhg" ? "%.2fin" : "%i%shPa"; |
| 564 |
var fmt = "%.2fIN"; |
| 565 |
me.setTextElement("BARO-text", sprintf(fmt, baro)); |
| 566 |
}, |
| 567 |
|
| 568 |
updateOAT : func (oat) { |
| 569 |
# TODO: Support FAHRENHEIT |
| 570 |
me.setTextElement("OAT-text", sprintf((abs(oat) < 10) ? "%.1f %s" : "%i %s", oat, "°C")); |
| 571 |
}, |
| 572 |
|
| 573 |
updateTime : func (time_sec) { |
| 574 |
var sec = math.mod(time_sec, 60); |
| 575 |
var mins = math.mod((time_sec - sec) / 60, 60); |
| 576 |
var hours = math.mod((time_sec - mins - sec) / 3600, 12); |
| 577 |
me.setTextElement("TIME-text", sprintf("%02d:%02d:%02d", hours, mins, sec)); |
| 578 |
}, |
| 579 |
|
| 580 |
updateHSI : func (hdg) { |
| 581 |
me.getElement("Rose").setRotation(-hdg * D2R); |
| 582 |
me.setTextElement("HDG-text", sprintf("%03u°", hdg)); |
| 583 |
}, |
| 584 |
|
| 585 |
updateHDG : func (hdg) { |
| 586 |
me.getElement("Heading-bug").setRotation(hdg * D2R); |
| 587 |
me.setTextElement("SelectedHDG-text", sprintf("%03d°%s", hdg, "")); |
| 588 |
}, |
| 589 |
|
| 590 |
# Indicate the selected course, from a given source (OFF, NAV, GPS) |
| 591 |
updateCRS : func (crs) { |
| 592 |
me.getElement("SelectedCRS-text") |
| 593 |
.setText(sprintf("%03d°%s", crs, "")) |
| 594 |
.setColor(me.getController().getCDISource() == "GPS" ? me.COLORS.magenta : me.COLORS.green); |
| 595 |
}, |
| 596 |
|
| 597 |
updateSelectedALT : func (selected_alt) { |
| 598 |
me.setTextElement("SelectedALT-text", sprintf("%i", selected_alt)); |
| 599 |
}, |
| 600 |
|
| 601 |
setSelectedSPDVisible : func(visible) { |
| 602 |
me._selected_spd_visible = visible; |
| 603 |
if (visible) { |
| 604 |
me.getElement("SelectedSPD-text").show(); |
| 605 |
me.getElement("SelectedSPD-bg").show(); |
| 606 |
me.getElement("SelectedSPD-bug").show(); |
| 607 |
me.getElement("SelectedSPD-symbol").show(); |
| 608 |
} else { |
| 609 |
me.getElement("SelectedSPD-text").hide(); |
| 610 |
me.getElement("SelectedSPD-bg").hide(); |
| 611 |
me.getElement("SelectedSPD-bug").hide(); |
| 612 |
me.getElement("SelectedSPD-symbol").hide(); |
| 613 |
} |
| 614 |
}, |
| 615 |
|
| 616 |
updateSelectedSPD : func (selected_spd) { |
| 617 |
me._selected_spd = selected_spd; |
| 618 |
me.setTextElement("SelectedSPD-text", sprintf("%ikt", me._selected_spd)); |
| 619 |
}, |
| 620 |
|
| 621 |
setBRG1 : func(option) { me._setBRG("BRG1",option); }, |
| 622 |
setBRG2 : func(option) { me._setBRG("BRG2",option); }, |
| 623 |
|
| 624 |
_setBRG : func (brg, option) { |
| 625 |
if (option == "OFF") { |
| 626 |
me.getElement(brg).hide(); |
| 627 |
me.getElement(brg ~ "-pointer").hide(); |
| 628 |
if ((me.getController().getBRG1() == "OFF") and (me.getController().getBRG2() == "OFF")) { |
| 629 |
# Hide the circle if there are now BRGs selected |
| 630 |
me.getElement("BRG-circle").hide(); |
| 631 |
} |
| 632 |
} else { |
| 633 |
me.getElement(brg).show(); |
| 634 |
me.getElement(brg ~ "-pointer").show(); |
| 635 |
me.getElement("BRG-circle").show(); |
| 636 |
|
| 637 |
me.getElement(brg ~ "-SRC-text").setText(option); |
| 638 |
me.getElement(brg ~ "-WPID-text").setText("----"); |
| 639 |
|
| 640 |
if (option == "ADF") { |
| 641 |
# Special case. We won't have a distance and the "ID" will be the ADF |
| 642 |
# frequency |
| 643 |
me.getElement(brg ~ "-DST-text").setText(""); |
| 644 |
} else { |
| 645 |
me.getElement(brg ~ "-DST-text").setText("--nm"); |
| 646 |
} |
| 647 |
} |
| 648 |
}, |
| 649 |
|
| 650 |
# Update BRG information |
| 651 |
updateBRG1 : func(valid, id, dst, current_heading, brg_heading) { |
| 652 |
me._updateBRG("BRG1", me.getController().getBRG1(), valid, id, dst, current_heading, brg_heading); |
| 653 |
}, |
| 654 |
updateBRG2 : func(valid, id, dst, current_heading, brg_heading) { |
| 655 |
me._updateBRG("BRG2", me.getController().getBRG2(), valid, id, dst, current_heading, brg_heading); |
| 656 |
}, |
| 657 |
_updateBRG : func (brg, source, valid, id, dst, current_heading, brg_heading) { |
| 658 |
if (source == "OFF") return; |
| 659 |
|
| 660 |
if (valid) { |
| 661 |
me.getElement(brg ~ "-SRC-text").setText(source); |
| 662 |
me.getElement(brg ~ "-WPID-text").setText(id); |
| 663 |
|
| 664 |
if (source == "ADF") { |
| 665 |
# Special case. We won't have a distance and the "ID" will be the ADF |
| 666 |
# frequency |
| 667 |
me.getElement(brg ~ "-DST-text").setText(""); |
| 668 |
} else { |
| 669 |
me.getElement(brg ~ "-DST-text").setText(sprintf("%.1fNM", dst)); |
| 670 |
} |
| 671 |
|
| 672 |
var rot = (brg_heading - current_heading) * D2R; |
| 673 |
me.getElement(brg ~ "-pointer").setRotation(rot).show(); |
| 674 |
} else { |
| 675 |
# Data is not valid - hide the pointer and display NO DATA |
| 676 |
me.getElement(brg ~ "-SRC-text").setText(source); |
| 677 |
me.getElement(brg ~ "-WPID-text").setText("NO DATA"); |
| 678 |
me.getElement(brg ~ "-DST-text").setText(""); |
| 679 |
me.getElement(brg ~ "-pointer").hide(); |
| 680 |
} |
| 681 |
}, |
| 682 |
|
| 683 |
toggleDME : func() { |
| 684 |
me.setDME(! me._DME); |
| 685 |
}, |
| 686 |
|
| 687 |
setDME : func (enabled) { |
| 688 |
me._DME = enabled; |
| 689 |
me.getElement("DME1").setVisible(enabled); |
| 690 |
}, |
| 691 |
|
| 692 |
updateDME : func (mode, freq, dst) { |
| 693 |
if (me._DME == 0) return; |
| 694 |
me.getElement("DME1-SRC-text").setText(mode); |
| 695 |
me.getElement("DME1-FREQ-text").setText(sprintf("%.2f", freq)); |
| 696 |
me.getElement("DME1-DST-text").setText(sprintf("%.2fNM", dst)); |
| 697 |
}, |
| 698 |
|
| 699 |
setCDISource : func(source) { |
| 700 |
foreach (var s; ["GPS", "NAV1", "NAV2"]) { |
| 701 |
me.getElement(s ~ "-pointer").setVisible(source == s); |
| 702 |
me.getElement(s ~ "-CDI").setVisible(source == s); |
| 703 |
me.getElement(s ~ "-FROM").setVisible(source == s); |
| 704 |
me.getElement(s ~ "-TO").setVisible(source == s); |
| 705 |
} |
| 706 |
|
| 707 |
me.getElement("CDI-SRC-text") |
| 708 |
.setText(source) |
| 709 |
.setColor(source == "GPS" ? me.COLORS.magenta : me.COLORS.green) |
| 710 |
.setVisible(source != "OFF"); |
| 711 |
}, |
| 712 |
|
| 713 |
updateCDI : func (heading, course, waypoint_valid, course_deviation_deg, deflection_dots, xtrk_nm, from, annun, loc) { |
| 714 |
|
| 715 |
var source = me.getController().getCDISource(); |
| 716 |
if (source == "OFF") return; |
| 717 |
|
| 718 |
# While the user selects between GPS, NAV1, NAV2, we display localizers as LOC1 and LOC2 |
| 719 |
if ((source == "NAV1") and (loc == 1)) me.getElement("CDI-SRC-text").setText("LOC1"); |
| 720 |
if ((source == "NAV2") and (loc == 1)) me.getElement("CDI-SRC-text").setText("LOC2"); |
| 721 |
|
| 722 |
if (waypoint_valid == 0) { |
| 723 |
me.getElement(source ~ "-CDI").hide(); |
| 724 |
me.getElement(source ~ "-FROM").hide(); |
| 725 |
me.getElement(source ~ "-TO").hide(); |
| 726 |
me.getElement(source ~ "-pointer").hide(); |
| 727 |
me.getElement("CDI").setRotation(0); |
| 728 |
me.getElement("GPS-CTI-diamond").hide(); |
| 729 |
me.getElement("CDI-GPS-XTK-text").hide(); |
| 730 |
me.getElement("CDI-GPS-ANN-text").setText("NO DATA").show(); |
| 731 |
} else { |
| 732 |
me.getElement(source ~ "-CDI").show(); |
| 733 |
|
| 734 |
var rot = (course - heading) * D2R; |
| 735 |
me.getElement("CDI").setRotation(rot).show(); |
| 736 |
me.getElement("GPS-CTI-diamond").setRotation(course_deviation_deg * D2R).setVisible(source == "GPS"); |
| 737 |
|
| 738 |
if ((source == "GPS") and (abs(deflection_dots) > 2.0)) { |
| 739 |
# Only display the cross-track error if the error exceeds the maximum |
| 740 |
# deflection of two dots. |
| 741 |
me.getElement("CDI-GPS-XTK-text") |
| 742 |
.setText(sprintf("XTK %.2fNM", abs(xtrk_nm))) |
| 743 |
.show(); |
| 744 |
} else { |
| 745 |
me.getElement("CDI-GPS-XTK-text").hide(); |
| 746 |
} |
| 747 |
|
| 748 |
if (source == "GPS") { |
| 749 |
me.getElement("CDI-GPS-ANN-text").setText(annun).show(); |
| 750 |
} else { |
| 751 |
me.getElement("CDI-GPS-ANN-text").hide(); |
| 752 |
} |
| 753 |
|
| 754 |
var scale = math.clamp(deflection_dots, -2.4, 2.4); |
| 755 |
me.getElement(source ~ "-CDI").setTranslation(80 * scale / 2.4, 0); |
| 756 |
|
| 757 |
# Display the appropriate TO/FROM indication for the selected source, |
| 758 |
# switching all others off. |
| 759 |
me.getElement(source ~ "-TO").setVisible(from == 0); |
| 760 |
me.getElement(source ~ "-FROM").setVisible(from); |
| 761 |
} |
| 762 |
}, |
| 763 |
|
| 764 |
# Update the wind display. There are three options: |
| 765 |
# 0 - No wind data displayed |
| 766 |
# 1 - Numeric headwind and crosswind components |
| 767 |
# 2 - Direction arrow and numeric speed |
| 768 |
# 3 - Direction arrow, and numeric True direction and speet |
| 769 |
setWindDisplay : func(option) { |
| 770 |
me.getElement("WindData").setVisible(option != 0); |
| 771 |
me.getElement("WindData-OPTN1").setVisible(option == 1); |
| 772 |
me.getElement("WindData-OPTN2").setVisible(option == 2); |
| 773 |
me.getElement("WindData-OPTN3").setVisible(option == 3); |
| 774 |
|
| 775 |
me._windDataDisplay = option; |
| 776 |
}, |
| 777 |
|
| 778 |
updateWindData : func (hdg, wind_hdg, wind_spd, no_data) { |
| 779 |
if (no_data and (me._windDataDisplay > 0)) { |
| 780 |
me.getElement("WindData-NODATA").show(); |
| 781 |
me.getElement("WindData-NODATA-bg").show(); |
| 782 |
return; |
| 783 |
} else { |
| 784 |
me.getElement("WindData-NODATA").hide(); |
| 785 |
me.getElement("WindData-NODATA-bg").hide(); |
| 786 |
} |
| 787 |
|
| 788 |
var alpha = (wind_hdg - hdg); |
| 789 |
|
| 790 |
# Stop the wind arrows oscillating |
| 791 |
if (wind_spd < 1) { |
| 792 |
alpha = 0; |
| 793 |
wind_hdg = 0; |
| 794 |
} |
| 795 |
|
| 796 |
if (me._windDataDisplay == 0) { |
| 797 |
me.getElement("WindData").hide(); |
| 798 |
} elsif (me._windDataDisplay == 1) { |
| 799 |
# Headwind/Crosswind numeric display |
| 800 |
var Vt = wind_spd * math.sin(alpha * D2R); |
| 801 |
var Ve = wind_spd * math.cos(alpha * D2R); |
| 802 |
me.getElement("WindData-OPTN1-crosswind-text").setText(sprintf("%i", abs(Vt))); |
| 803 |
me.getElement("WindData-OPTN1-crosswind").setRotation(Vt > 0.1 ? 180*D2R : 0); |
| 804 |
me.getElement("WindData-OPTN1-headwind-text").setText(sprintf("%i", abs(Ve))); |
| 805 |
me.getElement("WindData-OPTN1-headwind").setRotation(Ve > 0.1 ? 180*D2R : 0); |
| 806 |
} elsif (me._windDataDisplay == 2) { |
| 807 |
# Direction arrow and numeric speed |
| 808 |
me.getElement("WindData-OPTN2-HDG").setRotation((alpha + 180) * D2R); |
| 809 |
me.getElement("WindData-OPTN2-SPD-text").setText(sprintf("%i", wind_spd)); |
| 810 |
} elsif (me._windDataDisplay == 3) { |
| 811 |
# Direction arrow with numeric true direction and speed |
| 812 |
me.getElement("WindData-OPTN3-HDG").setRotation((alpha + 180) * D2R); |
| 813 |
me.getElement("WindData-OPTN3-HDG-text").setText(sprintf("%03i°T", wind_hdg)); |
| 814 |
me.getElement("WindData-OPTN3-SPD-text").setText(sprintf("%iKT", wind_spd)); |
| 815 |
} else { |
| 816 |
print("Unknown wind data option " ~ me._windDataDisplay); |
| 817 |
} |
| 818 |
}, |
| 819 |
|
| 820 |
# Enable/disable the multiline display on the right hand side of the PFD |
| 821 |
setMultiline : func(enabled) { |
| 822 |
me._Multiline = enabled; |
| 823 |
me.getElement("PFD-Multilines").setVisible(enabled); |
| 824 |
}, |
| 825 |
|
| 826 |
# Enable/disable the warning annunication window. |
| 827 |
setAnnunciation : func(enabled) { |
| 828 |
me._annunciation = enabled; |
| 829 |
me.getElement("Annunciation").setVisible(enabled); |
| 830 |
}, |
| 831 |
|
| 832 |
# set the Outer, Middle, Inner indicator |
| 833 |
setOMI : func(omi) { |
| 834 |
if (omi == "") { |
| 835 |
me.getElement("OMI").hide(); |
| 836 |
} else { |
| 837 |
me.getElement("OMI").show(); |
| 838 |
me.setTextElement("MarkerText", omi); |
| 839 |
} |
| 840 |
me._OMI = omi; |
| 841 |
}, |
| 842 |
|
| 843 |
setInsetMapVisible :func(enabled ) { |
| 844 |
me.getElement("PFD-Map").setVisible(enabled); |
| 845 |
me.getElement("PFD-Map-bg").setVisible(enabled); |
| 846 |
me.insetMap.setVisible(enabled); |
| 847 |
}, |
| 848 |
|
| 849 |
setFlightPlanVisible : func(enabled) { |
| 850 |
me.getElement("FlightPlanGroup").setVisible(enabled); |
| 851 |
}, |
| 852 |
|
| 853 |
# Update the FlightPlan display with an updated flightplan. |
| 854 |
setFlightPlan : func(fp) { |
| 855 |
var elements = []; |
| 856 |
|
| 857 |
if (fp == nil) return; |
| 858 |
|
| 859 |
var current_wp = fp.current; |
| 860 |
|
| 861 |
for (var i = 0; i < fp.getPlanSize(); i = i + 1) { |
| 862 |
var wp = fp.getWP(i); |
| 863 |
|
| 864 |
var element = { |
| 865 |
FlightPlanArrow : 0, |
| 866 |
FlightPlanID : "", |
| 867 |
FlightPlanType : "", |
| 868 |
FlightPlanDTK : 0, |
| 869 |
FlightPlanDIS : 0, |
| 870 |
}; |
| 871 |
|
| 872 |
if (wp.wp_name != nil) element.FlightPlanID = substr(wp.wp_name, 0, 7); |
| 873 |
if (wp.wp_role != nil) element.FlightPlanType = substr(wp.wp_role, 0, 4); |
| 874 |
|
| 875 |
if (i < current_wp) { |
| 876 |
# Passed waypoints are blanked out on the display |
| 877 |
element.FlightPlanDIS = "___nm"; |
| 878 |
element.FlightPlanDTK = "___°"; |
| 879 |
} else { |
| 880 |
if (wp.leg_distance != nil) element.FlightPlanDIS = sprintf("%.1fnm", wp.leg_distance); |
| 881 |
if (wp.leg_bearing != nil) element.FlightPlanDTK = sprintf("%03d°", wp.leg_bearing); |
| 882 |
} |
| 883 |
append(elements, element); |
| 884 |
} |
| 885 |
|
| 886 |
me.flightplanList.setValues(elements); |
| 887 |
me.flightplanList.setCRSR(current_wp); |
| 888 |
|
| 889 |
# Determine a suitable name to display, using the flightplan name if there is one, |
| 890 |
# but falling back to the flightplan departure / destination airports, or failing |
| 891 |
# that the IDs of the first and last waypoints. |
| 892 |
if ((fp.id == nil) or (fp.id == "default-flightplan")) { |
| 893 |
var from = "????"; |
| 894 |
var dest = "????"; |
| 895 |
|
| 896 |
if ((fp.getWP(0) != nil) and (fp.getWP(0).wp_name != nil)) { |
| 897 |
from = fp.getWP(0).wp_name; |
| 898 |
} |
| 899 |
|
| 900 |
if ((fp.getWP(fp.getPlanSize() -1) != nil) and (fp.getWP(fp.getPlanSize() -1).wp_name != nil)) { |
| 901 |
dest = fp.getWP(fp.getPlanSize() -1).wp_name; |
| 902 |
} |
| 903 |
|
| 904 |
if (fp.departure != nil) from = fp.departure.id; |
| 905 |
if (fp.destination != nil) dest = fp.destination.id; |
| 906 |
me.getElement("FlightPlanName").setText(from ~ " / " ~ dest); |
| 907 |
} else { |
| 908 |
me.getElement("FlightPlanName").setText(fp.id); |
| 909 |
} |
| 910 |
}, |
| 911 |
|
| 912 |
# Update the FlightPlan display to indicate the current waypoint |
| 913 |
updateFlightPlan : func(current_wp) { |
| 914 |
if (current_wp == -1) return; |
| 915 |
me.flightplanList.setCRSR(current_wp); |
| 916 |
me.flightplanList.displayGroup(); |
| 917 |
}, |
| 918 |
|
| 919 |
# Update the Transponder display |
| 920 |
updateTransponder : func(mode, code, ident, edit=0) { |
| 921 |
# Data validation on the mode and code itself |
| 922 |
if (mode < 0) mode = 0; |
| 923 |
if (mode > 5) mode = 5; |
| 924 |
if ((code == nil) or (! isnum(code))) code = 0; |
| 925 |
|
| 926 |
# Ensure the code is a 4 digit string representation of a number. |
| 927 |
# Normally this means padding with 0's at the left e.g. 42 becomes 0042. |
| 928 |
# In editing mode we enter values from the left, so we want " " padding on the |
| 929 |
# right, so 42 becomes "42 ". Note also that the code is a string value |
| 930 |
# so we can have "004 " |
| 931 |
if (edit) { |
| 932 |
code = sprintf("%-4s", code); |
| 933 |
} else { |
| 934 |
code = sprintf("%04i", code); |
| 935 |
} |
| 936 |
|
| 937 |
# Colour of display. White in OFF, STDBY, TEST modes, green in GND, ON, ALT |
| 938 |
var r = 1.0; |
| 939 |
var g = 1.0; |
| 940 |
var b = 1.0; |
| 941 |
if (mode > 2) { |
| 942 |
r = 0.2; |
| 943 |
g = 1.0; |
| 944 |
b = 0.2; |
| 945 |
} |
| 946 |
|
| 947 |
if (ident) { |
| 948 |
me.getElement("XPDR-MODE-text").setText("IDNT").setColor(r,g,b); |
| 949 |
} else { |
| 950 |
me.getElement("XPDR-MODE-text").setText(TRANSPONDER_MODES[mode]).setColor(r,g,b); |
| 951 |
} |
| 952 |
|
| 953 |
var codes = split("", code); |
| 954 |
me.getElement("XPDR-DIGIT-3-text").setText(chr(code[0])).setColor(r,g,b); |
| 955 |
me.getElement("XPDR-DIGIT-2-text").setText(chr(code[1])).setColor(r,g,b); |
| 956 |
me.getElement("XPDR-DIGIT-1-text").setText(chr(code[2])).setColor(r,g,b); |
| 957 |
me.getElement("XPDR-DIGIT-0-text").setText(chr(code[3])).setColor(r,g,b); |
| 958 |
}, |
| 959 |
}; |