Пример #1
0
        private void CheckPttDevice()
        {
            bool isPressed = false;

            switch (mPttConfiguration.DeviceType)
            {
            case PTTDeviceType.None:
                isPressed = false;
                break;

            case PTTDeviceType.Keyboard:
                isPressed = ((GetAsyncKeyState(mPttConfiguration.ButtonOrKey) & 32768) > 0);
                break;

            case PTTDeviceType.Joystick:
                if (mJoystick != null && mPttConfiguration.JoystickAcquired && mPttConfiguration.ButtonOrKey >= 0)
                {
                    try
                    {
                        JoystickState currentState = mJoystick.GetCurrentState();
                        bool[]        buttons      = currentState.Buttons;
                        try
                        {
                            isPressed = buttons[mPttConfiguration.ButtonOrKey];
                        }
                        catch (IndexOutOfRangeException)
                        {
                        }
                    }
                    catch (SharpDXException)
                    {
                        mPttConfiguration.JoystickAcquired = false;
                        if (mJoystick != null)
                        {
                            mJoystick.Unacquire();
                            mJoystick.Dispose();
                        }
                        mJoystick = null;
                    }
                }
                break;
            }
            if (isPressed != mPttStatus)
            {
                mPttStatus = isPressed;
                PushToTalkStateChanged?.Invoke(this, new PushToTalkStateChangedEventArgs(mPttStatus));
            }
        }
        private void SetupSubscribers()
        {
            // com audio selection
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsAudioComSelection, 5, (e, v) => { mRadioStackState.ComAudioSelection = (uint)e.Value; });

            // com1 frequency
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom1FrequencyHz, 5, (e, v) => { mRadioStackState.Com1ActiveFreq = ((uint)e.Value * 10000).Normalize25KhzFrequency(); });
            // com1 standby frequency
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom1StandbyFrequencyHz, 5, (e, v) => { mRadioStackState.Com1StandbyFreq = ((uint)e.Value * 10000).Normalize25KhzFrequency(); });
            // com1 power
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom1Power, 5, (e, v) => { mRadioStackState.Com1Power = Convert.ToBoolean(e.Value); });
            // com1 listening
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsAudioSelectionCom1, 5, (e, v) => { mRadioStackState.Com1Listening = Convert.ToBoolean(e.Value); });
            // com1 volume
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsAudioVolumeCom1, 5, (e, v) =>
            {
                if (e.Value > 1.0f)
                {
                    e.Value = 1.0f;
                }
                if (e.Value < 0.0f)
                {
                    e.Value = 0.0f;
                }
                Com1VolumeChanged?.Invoke(this, new RadioVolumeChangedEventArgs(1, e.Value));
            });

            // com2 frequency
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom2FrequencyHz, 5, (e, v) => { mRadioStackState.Com2ActiveFreq = ((uint)e.Value * 10000).Normalize25KhzFrequency(); });
            // com2 standby frequency
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom2StandbyFrequencyHz, 5, (e, v) => { mRadioStackState.Com2StandbyFreq = ((uint)e.Value * 10000).Normalize25KhzFrequency(); });
            // com2 power
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsCom2Power, 5, (e, v) => { mRadioStackState.Com2Power = Convert.ToBoolean(e.Value); });
            // com2 listening
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsAudioSelectionCom2, 5, (e, v) => { mRadioStackState.Com2Listening = Convert.ToBoolean(e.Value); });
            // com2 volume
            mXplaneConnector.Subscribe(DataRefs.Cockpit2RadiosActuatorsAudioVolumeCom2, 5, (e, v) =>
            {
                if (e.Value > 1.0f)
                {
                    e.Value = 1.0f;
                }
                if (e.Value < 0.0f)
                {
                    e.Value = 0.0f;
                }
                Com2VolumeChanged?.Invoke(this, new RadioVolumeChangedEventArgs(2, e.Value));
            });

            // avionics power
            mXplaneConnector.Subscribe(DataRefs.Cockpit2SwitchesAvionicsPowerOn, 5, (e, v) => { mRadioStackState.AvionicsPower = Convert.ToBoolean(e.Value); });

            // latitude
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionLatitude, 5, (e, v) => { mUserAircraftData.Latitude = e.Value; });

            // longitude
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionLongitude, 5, (e, v) => { mUserAircraftData.Longitude = e.Value; });

            // true altitude msl
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionElevation, 5, (e, v) => { mUserAircraftData.AltitudeMsl = e.Value; });

            // pressure altitude
            mXplaneConnector.Subscribe(DataRefs.Cockpit2GaugesIndicatorsAltitudeFtPilot, 5, (e, v) => { mUserAircraftData.PressureAltitude = e.Value; });

            // heading
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionPsi, 5, (e, v) => { mUserAircraftData.Heading = e.Value; });

            // ground speed
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionGroundspeed, 5, (e, v) => { mUserAircraftData.GroundSpeed = e.Value * 1.94384; });

            // pitch
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionTheta, 5, (e, v) => { mUserAircraftData.Pitch = e.Value; });

            // bank
            mXplaneConnector.Subscribe(DataRefs.FlightmodelPositionPhi, 5, (e, v) => { mUserAircraftData.Bank = e.Value; });

            // transponder code
            mXplaneConnector.Subscribe(DataRefs.CockpitRadiosTransponderCode, 5, (e, v) => { mUserAircraftData.TransponderCode = Convert.ToInt32(e.Value); });

            // transponder mode
            mXplaneConnector.Subscribe(DataRefs.CockpitRadiosTransponderMode, 5, (e, v) => { mUserAircraftData.TransponderMode = Convert.ToInt32(e.Value); });

            // transponder ident
            mXplaneConnector.Subscribe(DataRefs.CockpitRadiosTransponderId, 5, (e, v) => { mUserAircraftData.TransponderIdent = Convert.ToBoolean(e.Value); SquawkingIdentChanged?.Invoke(this, new SquawkingIdentChangedEventArgs(Convert.ToBoolean(e.Value))); });

            // beacon light
            mXplaneConnector.Subscribe(DataRefs.CockpitElectricalBeaconLightsOn, 5, (e, v) => { mUserAircraftData.BeaconLightsOn = Convert.ToBoolean(e.Value); });

            // landing lights
            mXplaneConnector.Subscribe(DataRefs.CockpitElectricalLandingLightsOn, 5, (e, v) => { mUserAircraftData.LandingLightsOn = Convert.ToBoolean(e.Value); });

            // taxi lights
            mXplaneConnector.Subscribe(DataRefs.CockpitElectricalTaxiLightOn, 5, (e, v) => { mUserAircraftData.TaxiLightsOn = Convert.ToBoolean(e.Value); });

            // nav lights
            mXplaneConnector.Subscribe(DataRefs.CockpitElectricalNavLightsOn, 5, (e, v) => { mUserAircraftData.NavLightsOn = Convert.ToBoolean(e.Value); });

            // strobe lights
            mXplaneConnector.Subscribe(DataRefs.CockpitElectricalStrobeLightsOn, 5, (e, v) => { mUserAircraftData.StrobeLightsOn = Convert.ToBoolean(e.Value); });

            // flaps
            mXplaneConnector.Subscribe(DataRefs.FlightmodelControlsFlaprat, 5, (e, v) => { mUserAircraftData.FlapsPercentage = e.Value; });

            // gear
            mXplaneConnector.Subscribe(DataRefs.CockpitSwitchesGearHandleStatus, 5, (e, v) => { mUserAircraftData.GearDown = Convert.ToBoolean(e.Value); });

            // speed brakes
            mXplaneConnector.Subscribe(DataRefs.Cockpit2ControlsSpeedbrakeRatio, 5, (e, v) => { mUserAircraftData.SpeedBrakeDeployed = e.Value > 0; });

            // replay mode
            mXplaneConnector.Subscribe(DataRefs.OperationPrefsReplayMode, 5, (e, v) => { mUserAircraftData.ReplayModeEnabled = Convert.ToBoolean(e.Value); });

            // engine count
            var engCount = new DataRefElement
            {
                DataRef   = "sim/aircraft/engine/acf_num_engines",
                Frequency = 5
            };

            mXplaneConnector.Subscribe(engCount, 5, (e, v) => { mUserAircraftData.EngineCount = Convert.ToInt32(e.Value); });

            // engine1 running
            var engn0 = new DataRefElement
            {
                DataRef   = "sim/flightmodel/engine/ENGN_running[0]",
                Frequency = 5
            };

            // engine2 running
            var engn1 = new DataRefElement
            {
                DataRef   = "sim/flightmodel/engine/ENGN_running[1]",
                Frequency = 5
            };

            // engine3 running
            var engn2 = new DataRefElement
            {
                DataRef   = "sim/flightmodel/engine/ENGN_running[2]",
                Frequency = 5
            };

            // engine1 running
            var engn3 = new DataRefElement
            {
                DataRef   = "sim/flightmodel/engine/ENGN_running[3]",
                Frequency = 5
            };

            mXplaneConnector.Subscribe(engn0, 5, (e, v) => { mUserAircraftData.Engine1Running = Convert.ToBoolean(e.Value); });
            mXplaneConnector.Subscribe(engn1, 5, (e, v) => { mUserAircraftData.Engine2Running = Convert.ToBoolean(e.Value); });
            mXplaneConnector.Subscribe(engn2, 5, (e, v) => { mUserAircraftData.Engine3Running = Convert.ToBoolean(e.Value); });
            mXplaneConnector.Subscribe(engn3, 5, (e, v) => { mUserAircraftData.Engine4Running = Convert.ToBoolean(e.Value); });

            // on the ground
            mXplaneConnector.Subscribe(DataRefs.FlightmodelFailuresOngroundAny, 5, (e, v) => { mUserAircraftData.OnGround = Convert.ToBoolean(e.Value); });

            // ptt command
            var ptt = new DataRefElement
            {
                DataRef   = "xpilot/ptt",
                Frequency = 15
            };

            mXplaneConnector.Subscribe(ptt, 15, (e, v) =>
            {
                PushToTalkStateChanged?.Invoke(this, new PushToTalkStateChangedEventArgs(Convert.ToBoolean(e.Value)));
            });

            mXplaneConnector.Start();
        }