Jump to content
The simFlight Network Forums

How to properly read light switches @ [0D0C]?


Recommended Posts

I am having a bit of a hard time figuiring out how to determine exactly which light switch is on by simply reading the [0D0C] offset. According to the SDK the light switches are defined as follows;

0D0C 2 bytes Lights (FS2k/CFS2), a switch for each one:

0 Navigation

1 Beacon

2 Landing

3 Taxi

4 Strobes

5 Instruments

6 Recognition

7 Wing

8 Logo

If somebody has some sample code written in VB that would be great. Basically I am trying to determine each of the possible light switches if ON or OFF. When testing and had all lights off except for NAV the value in [0D0C] = 33, when I used the "L" key to switch everything on the value was 1023.

Does the value of the offset just need a conversion like Decimal to Binary?

Thanks!

John

Link to post
Share on other sites
Never mind on this post, that's exactly what it appears I needed to do is convert the decimal value returned from the offset to a binary string and read each byte from right to left to make the determination of ON/OFF.

Ernothing returns a DECIMAL number as such. Everything is in binary in any case. All you needed to do was test for each bit in turn. The bits are simple "flags".

So, if the value of 0D0C is in an integer variable called

nLights

you can test for Strobes, say, by seeing if

nLights AND 16

is non-zero (replace "AND" by whatever is used in your programming language for logical AND). The value 16 arises from the value of bit 4 (2 to the power 4 = 16). Here are the values to save you calculating them:

0 value 1 Navgation

1 value 2 Beacon

2 value 4 Landing

3 value 8 Taxi

4 value 16 Strobes

5 value 32 Instruments

6 value 64 Recognition

7 value 128 Wing

8 value 256 Logo

9 value 512 Cabin

The last one is new in FS2004.

Pete

Link to post
Share on other sites
  • 2 years later...

YankeeFan can you give me an example of your code. I am having the same problem. If YankeeFan is no longer on the form can someone give me an example. I can't figure out how to declear the variables. I see they are a S16 int but I don't know how to declear that in VB6. Thanks.

Link to post
Share on other sites
YankeeFan can you give me an example of your code. I am having the same problem. If YankeeFan is no longer on the form can someone give me an example. I can't figure out how to declear the variables. I see they are a S16 int but I don't know how to declear that in VB6. Thanks.

I don't think VB supports short integers, so just declare an ordinary Integer and set it to zero before reading the 2 bytes from offset 0D0C into it. The bits representing the light switches will still be in the right places, the top 16 bits (bit numbers 16 to 31) will be zero, is all.

Regards,

Pete

Link to post
Share on other sites
  • 14 years later...

In case someone wants to play around with it in JS...

Just open your webbrowsers Dev-Tools [F12] and execute the below snipet in your browsers console:

// set the numeric value as reported from FSUIPC Offset 0x0D0C
fsuipc_0d0c = 234

fsuipc_0d0c = (fsuipc_0d0c >>> 0).toString(2);

// log the bit-sequence as string to console
console.log(fsuipc_0d0c)

light = {}
light.navigation = fsuipc_0d0c.charAt(0)* 1
light.beacon = fsuipc_0d0c.charAt(1) * 1
light.landing = fsuipc_0d0c.charAt(2)* 1
light.taxi = fsuipc_0d0c.charAt(3)* 1
light.strobes = fsuipc_0d0c.charAt(4)* 1
light.instruments = fsuipc_0d0c.charAt(5)* 1
light.recognition = fsuipc_0d0c.charAt(6)* 1
light.wing = fsuipc_0d0c.charAt(7)* 1
light.logo = fsuipc_0d0c.charAt(8)* 1
light.cabin = fsuipc_0d0c.charAt(9)* 1

// log as object
console.log(light) 

// log as beautified string
console.log(JSON.stringify(light,null, '\t')) 

which results in 

{
	"navigation": 1,
	"beacon": 1,
	"landing": 1,
	"taxi": 0,
	"strobes": 1,
	"instruments": 0,
	"recognition": 1,
	"wing": 0,
	"logo": 0,
	"cabin": 0
}

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • 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.