event updates in AM panel but not in the SIM

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

event updates in AM panel but not in the SIM

#1 Post by dpiddy »

I have a project similar to others I have seen posted where I have a real bendix transponder that connects via Arduino to Air manager and FS2020. When knobs are turned, I send the new xponder value to AM and it works great. I see immediate updates in my custom made transponder.
IMG_3898.jpeg
the bendix hardware is in the foreground
the custom xponder panel is in the middle on the ipad
the sim is in the background

The problem is that while the AM panel updates as expected, the xponder in FS2020 does not. The only way I can get it to update is to click on the xponder in the AM panel and change a digit for instance.

Here is a simplified snippet from the function new_transponder_F2020(code, mode, bus_volts) function. What this does is change the value of the AM xponder by calling an event when it detects a difference.

xx = math.floor(arduinovalue) // the latest value sent from arduino

if (xx ~= math.floor(simcode) ) then // compare to the current value from the SIM

print("1 loop" .. " ".. xx.." ".. math.floor(simcode))
fs2020_event("XPNDR_1_INC") // shouldnt this event change the xponder value and image in the SIM?

end


I feel like this is a cludge I would rather use something like fs2020_event("TRANSPONDER CODE:1", "INT", newvalue ) or fs2020_variable_write("TRANSPONDER CODE:1", "hz", newvalue) but that has no affect either. I am very new to AM so it could be formatting etc..

Any assistance would be much appreciated.

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

Re: event updates in AM panel but not in the SIM

#2 Post by Ralph »

You can look at the Flight Illusion gauge for their transponder, this one writes the complete value to the simulator.

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: event updates in AM panel but not in the SIM

#3 Post by dpiddy »

Ralph wrote: Wed Sep 07, 2022 4:04 pm You can look at the Flight Illusion gauge for their transponder, this one writes the complete value to the simulator.
im not sure I understand, is there source code to look at or are you suggesting I scrap the project and buy the flight illusion transponder?

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

Re: event updates in AM panel but not in the SIM

#4 Post by Ralph »

I was suggesting to look at the script, not buying a new unit :)

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: event updates in AM panel but not in the SIM

#5 Post by SimPassion »

FI Transponder

Code: Select all

vfr_code_user_prop = user_prop_add_integer("VFR code", 1, 7777, 7000, "Standard VFR squawk code")
fi_gauge_prop_set(__fi_gauge_id, "VFR_CODE", user_prop_get(vfr_code_user_prop) )
receive_prop = user_prop_add_boolean("Receive light", true, "Show (random) receive light in FS2020, FSX or Prepar3D")

fi_gauge_prop_set(__fi_gauge_id, "RECEIVE_LED", false)
fi_gauge_prop_set(__fi_gauge_id, "FLIGHT_LEVEL", 0)

local gbl_mode = 0
local gbl_code = user_prop_get(vfr_code_user_prop)
local gbl_avcs = false
local gbl_idnt = false
math.randomseed(os.time())

local function do_request_callback()
    if xpl_connected() then request_callback(new_data_xpl) end
    if fsx_connected() or p3d_connected() or fs2020_connected() then request_callback(new_data_fsx) end
end

fi_gauge_prop_subscribe(__fi_gauge_id, "MODE", function(value)
    gbl_mode = value
    do_request_callback()
end)

fi_gauge_prop_subscribe(__fi_gauge_id, "CODE", function(value)
    gbl_code = value
    do_request_callback()
end)

fi_gauge_command_subscribe(__fi_gauge_id, "IDT_PRESSED", function()
    xpl_command("sim/transponder/transponder_ident")
    if (fsx_connected() or p3d_connected() or fs2020_connected()) and gbl_mode > 0 then
        gbl_idnt = true
    end
end)

function new_data_xpl(altitude, avionics, bus_volts, xpdr_lit)

    fi_gauge_prop_set(__fi_gauge_id, "DISPLAY_ON", avionics == 1 and bus_volts[1] >= 5)
    fi_gauge_prop_set(__fi_gauge_id, "FLIGHT_LEVEL", math.floor(var_cap(altitude / 100, 0, 999)) )
    fi_gauge_prop_set(__fi_gauge_id, "RECEIVE_LED", xpdr_lit == 1 and avionics == 1)
    xpl_dataref_write("sim/cockpit/radios/transponder_code", "INT", gbl_code)

    local sim_mode = 0
    if gbl_mode == 0 then
        sim_mode = 0
    elseif gbl_mode == 1 then
        sim_mode = 1
    elseif gbl_mode == 2 then
        sim_mode = 4
    elseif gbl_mode == 3 then
        sim_mode = 2
    elseif gbl_mode == 4 then
        sim_mode = 3
    end

    -- X-Plane modes
    -- 0: OFF
    -- 1: STANDBY
    -- 2: ON
    -- 3: ALT
    -- 4: TEST

    xpl_dataref_write("sim/cockpit/radios/transponder_mode", "INT", sim_mode)

end

function new_data_fsx(altitude, avionics, bus_volts)

    fi_gauge_prop_set(__fi_gauge_id, "DISPLAY_ON", avionics and bus_volts >= 5)
    fi_gauge_prop_set(__fi_gauge_id, "FLIGHT_LEVEL", math.floor(var_cap(altitude / 100, 0, 999)) )
    fsx_event("XPNDR_SET", decimal_to_bcd16(gbl_code))
    fs2020_event("XPNDR_SET", decimal_to_bcd16(gbl_code))
    gbl_avcs = avionics

    -- Setting the transponder mode for FS2020
    fs2020_variable_write("TRANSPONDER STATE:1", "ENUM", gbl_mode)

end

xpl_dataref_subscribe("sim/flightmodel/misc/h_ind", "FLOAT", 
                      "sim/cockpit/electrical/avionics_on", "INT",
                      "sim/cockpit2/electrical/bus_volts", "FLOAT[6]",
                      "sim/cockpit/radios/transponder_light", "INT", new_data_xpl)

fsx_variable_subscribe("PRESSURE ALTITUDE", "Feet", 
                       "CIRCUIT AVIONICS ON", "Bool",
                       "ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_data_fsx)

fs2020_variable_subscribe("PRESSURE ALTITUDE", "Feet", 
                          "CIRCUIT AVIONICS ON", "Bool",
                          "ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_data_fsx)

timer_start(nil, 500, function()
    if not gbl_idnt then
        fi_gauge_prop_set(__fi_gauge_id, "RECEIVE_LED", math.random(100)%5 == 1 and gbl_avcs and (fsx_connected() or p3d_connected() or fs2020_connected()) and gbl_mode > 0 and user_prop_get(receive_prop))
    else
        timer_stop(timer_ident)
        fi_gauge_prop_set(__fi_gauge_id, "RECEIVE_LED", gbl_avcs and (fsx_connected() or p3d_connected() or fs2020_connected()) and gbl_mode > 0 and user_prop_get(receive_prop))
        timer_start(18000, nil, function()
            fi_gauge_prop_set(__fi_gauge_id, "RECEIVE_LED", false)
            gbl_idnt = false
        end)
    end
end)

-- Instrument light brightness --
light_user_prop = user_prop_add_percentage("Light intensity", 0.0, 1.0, 1.0, "Drag the slider to define full brightness")
si_variable_subscribe("si/backlight_intensity", "DOUBLE", function(intensity)
    fi_gauge_prop_set(__fi_gauge_id, "DISPLAY_INTENSITY", intensity * user_prop_get(light_user_prop) )
    fi_gauge_prop_set(__fi_gauge_id, "LIGHTS", intensity * user_prop_get(light_user_prop) )
end)

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: event updates in AM panel but not in the SIM

#6 Post by Tetrachromat »

dpiddy wrote: Wed Sep 07, 2022 2:51 pm

Code: Select all

fs2020_event("XPNDR_1_INC")
.. shouldnt this event change the xponder value and image in the SIM?

Yes, this should set the value in FS2020 for the last digit. At least on my side it does so.
dpiddy wrote: Wed Sep 07, 2022 2:51 pm I feel like this is a cludge I would rather use something like fs2020_event("TRANSPONDER CODE:1", "INT", newvalue ) or fs2020_variable_write("TRANSPONDER CODE:1", "hz", newvalue) but that has no affect either. I am very new to AM so it could be formatting etc..
You could use the event 'XPNDR_SET', but you ned to convert the squawk value to BCD format before sending. Here is the code for the conversion function and the event call:

Code: Select all

local to_bcd16 = function ( s )
  local bcd = 0
  for char in string.gmatch(s, "%d") do
    bcd = (bcd << 4) + tonumber(char)
  end
  return bcd
end

fs2020_event("XPNDR_SET", to_bcd16(squawk))
Paul

dpiddy
Posts: 12
Joined: Mon Apr 25, 2022 1:20 pm

Re: event updates in AM panel but not in the SIM

#7 Post by dpiddy »

thanks all, i have alot to try now! I appreciate the assistance.

Post Reply