Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Could someone please confirm event.button() is working in the latest FSUIPC7 ver 7.3.7.  I have tried using the example TripleUse.lua script "as is" (copy and paste) except for my particular yoke and button, and can not get it to work. When I press the button on my yoke the FSUIPC7 button assignment window shows Joy# Y and Btn# 0, so in the top of the script I have assigned joy = "Y" and btn = 0.

My FSUIPC7.ini file shows my yoke as below, so I have also tried using joy=0 in the lua script but it made no difference.

Y=Fulcrum One Yoke
Y.GUID={99F39220-9632-11EB-8001-444553540000}
0=Fulcrum One Yoke
0.GUID={99F39220-9632-11EB-8001-444553540000}

I have been able to confirm the script is being called when I push the yoke button, but event.button() does not seem to be calling the function "buttonpress".

Here is the complete script:

joy ="Y"
btn = 0
interval = 500    -- 1/2 second press, gap, press limits
ignorepress = false

-- Function to time the button being pressed or left released
-- Allow only up to "interval" till decide no change

local function timebutton(test)
  while true do
        time2 = ipc.elapsedtime()
        if (time2 - time1) > interval then
            ignorepress = false
            return false
        end
         if ipc.testbutton(joy, btn) == test then
            time1 = time2
            return true
        end
         ipc.sleep(20)
    end
end

function buttonpress(j, b, du)
 --    ipc.control(66375)            -- GPS/NAV toggle used just for testing if buttonpress() is being called. This does not work when the ipc.control code is enabled.
    if ignorepress then
       ignorepress = false
       return
    end
 
    -- Note time button was pressed
    time1 = ipc.elapsedtime()
    time2 = 0

    if timebutton(false) then
        -- First press / release counts: see if there's another
        if timebutton(true) then
            -- got another press in time, look for release
            if timebutton(false) then
                -- this was a double press, send VIEW RIGHT
                ipc.control(65676)
            end
      else    
            -- This was a single press, send VIEW LEFT
            ipc.control(65680)
            ignorepress = false
        end
    else
        -- This was a longer press, send VIEW FORWARD
           ipc.control(65674)
    end
end

 --    ipc.control(66375)            -- GPS/NAV toggle used just for testing if script is being called. This does work when the ipc.control code is enabled.

-- Enable event on button being pressed (only)

event.button(joy, btn, 1, "buttonpress")

If event.button() is working for others, than I will go back and see if I can figure out what I'm missing.

Thanks,

Al

Posted
14 hours ago, ark1320 said:

I have been able to confirm the script is being called when I push the yoke button, but event.button() does not seem to be calling the function "buttonpress".

How have you confirmed this? Is it running from an [Auto] ot profile-specific [Auto.xxx] section?

14 hours ago, ark1320 said:

 --    ipc.control(66375)            -- GPS/NAV toggle used just for testing if script is being called. This does work when the ipc.control code is enabled.

If the script is running and working correctly, that control must always be sent (when uncommented) as it is not within a function definition. If that is not being calles, then neither is the event.button(joy, btn, 1, "buttonpress") call.

Could you please activate debugging for Buttons & Keys and Lua Plugins, generate a log file where you load your aircraft and start the lua and then press the assigned button  (joystick Y, button 0), and then exit. Then attach (not copy) your FSUIPC7.log, FSUIPC7.ini and lua script.

John

Posted
1 hour ago, John Dowson said:

Is it running from an [Auto] or profile-specific [Auto.xxx] section?

If the script is running and working correctly, that control must always be sent (when uncommented) as it is not within a function definition. If that is not being calles, then neither is the event.button(joy, btn, 1, "buttonpress") call.

Hi John,

Yes, the script is running from an [Auto] section.

In addition to the [Auto] section, for testing I assigned a 2nd button to call the script, and when the script is called either initially by [Auto] or by the 2nd button, the uncommented  control near the bottom of the script does work.  However, when uncommented, the control inside the buttonpress function does not work when the button that is to be detected by event.button() is pushed (I only uncomment one of the controls at a time to see what is happening).

I will get the files you requested.

Thanks,

Al

Posted
3 minutes ago, John Dowson said:

It is the debug log that will show you what is happening....

John

Well, after cleaning out some of my apparently not so brilliant test code (☹️), the basic script works, but with a bug. I am using the script to turn the AP on and off -- one push of the yoke button to turn the AP on, a double push to turn the AP off.  The single push does turn the AP on, but the double push first turns the AP off and then immediately turns if back on. So I seem to have a timing issue that I need to figure out.

Thanks.

Al

Posted
8 minutes ago, ark1320 said:

So I seem to have a timing issue that I need to figure out.

Use the lua plugin logging facility - that should tell you what is happening, and maybe also log Events...

John

Posted

I was able to get the script working by adding the line below in the double push code section.  For some reason after a double button push was detected and the AP turned off, apparently an additional push was detected and the AP turned right back on. I have to wonder if there might be some kind of "delay" due to how MSFS responds to a button push such that the 2nd push of a double push sequence shows up "again" outside the 500ms window. I looked at the log files and they show the AP was turned off, and then back on about 875 msec later.  I did try using a button on a different controller in case the yoke button was noisy, but the results were the same. Thanks for the help, John.

So in case if helps someone else here is what I ended up with. One button push to turn on the AP and YD, and a double push to turn them off. I am not using the "long push" option.

function timebutton(test)
    while true do
        time2 = ipc.elapsedtime()
        if (time2 - time1) > interval then
            ignorepress = false
            return false
        end
         if ipc.testbutton(joy, btn) == test then
            time1 = time2
            return true
        end
         ipc.sleep(20)    
    end
end

function buttonpress(j, b, du)
   --  ipc.control(66375)            --toggles GPS/VLOC and NAV for testing purposes

    if ignorepress == true then
          ignorepress = false
          return
    end
    -- Note time button was pressed
    time1 = ipc.elapsedtime()
    time2 = 0

    if timebutton(false) then
        -- First press / release counts: see if there's another
        if timebutton(true) then
            -- got another press in time, look for release
            if timebutton(false) then
                -- this was a double press, AP and YD OFF
                ipc.control(65791)                        -- turn AP off
                ipc.control(66070)                        -- turn YD off. Button on yoke should turn YD off when same button turns AP off.
                ignorepress = true                          --  added this line
            end
         else    
            -- This was a single press, AP and YD on
            ipc.control(65792)                        -- turn AP on
            ipc.control(66069)                        -- turn YD on
            ignorepress = false
       end
    -- else
           -- This was a longer press, this is not used.
           -- do something here for long press

    end
end

-- ************************  Main Program  **********************************

joy = "Y"      -- Fulcrum yoke
btn = 0        -- red button on yoke
interval = 500       -- 1/2 second (500ms) press , gap, press limits
ignorepress = false

-- Enable event on button being pressed (only)
event.button(joy, btn, 1, "buttonpress")

Posted

Yes, looking at the code, that would seem to be needed. All the controls are sent on the first button push, even if there is a double push, so the second push is triggering the single push action when it should be ignored. In fact, without that additional line, the ignorepress variable is never set to true! I am not sure why this hasn't been picked-up before, but I will update the example script.

Thanks for reporting back,

John

Posted
8 hours ago, John Dowson said:

In fact, without that additional line, the ignorepress variable is never set to true!

Yes, I noticed that as well.  🙂

Al

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.