Debian Codegraph @

Aircraft/Instruments-3d/SCR-522C/Nasal/SCR-522C.nas

raw
1 #####################################################################################
2 # This script provides the gui to set up the TR1133/SCR-522C radio #
3 # using a BC-602-A control box #
4 # #
5 # Author Vivian Meazza June 2011 #
6 # #
7 # mods Hal V. Engel June 2011 #
8 # #
9 #####################################################################################
10
11 # ================================ Initalize ======================================
12 # Make sure all needed properties are present and accounted
13 # for, and that they have sane default values.
14
15 var channelA_node = props.globals.initNode("instrumentation/comm/channels/A-mhz", 0, "DOUBLE");
16 var channelB_node = props.globals.initNode("instrumentation/comm/channels/B-mhz", 0, "DOUBLE");
17 var channelC_node = props.globals.initNode("instrumentation/comm/channels/C-mhz", 0, "DOUBLE");
18 var channelD_node = props.globals.initNode("instrumentation/comm/channels/D-mhz", 0, "DOUBLE");
19
20 var channel_selected_node = props.globals.initNode("instrumentation/comm/SCR-522C/frequencies/channel-selected", 0, "INT");
21 var tr_node = props.globals.initNode("instrumentation/comm/SCR-522C/tr", 0, "INT");
22 props.globals.initNode("instrumentation/comm/SCR-522C/frequencies/channel", "", "STRING");
23 props.globals.initNode("instrumentation/comm/SCR-522C/mask", 0, "BOOL");
24 props.globals.initNode("instrumentation/comm/SCR-522C/tr-lock", 0, "BOOL");
25 props.globals.initNode("instrumentation/comm/SCR-522C/remote-pushed", 0, "BOOL");
26
27 # turn the radio off
28 props.globals.initNode("instrumentation/comm/serviceable", 0, "BOOL");
29
30 var comm_selected_node = props.globals.getNode("instrumentation/comm/frequencies/selected-mhz", 1);
31 var comm_standby_node = props.globals.getNode("instrumentation/comm/frequencies/standby-mhz", 1);
32 var comm1_selected_node = props.globals.getNode("instrumentation/comm[1]/frequencies/selected-mhz", 1);
33 var comm1_standby_node = props.globals.getNode("instrumentation/comm[1]/frequencies/standby-mhz", 1);
34
35 var channel = ["OFF","A","B","C","D"];
36 setprop("instrumentation/comm/SCR-522C/frequencies/channel", channel[channel_selected_node.getValue()]);
37
38 # override default Equipment --> radio menu item
39 # Radio needs to be global in scope since it needs to presist for this to work
40
41 var Radio = gui.Dialog.new("sim/gui/dialogs/SCR-522C/dialog",
42 "Aircraft/Instruments-3d/SCR-522C/Dialogs/radios.xml");
43
44 gui.menuBind("radio", "SCR_522C.Radio.open()");
45
46 # override controls.ptt. This implements a REMote ptt switch.
47
48 controls.ptt = func {
49 # T/R/REM set to REM remote ptt switch controls transmitter
50 # print("intercept ptt for BC-602-A");
51 if (getprop("instrumentation/comm/SCR-522C/tr") == 0 and # in REMote ptt switch mode
52 getprop("instrumentation/comm/SCR-522C/frequencies/channel-selected") > 0) # and radio is on
53 setprop("instrumentation/comm/ptt", arg[0]); # let remote ptt control transmitter
54 else # otherwise
55 setprop("instrumentation/comm/ptt", 0); # the remote ptt does nothing
56 setprop("instrumentation/comm/SCR-522C/remote-pushed", arg[0]); # use to animate remote ptt button
57 }
58
59 # =============================== listeners ===============================
60 #
61
62 # listener for channel selector. Will cause the frequency of the transceiver to be changed.
63 # will also turn the radio on and off
64
65 var listenChannelSelected = func(n) {
66 var channel_no = n.getValue();
67
68 if (channel_no == nil) channel_no = 0;
69
70 # print("channel", channel_no, " ", channel[channel_no]);
71 setprop("instrumentation/comm/SCR-522C/frequencies/channel", channel[channel_no]);
72 if (channel_no == 0)
73 setprop("instrumentation/comm/serviceable", 0);
74 else {
75 setprop("instrumentation/comm/serviceable", 1);
76 if (channel_no == 1) {
77 setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/A-mhz"));
78 setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/A-mhz"));
79 }
80 else if (channel_no == 2){
81 setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/B-mhz"));
82 setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/B-mhz"));
83 }
84 else if (channel_no == 3){
85 setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/C-mhz"));
86 setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/C-mhz"));
87 }
88 else if (channel_no == 4){
89 setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/D-mhz"));
90 setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/D-mhz"));
91 }
92 }
93 }
94
95 # listener for the local TR switch.
96
97 var listenTr = func(t) {
98 var tr = t.getValue();
99 # print("tr ",tr);
100
101 if (tr == nil) tr = 0;
102 if (tr == 2 and getprop("instrumentation/comm/SCR-522C/frequencies/channel-selected") > 0)
103 setprop("instrumentation/comm/ptt", 1);
104 else if (tr == 1)
105 setprop("instrumentation/comm/ptt", 0);
106 if (tr == 0 and getprop("/instrumentation/comm/SCR-522C/tr-lock"))
107 setprop("/instrumentation/comm/SCR-522C/tr", 1);
108 }
109
110 # listener for the local TR lock.
111
112 var listenTrLock = func(i) {
113 var tr_lock = i.getValue();
114 # print("tr_lock");
115
116 if (tr_lock == nil) tr_lock = false;
117 if (tr_lock and getprop("/instrumentation/comm/SCR-522C/tr") == 0)
118 setprop("/instrumentation/comm/SCR-522C/tr", 1);
119 # else if (getprop("/instrumentation/comm/SCR-522C/tr") == 2)
120 # setprop("/instrumentation/comm/SCR-522C/tr", 1);
121
122 }
123
124 var SCR_522C_init = func(){
125
126 var channelA_init = comm_selected_node.getValue();
127 var channelB_init = comm_standby_node.getValue();
128 var channelC_init = comm1_selected_node.getValue();
129 var channelD_init = comm1_standby_node.getValue();
130
131 channelA_node.setValue(channelA_init);
132 channelB_node.setValue(channelB_init);
133 channelC_node.setValue(channelC_init);
134 channelD_node.setValue(channelD_init);
135
136 comm_selected_node.setValue(0);
137 comm_standby_node.setValue(0);
138 comm1_selected_node.setValue(0);
139 comm1_standby_node.setValue(0);
140
141 # over ride F12
142 setprop("input/keyboard/key[268]/binding/dialog-name", "SCR-522C-radio");
143 setprop("input/keyboard/key[268]/binding/command", "dialog-show");
144
145
146 # =============================== start listeners ===============================
147 #
148
149 setlistener("instrumentation/comm/SCR-522C/frequencies/channel-selected", listenChannelSelected, 1, 0);
150
151 setlistener("instrumentation/comm/SCR-522C/tr", listenTr, 1, 0);
152
153 setlistener("instrumentation/comm/SCR-522C/tr-lock", listenTrLock, 1, 0);
154
155 # print("... done");
156
157 } # end func initialize
158
159 # run initialization
160
161 setlistener("sim/signals/fdm-initialized", SCR_522C_init);