Ejemplo n.º 1
0
        private void SendToFSX(double aileron, double rudder, double elevator, double throttle, int gear, int flaps)
        {
            FsDataObjects.ControlDataStructure controls;
            controls.elevator  = elevator;
            controls.aileron   = aileron;
            controls.rudder    = rudder;
            controls.throttle1 = throttle * 100;
            controls.throttle2 = throttle * 100;
            controls.throttle3 = throttle * 100;
            controls.throttle4 = throttle * 100;

            simconnect.SetDataOnSimObject(FsDataObjects.DEFINITIONS.ControlDataStruct, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, controls);

            ControlsLatest = controls;

            if (gear != gear_last)
            {
                gear_last = gear;

                FsDataObjects.EVENTS g_state = (gear == 1) ? FsDataObjects.EVENTS.GEAR_UP : FsDataObjects.EVENTS.GEAR_DOWN;

                simconnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, g_state, 0, FsDataObjects.NOTIFICATION_GROUPS.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }

            if (flaps != flaps_last)
            {
                flaps_last = flaps;

                FsDataObjects.EVENTS f_state = FsDataObjects.EVENTS.FLAPS0;

                if (flaps == 0)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS0;
                }
                else if (flaps == 1)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS1;
                }
                else if (flaps == 2)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS2;
                }

                play_flap = true;

                simconnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, f_state, 0, FsDataObjects.NOTIFICATION_GROUPS.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends the input parameters to FSX
        /// </summary>
        /// <param name="aileron">An aileron input in percent, between -1 and 1</param>
        /// <param name="rudder">An rudder input in percent, between -1 and 1</param>
        /// <param name="elevator">An elevator input in percent, between -1 and 1</param>
        /// <param name="throttle">An throttle input in percent, between 0 and 1</param>
        /// <param name="gear">The landing gear status, 0 being down and 1 being up</param>
        /// <param name="flaps">The flap status, with 0 being up, 1 being halfway, and 2 being down</param>
        private void SendToFSX(
            double aileron,
            double rudder,
            double elevator,
            double throttle,
            int gear,
            int flaps)
        {
            // Skip if not connected
            if (simconnect == null)
            {
                return;
            }

            // Set the data in the control data structure
            FsDataObjects.ControlDataStructure controls;
            controls.elevator  = elevator;
            controls.aileron   = aileron;
            controls.rudder    = rudder;
            controls.throttle1 = throttle * 100;
            controls.throttle2 = throttle * 100;
            controls.throttle3 = throttle * 100;
            controls.throttle4 = throttle * 100;

            // Set the data in the simconnect object
            simconnect.SetDataOnSimObject(
                FsDataObjects.DEFINITIONS.ControlDataStruct,
                SimConnect.SIMCONNECT_OBJECT_ID_USER,
                0,
                controls);

            // Save the latest controls parameters
            ControlsLatest = controls;

            // Transmit the gear state if it is different from the last gear state
            if (gear != gear_last)
            {
                gear_last = gear;

                FsDataObjects.EVENTS g_state = (gear == 1) ? FsDataObjects.EVENTS.GEAR_UP : FsDataObjects.EVENTS.GEAR_DOWN;

                simconnect.TransmitClientEvent(
                    SimConnect.SIMCONNECT_OBJECT_ID_USER,
                    g_state,
                    0,
                    FsDataObjects.NOTIFICATION_GROUPS.GROUP0,
                    SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }

            // Transmit the flaps state if it is different from the last flaps state
            if (flaps != flaps_last)
            {
                flaps_last = flaps;

                FsDataObjects.EVENTS f_state = FsDataObjects.EVENTS.FLAPS0;

                if (flaps == 0)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS0;
                }
                else if (flaps == 1)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS1;
                }
                else if (flaps == 2)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS2;
                }

                simconnect.TransmitClientEvent(
                    SimConnect.SIMCONNECT_OBJECT_ID_USER,
                    f_state,
                    0,
                    FsDataObjects.NOTIFICATION_GROUPS.GROUP0,
                    SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }
        }