Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

I am trying to read a joystick's axis in a lua script. My controllers have letters assigned and the axis is recognised in the FSUIPC tab as Joy "A" axis "X" (screenshot).

When I run my script this line alway returns 16191 no matter what: m = ipc.axis("A", "X")

I even tried using 0 as joystick number and reading other axises (?) but the result is the same. I have seen this in use e.g. the smooth brake lua script but what am I doing wrong here?

Thanks!

 

Code:

function readX()

m = ipc.axis("A", "X")
strDisplay = m.." "

m = ipc.axis("A", "Y")
strDisplay = strDisplay..m.." "

m = ipc.axis("A", "Z")
strDisplay = strDisplay..m.." "

m = ipc.axis("A", "R")
strDisplay = strDisplay..m.." "

m = ipc.axis("A", "U")
strDisplay = strDisplay..m.." "

m = ipc.axis("A", "V")
strDisplay = strDisplay..m.." "

ipc.display(strDisplay)
end

event.timer(1000, "readX")

 

Log:

1637027 LUA.0: Waiting for an event in "C:\FSX\Modules\pwr.lua"
1638026 LUA.0: Timer event: calling "readX" in "C:\FSX\Modules\pwr.lua"
1638026 LUA.0: C:\FSX\Modules\pwr.lua:8
1638026 LUA.0: C:\FSX\Modules\pwr.lua:9
1638026 LUA.0: C:\FSX\Modules\pwr.lua:11
1638026 LUA.0: Global: strDisplay = 16191
1638026 LUA.0: C:\FSX\Modules\pwr.lua:12
1638026 LUA.0: C:\FSX\Modules\pwr.lua:14
1638026 LUA.0: Global: strDisplay = 16191 16191
1638026 LUA.0: C:\FSX\Modules\pwr.lua:15
1638041 LUA.0: C:\FSX\Modules\pwr.lua:17
1638041 LUA.0: Global: strDisplay = 16191 16191 16191
1638041 LUA.0: C:\FSX\Modules\pwr.lua:18
1638041 LUA.0: C:\FSX\Modules\pwr.lua:20
1638041 LUA.0: Global: strDisplay = 16191 16191 16191 16191
1638041 LUA.0: C:\FSX\Modules\pwr.lua:21
1638041 LUA.0: C:\FSX\Modules\pwr.lua:23
1638041 LUA.0: Global: strDisplay = 16191 16191 16191 16191 16191
1638041 LUA.0: C:\FSX\Modules\pwr.lua:24
1638041 LUA.0: C:\FSX\Modules\pwr.lua:26
1638041 LUA.0: Global: strDisplay = 16191 16191 16191 16191 16191 16191
1638057 LUA.0: C:\FSX\Modules\pwr.lua:27
1638057 LUA.0: Waiting for an event in "C:\FSX\Modules\pwr.lua"
1639040 LUA.0: ended "C:\FSX\Modules\pwr.lua"

 

FSUIPC4.ini

axisAssign.jpg

Posted

The problem is that you don't have any axes assigned to Joystick "A", so FSUIPC isn't actually scanning any of them. The ipc.axis function only grabs the last polled value for the specified axis, it doesn't institute a poll of its own.

"16191" is 3F3F in hex, and that's part of a 32-bit value "0x3F3F3F3F" used to initialise the read area so that the first change will be seen. The ipc.axis function only takes the lower 16 bits.

The Lua library description of ipc.axis does say:

Returns the current assigned axis value as read from the device (i.e.
before calibration). 

I suppose it could be a little more useful if, when a Lua program did use this function, that it either did its own poll, or maybe add the axis to those to be regularly polled. The former is quite a big addition, being new DirectInput code in the Lua package, and the latter would be rather wasteful if the Lua function was simply a one-off need in a session. However, if it s very important I could look to see how feasible one of these changes would be in the current structure.

The assignment need not be to anything of any effect.  For instance, assign to <custom control> with a value 65536. That's a reserved control value which does nothing at all.

Pete

 

 

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.