Code: Select all
-- KR87 --
-- Add images in Z-order --
img_add_fullscreen("KR 87.png")
adf_on = img_add("adf button.png", 122, 109, 49, 31)
bfo_on = img_add("bfo button.png", 189, 109, 49, 31)
frq_on = img_add("freq button.png", 255, 109, 49, 31)
ADFtxt_on = img_add("ADFtxt.png", 55, 25, 53, 55)
BFOtxt_on = img_add("BFOtxt.png", 240, 30, 36, 19)
fltet_on = img_add("FltEt.png", 323, 109, 49, 31)
adfoff = img_add("off.png", 505, 92, 33, 33)
-- Add text in Z-order --
adfstbytxt = txt_add("---", "size:44px; color: firebrick; halign: center;", 230, 28, 200, 60)
adf1txt = txt_add("---", "size:44px; color: firebrick; halign: center;", 85, 28, 200, 60)
Flight_Time = txt_add("---", "size:44px; color: firebrick; halign: center;", 260, 28, 200, 60)
Elaspe_Time = txt_add("---", "size:44px; color: firebrick; halign: center;", 260, 28, 200, 60)
txt_FLT = txt_add("FLT ", "size:19px; color: #fb2c00; halign: left;", 450, 30, 200, 200)
txt_ET = txt_add("ET", "size:19px; color: #fb2c00; halign: left;", 450, 48, 200, 200)
txt_FRQ = txt_add("FRQ", "size:20px; color: #fb2c00; halign: left;", 250, 52, 200, 200)
--HIDES ABOVE TXT DISPLAY WHEN UNIT TURNED OFF--
adf_display_off = img_add("display off.png", 17, 10, 458, 61)
-- DEFAULT VISBLE SETTING --
visible(fltet_on, false)
visible(frq_on, false)
visible(adfstbytxt, true)
visible(Flight_Time,false)
visible(Elaspe_Time,false)
visible(txt_FLT, false)
visible(txt_ET, false)
visible(adf_display_off, false)
-- ADF Swt --
--Subscribe - Receives Data--
function adfcallback(adf_lght)
if adf_lght == 1 then
visible(ADFtxt_on, true)
visible(adf_on, true)
adf_position = 1
else
adf_position = 0
visible(adf_on, false)
visible(ADFtxt_on, false)
end
end
--Sends data--
function adfswtcallback(adfswt)
--Swt position--
if adf_position == 1 then
fsx_variable_write("L:AdfAdfButton", "number", 0)
else
fsx_variable_write("L:AdfAdfButton", "number", 1)
end
end
--***********************************************************--
-- BFO Swt --
--Subscribe - Receives Data--
function bfocallback(bfo_light)
if bfo_light == 1 then
visible(bfo_on, true)
visible(BFOtxt_on, true)
bfo_position = 1
else
bfo_position = 0
visible(bfo_on, false)
visible(BFOtxt_on, false)
end
end
--Sends data--
function bfoswtcallback(bfoswt)
--Swt position--
if bfo_position == 1 then
fsx_variable_write("L:AdfBfoButton", "number", 0)
else
fsx_variable_write("L:AdfBfoButton", "number", 1)
end
end
--***********************************************************--
-- ADF ON/OFF Swt --
--Subscribe - Receives Data--
function adf_onoff_swt_pos(adfonoff)
if adfonoff == 1 then
visible(adfoff, false)
visible(adf_display_off, false)
StartTimer = 0
ET_Timer = 0
adfswt_position = 0
else
visible(adfoff, true)
visible(adf_display_off, true)
adfswt_position = 1
end
end
--Sends data--
function adf_on_off(adfswt)
if adfswt_position == 0 then
fsx_variable_write("L:AdfOnOffKnob", "", 0)
else
fsx_variable_write("L:AdfOnOffKnob", "", 1)
end
end
--***********************************************************--
--Subscribe - Receives Data--
--Sets Frq Display Data--
function adffrq(adf1)
adf1 = adf1/1000
active_freq(adf1)
end
function adfstdbyfrq(adfstby)
adfstby = adfstby/1000
inactive_freq(adfstby)
end
function active_freq(adf1)
if adf1 == 0 then
txt_set(adf1txt, "---")
else
txt_set(adf1txt, string.format("%.0f", adf1))
end
end
function inactive_freq(adfstby)
if adfstby == 0 then
txt_set(adfstbytxt, "---")
else
txt_set(adfstbytxt, string.format("%.0f", adfstby))
end
end
--Sends data--
function frq_pressed(frq_pressed)
fsx_variable_write("L:AdfFrqButton", "", 1)
visible(frq_on, true)
visible(fltet_on, false)
visible(adfstbytxt, true)
visible(txt_FRQ, true)
visible(Flight_Time,false)
visible(Elaspe_Time,false)
visible(txt_FLT, false)
visible(txt_ET, false)
end
function frq_released(frq_released)
fsx_variable_write("L:AdfFrqButton", "", 0)
end
--***********************************************************--
-- KR 87 AIR MANAGER TIMER --
function KR_87_FLT_Timer_callback()
StartTimer = StartTimer + 1
ET_Timer = ET_Timer + 1
vis_time = string.format("%.0f:%.0f:%.0f", StartTimer / 3600, StartTimer / 60 % 60, StartTimer %60)
txt_set(Flight_Time, vis_time)
vis_time = string.format("%.0f:%.0f:%.0f", ET_Timer / 3600, ET_Timer / 60 % 60, ET_Timer %60)
txt_set(Elaspe_Time, vis_time)
end
KR_87_Timer = timer_start(0,1000, KR_87_FLT_Timer_callback)
StartTimer = 0
ET_Timer = 0
--***********************************************************--
-- FltEt Swt --
--Sends data--
function FltEt_pressed()
if FltEtPos == 1 then
visible(fltet_on, true)
visible(frq_on, false)
visible(adfstbytxt, false)
visible(Flight_Time,true) -- Shows Flight Time
visible(Elaspe_Time,false) -- Shows Elaspe Time
visible(txt_FLT, true)
visible(txt_ET, false)
visible(txt_FRQ, false)
FltEtPos = FltEtPos +1
else
visible(fltet_on, true)
visible(frq_on, false)
visible(adfstbytxt, false)
visible(Flight_Time,false)-- Hides Flight Time
visible(Elaspe_Time,true) -- Shows Elaspe Time
visible(txt_FLT, false)
visible(txt_ET, true)
FltEtPos = 0
end
end
--FltEtPos = 0
function ET_data_callback(ET)
ET_Timer = 0
end
--Subscribe - Receives Data--
--NO DATA AVAILABLE FOR FLIGHT TIME OR ELASPE TIME OUTSIDE OF SIMULATOR FOR A2A CHEROKEE.
--***********************************************************--
--FRQ DIAL--
function new_adfbig(adfbigvar)
if adfbigvar == 1 then
fsx_event("ADF_100_INC")
elseif adfbigvar == -1 then
fsx_event("ADF_100_DEC")
end
end
function new_adfmid(adfmidvar)
if adfmidvar == 1 then
fsx_event("ADF_10_INC")
elseif adfmidvar == -1 then
fsx_event("ADF_10_DEC")
end
end
function new_adfsmall(adfsmlvar)
if adfsmlvar == 1 then
fsx_event("ADF_1_INC")
elseif adfsmlvar == -1 then
fsx_event("ADF_1_DEC")
end
end
--***********************************************************--
-- Switches --
ADF_switch_id = switch_add(nil,nil,122, 109, 46, 28,adfswtcallback)
BFO_switch_id = switch_add(nil,nil,189, 109, 46, 28,bfoswtcallback)
adf_onoff = switch_add(nil,nil, 505, 92, 32, 32, adf_on_off)
adffrqswap = button_add(nil, nil,255, 109, 46, 28, frq_pressed, frq_released)
-- Buttons --
fltet = button_add(nil, "FltEt.png",323, 109, 49, 31, FltEt_pressed, FltEt_released)
button_add (nil,"SetRst.png", 389,109,50,32, ET_data_callback)
-- Dials --
adfbig = dial_add(nil, 590, 33, 90, 90, new_adfbig)
adfmid = dial_add(nil, 602, 46, 65, 65, new_adfmid)
adfsmall = dial_add(nil, 614, 59, 40, 40, new_adfsmall)
function FltEtPos()
if FltEtPos == 1 then
print("A"..FltEtPos.." Equals 1")
else
print("B"..FltEtPos.." Equals 0")
end
end
-- Bus subscribe --
fsx_variable_subscribe("L:AdfAdfButton", "DOUBLE", adfcallback)
fsx_variable_subscribe("L:AdfBfoButton", "DOUBLE", bfocallback)
fsx_variable_subscribe("L:AdfOnOffKnob", "DOUBLE", adf_onoff_swt_pos)
fsx_variable_subscribe("ADF ACTIVE FREQUENCY:1", "Hz", adffrq)
fsx_variable_subscribe("ADF STANDBY FREQUENCY:1", "Hz", adfstdbyfrq)
--fsx_variable_subscribe("L:AdfFrqEtButton", "number", AdfFrqEt)
--fsx_variable_subscribe("L:AdfFrqRstButton", "double", AdfFrqRst)