private void Controler_ButtonPressed(object sender, XINPUT_GAMEPAD_BUTTONS e) { switch (e) { case XINPUT_GAMEPAD_BUTTONS.DPAD_UP: Timeline.ResetGameFromSavePointByMenu(); break; case XINPUT_GAMEPAD_BUTTONS.DPAD_DOWN: Timeline.UpdateLocationFromMenu(); break; case XINPUT_GAMEPAD_BUTTONS.START: MCP.BankHold = false; MCP.HeadingHold = false; MCP.VSHold = false; MCP.AltitudeHold = false; MCP.IASHold = false; MCP.LNAV = false; break; case XINPUT_GAMEPAD_BUTTONS.BACK: if (MCP.BankHold || MCP.HeadingHold || MCP.VSHold || MCP.AltitudeHold || MCP.IASHold | MCP.LNAV) { MCP.BankHold = false; MCP.HeadingHold = false; MCP.VSHold = false; MCP.AltitudeHold = false; MCP.IASHold = false; MCP.LNAV = false; } else { MCP.AltitudeHold = true; MCP.LNAV = true; MCP.IASHold = true; } break; } Trace.WriteLine($"Button Pressed: {e}"); }
private void Update() { var didAdvanceWaypoint = _plan.UpdateLocation(); if (didAdvanceWaypoint && _plan.CurrentIndex == 3) { Trace.WriteLine("Gear up"); SystemManager.Instance.App.Controller.Press(Interop.XINPUT_GAMEPAD_BUTTONS.LEFT_THUMB, 10); } // One waypoint before top of G/P if (didAdvanceWaypoint && _plan.CurrentIndex == _plan.Points.Count - 3) { _mcp.ALT = 800; _mcp.IAS = 80; glidePathTopAlt = _mcp.ALT; } if (didAdvanceWaypoint && IsOnGlideToThreshold) { isAt75PercentGlide = false; isAt4PercentGlide = false; isAt3PercentGlide = false; isFlare = false; Timeline.UpdateLocationFromMenu(); } if (IsOnGlideToThreshold) { var percent_done = OnGlidePathPercent(); if (percent_done < .7 && !isAt75PercentGlide) { isAt75PercentGlide = true; Timeline.UpdateLocationFromMenu(); } if (percent_done < .5 && !isAt3PercentGlide) { isAt3PercentGlide = true; Trace.WriteLine("Gear down"); SystemManager.Instance.App.Controller.Press(Interop.XINPUT_GAMEPAD_BUTTONS.LEFT_THUMB, 10); } if (percent_done < .3 && !isAt4PercentGlide) { isAt4PercentGlide = true; Timeline.UpdateLocationFromMenu(); } _mcp.ALT = Math.Round(Math2.MapValue(0, 1, _plan.Destination.Elevation, glidePathTopAlt, percent_done)); } // Flare if (_plan.CurrentIndex == _plan.Points.Count - 1) { _mcp.ALT = _plan.Destination.Elevation; if (!isFlare && Timeline.AltitudeAvg < _plan.Destination.Elevation + 25) { Trace.WriteLine("Flare"); isFlare = true; _mcp.IAS = 0; _mcp.VSHold = true; _mcp.VS = 10; } } // Disconnect if (_mcp.IASHold && _plan.CurrentIndex == _plan.Points.Count - 1 && Timeline.Speed < 20) { if (_mcp.LNAV) { Timeline.ResetGameFromSavePointByMenu(); } _mcp.IASHold = false; _mcp.VSHold = false; _mcp.LNAV = false; } if (_mcp.LNAV) { var targetHdg = _plan.TargetHeading; if (_plan.CurrentIndex > 0) { var tightHoldLine = (Timeline.Altitude < 800) || (_plan.CurrentIndex >= _plan.Points.Count - 2); var heading_cap = 8; var mult = (tightHoldLine ? 1.5 : 0.5); if (Timeline.Altitude < 150) { mult = 2; } var distanceFromTargetLine = mult * DistanceFromTargetLine; distanceFromTargetLine = Math.Max(Math.Min(heading_cap, distanceFromTargetLine), -1 * heading_cap); targetHdg -= distanceFromTargetLine; } _mcp.HDG = targetHdg; } }