Jump to content
The simFlight Network Forums

ValueChanged property in a BitArray


 Share

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

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...
 Share

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