private void BUT_detbutton_Click(object sender, EventArgs e) { string name = ((MyButton)sender).Name.Replace("mybut", ""); ComboBox cmb = (ComboBox)(this.Controls.Find("cmbbutton" + name, false)[0]); cmb.Text = JoystickBase.getPressedButton(CMB_joysticks.Text).ToString(); }
private void BUT_enable_Click(object sender, EventArgs e) { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { try { if (MainV2.joystick != null) { MainV2.joystick.UnAcquireJoyStick(); } } catch { } // all config is loaded from the xmls var joy = JoystickBase.Create(() => MainV2.comPort); joy.elevons = CHK_elevons.Checked; //show error message if a joystick is not connected when Enable is clicked if (!joy.start(CMB_joysticks.Text)) { CustomMessageBox.Show("Please Connect a Joystick", "No Joystick"); joy.Dispose(); return; } Settings.Instance["joystick_name"] = CMB_joysticks.Text; MainV2.joystick = joy; MainV2.joystick.enabled = true; BUT_enable.Text = "Disable"; //timer1.Start(); } else { MainV2.joystick.enabled = false; MainV2.joystick.clearRCOverride(); MainV2.joystick = null; //timer1.Stop(); BUT_enable.Text = "Enable"; } }
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; } }
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; }
private void timer1_Tick(object sender, EventArgs e) { try { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { //Console.WriteLine(DateTime.Now.Millisecond + " start "); var joy = MainV2.joystick; if (joy == null) { joy = JoystickBase.Create(() => MainV2.comPort); for (int a = 1; a <= maxaxis; a++) { var config = joy.getChannel(a); joy.setChannel(a, config.axis, config.reverse, config.expo); } joy.elevons = CHK_elevons.Checked; joy.AcquireJoystick(CMB_joysticks.Text); joy.name = CMB_joysticks.Text; noButtons = joy.getNumButtons(); noButtons = Math.Min(16, noButtons); SuspendLayout(); MainV2.joystick = joy; var maxctl = Controls.Find("axis" + 1, false).FirstOrDefault(); for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); doButtontoUI(name, maxctl.Right + 100, maxctl.Top + f * maxctl.Height); var config = joy.getButton(f); joy.setButton(f, config); } ResumeLayout(); ThemeManager.ApplyThemeTo(this); CMB_joysticks.SelectedIndex = CMB_joysticks.Items.IndexOf(joy.name); } MainV2.joystick.elevons = CHK_elevons.Checked; MainV2.comPort.MAV.cs.rcoverridech1 = joy.getValueForChannel(1); MainV2.comPort.MAV.cs.rcoverridech2 = joy.getValueForChannel(2); MainV2.comPort.MAV.cs.rcoverridech3 = joy.getValueForChannel(3); MainV2.comPort.MAV.cs.rcoverridech4 = joy.getValueForChannel(4); MainV2.comPort.MAV.cs.rcoverridech5 = joy.getValueForChannel(5); MainV2.comPort.MAV.cs.rcoverridech6 = joy.getValueForChannel(6); MainV2.comPort.MAV.cs.rcoverridech7 = joy.getValueForChannel(7); MainV2.comPort.MAV.cs.rcoverridech8 = joy.getValueForChannel(8); MainV2.comPort.MAV.cs.rcoverridech9 = joy.getValueForChannel(9); MainV2.comPort.MAV.cs.rcoverridech10 = joy.getValueForChannel(10); MainV2.comPort.MAV.cs.rcoverridech11 = joy.getValueForChannel(11); MainV2.comPort.MAV.cs.rcoverridech12 = joy.getValueForChannel(12); MainV2.comPort.MAV.cs.rcoverridech13 = joy.getValueForChannel(13); MainV2.comPort.MAV.cs.rcoverridech14 = joy.getValueForChannel(14); MainV2.comPort.MAV.cs.rcoverridech15 = joy.getValueForChannel(15); MainV2.comPort.MAV.cs.rcoverridech16 = joy.getValueForChannel(16); MainV2.comPort.MAV.cs.rcoverridech17 = joy.getValueForChannel(17); MainV2.comPort.MAV.cs.rcoverridech18 = joy.getValueForChannel(18); //Console.WriteLine(DateTime.Now.Millisecond + " end "); } } catch (SharpDX.SharpDXException ex) { ex.ToString(); if (MainV2.joystick != null && MainV2.joystick.enabled == true) { BUT_enable_Click(null, null); } if (ex.Message.Contains("DIERR_NOTACQUIRED")) { MainV2.joystick = null; } } catch { } try { for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); var items = this.Controls.Find("hbar" + name, false); if (items.Length > 0) { ((HorizontalProgressBar)items[0]).Value = MainV2.joystick.isButtonPressed(f) ? 100 : 0; } } } catch { } // this is for buttons - silent fail }