Jump to content

Sign in to follow this  
aerostar

Make a Button Function Toggle LUA

Recommended Posts

Posted (edited)

After failing to be able to use acceleration on my Heading rotary , I have tried to make it toggle between 1 deg steps and 10 deg steps by pressing the button on the rotary.

It's for the Aerosoft Airbus and there is a script for toggling the ALT but not the HDG.  Therefore I copied the ALT script and adjusted to toggle the HDG  but  can't get it to toggle.

Here is the relevant section...  much obliged if someone can help...

AB_HDGSTEP_set

function AB_HDG_Step_tog ()
         var = ipc.readLvar("AB_HDGSTEP_set")
    if var == 1 then
        AB_HDG_Step_1 ()
    else
        AB_HDG_Step_10 ()
    end
end

function AB_HDG_Step_1 ()
         LVarSet = ("AB_HDGSTEP_set")
         ipc.writeLvar(LVarSet, 0)
    Anim = ("AB_AP_HDG_Knob_Ani")
    ipc.writeLvar(Anim, 1)
    ipc.sleep(30)
    ipc.writeLvar(Anim, 0)
end

function AB_HDG_Step_10 ()
         LVarSet = ("AB_HDGSTEP_set")
         ipc.writeLvar(LVarSet, 1)
    Anim = ("AB_AP_HDG_Knob_Ani")
    ipc.writeLvar(Anim, -1)
    ipc.sleep(30)
    ipc.writeLvar(Anim, 0)
end

eb01db8b96357d10cd27f7116b416bf6.png

....and the log

598dc7e21a4b75e47e56dce62fd04383.png

 

The button animation doesn't toggle either (as an indication) but does work both ways in/out if set manually in the script.

 

AB_Triple_HDG.lua

Everything else works great...   press Twice for heading set mode  and press longer for heading managed mode

Edited by aerostar

                        mustang_banner_newstar2777.png

 


 
 
 
 

Share this post


Link to post
Share on other sites

Apologies for messing the Log was trying different things then editing my post... 

I have stripped out the unnecessary parts and this is the part that's not toggling/switching...  I have posted the corresponding Log

where it can be seen that on    button flag 4    it always stays at    ' AB_HDG_Step_10'

I have also included the full  Lua file attached...   not very big.

 

e3bbb65b29f00767f3896fa2a0df13f3.png

 

9206489cbe7cce08adbe5dbaa4a13c87.png

 

Here is the Lua file -              AB_Triple_HDG.lua

 

Ian


                        mustang_banner_newstar2777.png

 


 
 
 
 

Share this post


Link to post
Share on other sites

Are you sure about this LVar name, AB_HDGSTEP_set ? I took a quick look at the LINDA file for the Airbus and the ALT functions you seem to have replicated address an LVar called AB_AP_ALTSTEP. If you are sure, then I would try checking for var ~= 0 in place of var == 1.

  • Like 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites

Hi Mark,  thank you thank you...   I have replaced the   AB_HDGSTEP_set    with the     AB_AP_ALTSTEP     LVar  and now it toggles  and works good...   now the only thing is when I toggle the  HDG step  it also toggles the ALT step   as they are now sharing the same LVar...     I think  that means that I need to properly define the  AB_HDGSTEP_set   LVar as it's probably not being recognised,   I created it.   I thought by naming it and giving it a value outside the Function that would define it.   

I also changed the   ==    to    ~=      

Can I ask how I should define the LVar   AB_HDGSTEP_set    so that it is recognised and usable   ?

Thanks again, 

Ian


                        mustang_banner_newstar2777.png

 


 
 
 
 

Share this post


Link to post
Share on other sites
9 hours ago, aerostar said:

Can I ask how I should define the LVar   AB_HDGSTEP_set    so that it is recognised and usable   ?

Oh I see, you are defining this variable yourself. If you were using LINDA, you could create persistent local Lua variables like you have done here. That's because a LINDA Lua program stays running so all its module-level variables are persistent. But if you're just using plain old FSUIPC Lua, each Lua file is a separate program that runs and terminates when you bind it to a key or event. This means its local variable don't persist. But you can create persistent variables with the ipc.set() library function and read them from other Lua programs with ipc.get(). These aren't the same as LVars, which are variables defined inside of XML gauges.

  • Like 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites

Whoopee...   thanks again Mark,  using    ipc.get    and   .set   works a treat,  it's now all working...   can't figure how the   AB_AP_ALTSTEP    worked though as it is using    readLvar   and   writeLvar  ...

Now I may try and figure a way to get some kind of    Rotary Acceleration   working and then I wouldn't even need the button toggle which would free up another button...    do you use    Rotary Acceleration   and if so, what method do you use...

I hope I'm not over stepping with my questions...   

once again though ,  thank you Mark for your help...

Ian

 


                        mustang_banner_newstar2777.png

 


 
 
 
 

Share this post


Link to post
Share on other sites
40 minutes ago, aerostar said:

do you use    Rotary Acceleration   and if so, what method do you use...

No, I use pretty much the same method as you. The only difference is I set my toggle variable on and off in the button down and button up events for the rotary control's push button. So the push button acts like a SHIFT key. Now I can have slow increments if I just turn the knob, but fast increments if I push and turn it at the same time. Something like this (each of these functions will need to be a separate Lua file):

function Rotary_Shift_ON()  -- Call from the button-down event of the push switch
    ipc.set("RotaryShiftActive", 1)
end

function Rotary_Shift_OFF()  -- Call from the button-up event of the push switch
    ipc.set("RotaryShiftActive", 0)
end

function HDG_Bug_Inc()
    if ipc.get("RotaryShiftActive") == 1 then
        for n = 1, 10 do
            ipc.control(65879)  -- Increment the HDG bug
        end
    else
        ipc.control(65879)
    end
end

function HDG_Bug_Dec()
    if ipc.get("RotaryShiftActive") == 1 then
        for n = 1, 10 do
            ipc.control(65880)  -- Decrement the HDG bug
        end
    else
        ipc.control(65880)
    end
end

 

  • Like 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...