tjensen / fsuipc

Python client wrapper for FSUIPC
MIT License
15 stars 0 forks source link

reading lights #3

Closed carl0shd closed 2 years ago

carl0shd commented 4 years ago

Hi guys, when i want to read the offset 0D0C acording to the FSUIPC SDK the offset 0D0C is: Lights, a switch for each one (bits from lo to hi): 0 Navigation 1 Beacon 2 Landing 3 Taxi 4 Strobes 5 Instruments 6 Recognition 7 Wing 8 Logo 9 Cabin and is a offset of size 2.

it should return a tuple of the items described, for example [0,0,0,0,0,0,0,0,0,0] but only return 1 item ([0]). I test all types of sizes.

any help will be appreciated.

Thanks.

tjensen commented 4 years ago

Hi @carl0shd. Offset 0x0D0C gives you a single 16-bit (2-byte) unsigned integer, not a tuple. You need to treat the integer value as a bitmask; if you want to know the state of a particular light, you need to extract the corresponding bit. For example, you could do something like this to read the state of the "taxi" light:

>>> TAXI = 3
>>> lights = prepared_data.read()[0]
2
>>> taxi = (lights >> TAXI) & 1
0

Or, if you really want the lights represented as a list, you could convert the value like so:

>>> TAXI = 3
>>> lights = [int(bit) for bit in "{:016b}".format(prepared_data.read()[0])[::-1]]
>>> lights
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> taxi = lights[TAXI]
0

Hope this helps.

carl0shd commented 4 years ago

hi i tried to run the example that you sent but i dont have the prepare_data what you used for the example. I am sending it as H (2 bytes unsigned)

from fsuipc import FSUIPC

with FSUIPC() as fsuipc:
    prepared = fsuipc.prepare_data([
        (0x0D0C, "H")
    ], True)

    while True:
        lights = prepared.read()[0]

        TAXI = 3
        lightsfinal = [int(bit) for bit in "{:016b}".format(lights)[::-1]]
        taxi = lightsfinal[TAXI]

        print(f"taxi: {taxi}")

        input("Press ENTER to read again")

always returns 0 even if you change all the lights, including the taxi lights.

thanks again for the help and sorry for the inconvenience.

tjensen commented 4 years ago

Hi @carl0shd. What flight simulator version are you running? Perhaps it doesn't support offset 0x0D0C.

I ran the following with MS Flight Simulator X:

import time
from fsuipc import FSUIPC

with FSUIPC() as fsuipc:
    prepared = fsuipc.prepare_data([
        (0x0D0C, "H")
    ], True)

    while True:
        lights = prepared.read()[0]

        TAXI = 3
        lightsfinal = [int(bit) for bit in "{:016b}".format(lights)[::-1]]
        print(f"lights: {lightsfinal}")
        taxi = lightsfinal[TAXI]

        print(f"taxi: {taxi}")

        time.sleep(1)

It worked just fine for me, as you can see in this video: https://youtu.be/yta14OXXNpo

tjensen commented 4 years ago

Hi @carl0shd. I'm closing this issue due to inactivity and am assuming that you were able to resolve the issue on your end.

carl0shd commented 4 years ago

hi @tjensen, I'm sorry for answering delay, the simulator I'm using is X Plane 11, FSUIPC works since it uses XPUIPC which is almost the same in general terms, I tested the offset with a FSUIPC library in NodeJS and it works perfect, I also tried it with a tool called FSUIPC Monitor which also helps to test offsets and with Xplane it works fine too.

tjensen commented 4 years ago

@carl0shd I don't have X-Plane, so I'm going to have to rely on you to debug this issue any further.

tjensen commented 2 years ago

Closing this due to inactivity