Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas

raw
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 # Standard MFDPage Controller
18 #
19 # This should be extended by specific page controllers and the handle...()
20 # methods over-ridden to provide specific functions for the MFD buttons.
21
22 var MFDPageController = {
23
24 new : func (page)
25 {
26 var obj = { parents : [ MFDPageController ] };
27
28 # Emesary
29 obj._recipient = nil;
30 obj._page = page;
31 obj._transmitter = emesary.GlobalTransmitter;
32 obj._registered = 0;
33 return obj;
34 },
35
36 # Default handlers for all the Fascia hardkeys. These should be over-ridden
37 # as required by specific page function.
38
39 #
40 handleNavVol : func (value) { return me.page.mfd.SurroundController.handleNavVol(value); },
41 handleNavID : func (value) { return me.page.mfd.SurroundController.handleNavID(value); },
42 handleNavFreqTransfer : func (value) { return me.page.mfd.SurroundController.handleNavFreqTransfer(value); },
43 handleNavOuter : func (value) { return me.page.mfd.SurroundController.handleNavOuter(value); },
44 handleNavInner : func (value) { return me.page.mfd.SurroundController.handleNavInner(value); },
45 handleNavToggle : func (value) { return me.page.mfd.SurroundController.handleNavToggle(value); },
46 handleHeading : func (value) { return me.page.mfd.SurroundController.handleHeading(value); },
47 handleHeadingPress : func (value) { return me.page.mfd.SurroundController.handleHeadingPress(value); },
48
49 # Joystick
50 handleRange : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
51 handleJoystickHorizontal : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
52 handleJoystickHorizontal : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
53
54 #CRS/BARO
55 handleBaro : func (value) { return me.page.mfd.SurroundController.handleBaro(value); },
56 handleCRS : func (value) { return me.page.mfd.SurroundController.handleCRS(value); },
57 handleCRSCenter : func (value) { return me.page.mfd.SurroundController.handleCRSCenter(value); },
58
59 handleComOuter : func (value) { return me.page.mfd.SurroundController.handleComOuter(value); },
60 handleComInner : func (value) { return me.page.mfd.SurroundController.handleComInner(value); },
61 handleComToggle : func (value) { return me.page.mfd.SurroundController.handleComToggle(value); },
62
63 handleComFreqTransfer : func (value) { return me.page.mfd.SurroundController.handleComFreqTransfer(value); },
64 handleComFreqTransferHold : func (value) { return me.page.mfd.SurroundController.handleComFreqTransferHold(value); }, # Auto-tunes to 121.2 when pressed for 2 seconds
65
66 handleComVol : func (value) { return me.page.mfd.SurroundController.handleComVol(value); },
67 handleComVolToggle : func (value) { return me.page.mfd.SurroundController.handleComVolToggle(value); },
68
69 handleDTO : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
70
71
72 handleFPL : func (value) {
73 var fppage = me._page.getMFD().getPage("ActiveFlightPlanNarrow");
74 if (fppage != nil) {
75 me._page.getDevice().selectPage(fppage);
76 return emesary.Transmitter.ReceiptStatus_Finished;
77 } else {
78 return emesary.Transmitter.ReceiptStatus_NotProcessed;
79 }
80 },
81
82 handleClear : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
83
84 # Holding the Clear button goes straight to the Navigation Map page.
85 handleClearHold : func (value) {
86 var mappage = me._page.getMFD().getPage("NavigationMap");
87 assert(mappage != nil, "Unable to find NavigationMap page");
88 me._page.getDevice().selectPage(mappage);
89 return emesary.Transmitter.ReceiptStatus_Finished;
90 },
91
92 # By default, the FMS knobs will select a new page.
93 handleFMSOuter : func (value) { return me.page.mfd.SurroundController.handleFMSOuter(value); },
94 handleFMSInner : func (value) { return me.page.mfd.SurroundController.handleFMSInner(value); },
95 handleCRSR : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
96
97 handleMenu : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
98 handleProc : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
99 handleEnter : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
100
101 handleAltOuter : func (value) { return me.page.mfd.SurroundController.handleAltOuter(value); },
102 handleAltInner : func (value) { return me.page.mfd.SurroundController.handleAltInner(value); },
103
104 handleKeyInput : func (value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; },
105 handleStringInput : func (value) { print("Not handling " ~ value); return emesary.Transmitter.ReceiptStatus_NotProcessed; },
106
107 RegisterWithEmesary : func()
108 {
109 if (me._recipient == nil){
110 me._recipient = emesary.Recipient.new(me._page.pageName ~ "Controller_" ~ me._page.device.designation);
111 var pfd_obj = me._page.device;
112 var controller = me;
113 me._recipient.Receive = func(notification)
114 {
115 if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
116 notification.Device_Id == pfd_obj.device_id) {
117 if (notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed
118 and notification.EventParameter != nil)
119 {
120 var id = notification.EventParameter.Id;
121 var value = notification.EventParameter.Value;
122
123 #printf("Button pressed " ~ id ~ " " ~ value);
124
125 if (id == fg1000.FASCIA.NAV_VOL) return controller.handleNavVol(value);
126 if (id == fg1000.FASCIA.NAV_ID) return controller.handleNavID(value);
127 if (id == fg1000.FASCIA.NAV_FREQ_TRANSFER) return controller.handleNavFreqTransfer(value);
128 if (id == fg1000.FASCIA.NAV_OUTER) return controller.handleNavOuter(value);
129 if (id == fg1000.FASCIA.NAV_INNER) return controller.handleNavInner(value);
130 if (id == fg1000.FASCIA.NAV_TOGGLE) return controller.handleNavToggle(value);
131 if (id == fg1000.FASCIA.HEADING) return controller.handleHeading(value);
132 if (id == fg1000.FASCIA.HEADING_PRESS) return controller.handleHeadingPress(value);
133
134 # Joystick
135 if (id == fg1000.FASCIA.RANGE) return controller.handleRange(value);
136 if (id == fg1000.FASCIA.JOYSTICK_HORIZONTAL) return controller.handleJoystickHorizontal(value);
137 if (id == fg1000.FASCIA.JOYSTICK_VERTICAL) return controller.handleJoystickHorizontal(value);
138
139 #CRS/BARO
140 if (id == fg1000.FASCIA.BARO) return controller.handleBaro(value);
141 if (id == fg1000.FASCIA.CRS) return controller.handleCRS(value);
142 if (id == fg1000.FASCIA.CRS_CENTER) return controller.handleCRSCenter(value);
143
144 if (id == fg1000.FASCIA.COM_OUTER) return controller.handleComOuter(value);
145 if (id == fg1000.FASCIA.COM_INNER) return controller.handleComInner(value);
146 if (id == fg1000.FASCIA.COM_TOGGLE) return controller.handleComToggle(value);
147
148 if (id == fg1000.FASCIA.COM_FREQ_TRANSFER) return controller.handleComFreqTransfer(value);
149 if (id == fg1000.FASCIA.COM_FREQ_TRANSFER_HOLD) return controller.handleComFreqTransferHold(value); # Auto-tunes to 121.2 when pressed for 2 seconds
150
151 if (id == fg1000.FASCIA.COM_VOL) return controller.handleComVol(value);
152 if (id == fg1000.FASCIA.COM_VOL_TOGGLE) return controller.handleComVolToggle(value);
153
154 if (id == fg1000.FASCIA.DTO) return controller.handleDTO(value);
155 if (id == fg1000.FASCIA.FPL) return controller.handleFPL(value);
156 if (id == fg1000.FASCIA.CLR) return controller.handleClear(value);
157 if (id == fg1000.FASCIA.CLR_HOLD) return controller.handleClearHold(value);
158
159 if (id == fg1000.FASCIA.FMS_OUTER) return controller.handleFMSOuter(value);
160 if (id == fg1000.FASCIA.FMS_INNER) return controller.handleFMSInner(value);
161 if (id == fg1000.FASCIA.FMS_CRSR) return controller.handleCRSR(value);
162
163 if (id == fg1000.FASCIA.MENU) return controller.handleMenu(value);
164 if (id == fg1000.FASCIA.PROC) return controller.handleProc(value);
165 if (id == fg1000.FASCIA.ENT) return controller.handleEnter(value);
166
167 if (id == fg1000.FASCIA.ALT_OUTER) return controller.handleAltOuter(value);
168 if (id == fg1000.FASCIA.ALT_INNER) return controller.handleAltInner(value);
169
170 if (id == fg1000.FASCIA.KEY_INPUT) return controller.handleKeyInput(value);
171 if (id == fg1000.FASCIA.STRING_INPUT) return controller.handleStringInput(value);
172
173 # Autopilot controls - ignore for now as like to be handled elsewhere
174 #if (id == fg1000.FASCIA.AP ) return controller.handle(value);
175 #if (id == fg1000.FASCIA.HDG) return controller.handle(value);
176 #if (id == fg1000.FASCIA.NAV) return controller.handle(value);
177 #if (id == fg1000.FASCIA.APR) return controller.handle(value);
178 #if (id == fg1000.FASCIA.VS ) return controller.handle(value);
179 #if (id == fg1000.FASCIA.FLC) return controller.handle(value);
180 #if (id == fg1000.FASCIA.FD ) return controller.handle(value);
181 #if (id == fg1000.FASCIA.ALT) return controller.handle(value);
182 #if (id == fg1000.FASCIA.VNV) return controller.handle(value);
183 #if (id == fg1000.FASCIA.BC ) return controller.handle(value);
184 #if (id == fg1000.FASCIA.NOSE_UP) return controller.handle(value);
185 #if (id == fg1000.FASCIA.NOSE_DOWN) return controller.handle(value);
186 }
187 }
188 return emesary.Transmitter.ReceiptStatus_NotProcessed;
189 };
190 }
191
192 me._transmitter.Register(me._recipient);
193 me._registered = 1;
194 },
195
196 DeRegisterWithEmesary : func()
197 {
198 # remove registration from transmitter; but keep the recipient once it is created.
199 if (me._registered == 1) me._transmitter.DeRegister(me._recipient);
200 me._registered = 0;
201 },
202
203 # Set up the default waypoint to use if the DirectTo button is pressed
204 setDefaultDTOWayPoint : func(id)
205 {
206 # Use Emesary to set the default DTO waypoint
207 var notification = notifications.PFDEventNotification.new(
208 "MFD",
209 me.getDeviceID(),
210 notifications.PFDEventNotification.NavData,
211 {Id: "SetDefaultDTO", Value: id});
212
213 var response = me._transmitter.NotifyAll(notification);
214 if (me._transmitter.IsFailed(response)) print("Failed to set Default DTO waypoint");
215 },
216
217 getDeviceID : func() {
218 return me._page.mfd.getDeviceID();
219 },
220
221 # Simply query of the NavDataInterface
222 getNavData : func(queryID, value=nil) {
223 # Use Emesary to get the requested data
224 var notification = notifications.PFDEventNotification.new(
225 "MFD",
226 me.getDeviceID(),
227 notifications.PFDEventNotification.NavData,
228 {Id: queryID, Value: value});
229
230 var response = me._transmitter.NotifyAll(notification);
231
232 if (! me._transmitter.IsFailed(response)) {
233 return notification.EventParameter.Value;
234 } else {
235 return nil;
236 }
237 },
238
239 };