Define the desired API

This commit is contained in:
Mihai Dinculescu
2022-10-08 19:09:57 +01:00
parent 41ebdbd03d
commit 6d8fc61c0b
19 changed files with 642 additions and 300 deletions

View File

@@ -0,0 +1,7 @@
#[derive(Debug, Clone)]
pub struct AirportData {
pub icao: String,
pub lat: f64,
pub lon: f64,
pub alt: f64,
}

5
src/domain/condition.rs Normal file
View File

@@ -0,0 +1,5 @@
#[derive(Debug, Clone)]
pub enum ConditionEnum {
None,
Changed,
}

5
src/domain/data_type.rs Normal file
View File

@@ -0,0 +1,5 @@
#[derive(Debug, Clone)]
pub enum DataType {
F64,
Bool,
}

19
src/domain/event.rs Normal file
View File

@@ -0,0 +1,19 @@
use std::os::raw::c_char;
#[derive(Debug, Copy, Clone, num_enum::TryFromPrimitive)]
#[repr(u32)]
pub enum Event {
Brakes,
BrakesLeft,
AxisLeftBrakeSet,
}
impl Event {
pub(crate) fn into_c_char(self) -> *const c_char {
match self {
Event::Brakes => "BRAKES\0".as_ptr() as *const c_char,
Event::BrakesLeft => "BRAKES_LEFT\0".as_ptr() as *const c_char,
Event::AxisLeftBrakeSet => "AXIS_LEFT_BRAKE_SET\0".as_ptr() as *const c_char,
}
}
}

5
src/domain/group.rs Normal file
View File

@@ -0,0 +1,5 @@
#[derive(Copy, Clone)]
#[repr(u32)]
pub enum Group {
Group0,
}

15
src/domain/mod.rs Normal file
View File

@@ -0,0 +1,15 @@
mod airport_data;
mod condition;
mod data_type;
mod event;
mod group;
mod notification;
mod period;
pub use airport_data::*;
pub use condition::*;
pub use data_type::*;
pub use event::*;
pub use group::*;
pub use notification::*;
pub use period::*;

View File

@@ -0,0 +1,28 @@
use crate::{AirportData, Event, SimConnectObject};
pub enum Notification {
Open,
Event(Event),
Data(NotificationData),
AirportList(Vec<AirportData>),
Quit,
Exception(u32),
}
pub struct NotificationData {
pub(crate) type_id: String,
pub(crate) data_addr: *const u32,
}
impl NotificationData {
pub fn try_into<T: SimConnectObject>(&self) -> Option<T> {
let type_id: String = std::any::type_name::<T>().into();
if self.type_id == type_id {
let data: &T = unsafe { std::mem::transmute_copy(&self.data_addr) };
Some(data.clone())
} else {
None
}
}
}

5
src/domain/period.rs Normal file
View File

@@ -0,0 +1,5 @@
#[derive(Debug, Clone)]
pub enum PeriodEnum {
VisualFrame { interval: u32 },
Second,
}