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

#16 fix update example #18

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ac59d70
Add epsilon parameter to data definition
BitsAndDroids Dec 21, 2023
b694463
upped v
BitsAndDroids Dec 21, 2023
cdafdf2
Add optional epsilon parameter to add_data_definition functions
BitsAndDroids Dec 21, 2023
75538ba
Updated add_data_definition method to include optional epsilon parameter
BitsAndDroids Dec 21, 2023
14b1974
Update simconnect dependency in README
BitsAndDroids Dec 21, 2023
fe44a42
Update unsafe block code in Readme and lib.rs
BitsAndDroids Dec 21, 2023
c70a077
Update simconnect version and add new examples
BitsAndDroids Dec 24, 2023
574f5d6
Improve data update definition in aircraft example
BitsAndDroids Dec 24, 2023
7f557ef
Update aircraft data request to prevent overwrite
BitsAndDroids Dec 24, 2023
2a4e742
Add structured definitions to aircraft example
BitsAndDroids Dec 24, 2023
e2e18d0
Update Readme.md
Sequal32 Dec 26, 2023
4f51b6a
Update code comments and fix typographical issues
BitsAndDroids Dec 26, 2023
e8738ff
Merge branch 'master' of https://github.com/BitsAndDroids/simconnect-…
BitsAndDroids Dec 26, 2023
01253ee
Update terminology in Readme.md
BitsAndDroids Dec 26, 2023
36cff2c
Fix typo in connect function comment in main.rs
BitsAndDroids Dec 26, 2023
3215639
fix: cleanup clippy warnings
Sequal32 Dec 27, 2023
9310823
refactor: renamed SimobjectData -> SimObjectData
Sequal32 Dec 27, 2023
7e752ae
chore: increment breaking change version num
Sequal32 Dec 27, 2023
94af7e9
#16-fixed-example-pointer-logic
BitsAndDroids Mar 25, 2024
3b82c14
Merge branch '#16-fix-update-example' of github.com-bitsanddroids:Bit…
BitsAndDroids Mar 25, 2024
9c0bf8a
removed unused struct
BitsAndDroids Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "simconnect"
license = "MIT"
description = "Rust bindings for SimConnect"
version = "0.3.1"
version = "0.3.2"
authors = ["Connor T"]
edition = "2018"

Expand All @@ -15,9 +15,6 @@ path = "examples/aircraft_updates_on_change/main.rs"
name = "aircraft_updates"
path = "examples/aircraft_updates/main.rs"

[[example]]
name = "aircraft_inputs"
path = "examples/aircraft_inputs/main.rs"

[build-dependencies]
bindgen = "0.65"
bindgen = "0.69.4"
18 changes: 5 additions & 13 deletions examples/aircraft_updates_on_change/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ struct KeyValuePairString {
value: [u8; 255],
}

struct DataStringStruct {
data: [KeyValuePairString; MAX_RETURNED_ITEMS],
}

fn main() {
let mut conn = simconnect::SimConnector::new();
conn.connect("Program that returns data on changes"); // Initialize connection with SimConnect
Expand Down Expand Up @@ -128,17 +124,13 @@ fn main() {
}
1 => {
let sim_data_ptr =
std::ptr::addr_of!(data.dwData) as *const DataStringStruct;
std::ptr::addr_of!(data.dwData) as *const KeyValuePairString;
// The amount of strings received from the sim
let count = data.dwDefineCount as usize;
let sim_data_value = std::ptr::read_unaligned(sim_data_ptr);
let count = data.dwDefineCount as isize;
for i in 0..count {
//since we only defined 1 string variable the key returned should be 4
let key = sim_data_value.data[0].id;
//byte array to string
let string =
std::str::from_utf8(&sim_data_value.data[i].value).unwrap();
println!("{}", key);
let item_ptr = sim_data_ptr.offset(i);
let sim_data_value = std::ptr::read_unaligned(item_ptr);
let string = std::str::from_utf8(&sim_data_value.value).unwrap();
println!("{}", string);
}
}
Expand Down