more visible
Some checks failed
CI / Rust checks (push) Failing after 38s

This commit is contained in:
2024-10-21 13:40:06 +02:00
parent aa439c16ca
commit cfc5e4ad87
3 changed files with 64 additions and 57 deletions

View File

@@ -99,7 +99,7 @@ pub fn derive(input: TokenStream) -> TokenStream {
let expanded = quote! {
#[repr(C, packed)]
#vis struct #packed_ident {
#(#packed_fields,)*
#(#vis #packed_fields,)*
}
impl simconnect_sdk::SimConnectObjectExt for #name_ident {
fn register(client: &mut simconnect_sdk::SimConnect, id: u32) -> Result<(), simconnect_sdk::SimConnectError> {
@@ -193,6 +193,11 @@ fn build_sc_definition(
client.add_to_data_definition(id, #name, #unit, simconnect_sdk::DataType::String)?;
}
}
Some(value) if value == "[i8; 256]" => {
quote! {
client.add_to_data_definition(id, #name, #unit, simconnect_sdk::DataType::String)?;
}
}
_ => {
// this error is already caught in `parse_field_attributes`
mk_err(path, error_message)

View File

@@ -1,4 +1,5 @@
mod ctrl_c;
mod models;
use std::{
borrow::Cow,
@@ -8,54 +9,9 @@ use std::{
};
use ctrl_c::CtrlC;
use models::{AtcID, AtcIDCPacked, Fuel};
// use simconnect_rs::SimConnect;
use simconnect_sdk::{Notification, SimConnect, SimConnectObject, SystemEventRequest};
#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
struct AtcID {
#[simconnect(name = "ATC ID")]
value: String,
}
// #[derive(Debug, Clone, SimConnectObject)]
// #[simconnect(period = "second")]
// #[allow(dead_code)]
// struct AirplaneData {
// #[simconnect(name = "TITLE")]
// title: String,
// #[simconnect(name = "ATC ID")]
// atc_id: String,
// #[simconnect(name = "CATEGORY")]
// category: String,
// #[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
// lat: f64,
// #[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
// lon: f64,
// #[simconnect(name = "PLANE ALTITUDE", unit = "feet")]
// alt: f64,
// #[simconnect(name = "SIM ON GROUND")]
// sim_on_ground: bool,
// }
#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
struct Fuel {
#[simconnect(name = "FUEL TANK CENTER QUANTITY", unit = "gallons")]
ft1: f64,
#[simconnect(name = "FUEL TANK LEFT MAIN QUANTITY", unit = "gallons")]
wt1: f64,
#[simconnect(name = "FUEL TANK RIGHT MAIN QUANTITY", unit = "gallons")]
wt2: f64,
#[simconnect(name = "FUEL TANK EXTERNAL1 QUANTITY", unit = "gallons")]
et1: f64,
#[simconnect(name = "FUEL TANK EXTERNAL2 QUANTITY", unit = "gallons")]
et2: f64,
#[simconnect(name = "FUEL TANK CENTER3 QUANTITY", unit = "gallons")]
et3: f64,
#[simconnect(name = "FUEL TANK CENTER2 QUANTITY", unit = "gallons")]
ft2: f64,
}
use simconnect_sdk::{Notification, SimConnect, SystemEventRequest};
fn main() -> Result<(), anyhow::Error> {
use tracing::Level;
@@ -85,23 +41,22 @@ fn main() -> Result<(), anyhow::Error> {
Notification::Open => {
simconnect.subscribe_to_system_event(SystemEventRequest::FlightLoaded)?;
id = simconnect.register_object::<AtcID>()?;
simconnect.register_object::<AtcID>()?;
simconnect.register_object::<Fuel>()?;
let cs = CString::new("FAST")?;
let cs = CString::new("ITWORKS")?;
let mut buffer = [0i8; 256];
for (i, b) in cs.to_bytes_with_nul().iter().enumerate() {
buffer[i] = *b as i8;
}
simconnect
.set_data_on_sim_object_with_id(id, &mut AtcIDCPacked { value: buffer })?;
simconnect.set_data_on_sim_object(&mut AtcID { value: buffer })?;
tracing::info!("ATC_ID set");
simconnect.set_data_on_sim_object(&mut Fuel {
ft1: 0.0,
wt1: 20.0,
wt2: 20.0,
wt1: 10.0,
wt2: 0.0,
et1: 0.0,
et2: 0.0,
et3: 0.0,
@@ -117,7 +72,7 @@ fn main() -> Result<(), anyhow::Error> {
}
Notification::SystemEvent(system_event) => {
if let simconnect_sdk::SystemEvent::FlightLoaded { .. } = system_event {
let cs = CString::new("RAWR")?;
let cs = CString::new("ITWORKS")?;
let mut buffer = [0i8; 256];
for (i, b) in cs.to_bytes_with_nul().iter().enumerate() {
buffer[i] = *b as i8;
@@ -131,8 +86,8 @@ fn main() -> Result<(), anyhow::Error> {
simconnect.set_data_on_sim_object(&mut Fuel {
ft1: 0.0,
wt1: 20.0,
wt2: 20.0,
wt1: 10.0,
wt2: 0.0,
et1: 0.0,
et2: 0.0,
et3: 0.0,

47
testapp/src/models.rs Normal file
View File

@@ -0,0 +1,47 @@
use simconnect_sdk::SimConnectObject;
#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
pub(super) struct AtcID {
#[simconnect(name = "ATC ID")]
pub value: String,
}
// #[derive(Debug, Clone, SimConnectObject)]
// #[simconnect(period = "second")]
// #[allow(dead_code)]
// struct AirplaneData {
// #[simconnect(name = "TITLE")]
// title: String,
// #[simconnect(name = "ATC ID")]
// atc_id: String,
// #[simconnect(name = "CATEGORY")]
// category: String,
// #[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
// lat: f64,
// #[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
// lon: f64,
// #[simconnect(name = "PLANE ALTITUDE", unit = "feet")]
// alt: f64,
// #[simconnect(name = "SIM ON GROUND")]
// sim_on_ground: bool,
// }
#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
pub(super) struct Fuel {
#[simconnect(name = "FUEL TANK CENTER QUANTITY", unit = "gallons")]
pub ft1: f64,
#[simconnect(name = "FUEL TANK LEFT MAIN QUANTITY", unit = "gallons")]
pub wt1: f64,
#[simconnect(name = "FUEL TANK RIGHT MAIN QUANTITY", unit = "gallons")]
pub wt2: f64,
#[simconnect(name = "FUEL TANK EXTERNAL1 QUANTITY", unit = "gallons")]
pub et1: f64,
#[simconnect(name = "FUEL TANK EXTERNAL2 QUANTITY", unit = "gallons")]
pub et2: f64,
#[simconnect(name = "FUEL TANK CENTER3 QUANTITY", unit = "gallons")]
pub et3: f64,
#[simconnect(name = "FUEL TANK CENTER2 QUANTITY", unit = "gallons")]
pub ft2: f64,
}