public FlightManagementHandler(SmartPilot2020 main)
        {
            this.main = main;
            this.LoadNavigationDatabaseFromFile();

            main.MonitoringHandler.AddMessageTimed("NavigationDatabase has been loaded: " + NavigationPoints.Count + " entries", Color.LimeGreen, 4000);

            this.CurrentPage = FMCPage.INITIALIZATION;
        }
        public RemoteDataInterface(SmartPilot2020 main)
        {
            this.main = main;

            main.SetPacketOutputState(PacketOutputState);

            this.SerialPort = new SerialPort("COM13", 115200);
            this.SerialPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort_DataReceived);
        }
        public JoystickHandler(SmartPilot2020 main)
        {
            this.main = main;

            DirectInput directInput  = new DirectInput();
            Guid        joystickGuid = Guid.Empty;

            foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            Joystick joystick = new Joystick(directInput, joystickGuid);

            main.SetJoystickInfo(joystick.Information.ProductName);

            joystick.Properties.BufferSize = 128;
            joystick.Acquire();

            while (true)
            {
                joystick.Poll();
                JoystickUpdate[] datas = joystick.GetBufferedData();
                foreach (JoystickUpdate state in datas)
                {
                    switch (state.Offset)
                    {
                    case JoystickOffset.X:     // Roll input
                        main.FlightHandler.ProcessRoll(state.Value);
                        break;

                    case JoystickOffset.Y:     // Pitch input
                        main.FlightHandler.ProcessPitch(state.Value);
                        break;

                    case JoystickOffset.Sliders0:     // Thrust input
                        main.FlightHandler.ProcessThrust(Util.MapValue(state.Value, 65534, 0, 0, 65534));
                        break;

                    case JoystickOffset.RotationZ:     // Yaw input
                        main.FlightHandler.ProcessYaw(state.Value);
                        break;

                    case JoystickOffset.PointOfViewControllers0:     // Top knob/joystick input
                        main.FlightHandler.ProccessTrim(state.Value);
                        break;

                    case JoystickOffset.Buttons0:
                        if (main.FlightHandler.AutoPilotActive)
                        {
                            main.FlightHandler.AutoPilotActive = false;
                        }
                        break;
                    }
                }
            }
        }
Beispiel #4
0
        public FlightHandler(SmartPilot2020 main)
        {
            this.main           = main;
            this.CurrentGpsData = new GeoCoordinate();

            // Setup main system timer
            ProcessTimer          = new Timer();
            ProcessTimer.Tick    += new System.EventHandler(ProcessTimer_Tick);
            ProcessTimer.Interval = main.SystemTickInterval;
            ProcessTimer.Start();

            // Setup remote data interface (Serial port)
            this.RemoteDataInterface = new RemoteDataInterface(main);
            this.RemoteDataInterface.Connect();

            ControlsActiveCheckedGuid = main.MonitoringHandler.AddMessagePersistent("F/C UNCHECKED", System.Drawing.Color.Red);
        }
        // Method to draw the selection display above the AutoPilot buttons
        public static void DrawSelectorDispaly(Graphics g, SmartPilot2020 main)
        {
            g.DrawString("SPD", new Font("Arial", 6), Brushes.Orange, 10, 5);
            g.DrawString(main.FlightHandler.TargetSpeed.ToString(), new Font("DS-Digital", 24), Brushes.Orange, 5, 15);

            g.DrawString("HDG", new Font("Arial", 6), Brushes.Orange, 120, 5);
            if (main.FlightHandler.TargetHeading < 100 && main.FlightHandler.TargetHeading != 0)
            {
                g.DrawString("0" + main.FlightHandler.TargetHeading, new Font("DS-Digital", 24), Brushes.Orange, 115, 15);
            }
            else if (main.FlightHandler.TargetHeading == 0)
            {
                g.DrawString("000", new Font("DS-Digital", 24), Brushes.Orange, 115, 15);
            }
            else
            {
                g.DrawString(main.FlightHandler.TargetHeading.ToString(), new Font("DS-Digital", 24), Brushes.Orange, 115, 15);
            }

            g.DrawString("ALT", new Font("Arial", 6), Brushes.Orange, 220, 5);
            g.DrawString(main.FlightHandler.TargetAltitude.ToString(), new Font("DS-Digital", 24), Brushes.Orange, 220, 15);
        }
        // Method to draw the heading band below the PFD
        public static void DrawHeading(Graphics g, SmartPilot2020 main)
        {
            if (!main.FlightHandler.ControlsActiveChecked)
            {
                g.DrawString("X", new Font("Arial", 20, FontStyle.Bold), Brushes.Red, 135, 15);
                return;
            }

            g.DrawLine(new Pen(Brushes.White, 2), 0, 20, 300, 20);
            g.DrawLine(new Pen(Brushes.Gold, 5), 150, 0, 150, 20);

            g.DrawLine(new Pen(Brushes.White, 2), 50, 20, 50, 30);
            g.DrawLine(new Pen(Brushes.White, 2), 100, 20, 100, 30);
            g.DrawLine(new Pen(Brushes.White, 2), 150, 20, 150, 40);
            g.DrawLine(new Pen(Brushes.White, 2), 200, 20, 200, 30);
            g.DrawLine(new Pen(Brushes.White, 2), 250, 20, 250, 30);

            int currentHeading = main.FlightHandler.CurrentHeading;

            int width = 0;

            if (main.FlightHandler.CurrentHeading < 10)
            {
                width = 145;
            }
            else if (currentHeading >= 10 && currentHeading < 100)
            {
                width = 140;
            }
            else
            {
                width = 137;
            }

            g.DrawString(currentHeading.ToString(), Util.AirbusFont10(), Brushes.White, width, 42);
        }
 public NavigationHandler(SmartPilot2020 main)
 {
     this.main = main;
     main.MonitoringHandler.AddMessageTimed("NavigationHandler has been loaded.", Color.LimeGreen, 4000);
 }
        /////////////////////////
        // Graphical functions //
        /////////////////////////

        public void DrawFMC(Graphics g, SmartPilot2020 main)
        {
            // Base lines
            g.DrawLine(new Pen(Brushes.Black, 4), 0, 0, 240, 0);
            g.DrawLine(new Pen(Brushes.Black, 4), 0, 0, 0, 380);
            g.DrawLine(new Pen(Brushes.Black, 4), 239, 0, 239, 380);
            g.DrawLine(new Pen(Brushes.Black, 4), 0, 379, 239, 379);

            // Monitor
            g.FillRectangle(Brushes.Black, new Rectangle(20, 20, 200, 280));

            // Button controls
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(20, 310, 40, 20));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(70, 310, 40, 20));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(120, 310, 40, 20));
            g.FillRectangle(Brushes.Green, new Rectangle(170, 310, 50, 20));
            g.DrawString("INIT", Util.MCUD10(), Brushes.White, 22, 314);
            g.DrawString("FMAN", Util.MCUD10(), Brushes.White, 72, 314);
            g.DrawString("CLR", Util.MCUD10(), Brushes.White, 126, 314);
            g.DrawString("EXC", Util.MCUD10(), Brushes.White, 181, 314);

            // Input buttons
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 90, 18, 15));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 110, 18, 15));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 130, 18, 15));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 150, 18, 15));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 170, 18, 15));
            g.FillRectangle(Brushes.CadetBlue, new Rectangle(220, 190, 18, 15));
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 91);
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 111);
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 131);
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 151);
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 171);
            g.DrawString("-", Util.MCUD10(), Brushes.White, 223, 191);

            switch (this.CurrentPage)
            {
            case FMCPage.INITIALIZATION:
                g.DrawString("INITIALIZATION", Util.MCUD10(), Brushes.LimeGreen, 60, 30);

                g.DrawString("PROTECTION", Util.MCUD10(), Brushes.LimeGreen, 35, 60);

                g.DrawString("PITCH UP", Util.MCUD10(), Brushes.White, 45, 90);
                g.DrawString(main.FlightHandler.ProtectedPitchUpAngle + "°", Util.MCUD10(), Brushes.Cyan, 160, 90);

                g.DrawString("PITCH DOWN", Util.MCUD10(), Brushes.White, 45, 110);
                g.DrawString(main.FlightHandler.ProtectedPitchDownAngle + "°", Util.MCUD10(), Brushes.Cyan, 160, 110);

                g.DrawString("ROLL", Util.MCUD10(), Brushes.White, 45, 130);
                g.DrawString(main.FlightHandler.ProtectedRollAngle + "°", Util.MCUD10(), Brushes.Cyan, 160, 130);

                g.DrawString("ALTITUDE", Util.MCUD10(), Brushes.White, 45, 150);
                g.DrawString(main.FlightHandler.ProtectedAltitude + "m", Util.MCUD10(), Brushes.Cyan, 160, 150);

                g.DrawString("OVERSPEED", Util.MCUD10(), Brushes.White, 45, 170);
                g.DrawString(main.FlightHandler.ProtectedOverSpeed + "m/s", Util.MCUD10(), Brushes.Cyan, 160, 170);

                g.DrawString("STALLSPEED", Util.MCUD10(), Brushes.White, 45, 190);
                g.DrawString(main.FlightHandler.ProtectedStallSpeed + "m/s", Util.MCUD10(), Brushes.Cyan, 160, 190);

                break;

            case FMCPage.FLIGHTMANEUVER:
                g.DrawString("FLIGHT MANEUVER", Util.MCUD10(), Brushes.LimeGreen, 55, 30);

                g.DrawString("HOLDING R", Util.MCUD10(), Brushes.LimeGreen, 35, 90);
                g.DrawString("HOLDING L", Util.MCUD10(), Brushes.LimeGreen, 35, 110);

                break;
            }
        }
        public void HandleFMCClick(SmartPilot2020 main, TextBox inputBox, int posX, int posY)
        {
            // INITIALIZATION button pressed
            if (Util.IsWithin(posX, 20, 60) && Util.IsWithin(posY, 310, 330))
            {
                this.CurrentPage = FMCPage.INITIALIZATION;
            }

            // FLIGHTMANEUVER button pressed
            if (Util.IsWithin(posX, 70, 110) && Util.IsWithin(posY, 310, 330))
            {
                this.CurrentPage = FMCPage.FLIGHTMANEUVER;
            }

            // CLEAR button pressed
            if (Util.IsWithin(posX, 120, 160) && Util.IsWithin(posY, 310, 330))
            {
                inputBox.Clear();
            }

            // EXC button pressed
            if (Util.IsWithin(posX, 170, 220) && Util.IsWithin(posY, 310, 330))
            {
                switch (inputBox.Text)
                {
                case "[?] JOIN RIGHT HOLDING":

                    if (!main.FlightHandler.AutoPilotActive)
                    {
                        inputBox.Text = "A/P IS NOT ENGAGED";
                        return;
                    }

                    main.Log("[!] JOINING RIGHT HOLDING");
                    break;

                case "[?] JOIN LEFT HOLDING":

                    if (!main.FlightHandler.AutoPilotActive)
                    {
                        inputBox.Text = "A/P IS NOT ENGAGED";
                        return;
                    }

                    main.Log("[!] JOINING LEFT HOLDING");
                    break;
                }
            }

            // R1 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 90, 105))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedPitchUpAngle = Int32.Parse(inputBox.Text);
                }

                if (this.CurrentPage == FMCPage.FLIGHTMANEUVER)
                {
                    if (!main.FlightHandler.AutoPilotActive)
                    {
                        inputBox.Text = "A/P IS NOT ENGAGED";
                        return;
                    }

                    inputBox.Text = "[?] JOIN RIGHT HOLDING";
                }
            }

            // R2 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 110, 125))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedPitchDownAngle = Int32.Parse(inputBox.Text);
                }

                if (this.CurrentPage == FMCPage.FLIGHTMANEUVER)
                {
                    if (!main.FlightHandler.AutoPilotActive)
                    {
                        inputBox.Text = "A/P IS NOT ENGAGED";
                        return;
                    }

                    inputBox.Text = "[?] JOIN LEFT HOLDING";
                }
            }

            // R3 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 130, 145))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedRollAngle = Int32.Parse(inputBox.Text);
                }
            }

            // R4 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 150, 165))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedAltitude = Int32.Parse(inputBox.Text);
                }
            }

            // R5 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 170, 185))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedOverSpeed = Int32.Parse(inputBox.Text);
                }
            }

            // R6 button
            if (Util.IsWithin(posX, 220, 240) && Util.IsWithin(posY, 190, 205))
            {
                if (this.CurrentPage == FMCPage.INITIALIZATION)
                {
                    main.FlightHandler.ProtectedStallSpeed = Int32.Parse(inputBox.Text);
                }
            }
        }
 public MonitoringHandler(SmartPilot2020 main)
 {
     this.main     = main;
     this.messages = new List <Message>();
 }
        // Method to draw the speed display band on the left side of the PFD
        public static void DrawSpeed(Graphics g, SmartPilot2020 main)
        {
            g.DrawLine(new Pen(Brushes.White, 2), 40, 0, 40, 300);

            if (!main.FlightHandler.ControlsActiveChecked)
            {
                g.DrawString("X", new Font("Arial", 20, FontStyle.Bold), Brushes.Red, 10, 135);
                return;
            }

            g.FillRectangle(Brushes.Gold, new Rectangle(0, 147, 6, 6));
            g.DrawLine(new Pen(Brushes.Gold, 2), 0, 150, 60, 150);
            g.DrawLine(new Pen(Brushes.Gold, 6), 40, 150, 60, 150);

            int CurrentSpeed = main.FlightHandler.CurrentSpeed;

            if (CurrentSpeed == 0)
            {
                g.DrawLine(new Pen(Brushes.White, 2), 30, 30, 40, 30);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 60, 40, 60);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 90, 40, 90);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 120, 40, 120);

                g.DrawString("4", Util.AirbusFont10(), Brushes.White, 7, 22);
                g.DrawString("3", Util.AirbusFont10(), Brushes.White, 7, 52);
                g.DrawString("2", Util.AirbusFont10(), Brushes.White, 7, 82);
                g.DrawString("1", Util.AirbusFont10(), Brushes.White, 7, 112);
            }
            else
            {
                g.DrawLine(new Pen(Brushes.White, 2), 30, 30, 40, 30);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 60, 40, 60);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 90, 40, 90);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 120, 40, 120);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 150, 40, 150); // mid
                g.DrawLine(new Pen(Brushes.White, 2), 30, 180, 40, 180);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 210, 40, 210);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 240, 40, 240);
                g.DrawLine(new Pen(Brushes.White, 2), 30, 270, 40, 270);

                g.DrawString((CurrentSpeed + 1).ToString(), Util.AirbusFont10(), Brushes.White, 7, 112);
                g.DrawString((CurrentSpeed + 2).ToString(), Util.AirbusFont10(), Brushes.White, 7, 82);
                g.DrawString((CurrentSpeed + 3).ToString(), Util.AirbusFont10(), Brushes.White, 7, 52);
                g.DrawString((CurrentSpeed + 4).ToString(), Util.AirbusFont10(), Brushes.White, 7, 22);
                g.DrawString(CurrentSpeed.ToString(), Util.AirbusFont10(), Brushes.White, 7, 142);
                g.DrawString((CurrentSpeed - 1) > 0 ? (CurrentSpeed - 1).ToString() : "", Util.AirbusFont10(), Brushes.White, 7, 172);
                g.DrawString((CurrentSpeed - 2) > 0 ? (CurrentSpeed - 2).ToString() : "", Util.AirbusFont10(), Brushes.White, 7, 202);
                g.DrawString((CurrentSpeed - 3) > 0 ? (CurrentSpeed - 3).ToString() : "", Util.AirbusFont10(), Brushes.White, 7, 232);
                g.DrawString((CurrentSpeed - 4) > 0 ? (CurrentSpeed - 4).ToString() : "", Util.AirbusFont10(), Brushes.White, 7, 262);
            }

            if (main.FlightHandler.AutoThrustActive)
            {
                if ((CurrentSpeed + 4) >= main.FlightHandler.TargetSpeed && (CurrentSpeed - 4) <= main.FlightHandler.TargetSpeed)
                {
                    if (CurrentSpeed == main.FlightHandler.TargetSpeed)
                    {
                        g.DrawLine(new Pen(Brushes.Cyan, 2), 40, 150, 55, 135);
                        g.DrawLine(new Pen(Brushes.Cyan, 2), 55, 135, 55, 165);
                        g.DrawLine(new Pen(Brushes.Cyan, 2), 55, 165, 40, 150);
                        return;
                    }

                    int dif = main.FlightHandler.TargetSpeed - CurrentSpeed;

                    g.DrawLine(new Pen(Brushes.Cyan, 2), 40, 150 - (dif * 30), 55, 135 - (dif * 30));
                    g.DrawLine(new Pen(Brushes.Cyan, 2), 55, 135 - (dif * 30), 55, 165 - (dif * 30));
                    g.DrawLine(new Pen(Brushes.Cyan, 2), 55, 165 - (dif * 30), 40, 150 - (dif * 30));
                }
            }
        }
        // Method to draw the monitor band above the PFD
        public static void DrawMonitor(Graphics g, SmartPilot2020 main)
        {
            if (!main.FlightHandler.ControlsActiveChecked)
            {
                g.DrawString("Flightcontrols unchecked", new Font("Arial", 12, FontStyle.Bold), Brushes.Red, 110, 20);
                return;
            }

            g.DrawLine(new Pen(Brushes.White, 1), 62.5F, 5, 62.5F, 55);

            ///////////////////////////////
            // Thrust mode visualization //
            ///////////////////////////////

            if (main.FlightHandler.AutoThrustActive)
            {
                g.DrawString("A/THR", new Font("Arial", 12, FontStyle.Bold), Brushes.LimeGreen, 3, 20);
                g.DrawRectangle(Pens.White, new Rectangle(3, 19, 55, 19));
            }
            else
            {
                if (main.FlightHandler.ThrustValue == main.FlightHandler.ThrustPulse[0])
                {
                    g.DrawString("IDLE", new Font("Arial", 12, FontStyle.Bold), Brushes.White, 9, 20);
                    g.DrawRectangle(Pens.White, new Rectangle(8, 19, 45, 19));
                }
                else if (main.FlightHandler.ThrustValue == main.FlightHandler.ThrustPulse[1])
                {
                    g.DrawString("PWR", new Font("Arial", 12, FontStyle.Bold), Brushes.LimeGreen, 10, 20);
                    g.DrawRectangle(Pens.White, new Rectangle(10, 19, 43, 19));
                }
                else
                {
                    g.DrawString("M/THR", new Font("Arial", 12, FontStyle.Bold), Brushes.Orange, 3, 20);
                }
            }

            /////////////////////////////////
            /// Mode-Values visualization ///
            /////////////////////////////////

            if (main.FlightHandler.AutoThrustActive)
            {
                g.DrawString("SPD", new Font("Arial", 8, FontStyle.Bold), Brushes.Orange, 80, 12);
                g.DrawString(main.FlightHandler.TargetSpeed + "m/s", new Font("Arial", 12, FontStyle.Bold), Brushes.Cyan, 75, 25);
            }

            if (main.FlightHandler.AutoPilotActive)
            {
                g.DrawString("HDG", new Font("Arial", 8, FontStyle.Bold), Brushes.Orange, 145, 12);
                g.DrawString(main.FlightHandler.TargetHeading + "°", new Font("Arial", 12, FontStyle.Bold), Brushes.Cyan, 140, 25);

                g.DrawString("ALT", new Font("Arial", 8, FontStyle.Bold), Brushes.Orange, 200, 12);
                g.DrawString(main.FlightHandler.TargetAltitude + "m", new Font("Arial", 12, FontStyle.Bold), Brushes.Cyan, 195, 25);
            }

            g.DrawLine(new Pen(Brushes.White, 1), 250, 5, 250, 55);

            //////////////////////////
            /// Mode visualization ///
            //////////////////////////

            g.DrawLine(new Pen(Brushes.White, 1), 370, 5, 370, 55);

            if (main.FlightHandler.AutoPilotActive)
            {
                g.DrawString("AP", new Font("Arial", 10, FontStyle.Bold), Brushes.LimeGreen, 392, 5);
            }
            else
            {
                g.DrawString("AP", new Font("Arial", 10, FontStyle.Bold), Brushes.Red, 392, 5);
            }

            if (main.FlightHandler.ProtectionActive)
            {
                g.DrawString("FE", new Font("Arial", 10, FontStyle.Bold), Brushes.LimeGreen, 392, 23);
            }
            else
            {
                g.DrawString("FE", new Font("Arial", 10, FontStyle.Bold), Brushes.Red, 392, 23);
            }

            if (main.FlightHandler.AutoThrustActive)
            {
                g.DrawString("A/THR", new Font("Arial", 10, FontStyle.Bold), Brushes.LimeGreen, 380, 40);
            }
            else
            {
                g.DrawString("A/THR", new Font("Arial", 10, FontStyle.Bold), Brushes.Red, 380, 40);
            }
        }