Sign in to follow this  
MarkDH

Synchronize FSX with your switches

Recommended Posts

I have written a function that scans all of the switches on all of the joysticks you have connected and determines whether each switch is ON or OFF. It then calls the Lua functions you have associated with those switches in LINDA. This ensures that your FSX aircraft is in sync with your switches. It seems to work pretty well for me, so I am uploading it here for people to try out.

 

To use this, just download the file and put it in your fsx\modules\linda\libs folder, then you can call the function, SYNC_Aircraft_To_Switch_Settings(), by linking it to a button. The only thing to note is that this will never call any Lua function with the word 'toggle' in its name.

 

If you want to try this out, you can download the file here.

 

Let me know how it works for you!

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Can you post it here?  I don't have an account there.

 

Well no, I can't seem to add attachments here. However, I have added a reply to the post linked above with the text of the Lua file. Just create your own text file and paste the text into it.

Share this post


Link to post
Share on other sites

I'll try it out.  (I wish developers would avoid toggle commands).

Share this post


Link to post
Share on other sites

I'll try it out.  (I wish developers would avoid toggle commands).

 

Yes, toggles really screw things up :(

Share this post


Link to post
Share on other sites

:smile:Thank you.

Now to try it....

Didn't work.  I have 5 controller boards that I use for switches and buttons.  Should I have to edit anything to get the script to see them?  Linda sees the boards.

 

Is it sufficient to assign the script to the default aircraft in FSX to have it work with any aircraft or do I have to assign it for each aircraft I use?  (dodo and some asa aircraft)

 

The ShowMessageWindow("Scanning switches...") never shows.

Linda Console says attempt to call global 'ShowMessageWindow' (a nil value)

Share this post


Link to post
Share on other sites

Commenting out the ShowMessage, ShowMessageWindow and HideMessageWindow calls allowed it to work, somewhat.

 

It missed a couple of switches. Could this be a timing issue???

 

Also, one of my controllers has 64 buttons.  Can this routine handle it?

Share this post


Link to post
Share on other sites

 

 


I'll try it out. (I wish developers would avoid toggle commands).

 

It's not always the developers fault, they're just using the standard FSX commands in many of those cases.  There's an annoying amount of those that are toggles.

 

However, the way around (with something like LINDA, or using the built-in FSUIPC functionality) it is to write Lua code that checks the state of the item in the simulator being toggled, before it actually activates the toggle. That way, it's impossible to get a switch out of sync.  However, to keep from having switches start off being out of sync, something like what the OP has done is very useful.

 

It's possible to have Lua code that automatically polls the status of both the sim and the switches, but you have to be really careful or else you can quickly add a performance penalty.

Share this post


Link to post
Share on other sites

to write Lua code that checks the state of the item in the simulator being toggled, before it actually activates the toggle

Jimmy, that is brilliant and I am going to try to add it to those of my LINDA functions built around toggles (the RXP GPS ON/OFF, for example, is a recurrent pain)!

Commenting out the ShowMessage, ShowMessageWindow and HideMessageWindow calls allowed it to work, somewhat.

 

It missed a couple of switches. Could this be a timing issue???

 

Also, one of my controllers has 64 buttons. Can this routine handle it?

Last one first - no, it will not handle 64-button controllers as FSUIPC does not handle them.

 

The ShowMessage puzzles me, but try moving the message functions to the top of the file. That error suggests they need to be defined above the main function. (I already have these functions defined in a different library so this may be hiding the problem for me.) The ShowMessage stuff slows it down too, but as this takes 10+ seconds to run (for me) any way I think it's better to see that something is happening.

 

It seems crucial for me to discover how it missed some functions. It would helpful if you could uncomment ALL the ipc.log calls in the code and then send me (or post here) the log (copied from fsuipc.log). You may have some switch combinations that I have not anticipated. You will also need to say which ones were missed and, if possible, something about the switch (e.g. if it is part or an ON-OFF-ON or an ON-ON-ON switch). It may be able the order in which the LINDA functions are called that's the issue.

 

Thanks for trying!

Share this post


Link to post
Share on other sites

Moving the message functions to the top fixed that....except the message window doesn't close.

 

The switches that are missed are either greater than 32 or on a controller that only temporarily shows them as on.  IE, when the toggle is thrown the on condition shows for about 1 sec then goes off.  This is by design.  Hence, your software has no idea what the state of the switch would be. 

 

That said, except for the window not closing, everything seems to be working great.

Share this post


Link to post
Share on other sites

The switches that are missed are either greater than 32 or on a controller that only temporarily shows them as on.  IE, when the toggle is thrown the on condition shows for about 1 sec then goes off.

 

Ah, interesting. How do you normally use those momentary switches? I would have thought they would only be useful with toggled functions, unless you have them connected to something other than FSUIPC. I have checked out the Message functions and there were indeed issues. You can re-download the file (or text), or you can fix yours by changing the second-last line of the function to read

    HideMsgWindow("Setting OFF actions")

instead of

    HideMsgWindow("")

Share this post


Link to post
Share on other sites

The momentary toggles are an artifact of another application.  A flight game that only read push buttons.  I can't remember its name.  I just redid the settings and converted the momentary setting to toggle.  Everything is fine now (for buttons less than 33).

Share this post


Link to post
Share on other sites

Is there a way to active this routine from a key press? 

 

Reason: using VAC (voice active commands), I already synchronize Linda by sending a key string to Autohotkey which moves the mouse to click on the sync button in Linda.

Using the same Autohotkey routine, I'd also like to run the script after Linda in synchronized with FSX.  So a key press or function call (outside of Linda) would be great. 

Share this post


Link to post
Share on other sites

Is there a way to active this routine from a key press? 

 

I have a feeling this discussion has happened before - can LINDA functions be triggered from keypresses? I do not know a way, but perhaps someone else will comment.

Share this post


Link to post
Share on other sites

I changed the HideMsgWindow call to have ("Setting OFF actions").

Window still doesn't disappear and the Linda console says:

211: attempt to call global "HideMsgWindow' (a nil value)

 

I think the problem is the call is to HideMsgWindow and your function is called HideMessageWindow.

 

I'll name them the same.

Share this post


Link to post
Share on other sites

I think the problem is the call is to HideMsgWindow and your function is called HideMessageWindow.

 

Yeah I know, I saw that but I assumed you'd figure it out! I changed all the names to Msg when I discovered there's a built-in function called ShowMessage. I think I need to work on those message functions anyway. The original problem was that you have to call the 'close' with the same window title - but I'm not really closing them at all (I couldn't see a way) so I suspect I may be accumulating open windows that are positioned off-screen... :blink:

 

I'd forgotten how tedious programming can be :mellow:

 

P.S. I am trying to figure out how to sync the analogue axes. I'm sort of half-way there but I don't think it's going to be quite as straightforward.)

 

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
Sign in to follow this