mihai-dinculescu / simconnect-sdk-rs

SimConnect SDK in Rust. An opinionated SimConnect Client that encapsulates the C API fully and optimizes for developer experience.
MIT License
11 stars 6 forks source link

SimConnect_TransmitClientEvent Implementation #27

Open Sector95 opened 1 year ago

Sector95 commented 1 year ago

Example usage, setting the COM1 standby frequency to 127.625 and transponder to 7700:

use simconnect_sdk::{SimConnect, EventFlag, ClientEventRequest, ClientEvent};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = SimConnect::new("Test");

    match client {
        Ok(mut client) => {
            client.subscribe_to_client_event(ClientEventRequest::Com1RadioStbySet)?;
            client.subscribe_to_client_event(ClientEventRequest::TransponderSet)?;

            let com1_event: ClientEvent = ClientEvent::Com1RadioStbySet { value: 123.625 };
            client.transmit_client_event(0, com1_event, EventFlag::DoNothing)?;

            let xpndr_event: ClientEvent = ClientEvent::TransponderSet { value: 7700 };
            client.transmit_client_event(0, xpndr_event, EventFlag::DoNothing)?;
        }
        Err(e) => {
            println!("Error: {e:?}")
        }
    }

    Ok(())
}
mihai-dinculescu commented 1 year ago

This is very welcome. Thank you!

Unfortunately, the little there is about ClientEvent and NotificationGroup is neither correct nor ergonomic. Please give me a few days to develop something better to base this PR on.

mihai-dinculescu commented 1 year ago

OK, it's done. It ended up being a pretty chunky refactor. https://github.com/mihai-dinculescu/simconnect-sdk-rs/commit/d89fa524c2bc585f806f44143a7d95d09040968f.

Probably it's best to read the whole changelog for the rebase, but here are the main takeaways:

Sector95 commented 1 year ago

Thanks, I'll take a look and rebase when I get a moment here 👍

SafeShows commented 1 year ago

Hey @Sector95 How's the feature coming along as I have an app idea that need to write data to sim and or trigger events in the sim

Sector95 commented 1 year ago

Hey @Sector95 How's the feature coming along as I have an app idea that need to write data to sim and or trigger events in the sim

Hey sorry, life's been wild, I'll try to tackle this sometime this week!

Sector95 commented 1 year ago

Updated the example, and merged in your code changes. Sorry for the delay!

Sector95 commented 1 year ago

Implemented a little cleaner of an interface for both radios and transponders, so the client doesn't have to do conversion or encoding. Updated the example on this PR for the new pattern, demonstrating both setting radios and transponders.

Also swapped i32 for u32 for the From<ClientEvent> for (ClientEventRequest, i32) trait, as the SimConnect::transmit_client_event function requires a u32 for the dword value anyway.

Sector95 commented 1 year ago

Think I've addressed what showed up in the format workflow there. Let me know if they're is anything else left outstanding.

mihai-dinculescu commented 1 year ago

The BCD conversion is excellent! Thanks for adding it!

MrMinimal commented 12 months ago

Given that this isn't merged, does simconnect-sdk-rs currently have the ability to transmit client events and set data (e. g. frequencies) in the sim?

mihai-dinculescu commented 11 months ago

Given that this isn't merged, does simconnect-sdk-rs currently have the ability to transmit client events and set data (e. g. frequencies) in the sim?

Not without this PR.

@Sector95 are you happy to wrap up the PR? I believe that it's getting very close.