Jump to content
The simFlight Network Forums

problem comparing values and sending ipc.controls


Recommended Posts

Dear John,
I am working on a Lua script for the mode knob on an A320 EFIS. The knob has five positions which are five separate buttons. Each button calls a LuaValue function and assigns a parameter, "0" for the left most position (ILS), "10" for the next (VOR) etc. until "40" for the right most position (PLAN).

This moves the button as planned but does not change the display on the ND. The display can only be changed by sending rotor brake codes for decreasing and increasing.

My script sends four decreasing ipc.control commands for the left most and four increasing for the right most position. This syncs the display with the knob, but only in these positions.

I would like to send a decreasing or increasing command for the positions in between, but I can't get it to work. Could you have a look at my script?

 

function modeKnob(param)
    old_param = ipc.readLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob")
-- reads the position of the knob from the Lvar before the new param is written and names it "old_param"
    ipc.writeLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob", ipcPARAM) -- writes the new param into the Lvar
    new_param = ipc.readLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob") -- names the new param as global function
    if ipcPARAM == 0 then -- four decreasing inputs for the left most position
        ipc.control(66587,71021)
        ipc.control(66587,71024)
        ipc.control(66587,71021)
        ipc.control(66587,71024)
        ipc.control(66587,71021)
        ipc.control(66587,71024)
        ipc.control(66587,71021)
        ipc.control(66587,71024)
    elseif ipcPARAM == 40 then
-- four increasing inputs for the right most position
        ipc.control(66587,71025)
        ipc.control(66587,71022)
        ipc.control(66587,71025)
        ipc.control(66587,71022)
        ipc.control(66587,71025)
        ipc.control(66587,71022)
        ipc.control(66587,71025)
        ipc.control(66587,71022)
    elseif (old_param < new_param) then
-- compare old and new param and increase of decrease setting of ND accordingly
        ipc.control(66587,71021)
        ipc.control(66587,71024)
    else
        ipc.control(66587,71022)
        ipc.control(66587,71025)
    end
end

event.param("modeKnob")

 

------------------

Extract from the log:

 

811109 LUA: Waiting for an event in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   811890 LUA: ipcPARAM event: calling "modeKnob" in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   811890 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:2
   811890 LUA: Global: ipcPARAM = 20
   811890 LUA: Local: param = 20
   811890 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:3
   811906 LUA: Global: old_param = 30
   811953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:4
   811953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:5
   811953 LUA: Global: new_param = 20
   811953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:14
   811953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:23
   811968 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:27
   812015 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:28
   812031 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:30
   812031 LUA: Waiting for an event in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   813156 LUA: ipcPARAM event: calling "modeKnob" in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   813156 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:2
   813156 LUA: Global: ipcPARAM = 10
   813156 LUA: Local: param = 10
   813156 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:3
   813156 LUA: Global: old_param = 20
   813218 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:4
   813218 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:5
   813218 LUA: Global: new_param = 10
   813218 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:14
   813218 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:23
   813218 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:27
   813265 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:28
   813265 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:30
   813265 LUA: Waiting for an event in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   813609 LUA: ipcPARAM event: calling "modeKnob" in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"
   813609 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:2
   813625 LUA: Global: ipcPARAM = 0
   813625 LUA: Local: param = 0
   813625 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:3
   813625 LUA: Global: old_param = 10
   813765 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:4
   813765 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:5
   813765 LUA: Global: new_param = 0
   813781 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:6
   813781 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:7
   813781 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:8
   813781 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:9
   813937 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:10
   813937 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:11
   813953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:12
   813953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:13
   813953 LUA: E:\FSX\Flight Simulator X\Modules\A320 Mode.lua:30
   813953 LUA: Waiting for an event in "E:\FSX\Flight Simulator X\Modules\A320 Mode.lua"

 

 

Link to comment
Share on other sites

What A320 are you using - Asobo, Fenix or FBW (dev/stable/experimental)?

16 hours ago, shorthauler said:

    old_param = ipc.readLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob") -- reads the position of the knob from the Lvar before the new param is written and names it "old_param"
    ipc.writeLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob", ipcPARAM) -- writes the new param into the Lvar
    new_param = ipc.readLvar("VC_GSLD_CP_EFIS_ND_Mode_Knob") -- names the new param as global function

You are updating an lvar ( ipc.writeLvar) and then reading its value directly afterwards (ipc.readLvar). Due to the time it takes to update an lvar and the asynchronous nature of the request/communication (a request is sent to update the lvar, and later the updated lvar value is passed back to FSUIPC), you will be reading the original value of the lvar and not the new value, i.e. it will be the same as old_para. To prevent this, you can add a delay between the write and read (e.g. ipc.sleep(200)), or just assume that the update/write request has succeeded and just set 'new_param = ipcPARAM'.

But isn't it the case that whatever value is set, the previous value must have been either 10 higher or 10 lower? So, if the current ipcPARAM value is 0, the previous knob position must have been 10, if the current  ipcPARAM value is 10, the previous knob position must have been either 0 or 20, etc. So You only need to either increment or decrement to change the knob one position at a time.

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.