private void timer1_Tick(object sender, EventArgs e) { try { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { //Console.WriteLine(DateTime.Now.Millisecond + " start "); Joystick joy = MainV2.joystick; if (joy == null) { joy = new Joystick(); joy.setChannel(1, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH1.Text), revCH1.Checked, int.Parse(expo_ch1.Text)); joy.setChannel(2, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH2.Text), revCH2.Checked, int.Parse(expo_ch2.Text)); joy.setChannel(3, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH3.Text), revCH3.Checked, int.Parse(expo_ch3.Text)); joy.setChannel(4, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH4.Text), revCH4.Checked, int.Parse(expo_ch4.Text)); joy.setChannel(5, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH5.Text), revCH5.Checked, int.Parse(expo_ch5.Text)); joy.setChannel(6, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH6.Text), revCH6.Checked, int.Parse(expo_ch6.Text)); joy.setChannel(7, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH7.Text), revCH7.Checked, int.Parse(expo_ch7.Text)); joy.setChannel(8, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH8.Text), revCH8.Checked, int.Parse(expo_ch8.Text)); joy.elevons = CHK_elevons.Checked; joy.AcquireJoystick(CMB_joysticks.Text); joy.name = CMB_joysticks.Text; noButtons = joy.getNumButtons(); noButtons = Math.Min(15, noButtons); for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); doButtontoUI(name, 10, CMB_CH8.Bottom + 20 + f * 25); var config = joy.getButton(f); joy.setButton(f, config); } MainV2.joystick = joy; 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, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech2 = joy.getValueForChannel(2, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech3 = joy.getValueForChannel(3, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech4 = joy.getValueForChannel(4, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech5 = joy.getValueForChannel(5, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech6 = joy.getValueForChannel(6, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech7 = joy.getValueForChannel(7, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech8 = joy.getValueForChannel(8, CMB_joysticks.Text); //Console.WriteLine(DateTime.Now.Millisecond + " end "); } } catch (InputLostException ex) { if (MainV2.joystick != null && MainV2.joystick.enabled == true) { BUT_enable_Click(null, null); } } catch { } progressBarRoll.Value = MainV2.comPort.MAV.cs.rcoverridech1; progressBarPith.Value = MainV2.comPort.MAV.cs.rcoverridech2; progressBarThrottle.Value = MainV2.comPort.MAV.cs.rcoverridech3; progressBarRudder.Value = MainV2.comPort.MAV.cs.rcoverridech4; ProgressBarCH5.Value = MainV2.comPort.MAV.cs.rcoverridech5; ProgressBarCH6.Value = MainV2.comPort.MAV.cs.rcoverridech6; ProgressBarCH7.Value = MainV2.comPort.MAV.cs.rcoverridech7; ProgressBarCH8.Value = MainV2.comPort.MAV.cs.rcoverridech8; try { for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); ((HorizontalProgressBar)this.Controls.Find("hbar" + name, false)[0]).Value = MainV2.joystick.isButtonPressed(f) ? 100 : 0; } } catch { } // this is for buttons - silent fail }
private void timer1_Tick(object sender, EventArgs e) { try { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { //Console.WriteLine(DateTime.Now.Millisecond + " start "); Joystick joy = MainV2.joystick; if (joy == null) { joy = new Joystick(); joy.setChannel(1, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH1.Text), revCH1.Checked, int.Parse(expo_ch1.Text)); joy.setChannel(2, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH2.Text), revCH2.Checked, int.Parse(expo_ch2.Text)); joy.setChannel(3, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH3.Text), revCH3.Checked, int.Parse(expo_ch3.Text)); joy.setChannel(4, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH4.Text), revCH4.Checked, int.Parse(expo_ch4.Text)); joy.setChannel(5, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH5.Text), revCH5.Checked, int.Parse(expo_ch5.Text)); joy.setChannel(6, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH6.Text), revCH6.Checked, int.Parse(expo_ch6.Text)); joy.setChannel(7, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH7.Text), revCH7.Checked, int.Parse(expo_ch7.Text)); joy.setChannel(8, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH8.Text), revCH8.Checked, int.Parse(expo_ch8.Text)); joy.elevons = CHK_elevons.Checked; joy.AcquireJoystick(CMB_joysticks.Text); joy.name = CMB_joysticks.Text; noButtons = joy.getNumButtons(); noButtons = Math.Min(15, noButtons); for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); doButtontoUI(name, 10, CMB_CH8.Bottom + 20 + f * 25); var config = joy.getButton(f); joy.setButton(f, config); } MainV2.joystick = joy; 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, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech2 = joy.getValueForChannel(2, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech3 = joy.getValueForChannel(3, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech4 = joy.getValueForChannel(4, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech5 = joy.getValueForChannel(5, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech6 = joy.getValueForChannel(6, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech7 = joy.getValueForChannel(7, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech8 = joy.getValueForChannel(8, CMB_joysticks.Text); //Console.WriteLine(DateTime.Now.Millisecond + " end "); } } catch (InputLostException ex) { ex.ToString(); if (MainV2.joystick != null && MainV2.joystick.enabled == true) { BUT_enable_Click(null, null); } } catch { } progressBarRoll.Value = MainV2.comPort.MAV.cs.rcoverridech1; progressBarPith.Value = MainV2.comPort.MAV.cs.rcoverridech2; progressBarThrottle.Value = MainV2.comPort.MAV.cs.rcoverridech3; progressBarRudder.Value = MainV2.comPort.MAV.cs.rcoverridech4; ProgressBarCH5.Value = MainV2.comPort.MAV.cs.rcoverridech5; ProgressBarCH6.Value = MainV2.comPort.MAV.cs.rcoverridech6; ProgressBarCH7.Value = MainV2.comPort.MAV.cs.rcoverridech7; ProgressBarCH8.Value = MainV2.comPort.MAV.cs.rcoverridech8; try { for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); ((HorizontalProgressBar)this.Controls.Find("hbar" + name, false)[0]).Value = MainV2.joystick.isButtonPressed(f) ? 100 : 0; } } catch { } // this is for buttons - silent fail }
private void timer1_Tick(object sender, EventArgs e) { try { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { //Console.WriteLine(DateTime.Now.Millisecond + " start "); Joystick joy = MainV2.joystick; if (joy == null) { joy = new Joystick(); if (CMB_CH1.Text != "") { joy.setChannel(1, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH1.Text), revCH1.Checked, int.Parse(expo_ch1.Text)); } if (CMB_CH2.Text != "") { joy.setChannel(2, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH2.Text), revCH2.Checked, int.Parse(expo_ch2.Text)); } if (CMB_CH3.Text != "") { joy.setChannel(3, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH3.Text), revCH3.Checked, int.Parse(expo_ch3.Text)); } if (CMB_CH4.Text != "") { joy.setChannel(4, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH4.Text), revCH4.Checked, int.Parse(expo_ch4.Text)); } if (CMB_CH5.Text != "") { joy.setChannel(5, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH5.Text), revCH5.Checked, int.Parse(expo_ch5.Text)); } if (CMB_CH6.Text != "") { joy.setChannel(6, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH6.Text), revCH6.Checked, int.Parse(expo_ch6.Text)); } if (CMB_CH7.Text != "") { joy.setChannel(7, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH7.Text), revCH7.Checked, int.Parse(expo_ch7.Text)); } if (CMB_CH8.Text != "") { joy.setChannel(8, (Joystick.joystickaxis)Enum.Parse(typeof(Joystick.joystickaxis), CMB_CH8.Text), revCH8.Checked, int.Parse(expo_ch8.Text)); } joy.elevons = CHK_elevons.Checked; joy.AcquireJoystick(CMB_joysticks.Text); joy.name = CMB_joysticks.Text; noButtons = joy.getNumButtons(); noButtons = Math.Min(15, noButtons); SuspendLayout(); MainV2.joystick = joy; for (int f = 0; f < noButtons; f++) { string name = (f).ToString(); doButtontoUI(name, 10, CMB_CH8.Bottom + 20 + f * 25); 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, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech2 = joy.getValueForChannel(2, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech3 = joy.getValueForChannel(3, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech4 = joy.getValueForChannel(4, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech5 = joy.getValueForChannel(5, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech6 = joy.getValueForChannel(6, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech7 = joy.getValueForChannel(7, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech8 = joy.getValueForChannel(8, CMB_joysticks.Text); //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 { } progressBarRoll.Value = MainV2.comPort.MAV.cs.rcoverridech1; progressBarPith.Value = MainV2.comPort.MAV.cs.rcoverridech2; progressBarThrottle.Value = MainV2.comPort.MAV.cs.rcoverridech3; progressBarRudder.Value = MainV2.comPort.MAV.cs.rcoverridech4; ProgressBarCH5.Value = MainV2.comPort.MAV.cs.rcoverridech5; ProgressBarCH6.Value = MainV2.comPort.MAV.cs.rcoverridech6; ProgressBarCH7.Value = MainV2.comPort.MAV.cs.rcoverridech7; ProgressBarCH8.Value = MainV2.comPort.MAV.cs.rcoverridech8; try { if (MainV2.joystick != null) { progressBarRoll.maxline = MainV2.joystick.getRawValueForChannel(1); progressBarPith.maxline = MainV2.joystick.getRawValueForChannel(2); progressBarThrottle.maxline = MainV2.joystick.getRawValueForChannel(3); progressBarRudder.maxline = MainV2.joystick.getRawValueForChannel(4); ProgressBarCH5.maxline = MainV2.joystick.getRawValueForChannel(5); ProgressBarCH6.maxline = MainV2.joystick.getRawValueForChannel(6); ProgressBarCH7.maxline = MainV2.joystick.getRawValueForChannel(7); ProgressBarCH8.maxline = MainV2.joystick.getRawValueForChannel(8); } } catch { //Exception Error in the application. -2147024866 (DIERR_INPUTLOST) } 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 }
private void timer1_Tick(object sender, EventArgs e) { try { if (MainV2.joystick == null || MainV2.joystick.enabled == false) { //Console.WriteLine(DateTime.Now.Millisecond + " start "); Joystick joy = MainV2.joystick; if (joy == null) { joy = new Joystick(() => 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, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech2 = joy.getValueForChannel(2, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech3 = joy.getValueForChannel(3, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech4 = joy.getValueForChannel(4, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech5 = joy.getValueForChannel(5, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech6 = joy.getValueForChannel(6, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech7 = joy.getValueForChannel(7, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech8 = joy.getValueForChannel(8, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech9 = joy.getValueForChannel(9, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech10 = joy.getValueForChannel(10, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech11 = joy.getValueForChannel(11, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech12 = joy.getValueForChannel(12, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech13 = joy.getValueForChannel(13, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech14 = joy.getValueForChannel(14, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech15 = joy.getValueForChannel(15, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech16 = joy.getValueForChannel(16, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech17 = joy.getValueForChannel(17, CMB_joysticks.Text); MainV2.comPort.MAV.cs.rcoverridech18 = joy.getValueForChannel(18, CMB_joysticks.Text); //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 }