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  @SuppressWarnings("this-escape")
017  public XboxControllerSim(XboxController joystick) {
018    super(joystick);
019    setAxisCount(6);
020    setButtonCount(10);
021    setPOVCount(1);
022  }
023
024  /**
025   * Constructs from a joystick port number.
026   *
027   * @param port port number
028   */
029  @SuppressWarnings("this-escape")
030  public XboxControllerSim(int port) {
031    super(port);
032    setAxisCount(6);
033    setButtonCount(10);
034    setPOVCount(1);
035  }
036
037  /**
038   * Change the left X value of the joystick.
039   *
040   * @param value the new value
041   */
042  public void setLeftX(double value) {
043    setRawAxis(XboxController.Axis.kLeftX.value, value);
044  }
045
046  /**
047   * Change the right X value of the joystick.
048   *
049   * @param value the new value
050   */
051  public void setRightX(double value) {
052    setRawAxis(XboxController.Axis.kRightX.value, value);
053  }
054
055  /**
056   * Change the left Y value of the joystick.
057   *
058   * @param value the new value
059   */
060  public void setLeftY(double value) {
061    setRawAxis(XboxController.Axis.kLeftY.value, value);
062  }
063
064  /**
065   * Change the right Y value of the joystick.
066   *
067   * @param value the new value
068   */
069  public void setRightY(double value) {
070    setRawAxis(XboxController.Axis.kRightY.value, value);
071  }
072
073  /**
074   * Change the value of the left trigger axis on the joystick.
075   *
076   * @param value the new value
077   */
078  public void setLeftTriggerAxis(double value) {
079    setRawAxis(XboxController.Axis.kLeftTrigger.value, value);
080  }
081
082  /**
083   * Change the value of the right trigger axis on the joystick.
084   *
085   * @param value the new value
086   */
087  public void setRightTriggerAxis(double value) {
088    setRawAxis(XboxController.Axis.kRightTrigger.value, value);
089  }
090
091  /**
092   * Change the value of the left bumper on the joystick.
093   *
094   * @param state the new value
095   */
096  public void setLeftBumper(boolean state) {
097    setRawButton(XboxController.Button.kLeftBumper.value, state);
098  }
099
100  /**
101   * Change the value of the right bumper on the joystick.
102   *
103   * @param state the new value
104   */
105  public void setRightBumper(boolean state) {
106    setRawButton(XboxController.Button.kRightBumper.value, state);
107  }
108
109  /**
110   * Change the value of the left stick button on the joystick.
111   *
112   * @param state the new value
113   */
114  public void setLeftStickButton(boolean state) {
115    setRawButton(XboxController.Button.kLeftStick.value, state);
116  }
117
118  /**
119   * Change the value of the right stick button on the joystick.
120   *
121   * @param state the new value
122   */
123  public void setRightStickButton(boolean state) {
124    setRawButton(XboxController.Button.kRightStick.value, state);
125  }
126
127  /**
128   * Change the value of the A button.
129   *
130   * @param state the new value
131   */
132  public void setAButton(boolean state) {
133    setRawButton(XboxController.Button.kA.value, state);
134  }
135
136  /**
137   * Change the value of the B button.
138   *
139   * @param state the new value
140   */
141  public void setBButton(boolean state) {
142    setRawButton(XboxController.Button.kB.value, state);
143  }
144
145  /**
146   * Change the value of the X button.
147   *
148   * @param state the new value
149   */
150  public void setXButton(boolean state) {
151    setRawButton(XboxController.Button.kX.value, state);
152  }
153
154  /**
155   * Change the value of the Y button.
156   *
157   * @param state the new value
158   */
159  public void setYButton(boolean state) {
160    setRawButton(XboxController.Button.kY.value, state);
161  }
162
163  /**
164   * Change the value of the Back button.
165   *
166   * @param state the new value
167   */
168  public void setBackButton(boolean state) {
169    setRawButton(XboxController.Button.kBack.value, state);
170  }
171
172  /**
173   * Change the value of the Start button.
174   *
175   * @param state the new value
176   */
177  public void setStartButton(boolean state) {
178    setRawButton(XboxController.Button.kStart.value, state);
179  }
180}