Advanced Solutions for Flight Simulation

 

Sending Events to Mindstar Avionics

Looking for receiving events instead?  Click Here.

Overview

In order for external hardware to control Mindstar avionics, all our products are capable of receiving custom events sent through SimConnect, FSUIPC, or even the keyboard.   This event mechanism allows hardware knobs and buttons to notify the Mindstar software that a particular hardware item has been pressed or rotated.  Our software can then act on that event accordingly.

This page will explain the C++ code necessary for you to send these events to our software through SimConnect.   For this example, we will use the Mindstar G1000 gauge that works in FSX, FSX:Steam, and Prepar3D versions 1-3.  (Version 4 compatability is coming in mid-2020).  Details about the event mechanism are explained on our page about the G1000.INI

There are many controls on the G1000 that can be maniuplated in this way, but for this example, we will use the DIRECT-TO and the CLEAR buttons on the G1000 PFD.

                 Buttons used in this example
       

Relationship to G1000.INI

The events numbers you send to the Mindstar G1000 are determined by lines that appear in the [KEYBOARD] section of our G1000.INI file. That section lists all the available things the Mindstar G1000 can be told to do.

The section name [KEYBOARD] is a throwback to many years ago, prior to FSX, when the only control method available in our software was keyboard shortcuts. Over time, we added support for SimConnect and FSUIPC, but the section name remains the same. Don't let the name fool you!

Let's look at a highly simplified subsection of a G1000.INI below.  It is you, or your end user, who defines what hex event numbers are listed in this file.  If a hex number is entered after the '=' sign on any of these lines, then the Mindstar G1000 will listen for that event number to be broadcast by your program through SimConnect. If Mindstar software receives any of these events, it will act on that particular item by simulating the press of a knob or button accordingly.  The events are just hex numbers, as shown in red below:

    [KEYBOARD]
    PFD_DIRECT_TO=
0x11000
    PFD_CLR=
0x11005


C++ Code Example and Explanations

To send any of these events via SimConnect, you must write a C++ program that knows how to broadcast them.   This example uses only 2 of the numerous SimConnect function calls to accomplish this:

SimConnect_MapClientEventToSimEvent
SimConnect_TransmitClientEvent 

 

Your Event Enumeration

You start by coding an enumeration in your C++ program with entries that represent each of the individual events you want to send to SimConnect. If you send events to other vendors' software in addition to Mindstar, you must incorporate all the events ID's into this single enumeration.  

IMPORTANT
This must be the same enumeration you use for any events you wish to receive from SimConnect as well. Receiving events from SimConnect is covered in a seperate instruction page, but in order avoid cluttering this example, we'll only show the enumeration here with events we are planning to send.

 

static enum MY_SIMCONNECT_EVENT_IDS {
    NO_EVENT,
    MINDSTAR_PFD_DIRECT_TO_EVENT
,
    MINDSTAR_PFD_CLR_EVENT,
    etc,
    etc,...
};


Why do we need the enumeration?
Unfortunately, SimConnect does not let you directly broadcast the hex event number we've been talking about up to this point. Instead, SimConnect makes you assign these hex event numbers to items in your own enumeration.  This is explained below with the concept of "event mapping".

 

Connecting Your Enumeration to the Hex Event Numbers - Event Mapping

SimConnect does not let you directly transmit the hex event numbers. Instead, SimConnect makes you send one of your own enumeration IDs that have been previously matched up with one of the actual hex event numbers.  This matching, where you create a correllation between your enumeration items and the actual hex numbers is called "mapping" a client event to a sim event.

Each of your enumeration items are a client event
Each of the hex numbers from the G1000.INI are a sim event

The correllation ("mapping") between each hex event number and its corresponding item in your enumeration is accomplished during program initialization with a single function call for each event, as shown below:


HRESULT hr = E_FAIL;

if (hSimConnect)
{
   // --------------------------------------------------------------------------------------------
   // Tell SimConnect to correllate yoru enumeration items with a hex event number
   // --------------------------------------------------------------------------------------------
   hr = SimConnect_MapClientEventToSimEvent(hSimConnect, MINDSTAR_PFD_DIRECT_TO_EVENT, "#0x11000");

   hr = SimConnect_MapClientEventToSimEvent(hSimConnect, MINDSTAR_PFD_CLR_EVENT, "#0x11005");

}

Be very careful to format the hex event number into the string exactly as shown.   The string must contain a single pound sign # (or hashtag, depending on your age), followed by 0x and the 5 hex digits.  Don't add any more characters to that string or else SimConnect will not interpret it as a hex number.

 

Firing (Transmitting) the Events

When you are ready to tell the G1000 that one of these buttons has been pushed, you do this by telling SimConnect to fire the event.  But you do this by referencing your enumeration item.  The code below will fire the event for the PFD's Direct-To button, assuming the event number was specified in the G1000.INI, and mapped to your enumeration when your program initialized itself.

 

SIMCONNECT_OBJECT_ID objectID = SIMCONNECT_OBJECT_ID_USER; // direct the event to the user-aircraft
DWORD dwEventData = 0; // send 0 for unused event 'data'

SimConnect_TransmitClientEvent(objectID,
                               MINDSTAR_PFD_DIRECT_TO_EVENT, // event ID from your enumeration
                               dwEventData, // event DATA
                               SIMCONNECT_GROUP_PRIORITY_HIGHEST, // required parameter
                               SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY); // required parameter

 

Additional References

The SimConnect SDK is well-documented online on the Microsoft and Lockheed-Martin websites, or in the Help file delivered with the FSX or Prepar3D SDKs.   Our gauges are currently being modified to support Prepar3D V4, but until those modifications are complete, you must use either FSX, or Prepar3D versions 1 thru 3.   The SimConnect SDK functions used in these examples are practically the same in all those versions of the sim.  

Here are some useful links to the Lockheed-Martin website that show more information about the functions used in our examples on this page.

General SimConnect SDK Overview
SimConnect API Reference

SimConnect_MapClientEventToSimEvent
SimConnect_TransmitClientEvent