Jump to content
The simFlight Network Forums
Genew

Slider read problem in Lua library

Recommended Posts

I have a question regarding a slider axis control. I am running FSX in Windows 7, and I have a registered FSUIPC 4.974b. I also have Lua 5.1. My sim yoke is a PFC Cirrus, relatively new, operates direct with no included software drivers. This yoke has a “throttle” slider that I wish to repurpose for carb heat for my A2A PA28.

In the Axis Assignment in FSUIPC the slider control shows up as “Joy 0” lever “S” and shows changing values as I move the slider. On page 41 of the FSUIPC manual “S” is listed as a valid axis identification. On page 1 of the Lua library reference under ipc.axis, the “S” is not listed as an acceptable assignment. Enclosed here is my test Lua script, and the resulting log file. This proves that ipc.axis does indeed read values on the “X” axis of the yoke, but not the “S” values as I move the “throttle” lever. For testing purposes I forced the Lvar and that works. Am I missing something here?

-- Carb test pogram for A2A PA28  3-6-19
-- clear down the display
ipc.setowndisplay("Lua test",3,3,10,30)  -- My screen is 3 screen wide
ipc.lineDisplay("", 0)
val = 0
for loopaxis = 1,5 do
    n=ipc.axis(0,"S")    --Slider axis
    showit = string.format("Slider read: %d", n)
    ipc.lineDisplay(showit)
    ipc.log(showit)
    X=ipc.axis(0,"X")   --Yoke X axis
    showit = string.format("Aileron read: %d", X)
    ipc.lineDisplay(showit)
    ipc.log(showit)

    ipc.writeLvar("Eng1_CarbHeatSwitch",val)
    val = val+30
    ans = ipc.ask("Press q to exit")
    if ans == "q" then ipc.exit() end
end

********* LUA: "CarbTest" Log [from FSUIPC version 4.974b] *********
    60076 System time = 06/03/2019 11:55:11, Simulator time = 12:46:22 (16:46Z)
    60076 LUA: beginning "D:\FSX\Modules\CarbTest.lua"
    60107 LUA: Slider read: 16191
    60138 LUA: Aileron read: -680
    60154 LUA Asks: "Press q to exit"
   177373 LUA Reply: ""
   177373 LUA: Slider read: 16191
   177389 LUA: Aileron read: -1417
   177420 LUA Asks: "Press q to exit"
   181616 LUA Reply: ""


Thanks for any help you can provide.

 

Gene

 

FSUIPC4.JoyScan.csv

Share this post


Link to post
Share on other sites

Gene,

You could, as an option, use the available "LuaValue <my lua name>" assignment under "Type of action required" field on the left side of the "Axis Assignment"  tab of the FSUIPC user interface.
Basically you are assigning the values of the slider to be applied to the lua.
Any slider value change is caught by the event facilities in the lua library and sent to the called function. BTW, the event facilities are the "cats meow" . 👍😸
Have the lua be autostarted via [Auto], preferably in profiles.
Then, in the lua -

function carbHeatAxis(val)
	val = val --[[plus any required math to get the correct values]]
	ipc.writeLvar("Eng1_CarbHeatSwitch", val)
end

event.param("carbHeatAxis")

Hope this helps,
Roman

Share this post


Link to post
Share on other sites

Thank you, Roman. That is the help I needed. I spent the last couple days re-reading the manuals, I did not realize that the "send to FS as normal axis" had all those options, I have my normal axes all set as direct. I am aware of the event facilities, I previously wrote a couple Lua programs that control the radio buttons with my Go Flight hardware. They work just fine.

Gene

  • Upvote 1

Share this post


Link to post
Share on other sites
On 3/6/2019 at 6:33 PM, Genew said:

On page 41 of the FSUIPC manual “S” is listed as a valid axis identification. On page 1 of the Lua library reference under ipc.axis, the “S” is not listed as an acceptable assignment.

Both "S" and "T" are recognised by the ipc.axis function. The omission in the documentation dates from the FSUIPC3 implementation, so apologies. The document will be fixed.

As to why it didn't work or, rather, did, but returning the fixed value 16191 (?), that needs checking here. The treatment of the S and T axes is no different in the code to the other 6, so it doesn't make sense,  We'll have to find a device with an S axis to test. So it's good that you have an alternative suggestion.

Pete

 

Share this post


Link to post
Share on other sites

One question: is the S axis assigned in FSUIPC? If not, does the Lua code work if you do assign it? I've a feeling it needs to be assigned to be recorded, but I've not checked the code yet -- tomorrow. The difficulty for us is that we have no "S" axis device between us, so it is more complex trying to set up a simulation for it.

Pete

 

Share this post


Link to post
Share on other sites

Hi Pete, thank you for responding to this issue. I have all of my FSUIPC assignments as direct, as I read that is more efficient, & it makes perfect sense to me. I was trying to assign the slider to the carb heat function, but that is not an option in the direct assignments. So the answer is it was not assigned. I never thought to try to assign to FSX option as I did not see why that would make any difference. Roman's suggestion to look for the "Lua value" option caused me to poke around for it, which I found in "send to FS as normal value". Then 3 or 4 lines of Lua code completely solved the problem. Since I needed to send to an Lvar for my A2A PA28 this was the way to do it. I have been using FSUIPC for about 8 years now for my sim, and I just learned something new. And useful! Thank you!

Gene

Share this post


Link to post
Share on other sites
On 3/17/2019 at 9:29 PM, Genew said:

I was trying to assign the slider to the carb heat function, but that is not an option in the direct assignments.

No, but you can mix "direct" and "normal axis" controls. But even so, carb heat is an on-off control, isn't it? Not an axis control with variable settings. At least not in the prop aircraft I fly.

On 3/17/2019 at 9:29 PM, Genew said:

So the answer is it was not assigned. I never thought to try to assign to FSX option as I did not see why that would make any difference.

The problem, and it isn't made clear in the documentation at present, is that FSUIPC only stores the axis values for those axes it scans, and it only scans those which are assigned. This is for efficiency, as it tries to scan frequently enough to avoid missing much.

Of course if necessary you can assign to any innocuous axis control -- i.e. one having no effect or application in any of the aircraft you use.

Pete

 

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

×

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.