Results 1 to 3 of 3
-
03-14-2012, 06:32 PM #1
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 5
Combining commands and bit operations
Hi!
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,
Tim
-
03-15-2012, 11:00 AM #2
- Join Date
- Apr 2010
- Location
- Auburn, WA
- Posts
- 197
Re: Combining commands and bit operations
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)
else
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 #3
- Join Date
- Feb 2011
- Location
- Germany
- Posts
- 5
Re: Combining commands and bit operations
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...
Regards,
Tim
Pretty Girls from your city for night
Generic Analog Gauges