diff --git a/Cargo.lock b/Cargo.lock index f6a5b8c..7162d6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,13 +31,12 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.55.1" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" dependencies = [ "bitflags", "cexpr", - "cfg-if", "clang-sys", "clap", "env_logger", @@ -102,9 +101,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.7.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" dependencies = [ "atty", "humantime", @@ -130,12 +129,9 @@ dependencies = [ [[package]] name = "humantime" -version = "1.3.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "lazy_static" @@ -205,12 +201,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.7" @@ -252,9 +242,10 @@ checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" [[package]] name = "simconnect" -version = "0.1.2" +version = "0.1.4" dependencies = [ "bindgen", + "thread_local", ] [[package]] diff --git a/Readme.md b/Readme.md index a026545..dfa7183 100644 --- a/Readme.md +++ b/Readme.md @@ -55,3 +55,17 @@ loop { ``` ### Remarks I have not tested every single function from the api. If you find an error, feel free to make an issue or a pull request. + +### 32-Bit Support + +It is possible to build & target 32-bit versions of Prepar3D (All other 32-bit flight sims should be possible but I have not tested those). + +Requirements: + +- [32-bit Clang (tested with 11.0.1)](https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.0.1) +- 32-bit windows rust target. Run `rustup target add stable-i686-pc-windows-msvc` +- Visual Studio 2012 Command Prompt. Should be available if you install Visual Studio 2013. [Available here](https://visualstudio.microsoft.com/vs/older-downloads/) +- Building: + - From VS2012 Command Prompt, run `cargo +stable-i686-pc-windows-msvc build` +- Running: + - From VS2012 Command Prompt, run `cargo +stable-i686-pc-windows-msvc run` diff --git a/SimConnect.dll b/SimConnect.dll index da40b73..1cb5c9b 100644 Binary files a/SimConnect.dll and b/SimConnect.dll differ diff --git a/SimConnect.dll.64bit b/SimConnect.dll.64bit new file mode 100644 index 0000000..da40b73 Binary files /dev/null and b/SimConnect.dll.64bit differ diff --git a/build.rs b/build.rs index 352a668..2989dc6 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,11 @@ use std::{env, path::PathBuf}; fn main() { println!("cargo:rustc-link-search=libsrc/lib"); + println!("cargo:rustc-link-lib=static=ltod"); println!("cargo:rustc-link-lib=static=SimConnect"); + println!("cargo:rustc-link-lib=static=user32"); + println!("cargo:rustc-link-lib=static=ole32"); + println!("cargo:rustc-link-lib=static=shell32"); let bindings = bindgen::Builder::default() .header("libsrc/include/SimConnect.hpp") @@ -203,4 +207,4 @@ fn main() { bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); -} \ No newline at end of file +} diff --git a/libsrc/lib/SimConnect.lib b/libsrc/lib/SimConnect.lib index 561f59e..3f0abab 100644 Binary files a/libsrc/lib/SimConnect.lib and b/libsrc/lib/SimConnect.lib differ diff --git a/libsrc/lib/SimConnect.lib.64bit b/libsrc/lib/SimConnect.lib.64bit new file mode 100644 index 0000000..561f59e Binary files /dev/null and b/libsrc/lib/SimConnect.lib.64bit differ diff --git a/libsrc/lib/ltod.lib b/libsrc/lib/ltod.lib new file mode 100644 index 0000000..60c786e Binary files /dev/null and b/libsrc/lib/ltod.lib differ diff --git a/libsrc/lib/ole32.lib b/libsrc/lib/ole32.lib new file mode 100644 index 0000000..17d6af8 Binary files /dev/null and b/libsrc/lib/ole32.lib differ diff --git a/libsrc/lib/shell32.lib b/libsrc/lib/shell32.lib new file mode 100644 index 0000000..b723320 Binary files /dev/null and b/libsrc/lib/shell32.lib differ diff --git a/libsrc/lib/user32.lib b/libsrc/lib/user32.lib new file mode 100644 index 0000000..27e18c3 Binary files /dev/null and b/libsrc/lib/user32.lib differ diff --git a/src/lib.rs b/src/lib.rs index ba3793c..4ab43e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -482,4 +482,4 @@ impl Drop for SimConnector { self.close(); } } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8c224cc --- /dev/null +++ b/src/main.rs @@ -0,0 +1,41 @@ +use simconnect; +use std::time::Duration; +use std::thread::sleep; +use std::mem::transmute_copy; + +struct DataStruct { + lat: f64, + lon: f64, + alt: f64, +} + +pub fn main() { + let mut conn = simconnect::SimConnector::new(); + conn.connect("Simple Program"); // Intialize connection with SimConnect + conn.add_data_definition(0, "PLANE LATITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX); // Assign a sim variable to a client defined id + conn.add_data_definition(0, "PLANE LONGITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX); + conn.add_data_definition(0, "PLANE ALTITUDE", "Feet", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX); //define_id, units, data_type, datum_id + conn.request_data_on_sim_object(0, 0, 0, simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 0, 0, 0, 0); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft + + loop { + match conn.get_next_message() { + Ok(simconnect::DispatchResult::SimobjectData(data)) => { + unsafe { + match data.dwDefineID { + 0 => { + let sim_data: DataStruct = transmute_copy(&data.dwData); + println!("{:?} {:?} {:?}", sim_data.lat, sim_data.lon, sim_data.alt); + }, + _ => () + } + } + }, + Err(e) => { + eprintln!("Error was received: {}", e); + }, + _ => () + } + + sleep(Duration::from_millis(16)); // Will use up lots of CPU if this is not included, as get_next_message() is non-blocking + } +}