From ab8774a3e0aa3909ad284a65194f5d80dc097c6e Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Mon, 8 Jan 2018 21:39:39 +0000 Subject: [PATCH] Extend MFDPageController to handle Emesary register --- .../AirportInfo/AirportInfoController.nas | 42 +---- Aircraft/Instruments-3d/FG1000/Nasal/MFD.nas | 3 +- .../Instruments-3d/FG1000/Nasal/MFDPage.nas | 1 - .../FG1000/Nasal/MFDPageController.nas | 167 ++++++++++++++++++ .../Nasal/NavigationMap/NavigationMap.nas | 6 +- .../NavigationMap/NavigationMapController.nas | 96 +--------- .../NearestAirportsController.nas | 54 ++---- .../FG1000/Nasal/Surround/Surround.nas | 1 + .../Nasal/Surround/SurroundController.nas | 4 +- .../FG1000/Nasal/TrafficMap/TrafficMap.nas | 25 ++- .../Nasal/TrafficMap/TrafficMapController.nas | 75 ++------ Nasal/notifications.nas | 2 +- 12 files changed, 228 insertions(+), 248 deletions(-) create mode 100644 Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas index 0a75fd09f..1c315cf4a 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas @@ -24,7 +24,7 @@ var AirportInfoController = new : func (page, svg) { - var obj = { parents : [ AirportInfoController ] }; + var obj = { parents : [ AirportInfoController, MFDPageController.new(page)] }; obj.airport = ""; obj.runway = ""; obj.runwayIdx = -1; @@ -69,7 +69,7 @@ var AirportInfoController = zoomOut : func() { me.setZoom(me.current_zoom +1); }, - zoom : func(val) + handleRange : func(val) { var incr_or_decr = (val > 0) ? 1 : -1; me.setZoom(me.current_zoom + incr_or_decr); @@ -133,44 +133,6 @@ var AirportInfoController = return emesary.Transmitter.ReceiptStatus_NotProcessed; } }, - RegisterWithEmesary : func(transmitter = nil){ - if (transmitter == nil) - transmitter = emesary.GlobalTransmitter; - - if (me._recipient == nil){ - me._recipient = emesary.Recipient.new("AirportInfoController_" ~ me.page.device.designation); - var pfd_obj = me.page.device; - var controller = me; - me._recipient.Receive = func(notification) - { - if (notification.Device_Id == pfd_obj.device_id - and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { - if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed - and notification.EventParameter != nil) - { - var id = notification.EventParameter.Id; - var value = notification.EventParameter.Value; - #printf("Button pressed " ~ id ~ " " ~ value); - if (id == fg1000.FASCIA.FMS_CRSR) return controller.handleCRSR(); - if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value); - if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value); - if (id == fg1000.FASCIA.RANGE) return controller.zoom(value); - if (id == fg1000.FASCIA.ENT) return controller.handleEnter(value); - if (id == fg1000.FASCIA.CLR) return controller.handleClear(value); - } - } - 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() { diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFD.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFD.nas index 548e62c85..fd5c8091a 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/MFD.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFD.nas @@ -9,6 +9,7 @@ io.include("constants.nas"); var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/"; io.load_nasal(nasal_dir ~ '/MFDPage.nas', "fg1000"); +io.load_nasal(nasal_dir ~ '/MFDPageController.nas', "fg1000"); var MFDPages = [ "Surround", @@ -67,7 +68,7 @@ var MFD = parents : [ MFD ], EIS : nil, NavigationMap: nil, - Surround : nil, + Surround : nil, }; obj._svg = myCanvas.createGroup("softkeys"); diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPage.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPage.nas index 490dbe18a..224ecf4a5 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPage.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPage.nas @@ -51,7 +51,6 @@ addTextElements : func(symbols) { getTextElement : func(symbolName) { return me._symbols[symbolName]; - assert(sym != nil, "Unknown text element " ~ symbolName ~ " (check your addTextElements call?)"); }, getTextValue : func(symbolName) { diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas new file mode 100644 index 000000000..b71e08bd8 --- /dev/null +++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas @@ -0,0 +1,167 @@ +# Standard MFDPage Controller +# +# This should be extended by specific page controllers and the handle...() +# methods over-ridden to provide specific functions for the MFD buttons. + +var MFDPageController = { + +new : func (page) +{ + var obj = { parents : [ MFDPageController ] }; + + # Emesary + obj._recipient = nil; + obj._page = page; + obj._transmitter = emesary.GlobalTransmitter; + obj._registered = 0; + + + return obj; +}, + +# Default handlers for all the Fascia hardkeys. These should be over-ridden +# as required by specific page function. + +handleNavVol : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleNavVolToggle : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleNavFreqTransfer : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleNavOuter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleNavInner : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleToggle : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleHeading : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleHeadingPress : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +# Joystick +handleRange : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleJoystickHorizontal : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleJoystickHorizontal : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +#CRS/BARO +handleBaro : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleCRS : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleCRSCenter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +handleComOuter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleComInner : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleComToggle : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +handleFreqTransfer : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleFreqTransferHold : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Auto-tunes to 121.2 when pressed for 2 seconds + +handleComVol : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleComVolToggle : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },, + +handleDTO : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleFPL : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleCLR : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleCLRHold : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +# By default, the FMS knobs will select a new page. +handleFMSOuter : func (value) { return me.page.mfd._pageGroupController.handleFMSOuter(value); }, +handleFMSOuter : func (value) { return me.page.mfd._pageGroupController.handleFMSInner(value); }, +handleCRSR : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +handleMenu : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleProc : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleEnter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +handleAltOuter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, +handleAltInner : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, + +RegisterWithEmesary : func() +{ + if (me._recipient == nil){ + me._recipient = emesary.Recipient.new("MFDPageController_" ~ me.page.device.designation); + var pfd_obj = me.page.device; + var controller = me; + me._recipient.Receive = func(notification) + { + if (notification.Device_Id == pfd_obj.device_id + and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { + if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed + and notification.EventParameter != nil) + { + var id = notification.EventParameter.Id; + var value = notification.EventParameter.Value; + + #printf("Button pressed " ~ id ~ " " ~ value); + + if (id == fg1000.FASCIA.NAV_VOL) return controller.handleNavVol(value); + if (id == fg1000.FASCIA.NAV_VOL_TOGGLE) return controller.handleNavVolToggle(value); + if (id == fg1000.FASCIA.NAV_FREQ_TRANSFER) return controller.handleNavFreqTransfer(value); + if (id == fg1000.FASCIA.NAV_OUTER) return controller.handleNavOuter(value); + if (id == fg1000.FASCIA.NAV_INNER) return controller.handleNavInner(value); + if (id == fg1000.FASCIA.NAV_TOGGLE) return controller.handleToggle(value); + if (id == fg1000.FASCIA.HEADING) return controller.handleHeading(value); + if (id == fg1000.FASCIA.HEADING_PRESS) return controller.handleHeadingPress(value); + + # Joystick + if (id == fg1000.FASCIA.RANGE) return controller.handleRange(value); + if (id == fg1000.FASCIA.JOYSTICK_HORIZONTAL) return controller.handleJoystickHorizontal(value); + if (id == fg1000.FASCIA.JOYSTICK_VERTICAL) return controller.handleJoystickHorizontal(value); + + #CRS/BARO + if (id == fg1000.FASCIA.BARO) return controller.handleBaro(value); + if (id == fg1000.FASCIA.CRS) return controller.handleCRS(value); + if (id == fg1000.FASCIA.CRS_CENTER) return controller.handleCRSCenter(value); + + if (id == fg1000.FASCIA.COM_OUTER) return controller.handleComOuter(value); + if (id == fg1000.FASCIA.COM_INNER) return controller.handleComInner(value); + if (id == fg1000.FASCIA.COM_TOGGLE) return controller.handleComToggle(value); + + if (id == fg1000.FASCIA.COM_FREQ_TRANSFER) return controller.handleFreqTransfer(value); + if (id == fg1000.FASCIA.COM_FREQ_TRANSFER_HOLD) return controller.handleFreqTransferHold(value); # Auto-tunes to 121.2 when pressed for 2 seconds + + if (id == fg1000.FASCIA.COM_VOL) return controller.handleComVol(value); + if (id == fg1000.FASCIA.COM_VOL_TOGGLE) return controller.handleComVolToggle(value); + + if (id == fg1000.FASCIA.DTO) return controller.handleDTO(value); + if (id == fg1000.FASCIA.FPL) return controller.handleFPL(value); + if (id == fg1000.FASCIA.CLR) return controller.handleClear(value); + if (id == fg1000.FASCIA.CLR_HOLD) return controller.handleClearHold(value); + + if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value); + if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value); + if (id == fg1000.FASCIA.FMS_CRSR) return controller.handleCRSR(value); + + if (id == fg1000.FASCIA.MENU) return controller.handleMenu(value); + if (id == fg1000.FASCIA.PROC) return controller.handleProc(value); + if (id == fg1000.FASCIA.ENT) return controller.handleEnter(value); + + if (id == fg1000.FASCIA.ALT_OUTER) return controller.handleAltOuter(value); + if (id == fg1000.FASCIA.ALT_INNER) return controller.handleAltInner(value); + + # Autopilot controls - ignore for now as like to be handled elsewhere + #if (id == fg1000.FASCIA.AP ) return controller.handle(value); + #if (id == fg1000.FASCIA.HDG) return controller.handle(value); + #if (id == fg1000.FASCIA.NAV) return controller.handle(value); + #if (id == fg1000.FASCIA.APR) return controller.handle(value); + #if (id == fg1000.FASCIA.VS ) return controller.handle(value); + #if (id == fg1000.FASCIA.FLC) return controller.handle(value); + #if (id == fg1000.FASCIA.FD ) return controller.handle(value); + #if (id == fg1000.FASCIA.ALT) return controller.handle(value); + #if (id == fg1000.FASCIA.VNV) return controller.handle(value); + #if (id == fg1000.FASCIA.BC ) return controller.handle(value); + #if (id == fg1000.FASCIA.NOSE_UP) return controller.handle(value); + #if (id == fg1000.FASCIA.NOSE_DOWN) return controller.handle(value); + } + } + return emesary.Transmitter.ReceiptStatus_NotProcessed; + }; + } + + me._transmitter.Register(me._recipient); + me._registered = 1; + +}, + +DeRegisterWithEmesary : func() +{ + # remove registration from transmitter; but keep the recipient once it is created. + if (me._registered == 1) me._transmitter.DeRegister(me._recipient); + me._registered = 0; +}, + + + +}; diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMap.nas b/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMap.nas index f8b707a01..0d37e4c59 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMap.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMap.nas @@ -132,11 +132,11 @@ var NavigationMap = me._labelsFull.setVisible(0); me._labelsPartial.setVisible(1); - me.controller.ondisplayPartial(); + #me.controller.ondisplayPartial(); }, offdisplayPartial : func() { me._group.setVisible(0); - me.controller.offdisplayPartial(); + #me.controller.offdisplayPartial(); }, # Softkey assigments. For some pages (notably the NEAREST pages) @@ -199,6 +199,4 @@ var NavigationMap = svg.setVisible(1); # display function }, - - }; diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMapController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMapController.nas index 7a8e6cb39..f72d721c2 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMapController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/NavigationMap/NavigationMapController.nas @@ -83,7 +83,7 @@ var NavigationMapController = new : func (page, svg) { - var obj = { parents : [ NavigationMapController ] }; + var obj = { parents : [ NavigationMapController, MFDPageController.new(page) ] }; obj.current_zoom = 8; obj.declutter = 0; obj.airways = 0; @@ -91,10 +91,6 @@ var NavigationMapController = obj.setZoom(obj.current_zoom); obj.setOrientation(obj.ORIENTATIONS[0]); - # Emesary - obj._recipient = nil; - obj._zoomRecipient = nil; - return obj; }, zoomIn : func() { @@ -103,11 +99,6 @@ var NavigationMapController = zoomOut : func() { me.setZoom(me.current_zoom +1); }, - zoom : func(val) - { - var incr_or_decr = (val > 0) ? 1 : -1; - me.setZoom(me.current_zoom + incr_or_decr); - }, setZoom : func(zoom) { if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return; me.current_zoom = zoom; @@ -186,41 +177,12 @@ var NavigationMapController = # bottom right of the screen return me.page.mfd._pageGroupController.handleFMSOuter(value); }, - RegisterWithEmesary : func(transmitter = nil) { - if (transmitter == nil) - transmitter = emesary.GlobalTransmitter; + handleRange : func(val) + { + var incr_or_decr = (val > 0) ? 1 : -1; + me.setZoom(me.current_zoom + incr_or_decr); + }, - if (me._recipient == nil){ - me._recipient = emesary.Recipient.new("NavMapController_" ~ me.page.device.designation); - var pfd_obj = me.page.device; - var controller = me; - me._recipient.Receive = func(notification) - { - if (notification.Device_Id == pfd_obj.device_id - and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { - if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed - and notification.EventParameter != nil) - { - var id = notification.EventParameter.Id; - var value = notification.EventParameter.Value; - #printf("Button pressed " ~ id ~ " " ~ value); - if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value); - if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value); - if (id == fg1000.FASCIA.RANGE) return controller.zoom(value); - } - } - 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(); @@ -229,50 +191,4 @@ var NavigationMapController = me.DeRegisterWithEmesary(); }, - # Set controller for cases where the NavigationMap is displayed as part of - # another page, e.g. NearestAirports - # - # In this case we are only interested in a subset of the buttons to control - # the map. - - RegisterZoomWithEmesary : func(transmitter = nil) { - if (transmitter == nil) - transmitter = emesary.GlobalTransmitter; - - if (me._zoomRecipient == nil){ - me._zoomRecipient = emesary.Recipient.new("NavMapController_" ~ me.page.device.designation); - var pfd_obj = me.page.device; - var controller = me; - me._zoomRecipient.Receive = func(notification) - { - if (notification.Device_Id == pfd_obj.device_id - and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { - if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed - and notification.EventParameter != nil) - { - var id = notification.EventParameter.Id; - var value = notification.EventParameter.Value; - #printf("Button pressed " ~ id ~ " " ~ value); - if (id == fg1000.FASCIA.RANGE) return controller.zoom(value); - } - } - return emesary.Transmitter.ReceiptStatus_NotProcessed; - }; - } - transmitter.Register(me._zoomRecipient); - me.zoomTransmitter = transmitter; - }, - DeRegisterZoomWithEmesary : func(transmitter = nil) { - # remove registration from transmitter; but keep the recipient once it is created. - if (me.zoomTransmitter != nil) - me.zoomTransmitter.DeRegister(me._zoomRecipient); - me.zoomTransmitter = nil; - }, - - ondisplayPartial : func() { - me.RegisterZoomWithEmesary(); - }, - offdisplayPartial : func() { - me.DeRegisterZoomWithEmesary(); - }, }; diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/NearestAirports/NearestAirportsController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/NearestAirports/NearestAirportsController.nas index 58cd39aaf..3650d0896 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/NearestAirports/NearestAirportsController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/NearestAirports/NearestAirportsController.nas @@ -11,16 +11,13 @@ var NearestAirportsController = new : func (page, svg) { - var obj = { parents : [ NearestAirportsController ] }; + var obj = { parents : [ NearestAirportsController, MFDPageController.new(page) ] }; # Current active UI group. obj.page = page; obj._currentGroup = NearestAirportsController.UIGROUP.NONE; obj._crsrToggle = 0; - # Emesary - obj._recipient = nil; - return obj; }, @@ -33,6 +30,16 @@ var NearestAirportsController = var radius = 0; var apts = []; + # + # TODO: Use Emesary to query APT data - allows support for multiple + # data sources / abstraction. + # + #var airportNotification = notifications.PFDEventNotification.new(blah); + #var response = Emesary.GlobalTransmitter.notifyAll(airportNotification); + #if (response.isSuccess()) { + # me.page.updateAirports(airportNotification.value); + #} + while ((radius <= 200) and (size(apts) < 25)) { radius = radius + 50; apts = findAirportsWithinRange(radius); @@ -169,43 +176,14 @@ var NearestAirportsController = return emesary.Transmitter.ReceiptStatus_NotProcessed; } }, - RegisterWithEmesary : func(transmitter = nil){ - if (transmitter == nil) - transmitter = emesary.GlobalTransmitter; - if (me._recipient == nil){ - me._recipient = emesary.Recipient.new("AirportInfoController_" ~ me.page.device.designation); - var pfd_obj = me.page.device; - var controller = me; - me._recipient.Receive = func(notification) - { - if (notification.Device_Id == pfd_obj.device_id - and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { - if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed - and notification.EventParameter != nil) - { - var id = notification.EventParameter.Id; - var value = notification.EventParameter.Value; - #printf("Button pressed " ~ id ~ " " ~ value); - if (id == fg1000.FASCIA.FMS_CRSR) return controller.handleCRSR(); - if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value); - if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value); - if (id == fg1000.FASCIA.ENT) return controller.handleEnter(value); - } - } - 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; + handleRange : func(val) + { + # Pass any range entries to the NavMapController + me.page.mfd.NavigationMap.controller.handleZoom(val); }, + # Reset controller if required when the page is displayed or hidden ondisplay : func() { me._currentGroup = NearestAirportsController.UIGROUP.NONE; diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/Surround/Surround.nas b/Aircraft/Instruments-3d/FG1000/Nasal/Surround/Surround.nas index 1662f7aa5..173289b26 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/Surround/Surround.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/Surround/Surround.nas @@ -190,6 +190,7 @@ var Surround = assert(page != nil, "Unable to find page " ~ pageToLoad); me.device.selectPage(page); + me.hideMenu(); }, incrPageGroup : func(val) { var incr_or_decr = (val > 0) ? 1 : -1; diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/Surround/SurroundController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/Surround/SurroundController.nas index 4b41c53ce..b51b713e8 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/Surround/SurroundController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/Surround/SurroundController.nas @@ -41,9 +41,9 @@ var SurroundController = { if (me._page.isMenuVisible()) { # Change page group - me.incrPage(val); + me._page.incrPage(val); } - me.showMenu(); + me._page.showMenu(); return emesary.Transmitter.ReceiptStatus_Finished; }, diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMap.nas b/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMap.nas index 4b5515b88..2fbf42634 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMap.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMap.nas @@ -13,10 +13,8 @@ var TrafficMap = obj.mapgroup = obj._group.createChild("map"); # Dynamic text elements - obj.op_label = svg.getElementById("TrafficMapOpMode"); - obj.alt_label = svg.getElementById("TrafficMapAltMode"); - obj.outer_label = svg.getElementById("TrafficMapOuterRange"); - obj.inner_label = svg.getElementById("TrafficMapInnerRange"); + var textelements = ["OpMode", "AltMode", "OuterRange", "InnerRange"]; + obj.addTextElements(textelements); # Initialize the controller: var ctrl_ns = canvas.Map.Controller.get("Aircraft position"); @@ -139,14 +137,29 @@ var TrafficMap = setLayerVisible : func(name,n=1) { me.mapgroup.getLayer(name).setVisible(n); }, + setOperate : func(enabled) { + if (enabled) { + me.setTextElement("OpMode", "OPERATING"); + } else { + me.setTextElement("OpMode", "STANDBY"); + } + + me.mapgroup.getLayer("TFC").setVisible(enabled); + }, setRange : func(range, inner_label, outer_label) { me.mapgroup.setRange(range); - me.inner_label.setText(inner_label); - me.outer_label.setText(outer_label); + me.setTextElement("OuterRange", outer_label); + me.setTextElement("InnerRange", inner_label); }, setScreenRange : func(range) { me.mapgroup.setScreenRange(range); }, + setAlt : func(floor_ft, ceiling_ft, label) { + me.setTextElement("AltMode", label); + # Update the TFC controller to filter out the correct targets + me.mapgroup.getLayer("TFC").options.floor_ft = floor_ft; + me.mapgroup.getLayer("TFC").options.ceiling_ft = ceiling_ft; + }, offdisplay : func() { me._group.setVisible(0); diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMapController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMapController.nas index 88cae8a49..8ba0fe16b 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMapController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/TrafficMap/TrafficMapController.nas @@ -23,7 +23,7 @@ var TrafficMapController = new : func (page, svg) { - var obj = { parents : [ TrafficMapController ] }; + var obj = { parents : [ TrafficMapController, MFDPageController.new(page) ] }; obj.range = 1; obj.alt = "NORMAL"; obj.operating = 0; @@ -35,6 +35,8 @@ var TrafficMapController = obj._recipient = nil; obj.setZoom(obj.range); + obj.setAlt(obj.alt); + obj.setOperate(obj.operating); return obj; }, zoomIn : func() { @@ -43,11 +45,6 @@ var TrafficMapController = zoomOut : func() { me.setZoom(me.current_zoom +1); }, - zoom : func(val) - { - var incr_or_decr = (val > 0) ? 1 : -1; - me.setZoom(me.current_zoom + incr_or_decr); - }, setZoom : func(zoom) { if ((zoom < 0) or (zoom > (size(me.RANGES) - 1))) return; me.current_zoom = zoom; @@ -58,22 +55,12 @@ var TrafficMapController = }, setAlt : func(alt) { if (me.ALTS[alt] == nil) return; - me.page.alt_label.setText(me.ALTS[alt].label); + me.page.setAlt(me.ALTS[alt].floor_ft, me.ALTS[alt].ceiling_ft, me.ALTS[alt].label); me.alt = alt; - # Update the TFC controller to filter out the correct targets - me.page.mapgroup.getLayer("TFC").options.ceiling_ft = me.ALTS[alt].ceiling_ft; - me.page.mapgroup.getLayer("TFC").options.floor_ft = me.ALTS[alt].floor_ft; }, setOperate : func(enabled) { - if (enabled) { - me.page.op_label.setText("OPERATING"); - me.page.setLayerVisible("TFC", 1); - me.operating = 1; - } else { - me.page.op_label.setText("STANDBY"); - me.page.setLayerVisible("TFC", 0); - me.operating = 0; - } + me.page.setOperate(enabled); + me.operating = enabled; }, setFlightID : func(enabled) { me.flight_id = enabled; @@ -91,52 +78,10 @@ var TrafficMapController = if (me.flight_id == 1 and label == "FLT ID") return 1; return 0; }, - handleFMSInner : func(value) { - # This page has no use for the FMS knob, so we pass all such - # events to the pageGroupController which displays the page menu in the - # bottom right of the screen - return me.page.mfd._pageGroupController.handleFMSInner(value); - }, - handleFMSOuter : func(value) { - # This page has no use for the FMS knob, so we pass all such - # events to the pageGroupController which displays the page menu in the - # bottom right of the screen - return me.page.mfd._pageGroupController.handleFMSOuter(value); - }, - RegisterWithEmesary : func(transmitter = nil){ - if (transmitter == nil) - transmitter = emesary.GlobalTransmitter; - - if (me._recipient == nil){ - me._recipient = emesary.Recipient.new("TrafficMapController_" ~ me.page.device.designation); - var pfd_obj = me.page.device; - var controller = me; - me._recipient.Receive = func(notification) - { - if (notification.Device_Id == pfd_obj.device_id - and notification.NotificationType == notifications.PFDEventNotification.DefaultType) { - if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed - and notification.EventParameter != nil) - { - var id = notification.EventParameter.Id; - var value = notification.EventParameter.Value; - #printf("Button pressed " ~ id ~ " " ~ value); - if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value); - if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value); - if (id == fg1000.FASCIA.RANGE) return controller.zoom(value); - } - } - 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; + handleRange : func(val) + { + var incr_or_decr = (val > 0) ? 1 : -1; + me.setZoom(me.current_zoom + incr_or_decr); }, # Reset controller if required when the page is displayed or hidden diff --git a/Nasal/notifications.nas b/Nasal/notifications.nas index 433219ae2..66e507035 100644 --- a/Nasal/notifications.nas +++ b/Nasal/notifications.nas @@ -553,7 +553,7 @@ var PFDEventNotification = ChangeMenuText : 3, #event parameter contains array of { Id: , Text: } tuples HardKeyPushed : 4, #event parameter contains single { Id: , Value: } tuple EngineData : 5, #event parameter contains an array of hashes, each containing information about a given engine. - NavComData : 6, #event paramterr contains a hash of updated Nav/Com settings + NavComData : 6, #event parameter contains a hash of updated Nav/Com settings DefaultType : "PFDEventNotification",