Jump to content
The simFlight Network Forums

[Lua] Scan controller buttons from Lua on startup / auto


Recommended Posts

Posted

Looking for the easiest way to get the button state from a controller in a lua script that I'm running as "Auto" when FSUIPC starts up. My code is working, but things don't fall into place until I put some input on the controller I'm mapping. As soon as I provide any input - everything starts acting as expected.

I tried using the initreport from com.openhid, but I may not be doing this right. Here's what I'm at with this:

handle, rd, rdf, wr, initreport = com.openhid(0x04D8, 0x8A3D);

for i = 0, 3, 1 do
    local state = com.testhidbutton(handle, i, initreport);
    if (state) then
        ipc.log(i .. ": on");
    else
        ipc.log(i .. ": off");
    end
end

Regardless of the actual button state (actual physical switches in my case), all buttons come back as false, until I trigger any button - at which point they all immediately start reporting correctly. Is there a way to force it to "scan" the controller, or maybe I'm just doing it wrong?

Posted

Ok - this seems to take care of it:

handle, rd, rdf, wr, initreport = com.openhid(0x04D8, 0x8A3D);
initreport = com.readreport(handle, 0);

for i = 0, 3, 1 do
    local state = com.testhidbutton(handle, i, initreport);
    if (state) then
        ipc.log(i .. ": on");
    else
        ipc.log(i .. ": off");
    end
end
ipc.log("val1: " .. com.gethidbuttons(handle, initreport));

I'm not sure if that com.readreport is the right approach, but it's working. If anyone has a thought on this, please share.

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.