Debian Codegraph @

Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/GMA1347Interface.nas

raw
1 # Copyright 2021 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 # Emesary interface to interface with the GMA1347 audio panel.
18 #
19
20 var GMA1347Interface = {
21
22 new : func ()
23 {
24 var obj = { parents : [ GMA1347Interface ] };
25
26 # Emesary
27 obj._recipient = nil;
28 obj._transmitter = emesary.GlobalTransmitter;
29 obj._registered = 0;
30
31 obj._com1 = globals.props.getNode("/instrumentation/audio-panel/com[0]", 1);
32 obj._com1mic = globals.props.getNode("/instrumentation/audio-panel/com-mic[0]", 1);
33
34 obj._com2 = globals.props.getNode("/instrumentation/audio-panel/com[1]", 1);
35 obj._com2mic = globals.props.getNode("/instrumentation/audio-panel/com-mic[1]", 1);
36
37 # The G1000 separates the selected COM radio (being modified) from the radio being listened to.
38 obj._com_selected = globals.props.getNode("/instrumentation/audio-panel/audio-com-selected", 1);
39 obj._com_selected.setIntValue(obj._com1mic.getBoolValue() ? 1 : 2);
40
41 obj._nav1 = globals.props.getNode("/instrumentation/nav[0]/ident", 1);
42 obj._nav2 = globals.props.getNode("/instrumentation/nav[1]/ident", 1);
43 obj._dme = globals.props.getNode("/instrumentation/dme[0]/ident", 1);
44 obj._hisense = globals.props.getNode("/instrumentation/audio-panel/hi", 1);
45 obj._mkrmute = globals.props.getNode("/instrumentation/audio-panel/mkr", 1);
46 obj._spkr = globals.props.getNode("/instrumentation/audio-panel/spkr", 1);
47
48 return obj;
49 },
50
51
52 handleCOM1MIC : func(value) {
53 me._com_selected.setIntValue(1);
54 me._com1.setBoolValue(1);
55 me._com1mic.setBoolValue(1);
56 me._com2.setBoolValue(0);
57 me._com2mic.setBoolValue(0);
58 return emesary.Transmitter.ReceiptStatus_Finished;
59 },
60
61 handleCOM2MIC : func(value) {
62 me._com_selected.setIntValue(2);
63 me._com1.setBoolValue(0);
64 me._com1mic.setBoolValue(0);
65 me._com2.setBoolValue(1);
66 me._com2mic.setBoolValue(1);
67 return emesary.Transmitter.ReceiptStatus_Finished;
68 },
69
70 handleCOM3MIC : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
71 handleCOM12 : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
72 handlePA : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
73
74 handleMKRMUTE : func(value) {
75 me._mkrmute.toggleBoolValue();
76 return emesary.Transmitter.ReceiptStatus_Finished;
77 },
78
79 handleDME : func(value) {
80 me._dme.toggleBoolValue();
81 return emesary.Transmitter.ReceiptStatus_Finished;
82 },
83
84 handleADF : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not implemented - optional ADF is not implemented in FG1000
85 handleAUX : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
86 handleMANSQ : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not implemented
87 handlePILOT : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not implemented
88
89 handleCOM1 : func(value) {
90 me._com1.toggleBoolValue();
91 return emesary.Transmitter.ReceiptStatus_Finished;
92 },
93
94 handleCOM2 : func(value) {
95 me._com2.toggleBoolValue();
96 return emesary.Transmitter.ReceiptStatus_Finished;
97 },
98
99 handleCOM3 : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
100 handleTEL : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not used on Cessna Nav III
101 handleSPKR : func(value) {
102 me._spkr.toggleBoolValue();
103 return emesary.Transmitter.ReceiptStatus_Finished;
104 },
105
106 handleHISENS : func(value) {
107 me._hisense.toggleBoolValue();
108 return emesary.Transmitter.ReceiptStatus_Finished;
109 },
110
111 handleNAV1 : func(value) {
112 me._nav1.toggleBoolValue();
113 return emesary.Transmitter.ReceiptStatus_Finished;
114 },
115
116 handleNAV2 : func(value) {
117 me._nav2.toggleBoolValue();
118 return emesary.Transmitter.ReceiptStatus_Finished;
119 },
120
121 handlePLAY : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not implemented
122 handleCOPLT : func(value) { return emesary.Transmitter.ReceiptStatus_NotProcessed; }, # Not implemented
123
124 RegisterWithEmesary : func()
125 {
126 if (me._recipient == nil){
127 me._recipient = emesary.Recipient.new("GMA1347Interface");
128 var controller = me;
129
130 # Note that unlike the various keys, this data isn't specific to a particular
131 # Device - it's shared by all. Hence we don't check for the notificaiton
132 # Device_Id.
133 me._recipient.Receive = func(notification)
134 {
135
136 if (notification.NotificationType == notifications.PFDEventNotification.DefaultType and
137 notification.Event_Id == notifications.PFDEventNotification.HardKeyPushed and
138 notification.EventParameter != nil)
139 {
140 var id = notification.EventParameter.Id;
141 var value = notification.EventParameter.Value;
142
143 if (id == fg1000.FASCIA.COM1MIC ) return controller.handleCOM1MIC(value);
144 if (id == fg1000.FASCIA.COM1MIC ) return controller.handleCOM1MIC(value);
145 if (id == fg1000.FASCIA.COM2MIC ) return controller.handleCOM2MIC(value);
146 if (id == fg1000.FASCIA.COM3MIC ) return controller.handleCOM3MIC(value);
147 if (id == fg1000.FASCIA.COM12 ) return controller.handleCOM12(value);
148 if (id == fg1000.FASCIA.PA ) return controller.handlePA(value);
149 if (id == fg1000.FASCIA.MKRMUTE ) return controller.handleMKRMUTE(value);
150 if (id == fg1000.FASCIA.DME ) return controller.handleDME(value);
151 if (id == fg1000.FASCIA.ADF ) return controller.handleADF(value);
152 if (id == fg1000.FASCIA.AUX ) return controller.handleAUX(value);
153 if (id == fg1000.FASCIA.MANSQ ) return controller.handleMANSQ(value);
154 if (id == fg1000.FASCIA.PILOT ) return controller.handlePILOT(value);
155 if (id == fg1000.FASCIA.COM1 ) return controller.handleCOM1(value);
156 if (id == fg1000.FASCIA.COM2 ) return controller.handleCOM2(value);
157 if (id == fg1000.FASCIA.COM3 ) return controller.handleCOM3(value);
158 if (id == fg1000.FASCIA.TEL ) return controller.handleTEL(value);
159 if (id == fg1000.FASCIA.SPKR ) return controller.handleSPKR(value);
160 if (id == fg1000.FASCIA.HISENS ) return controller.handleHISENS(value);
161 if (id == fg1000.FASCIA.NAV1 ) return controller.handleNAV1(value);
162 if (id == fg1000.FASCIA.NAV2 ) return controller.handleNAV2(value);
163 if (id == fg1000.FASCIA.PLAY ) return controller.handlePLAY(value);
164 if (id == fg1000.FASCIA.COPLT ) return controller.handleCOPLT(value);
165 }
166
167 return emesary.Transmitter.ReceiptStatus_NotProcessed;
168 };
169 }
170
171 me._transmitter.Register(me._recipient);
172 me._registered = 1;
173 },
174
175 DeRegisterWithEmesary : func()
176 {
177 # remove registration from transmitter; but keep the recipient once it is created.
178 if (me._registered == 1) me._transmitter.DeRegister(me._recipient);
179 me._registered = 0;
180 },
181
182 start : func() {
183 me.RegisterWithEmesary();
184 },
185 stop : func() {
186 me.DeRegisterWithEmesary();
187 },
188
189 };