PDA

View Full Version : Coding the mastercard to work with FSUIPC



jmig
04-10-2008, 08:13 PM
I always knew I was a non entity when it came to programming. I just never knew how badly I sucked. I have been trying for two days to get one single little switch to do one simple little function, open and close the canopy.

I have read tutorials and looked at examples, all for naught. Here is what I need to do. I have a switch connected to a handle that I want to open and lower the canopy in FSX.

The switch is connected to the first pin on the master card and gives me 000 when closed in the OpenCockpits controller applet. So I know it and the MC are working.

I tried to use the IOCard config to have it change the status of offset $3367 within FSUPIC. The new FSX offset guide shows 3367 to be a single byte and it shows 2^0 = Exit1 & 2^3 = Exit4. I know that those are the bits to control different doors. However, I don’t know how to state 2^0 in SIOC or what the ^ means.

Using an example on making a switch turn on a LED I tried the following:

Var 0001, name canopySW, Link IOCARD_SW, Input 0, Type I

Var 0002, name canopy, Link FSUIPC_INOUT, Offset $3367, Length 1

IF &canopySW = 0 // If switch is OFF
{
&canopy = 0 // output is OFF
}
ELSE
{
&canopy = 1 // If not, output is ON
}

It too didn’t work. I feel embarrassed and frustrated that I can’t even get one little switch to work with FSUIPC and FSX. Can anyone help?

wanderer
04-10-2008, 09:44 PM
it shows 2^0 = Exit1 & 2^3 = Exit4. I know that those are the bits to control different doors. However, I don’t know how to state 2^0 in SIOC or what the ^ means.

From right to left, the 8 bits are numbered 0 to 7. So 2^0 is the right-most (or least significant) bit. 2^7 is the left-most (or most significant bit).

(The caret ^ is the power sign. e.g. 5^2 = 5 x 5 = 25 but you don't really need to know that for this exercise.)

SIOC is event-driven which means WHEN a variable changes, SIOC will execute the code ASSOCIATED with the variable. When you throw your switch, Var 0001 changes so you need some code UNDER var 0001 to change the bits in Var 0002.

For a starting point, you were close. You just need to move the code to under Var 0001. Note the extra set of braces (curly brackets). Without them, the ENTIRE code may or may NOT be associated properly with Var 0001

Var 0001, name canopySW, Link IOCARD_SW, Input 0, Type I
{
IF &canopySW = 0 // If switch is OFF
{
&canopy = 0 // output is OFF
}
ELSE
{
&canopy = 1 // If not, output is ON
}
}

Var 0002, name canopy, Link FSUIPC_INOUT, Offset $3367, Length 1

For now, you don't need any code under var 0002. You would need code under var 0002 if, say later, you wanted to control an LED whenever the door was opened/closed.

After you get this going, you will need to modify your code to change only a SINGLE bit. For $3367, you say the bit 3 (or 2^3) opens/closes another door (exit4). If so, your switch will always close all other doors because you would always be changing the other bits to 0 (because you are always assigning 00000000 or 00000001 to Var 0002).

You'd need to use CLEARBIT or SETBIT to alter a single bit. (CHANGEBIT and CHANGEBITN can also be used to condense the IF/THEN/ELSE downto a single line.)

Checkout Nico Kaan's SIOC How-To (http://www.lekseecon.nl/howto.html) page if you haven't already. (His "Landing Lights" example is similar to what you're doing.)

jmig
04-10-2008, 10:47 PM
Thank you so much! I will try this tomorrow. I figure that once I get a couple under my belt, I can figure the rest out.

I was stumped.