1
0
Fork 0
fgdata/Aircraft/Instruments-3d/SCR-522C/Nasal/SCR-522C.nas

150 lines
6.9 KiB
Text
Raw Normal View History

#####################################################################################
# This script provides the gui to set up the TR1133/SCR-522C radio #
# using a BC-602-A control box #
# #
# Author Vivian Meazza June 2011 #
# #
# mods Hal V. Engel June 2011 #
# #
#####################################################################################
# ================================ Initalize ======================================
# Make sure all needed properties are present and accounted
# for, and that they have sane default values.
var channelA_node = props.globals.initNode("instrumentation/comm/channels/A-mhz", 0, "DOUBLE");
var channelB_node = props.globals.initNode("instrumentation/comm/channels/B-mhz", 0, "DOUBLE");
var channelC_node = props.globals.initNode("instrumentation/comm/channels/C-mhz", 0, "DOUBLE");
var channelD_node = props.globals.initNode("instrumentation/comm/channels/D-mhz", 0, "DOUBLE");
var channel_selected_node = props.globals.initNode("instrumentation/comm/SCR-522C/frequencies/channel-selected", 0, "INT");
var tr_node = props.globals.initNode("instrumentation/comm/SCR-522C/tr", 0, "INT");
props.globals.initNode("instrumentation/comm/SCR-522C/frequencies/channel", "", "STRING");
props.globals.initNode("instrumentation/comm/SCR-522C/mask", 0, "BOOL");
props.globals.initNode("instrumentation/comm/SCR-522C/tr-lock", 0, "BOOL");
var comm_selected_node = props.globals.getNode("instrumentation/comm/frequencies/selected-mhz", 1);
var comm_standby_node = props.globals.getNode("instrumentation/comm/frequencies/standby-mhz", 1);
var comm1_selected_node = props.globals.getNode("instrumentation/comm[1]/frequencies/selected-mhz", 1);
var comm1_standby_node = props.globals.getNode("instrumentation/comm[1]/frequencies/standby-mhz", 1);
var channel = ["OFF","A","B","C","D"];
setprop("instrumentation/comm/SCR-522C/frequencies/channel", channel[channel_selected_node.getValue()]);
var Radio = gui.Dialog.new("sim/gui/dialogs/SCR-522C/dialog",
"Aircraft/Instruments-3d/SCR-522C/Dialogs/radios.xml");
# gui.menuBind("radio", "dialogs.Radio.open()");
# override controls.ptt
controls.ptt = func {
# T/R/REM set to REM remote ptt switch controls transmitter
# print("intercept ptt for BC-602-A");
if (getprop("instrumentation/comm/SCR-522C/tr") == 0 and # set in REMote ptt switch mode
getprop("instrumentation/comm/SCR-522C/frequencies/channel-selected") > 0) # and radio is on
setprop("instrumentation/comm/ptt", arg[0]); # let remote ptt control transmitter
else # otherwise
setprop("instrumentation/comm/ptt", 0); # the remote ptt does nothing
}
# =============================== listeners ===============================
#
var listenChannelSelected = func(n) {
var channel_no = n.getValue();
if (channel_no == nil) channel_no = 0;
# print("channel", channel_no, " ", channel[channel_no]);
setprop("instrumentation/comm/SCR-522C/frequencies/channel", channel[channel_no]);
if (channel_no == 1) {
setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/A-mhz"));
setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/A-mhz"));
}
else if (channel_no == 2){
setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/B-mhz"));
setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/B-mhz"));
}
if (channel_no == 3){
setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/C-mhz"));
setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/C-mhz"));
}
else if (channel_no == 4){
setprop("instrumentation/comm/frequencies/selected-mhz", getprop("instrumentation/comm/channels/D-mhz"));
setprop("instrumentation/comm/frequencies/standby-mhz", getprop("instrumentation/comm/channels/D-mhz"));
}
}
var listenTr = func(t) {
var tr = t.getValue();
# print("tr ",tr);
if (tr == nil) tr = 0;
if (tr == 2 and getprop("instrumentation/comm/SCR-522C/frequencies/channel-selected") > 0)
setprop("instrumentation/comm/ptt", 1);
else if (tr == 1)
setprop("instrumentation/comm/ptt", 0);
}
var listenTrLock = func(i) {
var tr_lock = i.getValue();
# print("tr_lock");
if (tr_lock == nil) tr_lock = false;
if (tr_lock)
setprop("/instrumentation/comm/SCR-522C/tr", 2);
else if (getprop("/instrumentation/comm/SCR-522C/tr") == 2)
setprop("/instrumentation/comm/SCR-522C/tr", 1);
}
var SCR_522C_init = func(){
print ("initializing SCR-522C ...");
var channelA_init = comm_selected_node.getValue();
var channelB_init = comm_standby_node.getValue();
var channelC_init = comm1_selected_node.getValue();
var channelD_init = comm1_standby_node.getValue();
channelA_node.setValue(channelA_init);
channelB_node.setValue(channelB_init);
channelC_node.setValue(channelC_init);
channelD_node.setValue(channelD_init);
comm_selected_node.setValue(0);
comm_standby_node.setValue(0);
comm1_selected_node.setValue(0);
comm1_standby_node.setValue(0);
# over ride F12
setprop("input/keyboard/key[268]/binding/dialog-name", "SCR-522C-radio");
setprop("input/keyboard/key[268]/binding/command", "dialog-show");
# Disable the menu item "Equipment > radio" so we use our own gui: " > Radio".
# print("Disabling Menu: Equipment -> Radios GUI");
# override default radio menu
gui.menuEnable("radio",0);
setprop("sim/bindings/menu/binding[35]/dialog-name", "SCR-522C-radio");
setprop("sim/menubar/default/menu[5]/item[3]/binding/dialog-name", "SCR-522C-radio");
setprop("sim/menubar/default/menu[5]/item[3]/name", "SCR-522C-radio");
gui.menuEnable("SCR-522C-radio",1);
# gui.menuBind("radio", "dialogs.Radio.open()");
# =============================== start listeners ===============================
#
setlistener("instrumentation/comm/SCR-522C/frequencies/channel-selected", listenChannelSelected, 1, 0);
setlistener("instrumentation/comm/SCR-522C/tr", listenTr, 1, 0);
setlistener("instrumentation/comm/SCR-522C/tr-lock", listenTrLock, 1, 0);
# print("... done");
} # end func initialize
setlistener("sim/signals/fdm-initialized", SCR_522C_init);