1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-27 16:20:10 +00:00
msfs-popout-panel-manager/Orchestration/FlightSimOrchestrator.cs

485 lines
18 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.DomainModel.SimConnect;
using MSFSPopoutPanelManager.Shared;
2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.SimConnectAgent;
2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.WindowsAgent;
2022-07-23 19:23:32 +00:00
using System;
2023-07-12 22:41:31 +00:00
using System.Collections.Generic;
using System.Threading;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.Orchestration
{
2024-02-28 02:44:21 +00:00
public class FlightSimOrchestrator : BaseOrchestrator
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
private const int MSFS_GAME_EXIT_DETECTION_INTERVAL = 3000;
private System.Timers.Timer _msfsGameExitDetectionTimer;
2022-07-23 19:23:32 +00:00
private SimConnectProvider _simConnectProvider;
2023-07-12 22:41:31 +00:00
private bool _isTurnedOnPower;
private bool _isTurnedOnAvionics;
2024-02-28 02:44:21 +00:00
public FlightSimOrchestrator(SharedStorage sharedStorage) : base(sharedStorage)
2022-07-23 19:23:32 +00:00
{
_simConnectProvider = new SimConnectProvider();
}
2024-02-28 02:44:21 +00:00
public event EventHandler OnSimulatorExited;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
public event EventHandler OnFlightStarted;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
public event EventHandler OnFlightStopped;
2022-07-23 19:23:32 +00:00
public void StartSimConnectServer()
{
2024-02-28 02:44:21 +00:00
_simConnectProvider ??= new SimConnectProvider();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnConnected += (_, _) =>
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectActive = true;
FlightSimData.IsSimulatorStarted = true;
2023-07-12 22:41:31 +00:00
WindowProcessManager.GetSimulatorProcess(); // refresh simulator process
DetectMsfsExit();
2024-02-28 02:44:21 +00:00
DynamicLodManager.Attach(FlightSimData, AppSettingData); // Attach in memory override for Dynamic LOD
2022-07-23 19:23:32 +00:00
};
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnDisconnected += (_, _) =>
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectDataReceived = false;
FlightSimData.IsSimConnectActive = false;
2023-07-12 22:41:31 +00:00
WindowProcessManager.GetSimulatorProcess(); // refresh simulator process
2024-02-28 02:44:21 +00:00
FlightSimData.Reset();
2022-07-23 19:23:32 +00:00
};
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnException += (_, _) =>
2023-08-05 03:40:29 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectDataReceived = false;
FlightSimData.IsSimConnectActive = false;
2023-08-05 03:40:29 +00:00
};
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnSimConnectDataRequiredRefreshed += (_, e) =>
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
var electricalMasterBattery = Convert.ToBoolean(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.ElectricalMasterBattery).Value);
2024-02-28 02:44:21 +00:00
if (electricalMasterBattery != FlightSimData.ElectricalMasterBatteryStatus)
FlightSimData.ElectricalMasterBatteryStatus = electricalMasterBattery;
2022-08-05 03:43:51 +00:00
2023-07-12 22:41:31 +00:00
var avionicsMasterSwitch = Convert.ToBoolean(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.AvionicsMasterSwitch).Value);
2024-02-28 02:44:21 +00:00
if (avionicsMasterSwitch != FlightSimData.AvionicsMasterSwitchStatus)
FlightSimData.AvionicsMasterSwitchStatus = avionicsMasterSwitch;
2022-08-05 03:43:51 +00:00
2023-07-12 22:41:31 +00:00
var trackIR = Convert.ToBoolean(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.TrackIREnable).Value);
2024-02-28 02:44:21 +00:00
if (trackIR != FlightSimData.TrackIRStatus)
FlightSimData.TrackIRStatus = trackIR;
2023-07-30 21:30:47 +00:00
2024-02-29 00:54:25 +00:00
var cameraStateInt = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraState).Value);
var result = Enum.TryParse<CameraState>(cameraStateInt.ToString(), out var cameraState);
if (!result)
cameraState = CameraState.Unknown;
if (cameraState != FlightSimData.CameraState)
FlightSimData.CameraState = cameraState;
2023-07-30 21:30:47 +00:00
var cockpitCameraZoom = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CockpitCameraZoom).Value);
2024-02-28 02:44:21 +00:00
if (cockpitCameraZoom != FlightSimData.CockpitCameraZoom)
FlightSimData.CockpitCameraZoom = cockpitCameraZoom;
var planeAltAboveGround = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.PlaneAltAboveGround).Value);
if (planeAltAboveGround != FlightSimData.PlaneAltAboveGround)
FlightSimData.PlaneAltAboveGround = planeAltAboveGround;
var cameraViewTypeAndIndex0 = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex0).Value);
if (cameraViewTypeAndIndex0 != FlightSimData.CameraViewTypeAndIndex0)
FlightSimData.CameraViewTypeAndIndex0 = cameraViewTypeAndIndex0;
2023-08-14 04:35:14 +00:00
var cameraViewTypeAndIndex1 = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex1).Value);
2024-02-28 02:44:21 +00:00
if (cameraViewTypeAndIndex1 != FlightSimData.CameraViewTypeAndIndex1)
FlightSimData.CameraViewTypeAndIndex1 = cameraViewTypeAndIndex1;
var cameraViewTypeAndIndex1Max = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex1Max).Value);
if (cameraViewTypeAndIndex1Max != FlightSimData.CameraViewTypeAndIndex1Max)
FlightSimData.CameraViewTypeAndIndex1Max = cameraViewTypeAndIndex1Max;
2023-08-18 21:02:03 +00:00
2024-02-28 02:44:21 +00:00
var cameraViewTypeAndIndex2Max = Convert.ToInt32(e.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex2Max).Value);
if (cameraViewTypeAndIndex2Max != FlightSimData.CameraViewTypeAndIndex2Max)
FlightSimData.CameraViewTypeAndIndex2Max = cameraViewTypeAndIndex2Max;
FlightSimData.IsSimConnectDataReceived = true;
2023-07-12 22:41:31 +00:00
};
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnSimConnectDataHudBarRefreshed += (_, e) =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled)
2023-07-12 22:41:31 +00:00
MapHudBarSimConnectData(e);
};
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnActiveAircraftChanged += (_, e) =>
2023-07-12 22:41:31 +00:00
{
var aircraftName = String.IsNullOrEmpty(e) ? null : e;
2024-02-28 02:44:21 +00:00
if (FlightSimData.AircraftName != aircraftName)
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.AircraftName = aircraftName;
ProfileData.RefreshProfile();
2022-07-23 19:23:32 +00:00
}
};
2023-07-12 22:41:31 +00:00
2022-08-19 16:03:12 +00:00
_simConnectProvider.OnFlightStarted += HandleOnFlightStarted;
2022-07-23 19:23:32 +00:00
_simConnectProvider.OnFlightStopped += HandleOnFlightStopped;
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnIsInCockpitChanged += (_, e) =>
{
FlightSimData.IsInCockpit = e;
if (e)
FlightSimData.IsFlightStarted = true;
};
2022-07-23 19:23:32 +00:00
_simConnectProvider.Start();
}
public void EndSimConnectServer(bool appExit)
{
_simConnectProvider.Stop(appExit);
2023-07-12 22:41:31 +00:00
_simConnectProvider = null;
2022-07-23 19:23:32 +00:00
}
2023-08-16 03:41:14 +00:00
public void TurnOnTrackIR()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on TrackIR", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
_simConnectProvider.TurnOnTrackIR();
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.TrackIRStatus && count < 5);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.TrackIRStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
2023-08-16 03:41:14 +00:00
public void TurnOffTrackIR()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off TrackIR", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
_simConnectProvider.TurnOffTrackIR();
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.TrackIRStatus && count < 5);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.TrackIRStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
public void TurnOnPower()
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || FlightSimData.ElectricalMasterBatteryStatus)
2023-07-12 22:41:31 +00:00
return;
_isTurnedOnPower = true;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on battery", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOnPower(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.ElectricalMasterBatteryStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.ElectricalMasterBatteryStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOffPower()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || !_isTurnedOnPower)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off battery", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOffPower(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.ElectricalMasterBatteryStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.ElectricalMasterBatteryStatus;
2023-08-16 03:41:14 +00:00
});
2023-07-12 22:41:31 +00:00
_isTurnedOnPower = false;
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOnAvionics()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || FlightSimData.AvionicsMasterSwitchStatus)
2023-07-12 22:41:31 +00:00
return;
_isTurnedOnAvionics = true;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on avionics", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOnAvionics(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.AvionicsMasterSwitchStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.AvionicsMasterSwitchStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
public void TurnOffAvionics()
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || !_isTurnedOnAvionics)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off avionics", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOffAvionics(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.AvionicsMasterSwitchStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.AvionicsMasterSwitchStatus;
2023-08-16 03:41:14 +00:00
});
2023-07-12 22:41:31 +00:00
_isTurnedOnAvionics = false;
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOnActivePause()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on active pause", () =>
{
_simConnectProvider.TurnOnActivePause();
});
2023-07-12 22:41:31 +00:00
}
public void TurnOffActivePause()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off active pause", () =>
{
_simConnectProvider.TurnOffActivePause();
});
2023-07-12 22:41:31 +00:00
}
public void IncreaseSimRate()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (Convert.ToInt32(FlightSimData.HudBarData.SimRate) == 16)
2023-07-12 22:41:31 +00:00
return;
_simConnectProvider.IncreaseSimRate();
}
public void DecreaseSimRate()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (FlightSimData.HudBarData.SimRate.ToString("N2") == "0.25")
2023-07-12 22:41:31 +00:00
return;
_simConnectProvider.DecreaseSimRate();
}
2023-07-30 21:30:47 +00:00
public void SetCockpitCameraZoomLevel(int zoomLevel)
{
_simConnectProvider.SetCockpitCameraZoomLevel(zoomLevel);
}
2023-08-16 03:41:14 +00:00
public void ResetCameraView()
{
_simConnectProvider.SetCameraRequestAction(1);
}
2024-02-28 02:44:21 +00:00
public void SetFixedCamera(CameraType cameraType, int index)
{
2024-02-29 00:54:25 +00:00
if (FlightSimData.CameraState != CameraState.Cockpit)
{
_simConnectProvider.SetCameraState(CameraState.Cockpit);
Thread.Sleep(250);
ResetCameraView();
Thread.Sleep(250);
}
2024-02-28 02:44:21 +00:00
_simConnectProvider.SetCameraViewTypeAndIndex0(Convert.ToInt32(cameraType));
Thread.Sleep(250);
_simConnectProvider.SetCameraViewTypeAndIndex1(index);
}
2023-07-12 22:41:31 +00:00
public void SetHudBarConfig()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
var hudBarType = ProfileData.ActiveProfile.ProfileSetting.HudBarConfig.HudBarType;
2023-07-12 22:41:31 +00:00
switch (hudBarType)
{
case HudBarType.PMDG_737:
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData = new HudBarData737();
2023-07-12 22:41:31 +00:00
break;
case HudBarType.Generic_Aircraft:
default:
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData = new HudBarDataGeneric();
2023-07-12 22:41:31 +00:00
break;
}
_simConnectProvider.SetHudBarConfig(hudBarType);
}
public void StopHudBar()
{
_simConnectProvider.StopHudBar();
}
private void HandleOnFlightStarted(object sender, EventArgs e)
{
2024-02-28 02:44:21 +00:00
OnFlightStarted?.Invoke(this, EventArgs.Empty);
FlightSimData.IsFlightStarted = true;
DynamicLodManager.Attach(FlightSimData, AppSettingData); // Attach in memory override for Dynamic LOD
2022-07-23 19:23:32 +00:00
}
private void HandleOnFlightStopped(object sender, EventArgs e)
{
2024-02-28 02:44:21 +00:00
ProfileData.ResetActiveProfile();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
OnFlightStopped?.Invoke(this, EventArgs.Empty);
2023-07-12 22:41:31 +00:00
WindowActionManager.CloseAllPopOuts();
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData?.Clear();
FlightSimData.IsFlightStarted = false;
DynamicLodManager.Detach(); // Detach in memory override for Dynamic LOD
2023-07-12 22:41:31 +00:00
}
private void DetectMsfsExit()
{
_msfsGameExitDetectionTimer = new System.Timers.Timer();
_msfsGameExitDetectionTimer.Interval = MSFS_GAME_EXIT_DETECTION_INTERVAL;
_msfsGameExitDetectionTimer.Enabled = true;
2024-02-28 02:44:21 +00:00
_msfsGameExitDetectionTimer.Elapsed += (_, _) =>
2023-07-12 22:41:31 +00:00
{
WindowProcessManager.GetSimulatorProcess();
2024-02-28 02:44:21 +00:00
if (WindowProcessManager.SimulatorProcess != null)
return;
if (AppSettingData.ApplicationSetting.GeneralSetting.AutoClose)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
OnSimulatorExited?.Invoke(this, EventArgs.Empty);
return;
2023-07-12 22:41:31 +00:00
}
2024-02-28 02:44:21 +00:00
FlightSimData.Reset();
_simConnectProvider.StopAndReconnect();
2023-07-12 22:41:31 +00:00
};
}
private void MapHudBarSimConnectData(List<SimDataItem> simData)
{
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.ElevatorTrim, FlightSimData.HudBarData.ElevatorTrim, out var newValue))
FlightSimData.HudBarData.ElevatorTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.AileronTrim, FlightSimData.HudBarData.AileronTrim, out newValue))
FlightSimData.HudBarData.AileronTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.RudderTrim, FlightSimData.HudBarData.RudderTrim, out newValue))
FlightSimData.HudBarData.RudderTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.ParkingBrake, FlightSimData.HudBarData.ParkingBrake, out newValue))
FlightSimData.HudBarData.ParkingBrake = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.Flap, FlightSimData.HudBarData.Flap, out newValue))
FlightSimData.HudBarData.Flap = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearLeft, FlightSimData.HudBarData.GearLeft, out newValue))
FlightSimData.HudBarData.GearLeft = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearCenter, FlightSimData.HudBarData.GearCenter, out newValue))
FlightSimData.HudBarData.GearCenter = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearRight, FlightSimData.HudBarData.GearRight, out newValue))
FlightSimData.HudBarData.GearRight = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.SimRate, FlightSimData.HudBarData.SimRate, out newValue))
FlightSimData.HudBarData.SimRate = newValue;
2023-07-12 22:41:31 +00:00
}
private bool CompareSimConnectData(List<SimDataItem> simData, string propName, double source, out double newValue)
{
var propData = simData.Find(d => d.PropertyName == propName);
if (propData == null)
{
newValue = 0;
return false;
}
var value = Convert.ToDouble(simData.Find(d => d.PropertyName == propName).Value);
2024-02-28 02:44:21 +00:00
if (Math.Abs(value - source) > 0.000000000000001)
2023-07-12 22:41:31 +00:00
{
newValue = value;
return true;
}
newValue = 0;
return false;
2022-07-23 19:23:32 +00:00
}
}
}