public void UpdateJoystickButtons(game.Buttons buttons) { if (buttons.Pressed != null && buttons.Pressed.Count > 0) { string[] buttonString = buttons.Pressed.ConvertAll <string>( delegate(bool button) { return(button ? "X" : "O"); } ).ToArray(); lblButtons.Text = string.Join(" ", buttonString); if (chkStop.Checked && buttons.Pressed.Count > 2) { if (buttons.Pressed[2] == true) { chkStop.Checked = false; } } else if (buttons.Pressed[1] == true && buttons.Pressed.Count > 1) { chkStop.Checked = true; } if (buttons.Pressed[0] != chkDrive.Checked) { chkDrive.Checked = buttons.Pressed[0]; } } }
/// <summary> /// Handle the Joystick buttons /// </summary> /// <param name="buttons">The current state of all the buttons</param> public void UpdateJoystickButtons(joystick.Buttons buttons) { if (buttons.Pressed != null && buttons.Pressed.Count > 0) { string[] buttonString = buttons.Pressed.ConvertAll <string>( delegate(bool button) { return(button ? "X" : "O"); }).ToArray(); this.lblButtons.Text = string.Join(" ", buttonString); if (this.StopCheckBox.Checked && buttons.Pressed.Count > 2) { if (buttons.Pressed[2] == true) { this.StopCheckBox.Checked = false; } } else if (buttons.Pressed.Count > 1 && buttons.Pressed[1] == true) { this.StopCheckBox.Checked = true; } if (buttons.Pressed[0]) { // Toggle the Drive button this.DriveCheckBox.Checked = !this.DriveCheckBox.Checked; } } }
/// <summary> /// Handle the joystick buttons /// </summary> /// <param name="buttons">The current state of all the Joytick buttons</param> public void UpdateJoystickButtons(joystick.Buttons buttons) { if (buttons.Pressed != null && buttons.Pressed.Count >= 8) { if (buttons.Pressed[4]) { // RB shoulder button -> Increase PID parameter value this.pidControllersControl[this.currentPIDSelection].Item0.DownButton(); } else if (buttons.Pressed[5]) { // LB shoulder button -> Decrease PID parameter value this.pidControllersControl[this.currentPIDSelection].Item0.UpButton(); } else if (buttons.Pressed[6]) { // Back button -> Switch active PID parameter, to the left this.pidControllersControl[this.currentPIDSelection].Item1.Visible = false; this.currentPIDSelection = (this.currentPIDSelection == 0) ? (this.pidControllersControl.Count - 1) : (this.currentPIDSelection - 1); this.pidControllersControl[this.currentPIDSelection].Item1.Visible = true; } else if (buttons.Pressed[7]) { // Start button -> Switch active PID parameter, to the right this.pidControllersControl[this.currentPIDSelection].Item1.Visible = false; this.currentPIDSelection = (this.currentPIDSelection + 1) % this.pidControllersControl.Count; this.pidControllersControl[this.currentPIDSelection].Item1.Visible = true; } } }
private void HandleButton(object sender, bool down) { Button button = sender as Button; if (button == null) { return; } int number; if (int.TryParse(button.Text, out number)) { if (number >= 0 && number <= 9) { if (chkSticky.Checked) { if (down) { return; } bool pressed = false; if (button.Tag is bool) { pressed = (bool)button.Tag; } button.Tag = !pressed; down = !pressed; _buttonState[number] = !pressed; } using (Graphics g = Graphics.FromHwnd(button.Handle)) { if (down) { button.BackColor = SystemColors.ControlDarkDark; button.ForeColor = SystemColors.ControlLightLight; } else { button.BackColor = SystemColors.Control; button.ForeColor = SystemColors.ControlText; } } _buttonState[number] = down; gc.Buttons request = new gc.Buttons(); request.TimeStamp = DateTime.UtcNow; request.Pressed = new List <bool>(_buttonState); _fwdPort.UpdateButtons(request); } } }
private void chkSticky_CheckedChanged(object sender, EventArgs e) { bool sticky = chkSticky.Checked; if (!sticky) { bool update = false; foreach (Control control in Controls) { Button button = control as Button; if (button != null && button.Tag is bool) { int number; if (int.TryParse(button.Text, out number)) { bool pressed = (bool)button.Tag; if (pressed) { button.BackColor = SystemColors.Control; button.ForeColor = SystemColors.ControlText; update = true; } _buttonState[number] = false; } button.Tag = false; } } if (update) { gc.Buttons request = new gc.Buttons(); request.TimeStamp = DateTime.UtcNow; request.Pressed = new List <bool>(_buttonState); _fwdPort.UpdateButtons(request); } } }