Jump to content
The simFlight Network Forums

keeping track of a large amount of offset states


Recommended Posts

Hi,

I'm just learning c#, so I apologize for the newbie question.

I've looked at the WPF template, and basically got my head around how this works.

My application is an accessibility layer so that blind flight sim users can get speech feedback for various instruments and aircraft states.

In addition to reading many offsets (over 100), I need to keep track of the previous state of the offset. So, for example, I need to keep track of the previous Autopilot altitude, heading, speed, etc. offsets so I can let the user know when they change. Does anyone have any code snippet or technique for doing this? I know I can just store the previous value in another variable, but wondering if there is a more efficient way of doing this. 

I know this is more of a c# question than a fsuipc question, but just wondering if someone can throw me any suggestions.

 

 

 

Link to comment
Share on other sites

Hi Jason,

I could add a property to the offset class to tell you if the value was changed at the last Process() call. Would that be of use? You wouldn't be able to get the previous value, just know if it changed. Something like:

FSUIPCConnection.Process();
if (this.myOffset.ValueChanged) {
   // Tell the user
}

The problem I can see with this is that you won't be able to decide how much of a change to respond to. For example, your program may not care about a change in 1 foot of altitude, just maybe 100ft.

If knowing the previous value is important, or you need to be able to specify minimum changes, then the easiest way is just as you described. Just have a set of variables storing the previous values and test them applying your minimum thresholds.

Paul

Link to comment
Share on other sites

That would actually be really useful! A lot of the instruments I'm reading are toggles, so this would be really helpful.

One more question. For reading things like flaps and landing gear, I wwant to detect when they start changing, then read the value once they finish moving. So, for example, when you press F7 to extend flaps, I only want to read the value once they stop, so you don't hear updates as they are moving. I know how to do this by checking the offset, then sleeping a bit, then checking again. Once the old and new values are the same, read the value. The problem with this is that I believe this would block anything else from speaking until the flaps stop.

Can you think of another way of doing this?

 

 

 

 

Link to comment
Share on other sites

Okay, I'll add this in the next day or two.

For your flaps question: Yes, a Sleep will block the rest of your program, so don't do that.

I would set up a bool variable called FlapsInMotion. This starts off a false.

When it's false you look for any change in flap position. When you detect this you set FlapsInMotion to true.

When it's true you look for that value to stop changing (same as previous value). Then you set FlapsInMotion back to false and give the update on the new flap position.

This way you don't need to sleep, it all happens in the main timer loop. You're just doing different checks depending on what's happening with the flaps.

Paul

Link to comment
Share on other sites

Version 3.1.15 BETA is now available on NuGET. Remember to tick the 'Include Pre-release" box so that the beta version will show up.

After Process() you can now check the ValueChanged property on any offset to see if the value is different than the last time it was processed.

Also, if an offset was written in the last Process() then ValueChanged will be set to true.

Paul

Link to comment
Share on other sites

Hi Paul,

I've run into an issue.

The ValueChanged property doesn't appear to work on string type offsets. For example, offset 0x3d00 for the aircraft name. When I attempt to test if that offset has changed, it appears to read true all the time. 

I'm defining that offset as:

private Offset<string> AircraftName = new Offset<string>(0x3d00, 255);

 

I'm checking if it has changed like this:

if (AircraftName.ValueChanged)
                    {
                        Tolk.Output("Current aircraft: " + AircraftName.Value);
                    }
                    

At this point, my software just reads the aircraft name constantly. I can get around this by storing the old name in a variable, but just wanted to point this out in case there is a bug somewhere.

I'll need this in several places, since one of the things my software does is read Simconnect text messages out of the fsuipc offsets.

Thanks!

 

 

 

 

 

Link to comment
Share on other sites

  • 3 weeks later...
On 7/12/2020 at 3:08 PM, Paul Henty said:

Version 3.1.15 BETA is now available on NuGET. Remember to tick the 'Include Pre-release" box so that the beta version will show up.

After Process() you can now check the ValueChanged property on any offset to see if the value is different than the last time it was processed.

Also, if an offset was written in the last Process() then ValueChanged will be set to true.

Paul

Hi Paul,

very usefull :-). No need anymore for me to track previous values. Will make some of my programs shorter and better readable in future.

Ruediger

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.