Jump to content
The simFlight Network Forums

ValueChanged property in a BitArray


Recommended Posts

Hi Paul,

I've run across another issue I'm wondering if you can help out with.

Would it be possible to get a property on BitArray fields to know which bits have changed? I'm monitoring several of these offsets and want to be able to tell the user when a particular flag has changed. The lights or the nav1 flags for example. The current ValueChanged property will tell me when the offset itself has changed, but not which bit as far as I can tell.

Thanks!

 

 

 

Link to comment
Share on other sites

Hi Jason,

Yes, the ValueChanged would be for the entire BitArray, not individual bits.

I've had a look at the BitArray class. It's part of the .NET framework and unfortunately Microsoft decided to seal it so I can't extend it with any new properties.

I can probably create my own FsBitArray class that does the basic set/get bits but also with a HasChanged(n) property. I'll look at this over the next few days.

Paul

Link to comment
Share on other sites

Hi Jason,

I've added a new class FsBitArray to version 3.1.19-Beta. Now available on NuGet. Remember to tick the 'Include Pre-Release' option.

This is identical to the .NET BitArray except it can also tell you which bits have changed.

Use the new class when you declare the offset: e.g.

private Offset<FsBitArray> lights = new Offset<FsBitArray>(0xD0C, 2);

You can then use the HasChanged() method or use the array of booleans returned by the Changed property.

e.g. To test if the taxi lights have changed use either of these:
 

this.lights.Value.HasChanged(3)
this.lights.Value.Changed[3]

You can also use the array from the Changed property to iterate through all the bits:

            FsBitArray lightBits = this.lights.Value;
            for (int i = 0; i < lightBits.Changed.Length; i++)
            {
                if (lightBits.Changed[i])
                {
                    // Light i has changed.
                }
            }

The ValueChanged property on the offset will still tell you if ANY bits have changed. This could be checked first to save checking every bit if nothing has changed.

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.