Jason Fayre Posted August 14, 2020 Report Posted August 14, 2020 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!
Paul Henty Posted August 14, 2020 Report Posted August 14, 2020 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
Jason Fayre Posted August 15, 2020 Author Report Posted August 15, 2020 Thanks Paul! If you could, that would be awesome. There isn't that many of them, so I can code something myself if it's a pain to add.
Paul Henty Posted August 16, 2020 Report Posted August 16, 2020 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
Jason Fayre Posted August 16, 2020 Author Report Posted August 16, 2020 Thanks Paul! I'll play with this today. Do you accept donations for this library? You've been amazingly helpful!
Paul Henty Posted August 16, 2020 Report Posted August 16, 2020 Hi Jason, Donation details are on the website: http://fsuipc.paulhenty.com/#donations Thanks, Paul
Jason Fayre Posted August 16, 2020 Author Report Posted August 16, 2020 Done! Just set this up for reading the lights and it seems to be working well in initial testing.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now