Jump to content
The simFlight Network Forums

Help with slowdown Majestic Q400, LUA, P3D4.4


Recommended Posts

Hi, please could you help me out?  I wish to assign some commands to my joystick for the Majestic Q400 in P3D 4.4, FSUIPC (UpdatedByVersion=5150).

As an example, the speed bug setting.  I have the following in the lua (I found these commands in a file for LINDA):

-- MIP_SPDBUG_INC
if ipcPARAM == 105 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 43080)
end

-- MIP_SPDBUG_DEC
if ipcPARAM == 106 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", -1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 43080)
end

-- MIP_SPDBUG_PRESS
if ipcPARAM == 107 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 75899)
end

and in the fsuipc5.ini I have:

146=66,8,L10:R,107     -{B: Press=Lua mjc8q400 }-
148=66,9,L10:R,105     -{shft+B: Press=Lua mjc8q400 }-
150=66,10,L10:R,106     -{ctl+B: Press=Lua mjc8q400 }-

It I have assigned the keystrokes using my joystick's (X52 Pro) software to a wheel on the throttle (it's like a mouse wheel, and is seen as three buttons: up, down, press).  It works, but as the commands are sent, the sim is interrupted and drastic frame rate drops occur.  I am running in VR, so it makes it unusable.

I have also tried assigning directly to joystick button(s) (rather than using keystrokes w/ joystick software) and the same thing happens.

The same thing happens for other buttons and similar functions:  e.g. the VS wheel, on a toggle switch.  There are no issues assigning commands in the usual (fs controls, not lua) way (e.g. 73=190,8,65615,0     -{.>key: Press=ELEV_TRIM_UP }-)

It's been a while since I used lua / fsuipc, but I don't think I'm doing anything differently now, and I don't think I've ever had this issue before.

Thanks for any suggestions.

Link to comment
Share on other sites

9 hours ago, Hipp0 said:

It I have assigned the keystrokes using my joystick's (X52 Pro) software to a wheel on the throttle (it's like a mouse wheel, and is seen as three buttons: up, down, press).  It works, but as the commands are sent, the sim is interrupted and drastic frame rate drops occur.

How odd.   How have you assigned the keypresses to a wheel? I don't understand. 

Test them using the keyboard, not a wheel. After all they are keypresses. If the wheel is an axis input, how are you selecting where they keypresses are sent How do you stop masses of keyboard inputs being sent, clogging up Windows queues (Enabled key/button logging in FSUIPC Logging to see this).

9 hours ago, Hipp0 said:

I have also tried assigning directly to joystick button(s) (rather than using keystrokes w/ joystick software) and the same thing happens.

In that case I would guess that your PC is already fairly loaded up, and the act of invoking a Lua plug-in -- cresating the thread, compiling the program, running it, then destroying the thread, is too much. Instead of making this happen you should put the whole of the Lua code into a function, use event.param to invoke it when a parameter is supplied, and load the Lua up when the aircraft is loaded, using the [Auto.profile name] facility (or at the start of the session if you wish, using [Auto].

Then instead of assigning to Lua mjc8q400 you assign to LuaValue mjc8q400.

That method then merely uses existing compiled code in an existing thread because all the work to get it there has already been done, just once.

Pete

 

 

Link to comment
Share on other sites

Hi Pete,

Many thanks for replying.  Unfortunately I'm being dense, I sort of get what you mean but have no idea how to implement it.  I've skimmed through the manuals, and searched these threads, but am unable to find an example of what to do.  I wonder if I could trouble you to add a bit more detail to your response by way of an example.

Could you explain how to assign the following function to be activated on a joystick button press / or key:

I have the following in the mjc8q400.lua file:

function AP_AP_press ()
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 11)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 33470)
end

I have

[LuaFiles]
10=mjc8q400

in the fsuipc5.ini

I don't know what to do with event.param, I assume something like

event.param("AP_AP_press")

but where would this go, and is it correct?

I assume the [Auto.Q400] section goes into FSUIPC5.ini but have no idea what to put into it.

I assume that once the lua file and [Auto] section are correctly set up, I can assign each function to a button / key as always as you state above:

Quote

Then instead of assigning to Lua mjc8q400 you assign to LuaValue mjc8q400.

 

Link to comment
Share on other sites

25 minutes ago, Hipp0 said:

I've skimmed through the manuals, and searched these threads, but am unable to find an example of what to do. 

There are actually a lot of Lua examples in a Zip file in your FSUIPC documents folder. But in case you can't find one which you can follow:

27 minutes ago, Hipp0 said:

Could you explain how to assign the following function to be activated on a joystick button press / or key:

I have the following in the mjc8q400.lua file:

function AP_AP_press ()
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 11)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 33470)
end

But why have you lost the "ipcPARAM" checks, sending different Lvars for different functions? The whole point was to put you earlier code into a function, which is then called by event.param("function name"), which you place at the end of the Lua file. It's another line in your program, that's all!

Then, as i said, you assign as you did before, but using LuaValue mjc8q400 instead of Lua mjc8q400.

30 minutes ago, Hipp0 said:

[LuaFiles]
10=mjc8q400

in the fsuipc5.ini

That is not relevant. It is created automatically by FSUIPC. Don't edit that section at all. T

34 minutes ago, Hipp0 said:

I assume the [Auto.Q400] section goes into FSUIPC5.ini but have no idea what to put into it.

Just a line to run the Lua file, like 1=Lua mjc8q400.

Pete

 

Link to comment
Share on other sites

Thanks again Pete, sorry to ruin your Saturday.  I think I'm slowly getting there.  The issue of the slowdown seems to have gone, but I am not able to send each command more than once, e.g. for SPDBUG_INC, it will increment once, but no matter how many times I hit the key it won't increment again (until I press another key).

***

This is my mjc8q400.lua:
 

Quote

 

function q400Commands()

-- TOGA
if ipcPARAM == 100 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 27120)
end

-- AP DISC
if ipcPARAM == 101 then
    ipc.writeLvar("L:Q400_AP_DISENGAGE_KNOB", 1)
end

-- AP AP
if ipcPARAM == 102 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 11)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 33470)
end

-- AP VS PITCH DN
if ipcPARAM == 103 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 46987)
end

-- AP VS PITCH UP
if ipcPARAM == 104 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", -1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 46987)
end

-- MIP_SPDBUG_INC
if ipcPARAM == 105 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 43080)
end

-- MIP_SPDBUG_DEC
if ipcPARAM == 106 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", -1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 43080)
end

-- MIP_SPDBUG_PRESS
if ipcPARAM == 107 then
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", 1)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 75899)
end

end

event.param("q400Commands")

 

 

 

 

In the fsuipc5.ini I have:
 

Quote

 

[LuaFiles]
10=mjc8q400

[Auto.Q400]
1=Lua mjc8q400

 

[Keys.Q400]

 

89=81,8,L10:V,102     -{Q: Press=LuaValue mjc8q400 }-
91=87,8,L10:V,101     -{W: Press=LuaValue mjc8q400 }-
93=69,8,L10:V,100     -{E: Press=LuaValue mjc8q400 }-

 

139=86,9,L10:V,103     -{shft+V: Press=LuaValue mjc8q400 }-
141=86,10,L10:V,104     -{ctl+V: Press=LuaValue mjc8q400 }-

 

146=66,8,L10:V,107     -{B: Press=LuaValue mjc8q400 }-
148=66,9,L10:V,105     -{shft+B: Press=LuaValue mjc8q400 }-
150=66,10,L10:V,106     -{ctl+B: Press=LuaValue mjc8q400 }-

 

 

Link to comment
Share on other sites

41 minutes ago, Hipp0 said:

Thanks again Pete, sorry to ruin your Saturday.  I think I'm slowly getting there.  The issue of the slowdown seems to have gone, but I am not able to send each command more than once, e.g. for SPDBUG_INC, it will increment once, but no matter how many times I hit the key it won't increment again (until I press another key).

Ah. The problem with using event.param is that it reacts to a CHANGE in the parameter. Setting a value the same as the previous one doesn't look like anything happened, so it doesn't trigger.

You could do one of two things:

If you insist on using key presses (why is that, by the way -- you never explained this "wheel" assigning method), then assign the key RELEASE as well as PRESS, but make the release assignments send 0 as the parameter, which won't do anything.

Really all this is probably more efficient with buttons.

If you need to be able to hold the key down (or button) and have it repeating, then it gets more complicated. You'd really then be better off re-writing the Lua to read the key presses (or preferably button presses) itself, using event.key (or event.button). then you don't need to assign anything at all in FSUIPC assignments.

Pete

 

Link to comment
Share on other sites

Quote

If you insist on using key presses (why is that, by the way -- you never explained this "wheel" assigning method).

I wish I'd never mentioned this now as it's a bit of a red herring.  The wheel is like a mouse wheel, so in practice works as 3 buttons(2 for rotation, 1 as a press), each click-turn of the wheel is like a button press and release.  It is NOT an axis. 

I use keys and the joystick's software because if I do this I can get the display (the throttle has a small display) to tell me what each button assignment does as I press it (which was once very convenient - in VR not so much!).  Also, I use modifier buttons which are much easier to implement in the joystick software than with fsuipc.  I could do it all with buttons, and will do so if required.

Quote

If you need to be able to hold the key down (or button) and have it repeating ...

I think, in this case, that I don't.  However, I will do at some point, so will investigate.

Quote

 

If you insist on using key presses (why is that, by the way -- you never explained this "wheel" assigning method), then assign the key RELEASE as well as PRESS, but make the release assignments send 0 as the parameter, which won't do anything. 

Really all this is probably more efficient with buttons.

 

I will try to set the release as described.  But wouldn't you have to do the same thing with buttons?

I think everything will work fine, so hopefully will leave it there.   I have plenty of options to try it seems.  Thanks for all your help.

Link to comment
Share on other sites

12 minutes ago, Hipp0 said:

I will try to set the release as described.  But wouldn't you have to do the same thing with buttons?

Yes. It's just that FSUIPC detects button presses directly, whereas key presses go to windows which puts them into p3D's message queue, which FSUIPC hooks into iso it can see if it should process them or not. This is why, with any joystick use, I advise using button assignments if possible.

Pete

 

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.