View Full Version : Combining commands and bit operations

03-14-2012, 06:32 PM

I got a question regarding XUIPC.

I have a FSUIPC-Offset, where each bit represents a seperate switch. Each of this switches shall trigger a different command in X-Plane. Is there a way to get this working or would I have to put each switch on a different offset?

Any help is welcome!

Kind regards,

03-15-2012, 11:00 AM
Please clarify - are you making use of an existing offset which handles switch values, or are you defining your own offset for a group of switches?

If this is an existing offset, you need to build the bit-handling into the code that reads the switches, so that when the switch-flip is detected, only the appropriate bit is changed. Here's some pseudocode for a switch that changes the third bit in the offset byte. It's meant to illustrate the concept, so no effort has been made towards language-specific syntax.

&& = 'bitwise AND'
|| = 'bitwise OR'

on switch.changestate do
if switch.state = 'off' then
offsetbyte = offsetbyte && 251 (251 = '1111011'; this turns the 3rd bit off, leaves the rest as is)
offsetbyte = offsetbyte || 4 (4 = '0000100; this turns the 3rd bit on, leaves the rest as is)
end if
end do

03-15-2012, 06:37 PM
Hey! Thanks for your reply.

I noticed, I forgot some important information. Let me elaborate.

I am currently building a home cockpit using the IOcards from opencockpits. The script language they use is designed for Microsofts FS using FSUIPC. As I would like to switch over to X-Plane I am currently playing around with XUIPC. I already got parts working.
Now I got some hardware switches. To save offsets, I combined the states of these switches into one offset using one bit for each switch. So now, for example Bit 0 = 1 means, the fuel pumps are ON while Bit 1 = 1 means, that the wiper is activated.
In X-Plane, an the plane I'm using, an EC135. These Switches are triggered using a Command. I would now like to use XUIPC to split the Offset into 8 Commands, that are send to X-Plane if the according bits are true.

I hope that I am more understandable now. My english is not the best...