Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I'm trying to setup my miniFCU unit with the Majestic Q400 on FSX + FSUIPC 4.977.

In order to communicate with the autopilot commands I've written small lua scripts and assigned them using MobiFlight. When I rotate any of the encoders, it sends many Lua scripts calls at once and Flight Simulator freezes a bit while processing the commands. It works ok if the encoder is turned slowly one notch at a time. But if turned quickly, likely only a single command is registered. Any thoughts on how I can improve the performance?

Here is an example of the code used to change the pitch bug.

ipc.writeLvar("MJC_VAR_WRITE_VALUE", ipcPARAM)
ipc.writeLvar("MJC_VAR_WRITE_CODE", 46987)

 

Posted
1 minute ago, level7 said:

But if turned quickly, likely only a single command is registered. Any thoughts on how I can improve the performance?

Here is an example of the code used to change the pitch bug.

ipc.writeLvar("MJC_VAR_WRITE_VALUE", ipcPARAM)
ipc.writeLvar("MJC_VAR_WRITE_CODE", 46987)

I would need to see the complete lua script to advise. But for performance issues, make sure the lua is always running, i.e. it uses the event library and is not compiled and started each time on a button/key press.

Also, to improve lua performance, you should consider setting the  LuaAffinityMask ini parameter to move the lua execution threads off of core 0/1.
This goes in the [General] section and is a mask of the cores to use - if you are not sure what value to use, you can use this web page to calculate it for you: https://bitsum.com/tools/cpu-affinity-calculator/.

For example, I have 6 physical cores, but really 12 as I have hyper-threading (HT) active. To move lua threads off of core 0/1, and use 2-11, I would set
      LuaAffinityMask=xFFC

For rotary encoders that only have one button in each direction, you can also consider using a lua script that gives both fast and slow virtual buttons in each direction, so that you can assign larger inc/dec values on a fast virtual button. Such a script is provided in the example lua plugins.

John

Posted

Thanks John!

That is actually the entirety of the script that is run to change the pitch bug by 1. It is run once each notch of the encoder (yes sounds very inefficient).

How can I "make sure the lua is always running"? It didn't seem appropriate to include this in the [Auto] section since I don't need it to run on the airplane load.

Posted
28 minutes ago, level7 said:

That is actually the entirety of the script that is run to change the pitch bug by 1. It is run once each notch of the encoder (yes sounds very inefficient).

Yes, as each time the script is ran, it needs to be compiled first.

28 minutes ago, level7 said:

How can I "make sure the lua is always running"? It didn't seem appropriate to include this in the [Auto] section since I don't need it to run on the airplane load.

It needs to be auto-ran, but you need to modify the script and assignments first. As you are using ipcPARAM, you could try:

function setPitchBug(param)
    ipc.writeLvar("MJC_VAR_WRITE_VALUE", param)
    ipc.writeLvar("MJC_VAR_WRITE_CODE", 46987)
end

event.param("setPitchBug")

Have that auto-ran, and change your assignment to  use LuaValue <name-of-plugin> together with the parameter (if not using that already).
Alternatively, you could remove the assignments in FSUIPC, and use the lua event.button function to handle the rotary buttons and then send the appropriate commands in the handling function for the button press/release event(s).

John

 

 

Posted

Thanks John, I tried using the function but MobiFlight doesn't seem to be able to call the script with the function.

It seems there is inherently going to be some lag in using lua scripts with encoders 😞.

Posted
6 hours ago, level7 said:

Thanks John, I tried using the function but MobiFlight doesn't seem to be able to call the script with the function.

So you are assigning in MobiFlight and not in FSUIPC? How was mobiflight starting your original lua script?
Why don't you assign in FSUIPC rather than in  MobiFlight?

6 hours ago, level7 said:

It seems there is inherently going to be some lag in using lua scripts with encoders 😞.

No, this is just not true. Many people are using lua scripts to control encoders perfectly fine with FSUIPC.
But if assigning in MobiFlight I cannot help. 
If you are using MobiFlight, then why are you using lua? 
I don't know how (or why) you use FSUIPC's lua capabilities via MobiFlight,  but I would recommend either using lua via FSUIPC or asking on the MobiFlight discord how you can assign to set lvars in MobiFlight without using lua - I am sure that is possible (using a presetm for example). 

Posted

The main issue is the weird way Majestic did their Q400 variable interface. So as you saw before in order to execute certain commands you need to make 2 writes to an LVAR, one for the the "value" and the other for the "key".

The miniFCU device that I am using has a MobiFlight interface. There doesn't seem to be a good way for hardware inputs to make FSX/P3D LVAR changes without Lua. So what I think I'm left with is the MobiFlight's ability to call a Lua script to make the 2 LVAR writes. I could try some alternatives like 1) using MobiFlight's Keyboard or vJoy input as an interface to make the FSUIPC calls 2) having the encoder make calls to an offset and observing those offsets to make make the LVAR writes.

 

Posted
3 minutes ago, level7 said:

The main issue is the weird way Majestic did their Q400 variable interface. So as you saw before in order to execute certain commands you need to make 2 writes to an LVAR, one for the the "value" and the other for the "key".

But I thought MF has its own inteface to lvars - why don't you just use that? Or you can create a preset/calc. code to set both lvars,

I can't help with MobiFlight though - you should ask about this in their discord server. Note they they usually tell people that you don't need to use FSUIPC if using MobiFlight with MSFS.

7 minutes ago, level7 said:

2) having the encoder make calls to an offset and observing those offsets to make make the LVAR writes.

There are two ways to do this:
    - use offset 0x7C50
    - add the lvars that you want to update to spare/free FSUIPC offsets (via the FSUIPC7.ini file) and just write to those offsets

John

Posted

Thanks for the suggestions. The Q400 is for FSX/P3D but MobiFlight only writes to MSFS LVARs for some reason. When I have some time I'll check the offset approach.

image.png.40b5cb8ce6809030544578ee9289ba29.png

Posted
4 hours ago, level7 said:

The Q400 is for FSX/P3D but MobiFlight only writes to MSFS LVARs for some reason.

Ah, yes...sorry, was thinking of MSFS and not FSX/P3D...

Note that you can also call lua scripts with LuaValue by using offset 0x0D70. So if your script was auto-ran, you can send it the ipcParam value by first writing the value to offset 0x0D6C and then write "LuaValue <scriptName>" (where <scriptName> is the name of your lua script) to offset 0x0D70.

But if I were you I would ask for advice on the best way to accomplish this to the MobiFlight folks, as I am sure there must be an easier way...
I don't use MobiFlight so cannot really advise on this, but MF support is pretty good so try there...

Cheers,

John

 

Posted

One more thing...if a button/rotary is calling a lua script very fast (or on repeat), what happens is that the first press compiles and executes the lua, but when the next press is received, if the previous lua is still being compiled or ran. then that thread is terminated and a new thread started. So what is happening when you turn the rotary fast is that each lua execution thread is being terminated/killed before it is doing anything. What you can do is increase the LuaRerunDelay ini parameter, which will give each lua execution thread more time to run before it is killed. The default value of this parameter is 66 - try increasing to say 200 (ms), to see if that improves things, and you can adjust up/down from there.

John

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.