kama2004

Multi Panel - specific function to fetch value in user mod

Recommended Posts

I'm trying to make the Multi display work with VertxDA62.

It's quite easy to make something functionnal by changin a few lines in the file common.lua but it is cumbersome to manage diffferent version of this file for each airplane.

Would it be possible to have a function called from common.lua but just if a new function to get the values is defined in the user module for the aircraft.

For instance, this modification of the commmon.lua work well to get the altitude target of the autopilot.

getALTValue()

local ALT

ALT = round(ipc.realLvar("afcs:ALTS:Target")

return alt

end

So if for instance, we take as convention that if a function getALTValue2() exist in the user module, it should be called instead of the original code.

For this to work, it would need the possibility to check first is a getALTValue2() was created in the user module and if not, then the common.lua original code is executed.

Anybody have ever tried this?

Edited by ScotFlieger

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Hi Pierre

This is something I have not got around to doing. The Saitek Multi Panel implementation was first done by someone clever than I in LUA (see lib-saitek.lua library) which proved slow. I coded the solution in the GUI for a faster response switched by the Saitek Panels checkbox (LINDA Setup page). Both solutions rely on the standard FSX offsets documented with FSUIPC. This does not always work with more advanced add-ons.

A solution proposed some time ago would be to write code within the non-compliant aircraft module that reads the offset data and writes it to the corresponding aircraft LVar. This may have to be repeated in the reverse direction when the Lvar changes written to the offset.

Any such code should be added to the aircraft's user.lua file and called regularly from the event timers. Note that any function used in the user.lua will override (replace) any functions of the same name.

I hope this helps.

 

Edited by ScotFlieger

Share this post


Link to post
Share on other sites
4 hours ago, ScotFlieger said:

A solution proposed some time ago would be use write code within the non-compliant aircraft module that reads the offset data and writes it to the corresponding aircraft LVar. This may have to be repeated in the reverse direction when the Lvar changes written to the offset. Any such code should be added to the aircraft's user.lua file and called regularly from the event timers.

Note that any function used in the user.lua will override (replace) any functions of the same name.

Hi Scott,

If I understand well your last sentence, if I define a function getALTValue() in the user.lua, it will replace the same function in the common.lua? If so, it may be an easy solution for getting the standard offset called by the common.lua replaced by something more specific to aircraft. The other way do not seem too difficult as we can always write a user function that write directly to LVAR. 

I will have a look at this approach then if not working, maybe the copy to offset through a timer call would be the second bet.

Share this post


Link to post
Share on other sites

I made a first try with defining a new getALTValue() in the user.lua. And it indeed replace the one in common.lua and allow me to have the correct display for altitude. For changing the altitude, it is as simple as using the DA62_ALT_inc() that is already in the DA62 module. So there is now a two way possibility to change the altitude bug from the Saitek Multi panel button assigned to DA62_ALT_inc() and the getALTValue() in user.lua fetch the correct value. 

Next step is to repeat this process of user.lua functions that duplicate the common.lua function used to display values on the Saitek.

getALTValue()

getVSValue()

getSPDValue()

getHDGValue()

getCRSvalue()

beside these 5 functions, I need also to define a new IsAutopilotInVS() which is part of the MultiPanel display functions and do not work in DA62.

I will pursue testing but if this work, maybe the simple way to get the multi panel working for all is to add these 6 new functions inside the DA62 module, assuming that if worlk the same way and that any function of the same name in the DA62 module (not user function) will replace the one of the same name in common.lua.

I will continue some testing later this week and report back if success...

 

Share this post


Link to post
Share on other sites

So it is working, The following code when added either to the Actions.lua (not recommended unless the Linda authors incorporate the code in the official module) or to the user.lua (preferred method) file will correct the problem of wrong values displayed by the Saitek Multi Panel and they ensure a correct lighted buttons operation. Curiously, the Altitude, Vertical Speed, IAS, HDG et CRS values are easy to replace but the button lighting is more complex due to multiple internal modes in the DA62 for ILS, VOR, RNAV approaches.

If other persons use Saitek Multi Panel, please try this modification and report back to see if it is working also for you. If working well it could be interesting that the Linda DA62 module author incorporate those lines in the official module so everay multi saitek panel owners can benefit of it.

If it work for others, I may explore other popular aircrafts like Q400 and FSLabs A320.

-- ## Replacement function for multi dislplay saitek

-- test by Pierre Baillargeon - Kama2004 on Avsim, based on function found in common.lua by the original Linda authors.
-- do not assign those functions to any button. They are called by Linda main module automatically
-- These functions replace standard FSX offset data by the DA62 Lvars.
-- by choice, the NAV and APR button will light both in Armed mode and Captured mode,
-- so it is possible in some conditions to have both the HDG button (active mode) and NAV or APR button (armed mode) lighted at the same time.

function getALTValue ()
local alt
    alt = round(ipc.readLvar("afcs:ALTS:Target"))
    return alt
end

function getVSValue ()
local vs
    vs = ipc.readLvar("afcs:VsHold:Ref")
    return vs
end

function getSPDValue ()
    return ipc.readLvar("afcs:IasHold:Ref")
end

function getHDGValue ()
    return round(ipc.readLvar("afcs:Hdg:Display"))
end

function isAutopilotInVS ()
    return ipc.readLvar("afcs:Mode:Vert")==4
end

function buildLightsStatusForSMP ()
    local data = 0
    local bits

    if isAutopilotEngaged () then
        bits = { isAutopilotEngaged (), ipc.readLvar("afcs:Mode:Lat") == 1,
                ipc.readLvar("afcs:Mode:Lat") == 2 or ipc.readLvar("afcs:Mode:Lat") == 3 or ipc.readLvar("afcs:Mode:Lat") == 4 or ipc.readLvar("afcs:Mode:Lat:Arm") == 2 or ipc.readLvar("afcs:Mode:Lat:Arm") == 3 or ipc.readLvar("afcs:Mode:Lat:Arm") == 4,
                ipc.readLvar("afcs:Mode:Vert") == 5,
                ipc.readLvar("afcs:Mode:Vert") == 1, ipc.readLvar("afcs:Mode:Vert") == 4,
                ipc.readLvar("afcs:Mode:Lat") == 6 or ipc.readLvar("afcs:Mode:Lat") == 7 or ipc.readLvar("afcs:Mode:Lat") == 8 or ipc.readLvar("afcs:Mode:Lat:Arm") == 6 or ipc.readLvar("afcs:Mode:Lat:Arm") == 7 or ipc.readLvar("afcs:Mode:Lat:Arm") == 8,
                ipc.readLvar("afcs:Nav:BC:Active") == 1}
        for i, value in pairs(bits) do
            if value then
                data = data + (2 ^ (i - 1))
            end
        end
    end
    return string.char(data)
end

 

Share this post


Link to post
Share on other sites

Thank you for this valuable input. I will look at the method for other aircraft. I doubt if you will have success with the FSLabs A320X but the Q400 and Aerosoft Airbus are likely targets.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now