Jump to content
The simFlight Network Forums

Reading & re-assigning of button positions at startup


Recommended Posts

Hello All,

Not sure if anyone came across this issue before!

When starting flight sim (FS9 in my case) there seems to be a conflict between the buttons / switch configuration that is set in flight sim in relation to hardware buttons / switch positions.

To give an example, the auto pilot master switch is set to off in flight when a flight is loaded, but the hardware switch position is left in the ‘on’ position from the last flight! When the A/P master switch is operated in the new flight the switch is reversed! ‘Off’ on the hardware is ‘on’ to flight sim!

Is there a way for FSUIPC to read the hardware switch positions at FS loading and re-assign the switch positions in flight sim accordingly??

Thanks very much in advanced

Link to comment
Share on other sites

When starting flight sim (FS9 in my case) there seems to be a conflict between the buttons / switch configuration that is set in flight sim in relation to hardware buttons / switch positions.

Two points here. First: most devices do not signal their position until it is changed. FSUIPC and FSX react to changes. So for non-toggling switches (i.e. those using discrete On / Off controls), all you need to do is sync the switches initially by turning them on/off or off/on.

Second, if you've assigned to toggling functions, like most keypresses and many FS functions, then the command isn't differentiating between on and off. In this case the only way to synchronise is to change the FS switch on-screen to match the hardware position. In general it is always best to find distinct on/off functions. If there is no such FS control there is often a way to do it through FSUIPC offsets instead.

I always make sure that I close everything down, to cold and dark, before saving flights i intend to reload. Then i know in advance that the cockpit switches will match the FS settings.

To give an example, the auto pilot master switch is set to off in flight when a flight is loaded, but the hardware switch position is left in the ‘on’ position from the last flight! When the A/P master switch is operated in the new flight the switch is reversed! ‘Off’ on the hardware is ‘on’ to flight sim!

You need to say how you assigned the switch. You are probably using either the 'Z' key, whch is a toggle of course, or the "AP MASTER" FS control. In such a case, sync by changing the on-screen switch.

Is there a way for FSUIPC to read the hardware switch positions at FS loading and re-assign the switch positions in flight sim accordingly??

Not automatically. You'd have to waggle the switches. BUT you would need to only choose separate on/off assignments, not toggles. Toggle controls are really only suited to buttons, not switches -- FS was designed for joysticks with buttons. They never really helped much with switches.

For the AP Master you can assign as follows:

AP MASTER OFF: control Offset dword set , offset x7BC, parameter 0

AP MASTER ON: control Offset dword set , offset x7BC, parameter 1

You can do similar things for other values. The offsets needed are listed in the FSUIPC offsets lists, available in the FSUIPC SDK.

Regards

Pete

Link to comment
Share on other sites

Hi Pete, in relation to this topic, I also would like to somehow sync my switches automatically at startup.

The only way I can currently see to do it is via a lua script that reads all button states on a device and then sets the virtual switch in the sim.

Is there any possible way that lua could have some sort of a command to toggle a real switch, (by software), on a real device to trigger a "change" and then you would get a sync with the sim, as long as the switch was assigned discrete ON/OFF values for pressed and released and not a toggle function.

Another way would be to maybe parse the FSUIPC.INI file and determine the switches that have assignments, then get their actual state from the device and then set the sim state to match...... Am I approaching that the right way ?

This is something that's been bothering me and I am not sure the best way to handle it, there are quite a few switches to twiggle in a superhornet for which I have written a massive switch script for and I do think I need to address this somehow.

I know I could make sure the switch positions match the sim at shutdown and will come back the same way but what about when I startup a different saved flight that may not be in sync, there must be a better way.

I will look forward to any ideas that you could suggest.

Thanks Glenn.

Link to comment
Share on other sites

Is there any possible way that lua could have some sort of a command to toggle a real switch, (by software), on a real device to trigger a "change" and then you would get a sync with the sim, as long as the switch was assigned discrete ON/OFF values for pressed and released and not a toggle function.

No, there's no way to do that. But you can use the Lua com library HID functions to read the buttons states. Check the com.gethidbuttons function. This decodes button data from a packet read previously by the com.read function on a device opened by com.openhid.

Basically by using this you are using the raw USB interface to interrogate the device. It bypasses the DirectInput mechanism used by FSUIPC and FS for button detection and reads the current state.

Once you have the button states you simply process each one calling the appropriate action (ipc.control function for controls, and ipc.write... or ipc.togglebits... functions to affect offsets.

I know I could make sure the switch positions match the sim at shutdown and will come back the same way but what about when I startup a different saved flight that may not be in sync, there must be a better way.

Unless you have switches which can be electronically changed over from the PC (a VERY VERY expensive option involving magnetic or solenoid switch operations. Very bulky too), there is obviously NO WAY you can set your real hardware switches to match whatever flight you load. You can only do it the other way around -- i.e. change the FS settings to match the switches. But that could result in disaster, or at least difficulties, if you reload a flight in mid air and switch things around like fuel or iginition!

I always make sure I either shut down in a standard state (for me, cold and dark), and only load flights which are saved in that state, or, if I'm am trying to continue from a failed or time-limited earlier flight, just leave the cockpit the way it was when I saved.

Regards

Pete

Link to comment
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
×
×
  • 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.