001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj.simulation; 006 007import edu.wpi.first.wpilibj.XboxController; 008 009/** Class to control a simulated Xbox 360 or Xbox One controller. */ 010public class XboxControllerSim extends GenericHIDSim { 011 /** 012 * Constructs from a XboxController object. 013 * 014 * @param joystick controller to simulate 015 */ 016 public XboxControllerSim(XboxController joystick) { 017 super(joystick); 018 setAxisCount(6); 019 setButtonCount(10); 020 } 021 022 /** 023 * Constructs from a joystick port number. 024 * 025 * @param port port number 026 */ 027 public XboxControllerSim(int port) { 028 super(port); 029 setAxisCount(6); 030 setButtonCount(10); 031 } 032 033 /** 034 * Change the left X value of the joystick. 035 * 036 * @param value the new value 037 */ 038 public void setLeftX(double value) { 039 setRawAxis(XboxController.Axis.kLeftX.value, value); 040 } 041 042 /** 043 * Change the right X value of the joystick. 044 * 045 * @param value the new value 046 */ 047 public void setRightX(double value) { 048 setRawAxis(XboxController.Axis.kRightX.value, value); 049 } 050 051 /** 052 * Change the left Y value of the joystick. 053 * 054 * @param value the new value 055 */ 056 public void setLeftY(double value) { 057 setRawAxis(XboxController.Axis.kLeftY.value, value); 058 } 059 060 /** 061 * Change the right Y value of the joystick. 062 * 063 * @param value the new value 064 */ 065 public void setRightY(double value) { 066 setRawAxis(XboxController.Axis.kRightY.value, value); 067 } 068 069 /** 070 * Change the value of the left trigger axis on the joystick. 071 * 072 * @param value the new value 073 */ 074 public void setLeftTriggerAxis(double value) { 075 setRawAxis(XboxController.Axis.kLeftTrigger.value, value); 076 } 077 078 /** 079 * Change the value of the right trigger axis on the joystick. 080 * 081 * @param value the new value 082 */ 083 public void setRightTriggerAxis(double value) { 084 setRawAxis(XboxController.Axis.kRightTrigger.value, value); 085 } 086 087 /** 088 * Change the value of the left bumper on the joystick. 089 * 090 * @param state the new value 091 */ 092 public void setLeftBumper(boolean state) { 093 setRawButton(XboxController.Button.kLeftBumper.value, state); 094 } 095 096 /** 097 * Change the value of the right bumper on the joystick. 098 * 099 * @param state the new value 100 */ 101 public void setRightBumper(boolean state) { 102 setRawButton(XboxController.Button.kRightBumper.value, state); 103 } 104 105 /** 106 * Change the value of the left stick button on the joystick. 107 * 108 * @param state the new value 109 */ 110 public void setLeftStickButton(boolean state) { 111 setRawButton(XboxController.Button.kLeftStick.value, state); 112 } 113 114 /** 115 * Change the value of the right stick button on the joystick. 116 * 117 * @param state the new value 118 */ 119 public void setRightStickButton(boolean state) { 120 setRawButton(XboxController.Button.kRightStick.value, state); 121 } 122 123 /** 124 * Change the value of the A button. 125 * 126 * @param state the new value 127 */ 128 public void setAButton(boolean state) { 129 setRawButton(XboxController.Button.kA.value, state); 130 } 131 132 /** 133 * Change the value of the B button. 134 * 135 * @param state the new value 136 */ 137 public void setBButton(boolean state) { 138 setRawButton(XboxController.Button.kB.value, state); 139 } 140 141 /** 142 * Change the value of the X button. 143 * 144 * @param state the new value 145 */ 146 public void setXButton(boolean state) { 147 setRawButton(XboxController.Button.kX.value, state); 148 } 149 150 /** 151 * Change the value of the Y button. 152 * 153 * @param state the new value 154 */ 155 public void setYButton(boolean state) { 156 setRawButton(XboxController.Button.kY.value, state); 157 } 158 159 /** 160 * Change the value of the Back button. 161 * 162 * @param state the new value 163 */ 164 public void setBackButton(boolean state) { 165 setRawButton(XboxController.Button.kBack.value, state); 166 } 167 168 /** 169 * Change the value of the Start button. 170 * 171 * @param state the new value 172 */ 173 public void setStartButton(boolean state) { 174 setRawButton(XboxController.Button.kStart.value, state); 175 } 176}