Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing array datarefs #18

Open
realskudd opened this issue Mar 8, 2024 · 1 comment
Open

Accessing array datarefs #18

realskudd opened this issue Mar 8, 2024 · 1 comment

Comments

@realskudd
Copy link

I'd like to be able to read and write sim/flightmodel/weight/m_fuel, but with it being an array of floats, I'm not entirely sure how to make it work with xplm.

I've tried this:

        let fuel_weights: DataRef<f64, ReadOnly> = DataRef::find("sim/flightmodel/weight/m_fuel")?;

        let tanks = fuel_weights.get();
        let tank1 = tanks[0];
        let tank2 = tanks[1];

But it's not valid, given the f64 that .get() returns.

What's the right way to accomplish this? Is it even implemented yet?

@samcrow
Copy link
Owner

samcrow commented Mar 9, 2024

This is not obvious and there probably should be more examples, but it should work:

  • Create a DataRef<[f32], ReadOnly> or DataRef<[f32], ReadWrite>
  • That implements ArrayRead<[f32]>
  • Call as_vec to get a Vec<f32> with a copy of the dataref values. If performance is important, you can instead use get with a pre-allocated buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants