Cleanup the docs
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
[![CI][ci_badge]][ci]
|
[![CI][ci_badge]][ci]
|
||||||
|
|
||||||
|
An opinionated SimConnect SDK that encapsulates the C API fully and optimizes for developer experience.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
@@ -15,6 +17,7 @@ use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
|||||||
/// A data structure that will be used to receive data from SimConnect.
|
/// A data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone, SimConnectObject)]
|
#[derive(Debug, Clone, SimConnectObject)]
|
||||||
#[simconnect(period = "second")]
|
#[simconnect(period = "second")]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct GpsData {
|
struct GpsData {
|
||||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||||
lat: f64,
|
lat: f64,
|
||||||
@@ -25,7 +28,7 @@ struct GpsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Receiving data example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => {
|
Ok(mut client) => {
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
||||||
|
|
||||||
/// A data structure that will be used to receive data from SimConnect.
|
/// A data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone, SimConnectObject)]
|
#[derive(Debug, Clone, SimConnectObject)]
|
||||||
#[simconnect(period = "second")]
|
#[simconnect(period = "second")]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct GpsData {
|
struct GpsData {
|
||||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||||
lat: f64,
|
lat: f64,
|
||||||
@@ -15,7 +14,7 @@ struct GpsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Receiving data example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => {
|
Ok(mut client) => {
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
||||||
|
|
||||||
/// A data structure that will be used to receive data from SimConnect.
|
/// A data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone, SimConnectObject)]
|
#[derive(Debug, Clone, SimConnectObject)]
|
||||||
#[simconnect(period = "second")]
|
#[simconnect(period = "second")]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct GpsData {
|
struct GpsData {
|
||||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||||
lat: f64,
|
lat: f64,
|
||||||
@@ -17,13 +16,14 @@ struct GpsData {
|
|||||||
/// A second data structure that will be used to receive data from SimConnect.
|
/// A second data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone, SimConnectObject)]
|
#[derive(Debug, Clone, SimConnectObject)]
|
||||||
#[simconnect(period = "second", condition = "changed")]
|
#[simconnect(period = "second", condition = "changed")]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct OnGround {
|
pub struct OnGround {
|
||||||
#[simconnect(name = "SIM ON GROUND", unit = "bool")]
|
#[simconnect(name = "SIM ON GROUND", unit = "bool")]
|
||||||
sim_on_ground: bool,
|
sim_on_ground: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Receiving data example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => loop {
|
Ok(mut client) => loop {
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
@@ -7,6 +5,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
|||||||
/// A data structure that will be used to receive data from SimConnect.
|
/// A data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone, SimConnectObject)]
|
#[derive(Debug, Clone, SimConnectObject)]
|
||||||
#[simconnect(period = "second")]
|
#[simconnect(period = "second")]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct GpsData {
|
struct GpsData {
|
||||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||||
lat: f64,
|
lat: f64,
|
||||||
@@ -19,7 +18,7 @@ struct GpsData {
|
|||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
setup_logging()?;
|
setup_logging()?;
|
||||||
|
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Receiving data example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => {
|
Ok(mut client) => {
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use simconnect_sdk::{
|
use simconnect_sdk::{
|
||||||
Condition, DataType, Notification, Object, Period, SimConnect, SimConnectError,
|
Condition, DataType, Notification, Object, Period, SimConnect, SimConnectError,
|
||||||
SimConnectObjectExt,
|
SimConnectObjectExt,
|
||||||
@@ -7,6 +5,7 @@ use simconnect_sdk::{
|
|||||||
|
|
||||||
/// A data structure that will be used to receive data from SimConnect.
|
/// A data structure that will be used to receive data from SimConnect.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct GpsData {
|
pub struct GpsData {
|
||||||
lat: f64,
|
lat: f64,
|
||||||
lon: f64,
|
lon: f64,
|
||||||
@@ -34,7 +33,7 @@ impl TryFrom<&Object> for GpsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Receiving data example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => {
|
Ok(mut client) => {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
use simconnect_sdk::{FacilityType, Notification, SimConnect};
|
use simconnect_sdk::{FacilityType, Notification, SimConnect};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let client = SimConnect::new("Simple Program");
|
let client = SimConnect::new("Facilities example");
|
||||||
|
|
||||||
match client {
|
match client {
|
||||||
Ok(mut client) => loop {
|
Ok(mut client) => loop {
|
||||||
|
@@ -31,6 +31,10 @@ pub struct Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Object {
|
impl Object {
|
||||||
|
/// Try and transmute this SimConnect object as a `T` struct.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// - [`crate::SimConnectError::ObjectMismatch`] -- The type of this SimConnect object is different from `T`.
|
||||||
pub fn try_transmute<T: SimConnectObjectExt>(&self) -> Result<T, SimConnectError> {
|
pub fn try_transmute<T: SimConnectObjectExt>(&self) -> Result<T, SimConnectError> {
|
||||||
let type_name: String = std::any::type_name::<T>().into();
|
let type_name: String = std::any::type_name::<T>().into();
|
||||||
|
|
||||||
|
@@ -9,65 +9,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
//! use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
#![doc = include_str!("../../examples/src/data.rs")]
|
||||||
//!
|
|
||||||
//! /// 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](https://github.com/mihai-dinculescu/simconnect-sdk/tree/main/examples).
|
//! See [more examples](https://github.com/mihai-dinculescu/simconnect-sdk/tree/main/examples).
|
||||||
|
@@ -10,65 +10,7 @@ use crate::{
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// use simconnect_sdk::{Notification, SimConnect, SimConnectObject};
|
#[doc = include_str!("../../../examples/src/data.rs")]
|
||||||
///
|
|
||||||
/// /// 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(())
|
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SimConnect {
|
pub struct SimConnect {
|
||||||
|
@@ -17,7 +17,7 @@ impl SimConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unregister an object with SimConnect.
|
// Unregister an object with SimConnect.
|
||||||
#[tracing::instrument(name = "SimConnect::register_object")]
|
#[tracing::instrument(name = "SimConnect::unregister_object")]
|
||||||
pub fn unregister_object<T: SimConnectObjectExt>(&mut self) -> Result<u32, SimConnectError> {
|
pub fn unregister_object<T: SimConnectObjectExt>(&mut self) -> Result<u32, SimConnectError> {
|
||||||
let type_name: String = std::any::type_name::<T>().into();
|
let type_name: String = std::any::type_name::<T>().into();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user