| 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 |
# NearestVOR Controller |
| 18 |
var NearestVORController = |
| 19 |
{ |
| 20 |
|
| 21 |
UIGROUP : { |
| 22 |
NONE : 0, # No group currently selected, |
| 23 |
VOR : 1, |
| 24 |
FREQ : 2, |
| 25 |
}, |
| 26 |
|
| 27 |
new : func (page, svg) |
| 28 |
{ |
| 29 |
var obj = { parents : [ NearestVORController, MFDPageController.new(page) ] }; |
| 30 |
|
| 31 |
obj.page = page; |
| 32 |
obj._currentGroup = NearestVORController.UIGROUP.NONE; |
| 33 |
obj._crsrToggle = 0; |
| 34 |
|
| 35 |
return obj; |
| 36 |
}, |
| 37 |
|
| 38 |
selectVOR : func() { |
| 39 |
me.selectGroup(NearestVORController.UIGROUP.VOR) |
| 40 |
}, |
| 41 |
selectFrequencies : func() { |
| 42 |
me.selectGroup(NearestVORController.UIGROUP.FREQ); |
| 43 |
}, |
| 44 |
getSelectedGroup : func() { |
| 45 |
return me._currentGroup; |
| 46 |
}, |
| 47 |
selectGroup : func(grp) { |
| 48 |
me._currentGroup = grp; |
| 49 |
if (grp == NearestVORController.UIGROUP.VOR) me.page.select.showCRSR() else me.page.select.hideCRSR(); |
| 50 |
if (grp == NearestVORController.UIGROUP.FREQ) me.page.highlightTextElement("Freq") else me.page.unhighlightTextElement("Freq"); |
| 51 |
me._crsrToggle = 1; |
| 52 |
}, |
| 53 |
|
| 54 |
# Input Handling |
| 55 |
handleCRSR : func() { |
| 56 |
me._crsrToggle = (! me._crsrToggle); |
| 57 |
if (me._crsrToggle) { |
| 58 |
me.page.topMenu(me.page.device, me.page, nil); |
| 59 |
me.page.selectVOR(); |
| 60 |
me.selectVOR(); |
| 61 |
} else { |
| 62 |
me.page.hideCRSR(); |
| 63 |
} |
| 64 |
|
| 65 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 66 |
}, |
| 67 |
handleFMSInner : func(value) { |
| 68 |
if (me._crsrToggle == 1) { |
| 69 |
if (me._currentGroup == NearestVORController.UIGROUP.VOR) { |
| 70 |
# Scroll through whatever is the current list |
| 71 |
me.page.select.incrSmall(value); |
| 72 |
var id = me.page.select.getValue(); |
| 73 |
var data = me.getNavDataItem(id); |
| 74 |
if ((data != nil) and (size(data) >0)) me.page.updateNavDataItem(data[0]); |
| 75 |
} |
| 76 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 77 |
} else { |
| 78 |
return me.page.mfd.SurroundController.handleFMSInner(value); |
| 79 |
} |
| 80 |
}, |
| 81 |
handleFMSOuter : func(value) { |
| 82 |
if (me._crsrToggle == 1) { |
| 83 |
if (me._currentGroup == NearestVORController.UIGROUP.VOR) { |
| 84 |
# Scroll through whatever is the current list |
| 85 |
me.page.select.incrSmall(value); |
| 86 |
var id = me.page.select.getValue(); |
| 87 |
var data = me.getNavDataItem(id); |
| 88 |
if ((data != nil) and (size(data) >0)) me.page.updateNavDataItem(data[0]); |
| 89 |
} |
| 90 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 91 |
} else { |
| 92 |
return me.page.mfd.SurroundController.handleFMSOuter(value); |
| 93 |
} |
| 94 |
}, |
| 95 |
handleEnter : func(value) { |
| 96 |
if (me._crsrToggle == 1) { |
| 97 |
if (me._currentGroup == NearestVORController.UIGROUP.VOR) { |
| 98 |
# Scroll through whatever is the current list |
| 99 |
me.page.select.incrSmall(value); |
| 100 |
var id = me.page.select.getValue(); |
| 101 |
var data = me.getNavDataItem(id); |
| 102 |
if ((data != nil) and (size(data) >0)) me.page.updateNavDataItem(data[0]); |
| 103 |
} |
| 104 |
if (me._currentGroup == NearestVORController.UIGROUP.FREQ) { |
| 105 |
var freq = me.page.getTextValue("Freq"); |
| 106 |
if (freq != nil) { |
| 107 |
me.page.mfd.SurroundController.setStandbyNavComFreq(freq); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
return emesary.Transmitter.ReceiptStatus_Finished; |
| 112 |
} else { |
| 113 |
return emesary.Transmitter.ReceiptStatus_NotProcessed; |
| 114 |
} |
| 115 |
}, |
| 116 |
|
| 117 |
handleRange : func(val) |
| 118 |
{ |
| 119 |
# Pass any range entries to the NavMapController |
| 120 |
me.page.mfd.NavigationMap.getController().handleRange(val); |
| 121 |
}, |
| 122 |
|
| 123 |
# Reset controller if required when the page is displayed or hidden |
| 124 |
ondisplay : func() { |
| 125 |
me.RegisterWithEmesary(); |
| 126 |
var fixes = me.getNearestNavData("vor"); |
| 127 |
me.page.updateNavData(fixes); |
| 128 |
me.page.mfd.NavigationMap.getController().enableDTO(1); |
| 129 |
me._crsrToggle = 0; |
| 130 |
me.page.hideCRSR(); |
| 131 |
}, |
| 132 |
offdisplay : func() { |
| 133 |
me.page.mfd.NavigationMap.getController().enableDTO(0); |
| 134 |
me.DeRegisterWithEmesary(); |
| 135 |
}, |
| 136 |
|
| 137 |
getNearestNavData : func(type) { |
| 138 |
var notification = notifications.PFDEventNotification.new( |
| 139 |
"MFD", |
| 140 |
me.getDeviceID(), |
| 141 |
notifications.PFDEventNotification.NavData, |
| 142 |
{Id: "NavDataWithinRange", Value: { type: type } }); |
| 143 |
|
| 144 |
var response = me._transmitter.NotifyAll(notification); |
| 145 |
|
| 146 |
if (! me._transmitter.IsFailed(response)) { |
| 147 |
return notification.EventParameter.Value; |
| 148 |
} else { |
| 149 |
return nil; |
| 150 |
} |
| 151 |
}, |
| 152 |
|
| 153 |
getNavDataItem : func(id) { |
| 154 |
# Use Emesary to get the Navigation data |
| 155 |
var notification = notifications.PFDEventNotification.new( |
| 156 |
"MFD", |
| 157 |
me.getDeviceID(), |
| 158 |
notifications.PFDEventNotification.NavData, |
| 159 |
{Id: "NavAidByID", Value: { id: id, type: "vor"} }); |
| 160 |
|
| 161 |
var response = me._transmitter.NotifyAll(notification); |
| 162 |
|
| 163 |
if (! me._transmitter.IsFailed(response)) { |
| 164 |
return notification.EventParameter.Value; |
| 165 |
} else { |
| 166 |
return nil; |
| 167 |
} |
| 168 |
}, |
| 169 |
}; |