Ejemplo n.º 1
0
        private void CMB_joysticks_Click(object sender, EventArgs e)
        {
            CMB_joysticks.Items.Clear();

            var joysticklist = JoystickBase.getDevices();

            foreach (var device in joysticklist)
            {
                CMB_joysticks.Items.Add(device);
            }

            if (CMB_joysticks.Items.Count > 0 && CMB_joysticks.SelectedIndex == -1)
            {
                CMB_joysticks.SelectedIndex = 0;
            }
        }
Ejemplo n.º 2
0
        private void Joystick_Load(object sender, EventArgs e)
        {
            try
            {
                var joysticklist = JoystickBase.getDevices();

                foreach (var device in joysticklist)
                {
                    CMB_joysticks.Items.Add(device);
                }
            }
            catch
            {
                CustomMessageBox.Show("Error geting joystick list: do you have the directx redist installed?");
                this.Close();
                return;
            }

            if (CMB_joysticks.Items.Count > 0 && CMB_joysticks.SelectedIndex == -1)
            {
                CMB_joysticks.SelectedIndex = 0;
            }

            try
            {
                if (Settings.Instance.ContainsKey("joystick_name") && Settings.Instance["joystick_name"].ToString() != "")
                {
                    CMB_joysticks.Text = Settings.Instance["joystick_name"].ToString();
                }
            }
            catch
            {
            }

            try
            {
                if (Settings.Instance.ContainsKey("joy_elevons"))
                {
                    CHK_elevons.Checked = bool.Parse(Settings.Instance["joy_elevons"].ToString());
                }
            }
            catch
            {
            } // IF 1 DOESNT EXIST NONE WILL

            var tempjoystick = JoystickBase.Create(() => MainV2.comPort);

            label14.Text += " " + MainV2.comPort.MAV.cs.firmware.ToString();

            var y = label8.Bottom;

            this.SuspendLayout();

            for (int a = 1; a <= maxaxis; a++)
            {
                var config = tempjoystick.getChannel(a);

                var ax = new JoystickAxis()
                {
                    ChannelNo    = a,
                    Label        = "Ch " + a,
                    AxisArray    = (Enum.GetValues(typeof(joystickaxis))),
                    ChannelValue = config.axis.ToString(),
                    ExpoValue    = config.expo.ToString(),
                    ReverseValue = config.reverse,
                    Location     = new Point(0, y),
                    Name         = "axis" + a
                };

                ax.Detect  = () => JoystickBase.getMovingAxis(CMB_joysticks.Text, 16000).ToString();
                ax.Reverse = () => MainV2.joystick?.setReverse(ax.ChannelNo, ax.ReverseValue);
                ax.SetAxis = () => MainV2.joystick?.setAxis(ax.ChannelNo,
                                                            (joystickaxis)Enum.Parse(typeof(joystickaxis), ax.ChannelValue));
                ax.GetValue = () =>
                {
                    return((short)MainV2.comPort.MAV.cs.GetType().GetField("rcoverridech" + ax.ChannelNo)
                           .GetValue(MainV2.comPort.MAV.cs));
                };

                Controls.Add(ax);

                y += ax.Height;


                if ((ax.Bottom + 30) > this.Height)
                {
                    this.Height = ax.Bottom;
                }

                if ((ax.Right) > this.Width)
                {
                    this.Width = ax.Right;
                }
            }

            this.ResumeLayout();

            if (MainV2.joystick != null && MainV2.joystick.enabled)
            {
                timer1.Start();
                BUT_enable.Text = "Disable";
            }

            startup = false;
        }