1
0
Fork 0
fgdata/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
2018-01-26 19:06:06 +00:00

180 lines
9.3 KiB
Text

# 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 me.page.mfd.SurroundController.handleNavVol(value); },
handleNavID : func (value) { return me.page.mfd.SurroundController.handleNavID(value); },
handleNavFreqTransfer : func (value) { return me.page.mfd.SurroundController.handleNavFreqTransfer(value); },
handleNavOuter : func (value) { return me.page.mfd.SurroundController.handleNavOuter(value); },
handleNavInner : func (value) { return me.page.mfd.SurroundController.handleNavInner(value); },
handleNavToggle : func (value) { return me.page.mfd.SurroundController.handleNavToggle(value); },
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 me.page.mfd.SurroundController.handleComOuter(value); },
handleComInner : func (value) { return me.page.mfd.SurroundController.handleComInner(value); },
handleComToggle : func (value) { return me.page.mfd.SurroundController.handleComToggle(value); },
handleComFreqTransfer : func (value) { return me.page.mfd.SurroundController.handleComFreqTransfer(value); },
handleComFreqTransferHold : func (value) { return me.page.mfd.SurroundController.handleComFreqTransferHold(value); }, # Auto-tunes to 121.2 when pressed for 2 seconds
handleComVol : func (value) { return me.page.mfd.SurroundController.handleComVol(value); },
handleComVolToggle : func (value) { return me.page.mfd.SurroundController.handleComVolToggle(value); },
# DTO button brings up the DirectTo Page.
handleDTO : func (value) {
var dtopage = me._page.getMFD().getPage("DirectTo");
assert(dtopage != nil, "Unable to find the DirectTo page.");
me._page.getDevice().selectPage(dtopage);
return emesary.Transmitter.ReceiptStatus_Finished;
},
handleFPL : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
handleClear : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
# Holding the Clear button goes straight to the Navigation Map page.
handleClearHold : func (value) {
var mappage = me._page.getMFD().getPage("NavigationMap");
assert(mappage != nil, "Unable to find NavigationMap page");
me._page.getDevice().selectPage(mappage);
return emesary.Transmitter.ReceiptStatus_Finished;
},
# By default, the FMS knobs will select a new page.
handleFMSOuter : func (value) { return me.page.mfd.SurroundController.handleFMSOuter(value); },
handleFMSInner : func (value) { return me.page.mfd.SurroundController.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(me._page.pageName ~ "Controller_" ~ 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_ID) return controller.handleNavID(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.handleNavToggle(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.handleComFreqTransfer(value);
if (id == fg1000.FASCIA.COM_FREQ_TRANSFER_HOLD) return controller.handleComFreqTransferHold(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;
},
};