KR87 ADF

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

KR87 ADF

#1 Post by vangyver »

Trying to understand how FltEtPos (line 173) gets its value in the following script. I added a print function just above Bus subscribe to no help.

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)

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: KR87 ADF

#2 Post by Ralph »

This script doesn't look that great, and the use of FltEtPos is completely wrong. I wouldn't use this as an example.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: KR87 ADF

#3 Post by vangyver »

It’s an old instrument from AM 2.1 I have used it for over the past 6 years. The AM instrument works great and even the timer for Flt and ET. (FLT / ET AM Instrument only)
All the buttons / dials work and interact with the simulator great with the exception of the FLT / ET. (NO DATA AVAILABLE FOR FLIGHT TIME OR ELASPE TIME OUTSIDE OF SIMULATOR FOR A2A CHEROKEE.) Therefore I use the AM timer for the AM instrument.
The instrument is downloadable in AM4.02 (Van KR87 (A2A only)). It runs great in FSX and Prepar3d with AM4.02 !
I am using the instrument as a digital display only and the rotary encoder and buttons switches are wired through Leo`s usb card. I just cannot get the FLT / ET switch to work with a real switch. I am learning as much as I can as fast as I can and hope to figure it out. Knowing how line 173 ( if FltEtPos == 1 then ) gets it value I think is the key in understanding the instrument.
To simply sum it up, for my “radio stack” I am using Air Manager to display just the digital information with all rotary encoders, buttons and switches connected to the usb interface card.
I know your team at Air Manager must be extremely busy with such a great product and services you offer and I do understand if you do not reply. I will plug away at solving this or move onto other options if it is not doable.
Thank You so Much,
Sincerely, Van

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: KR87 ADF

#4 Post by vangyver »

It seems the image did not upload. Trying again.
KR87-1.jpg

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: KR87 ADF

#5 Post by vangyver »

2nd image
FLT ET.jpg

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: KR87 ADF

#6 Post by Sling »

As Ralph said that variable isn’t doing anything and it shares its name with the name of a function so that’s probably where the error is coming from. Variables can’t have the same name as functions.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: KR87 ADF

#7 Post by vangyver »

Thank you Ralph and Sling for taking the time to look at the script. I will play with it while getting some work done around the house for the next few weeks before the colder weather hits.
Thank You,
Van

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: KR87 ADF

#8 Post by vangyver »

I submitted an updated version 2 of the KR87 ADF. After viewing many video tutorials i realized many of my comments in the original instrument were incorrect. The new script is easier to read and the instrument works great in FSX and Prepar3d. This is the updated script.

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)
    
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

function adfswtcallback(adfswt)
    if adf_position == 1 then
        fsx_variable_write("L:AdfAdfButton", "number", 0)
    else
        fsx_variable_write("L:AdfAdfButton", "number", 1)
    end
end

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

function bfoswtcallback(bfoswt)
    if bfo_position == 1 then
        fsx_variable_write("L:AdfBfoButton", "number", 0)
    else
        fsx_variable_write("L:AdfBfoButton", "number", 1)
    end
end

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

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

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

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 FOR FLT/ET AND SET/RST
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

function FltEt_pressed()
    if FltEtPos == 0 then
    fsx_variable_write("L:AdfFrqEtButton", "", 1)
    visible(fltet_on, true)
    visible(frq_on, false)
    visible(adfstbytxt, false)
    visible(Flight_Time,true)
    visible(Elaspe_Time,false)
    visible(txt_FLT, true)
    visible(txt_ET, false)
    visible(txt_FRQ, false)
    FltEtPos = FltEtPos +1
    else
    fsx_variable_write("L:AdfFrqEtButton", "", 1)
    visible(fltet_on, true)
    visible(frq_on, false)
    visible(adfstbytxt, false)
    visible(Flight_Time,false)
    visible(Elaspe_Time,true)
    visible(txt_FLT, false)
    visible(txt_ET, true)    
    FltEtPos = 0
    end
end    

function FltEt_released()
    fsx_variable_write("L:AdfFrqEtButton", "", 0)
end

function ET_data_callback(ET)
    ET_Timer = 0
end    

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)

-- 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)

Post Reply