dependabot[bot] 165432874b Bump bindgen from 0.60.1 to 0.61.0
Bumps [bindgen](https://github.com/rust-lang/rust-bindgen) from 0.60.1 to 0.61.0.
- [Release notes](https://github.com/rust-lang/rust-bindgen/releases)
- [Changelog](https://github.com/rust-lang/rust-bindgen/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/rust-bindgen/compare/v0.60.1...v0.61.0)

---
updated-dependencies:
- dependency-name: bindgen
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-19 11:04:03 +01:00
2022-10-19 09:18:12 +01:00
2022-10-18 21:56:07 +01:00
2022-10-19 09:18:12 +01:00
2022-10-01 17:01:57 +01:00
2022-10-19 11:04:03 +01:00
2022-10-09 09:38:53 +01:00
2022-10-19 09:18:12 +01:00
2022-10-19 09:18:12 +01:00

SimConnect SDK in Rust

CI

Usage

[dependencies]
simconnect-sdk = { version = "0.1", features = ["derive"] }
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};

/// A data structure that will be used to receive data from SimConnect.
#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
struct GpsData {
    #[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
    lat: f64,
    #[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
    lon: f64,
    #[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
    alt: f64,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = SimConnect::new("Simple Program");

    match client {
        Ok(mut client) => {
            let mut notifications_received = 0;

            loop {
                let notification = client.get_next_dispatch()?;

                match notification {
                    Some(Notification::Open) => {
                        println!("Connection opened.");

                        // After the connection is successfully open, we register the struct
                        client.register_object::<GpsData>()?;
                    }
                    Some(Notification::Object(data)) => {
                        if let Ok(gps_data) = GpsData::try_from(&data) {
                            println!("{gps_data:?}");

                            notifications_received += 1;

                            // After we have received 10 notifications, we unregister the struct
                            if notifications_received > 10 {
                                client.unregister_object::<GpsData>()?;
                                println!("Subscription stopped.");
                                break;
                            }
                        }
                    }
                    _ => (),
                }

                // sleep for about a frame to reduce CPU usage
                std::thread::sleep(std::time::Duration::from_millis(16));
            }
        }
        Err(e) => {
            println!("Error: {e:?}")
        }
    }

    Ok(())
}

See more examples.

Description
No description provided
Readme MIT 704 KiB
Languages
Rust 68%
C 32%