diff --git a/GCSViews/ConfigurationView/ConfigPlanner.Designer.cs b/GCSViews/ConfigurationView/ConfigPlanner.Designer.cs index d168c8790b..f353891d10 100644 --- a/GCSViews/ConfigurationView/ConfigPlanner.Designer.cs +++ b/GCSViews/ConfigurationView/ConfigPlanner.Designer.cs @@ -123,6 +123,7 @@ private void InitializeComponent() this.label13 = new System.Windows.Forms.Label(); this.BUT_mapCacheDir = new MissionPlanner.Controls.MyButton(); this.CHK_rtsresetesp32 = new System.Windows.Forms.CheckBox(); + this.CHK_joystickautoenable = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.NUM_tracklength)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.num_gcsid)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.num_linelength)).BeginInit(); @@ -891,9 +892,17 @@ private void InitializeComponent() this.CHK_rtsresetesp32.UseVisualStyleBackColor = true; this.CHK_rtsresetesp32.CheckedChanged += new System.EventHandler(this.CHK_rtsresetesp32_CheckedChanged); // + // CHK_joystickautoenable + // + resources.ApplyResources(this.CHK_joystickautoenable, "CHK_joystickautoenable"); + this.CHK_joystickautoenable.Name = "CHK_joystickautoenable"; + this.CHK_joystickautoenable.UseVisualStyleBackColor = true; + this.CHK_joystickautoenable.CheckedChanged += new System.EventHandler(this.CHK_joystickautoenable_CheckedChanged); + // // ConfigPlanner // resources.ApplyResources(this, "$this"); + this.Controls.Add(this.CHK_joystickautoenable); this.Controls.Add(this.CHK_rtsresetesp32); this.Controls.Add(this.label10); this.Controls.Add(this.cmb_secondarydisplaystyle); @@ -1094,5 +1103,6 @@ private void InitializeComponent() public System.Windows.Forms.ComboBox CMB_mapCache; private Controls.MyButton BUT_mapCacheDir; private System.Windows.Forms.CheckBox CHK_rtsresetesp32; + private System.Windows.Forms.CheckBox CHK_joystickautoenable; } } diff --git a/GCSViews/ConfigurationView/ConfigPlanner.cs b/GCSViews/ConfigurationView/ConfigPlanner.cs index 4770d7bef9..6ca7c20a04 100644 --- a/GCSViews/ConfigurationView/ConfigPlanner.cs +++ b/GCSViews/ConfigurationView/ConfigPlanner.cs @@ -174,6 +174,7 @@ public void Activate() // setup other config state SetCheckboxFromConfig("CHK_resetapmonconnect", CHK_resetapmonconnect); SetCheckboxFromConfig("CHK_rtsresetesp32", CHK_rtsresetesp32); + SetCheckboxFromConfig("CHK_Joystick_AutoEnable", CHK_joystickautoenable); CMB_rateattitude.Text = MainV2.comPort.MAV.cs.rateattitude.ToString(); CMB_rateposition.Text = MainV2.comPort.MAV.cs.rateposition.ToString(); @@ -1190,5 +1191,10 @@ private void BUT_mapCacheDir_Click(object sender, EventArgs e) { } } + + private void CHK_joystickautoenable_CheckedChanged(object sender, EventArgs e) + { + Settings.Instance["CHK_Joystick_AutoEnable"] = CHK_joystickautoenable.Checked.ToString(); + } } } \ No newline at end of file diff --git a/GCSViews/ConfigurationView/ConfigPlanner.resx b/GCSViews/ConfigurationView/ConfigPlanner.resx index 86448cb9e4..ce8165f040 100644 --- a/GCSViews/ConfigurationView/ConfigPlanner.resx +++ b/GCSViews/ConfigurationView/ConfigPlanner.resx @@ -145,7 +145,7 @@ $this - 43 + 44 -1 @@ -211,7 +211,7 @@ $this - 44 + 45 True @@ -241,7 +241,7 @@ $this - 45 + 46 107, 35 @@ -262,7 +262,7 @@ $this - 46 + 47 True @@ -292,7 +292,7 @@ $this - 48 + 49 NoControl @@ -319,7 +319,7 @@ $this - 49 + 50 True @@ -349,7 +349,7 @@ $this - 50 + 51 NoControl @@ -376,7 +376,7 @@ $this - 51 + 52 True @@ -406,7 +406,7 @@ $this - 52 + 53 107, 300 @@ -427,7 +427,7 @@ $this - 54 + 55 True @@ -460,7 +460,7 @@ $this - 55 + 56 True @@ -490,7 +490,7 @@ $this - 56 + 57 NoControl @@ -517,7 +517,7 @@ $this - 57 + 58 Bottom, Left @@ -547,7 +547,7 @@ $this - 58 + 59 NoControl @@ -574,7 +574,7 @@ $this - 59 + 60 -1 @@ -640,7 +640,7 @@ $this - 60 + 61 NoControl @@ -667,7 +667,7 @@ $this - 61 + 62 NoControl @@ -694,7 +694,7 @@ $this - 62 + 63 NoControl @@ -721,7 +721,7 @@ $this - 63 + 64 True @@ -751,7 +751,7 @@ $this - 64 + 65 -1 @@ -817,7 +817,7 @@ $this - 65 + 66 -1 @@ -883,7 +883,7 @@ $this - 66 + 67 -1 @@ -946,7 +946,7 @@ $this - 67 + 68 NoControl @@ -974,7 +974,7 @@ $this - 68 + 69 True @@ -1004,7 +1004,7 @@ $this - 69 + 70 True @@ -1034,7 +1034,7 @@ $this - 70 + 71 107, 222 @@ -1055,7 +1055,7 @@ $this - 71 + 72 107, 195 @@ -1076,7 +1076,7 @@ $this - 72 + 73 True @@ -1106,7 +1106,7 @@ $this - 73 + 74 True @@ -1136,7 +1136,7 @@ $this - 74 + 75 True @@ -1169,7 +1169,7 @@ $this - 75 + 76 True @@ -1202,7 +1202,7 @@ $this - 76 + 77 True @@ -1235,7 +1235,7 @@ $this - 77 + 78 True @@ -1268,7 +1268,7 @@ $this - 78 + 79 True @@ -1298,7 +1298,7 @@ $this - 79 + 80 107, 62 @@ -1319,7 +1319,7 @@ $this - 80 + 81 107, 111 @@ -1340,7 +1340,7 @@ $this - 81 + 82 107, 139 @@ -1361,7 +1361,7 @@ $this - 82 + 83 True @@ -1391,7 +1391,7 @@ $this - 83 + 84 True @@ -1421,7 +1421,7 @@ $this - 84 + 85 NoControl @@ -1448,7 +1448,7 @@ $this - 85 + 86 True @@ -1478,7 +1478,7 @@ $this - 86 + 87 107, 8 @@ -1499,7 +1499,7 @@ $this - 87 + 88 True @@ -1529,7 +1529,7 @@ $this - 41 + 42 NoControl @@ -1556,7 +1556,7 @@ $this - 42 + 43 NoControl @@ -1583,7 +1583,7 @@ $this - 39 + 40 NoControl @@ -1610,7 +1610,7 @@ $this - 40 + 41 NoControl @@ -1637,7 +1637,7 @@ $this - 88 + 89 NoControl @@ -1664,7 +1664,7 @@ $this - 89 + 90 NoControl @@ -1691,7 +1691,7 @@ $this - 90 + 91 True @@ -1721,7 +1721,7 @@ $this - 38 + 39 107, 395 @@ -1742,7 +1742,7 @@ $this - 37 + 38 NoControl @@ -1769,7 +1769,7 @@ $this - 36 + 37 True @@ -1799,7 +1799,7 @@ $this - 35 + 36 107, 421 @@ -1820,7 +1820,7 @@ $this - 34 + 35 NoControl @@ -1847,7 +1847,7 @@ $this - 33 + 34 True @@ -1880,7 +1880,7 @@ $this - 32 + 33 NoControl @@ -1907,7 +1907,7 @@ $this - 31 + 32 True @@ -1937,7 +1937,7 @@ $this - 30 + 31 True @@ -1967,7 +1967,7 @@ $this - 29 + 30 True @@ -1997,7 +1997,7 @@ $this - 28 + 29 True @@ -2030,7 +2030,7 @@ $this - 21 + 22 True @@ -2060,7 +2060,7 @@ $this - 20 + 21 True @@ -2090,7 +2090,7 @@ $this - 19 + 20 True @@ -2120,7 +2120,7 @@ $this - 18 + 19 Bottom, Left @@ -2150,7 +2150,7 @@ $this - 17 + 18 True @@ -2180,7 +2180,7 @@ $this - 16 + 17 107, 448 @@ -2201,7 +2201,7 @@ $this - 15 + 16 True @@ -2231,7 +2231,7 @@ $this - 14 + 15 True @@ -2258,7 +2258,7 @@ $this - 13 + 14 True @@ -2288,7 +2288,7 @@ $this - 12 + 13 True @@ -2318,7 +2318,7 @@ $this - 10 + 11 320, 195 @@ -2339,7 +2339,7 @@ $this - 11 + 12 107, 475 @@ -2360,7 +2360,7 @@ $this - 9 + 10 True @@ -2390,7 +2390,7 @@ $this - 8 + 9 True @@ -2420,7 +2420,7 @@ $this - 7 + 8 True @@ -2450,7 +2450,7 @@ $this - 6 + 7 True @@ -2483,7 +2483,7 @@ $this - 5 + 6 NoControl @@ -2510,7 +2510,7 @@ $this - 4 + 5 True @@ -2540,7 +2540,7 @@ $this - 3 + 4 107, 524 @@ -2561,7 +2561,7 @@ $this - 2 + 3 True @@ -2591,7 +2591,7 @@ $this - 27 + 28 True @@ -2621,7 +2621,7 @@ $this - 1 + 2 True @@ -2651,7 +2651,7 @@ $this - 25 + 26 True @@ -2681,7 +2681,7 @@ $this - 24 + 25 True @@ -2711,7 +2711,7 @@ $this - 23 + 24 True @@ -2741,7 +2741,7 @@ $this - 22 + 23 768, 500 @@ -2762,7 +2762,7 @@ $this - 53 + 54 True @@ -2792,7 +2792,7 @@ $this - 47 + 48 True @@ -2822,7 +2822,7 @@ $this - 26 + 27 107, 653 @@ -2843,7 +2843,7 @@ $this - 92 + 93 True @@ -2873,7 +2873,7 @@ $this - 91 + 92 NoControl @@ -2900,7 +2900,7 @@ $this - 93 + 94 NoControl @@ -2927,6 +2927,36 @@ $this + 1 + + + True + + + NoControl + + + 212, 170 + + + 130, 17 + + + 132 + + + Auto Enable Joysticks + + + CHK_joystickautoenable + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Joystick/JoystickSetup.cs b/Joystick/JoystickSetup.cs index 4baff5bf98..971987669b 100644 --- a/Joystick/JoystickSetup.cs +++ b/Joystick/JoystickSetup.cs @@ -8,7 +8,7 @@ namespace MissionPlanner.Joystick -{ +{ public partial class JoystickSetup : MyUserControl, IDeactivate { bool startup = true; @@ -94,17 +94,17 @@ private void Joystick_Load(object sender, EventArgs e) { return (short)MainV2.comPort.MAV.cs.GetType().GetField("rcoverridech" + ax.ChannelNo) .GetValue(MainV2.comPort.MAV.cs); - }; - ax.Expo = () => - { - if (int.TryParse(ax.ExpoValue, out int expoValue)) - { - MainV2.joystick?.setExpo(ax.ChannelNo, expoValue); - } - }; - - Controls.Add(ax); - + }; + ax.Expo = () => + { + if (int.TryParse(ax.ExpoValue, out int expoValue)) + { + MainV2.joystick?.setExpo(ax.ChannelNo, expoValue); + } + }; + + Controls.Add(ax); + y += ax.Height; @@ -115,6 +115,8 @@ private void Joystick_Load(object sender, EventArgs e) this.Width = ax.Right; } + BUT_enable.Enabled = !Settings.Instance.GetBoolean("CHK_Joystick_AutoEnable"); + this.ResumeLayout(); if (MainV2.joystick != null && MainV2.joystick.enabled) @@ -178,8 +180,6 @@ private void BUT_enable_Click(object sender, EventArgs e) MainV2.joystick.clearRCOverride(); - MainV2.joystick = null; - //timer1.Stop(); @@ -299,8 +299,8 @@ private void timer1_Tick(object sender, EventArgs e) var items = this.Controls.Find("hbar" + name, false); - if (items.Length > 0) - ((HorizontalProgressBar)items[0]).Value = + if (items.Length > 0) + ((HorizontalProgressBar)items[0]).Value = MainV2.joystick.isButtonPressed(f) ? 100 : 0; } } @@ -372,20 +372,20 @@ void doButtontoUI(string name, int x, int y) butnumberlist.Location = new Point(butlabel.Right, y); butnumberlist.Size = new Size(70, 21); //butnumberlist.DataSource = getButtonNumbers(); - - butnumberlist.Items.AddRange(getButtonNumbers().Select(item => item.ToString()).ToArray()); - butnumberlist.SelectedIndex = 0; - - + + butnumberlist.Items.AddRange(getButtonNumbers().Select(item => item.ToString()).ToArray()); + butnumberlist.SelectedIndex = 0; + + butnumberlist.DropDownStyle = ComboBoxStyle.DropDownList; - butnumberlist.Name = "cmbbutton" + name; - - //butnumberlist.SelectedItem = "-1"; + butnumberlist.Name = "cmbbutton" + name; + + //butnumberlist.SelectedItem = "-1"; butnumberlist.SelectedItem = config.buttonno.ToString(); - //if (Settings.Instance["butno" + name] != null) + //if (Settings.Instance["butno" + name] != null) // butnumberlist.Text = (Settings.Instance["butno" + name].ToString()); - //if (config.buttonno != -1) + //if (config.buttonno != -1) //butnumberlist.Text = config.buttonno.ToString(); @@ -406,13 +406,13 @@ void doButtontoUI(string name, int x, int y) cmbaction.Location = new Point(hbar.Right + 5, y); cmbaction.Size = new Size(100, 21); - //cmbaction.DataSource = Enum.GetNames(typeof(buttonfunction)); - cmbaction.Items.AddRange(Enum.GetNames(typeof(buttonfunction))); - - - //Common.getModesList(MainV2.comPort.MAV.cs); - //cmbaction.ValueMember = "Key"; - //cmbaction.DisplayMember = "Value"; + //cmbaction.DataSource = Enum.GetNames(typeof(buttonfunction)); + cmbaction.Items.AddRange(Enum.GetNames(typeof(buttonfunction))); + + + //Common.getModesList(MainV2.comPort.MAV.cs); + //cmbaction.ValueMember = "Key"; + //cmbaction.DisplayMember = "Value"; cmbaction.Tag = name; cmbaction.DropDownStyle = ComboBoxStyle.DropDownList; cmbaction.Name = "cmbaction" + name; @@ -520,17 +520,17 @@ private void CHK_elevons_CheckedChanged(object sender, EventArgs e) private void chk_manualcontrol_CheckedChanged(object sender, EventArgs e) { MainV2.joystick.manual_control = chk_manualcontrol.Checked; - } - - public void Deactivate() - { + } + + public void Deactivate() + { timer1.Stop(); if (MainV2.joystick != null && MainV2.joystick.enabled == false) { MainV2.joystick.UnAcquireJoyStick(); MainV2.joystick = null; - } - } + } + } } } \ No newline at end of file diff --git a/MainV2.cs b/MainV2.cs index c940ab445d..1c9ba04ffb 100644 --- a/MainV2.cs +++ b/MainV2.cs @@ -2236,6 +2236,7 @@ private async void joysticksend() int count = 0; DateTime lastratechange = DateTime.Now; + DateTime start = DateTime.Now; joystickthreadrun = true; @@ -2255,6 +2256,37 @@ private async void joysticksend() { //joystick stuff + bool autoEnable = Settings.Instance.GetBoolean("CHK_Joystick_AutoEnable"); + + if (autoEnable && (DateTime.Now - start).TotalSeconds > 0.5 ) + { + string name = Settings.Instance["joystick_name"]; + if (joystick == null && name != null) + { + // all config is loaded from the xmls + Joystick.JoystickBase joy = JoystickBase.Create(() => MainV2.comPort); + + if (!joy.start(name)) + { + joy.Dispose(); + } + else + { + joystick = joy; + + if (Settings.Instance.ContainsKey("joy_elevons")) + { + joystick.elevons = bool.Parse(Settings.Instance["joy_elevons"].ToString()); + } + } + } + } + + if (joystick != null && !joystick.enabled && autoEnable) + { + joystick.enabled = true; + } + if (joystick != null && joystick.enabled) { if (!joystick.manual_control)