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.PS4Controller;
008
009/** Class to control a simulated PS4 controller. */
010public class PS4ControllerSim extends GenericHIDSim {
011  /**
012   * Constructs from a PS4Controller object.
013   *
014   * @param joystick controller to simulate
015   */
016  @SuppressWarnings("this-escape")
017  public PS4ControllerSim(PS4Controller joystick) {
018    super(joystick);
019    setAxisCount(6);
020    setButtonCount(14);
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 PS4ControllerSim(int port) {
031    super(port);
032    setAxisCount(6);
033    setButtonCount(14);
034    setPOVCount(1);
035  }
036
037  /**
038   * Change the X axis value of the controller's left stick.
039   *
040   * @param value the new value
041   */
042  public void setLeftX(double value) {
043    setRawAxis(PS4Controller.Axis.kLeftX.value, value);
044  }
045
046  /**
047   * Change the X axis value of the controller's right stick.
048   *
049   * @param value the new value
050   */
051  public void setRightX(double value) {
052    setRawAxis(PS4Controller.Axis.kRightX.value, value);
053  }
054
055  /**
056   * Change the Y axis value of the controller's left stick.
057   *
058   * @param value the new value
059   */
060  public void setLeftY(double value) {
061    setRawAxis(PS4Controller.Axis.kLeftY.value, value);
062  }
063
064  /**
065   * Change the Y axis value of the controller's right stick.
066   *
067   * @param value the new value
068   */
069  public void setRightY(double value) {
070    setRawAxis(PS4Controller.Axis.kRightY.value, value);
071  }
072
073  /**
074   * Change the L2 axis value of the controller.
075   *
076   * @param value the new value
077   */
078  public void setL2Axis(double value) {
079    setRawAxis(PS4Controller.Axis.kL2.value, value);
080  }
081
082  /**
083   * Change the R2 axis value of the controller.
084   *
085   * @param value the new value
086   */
087  public void setR2Axis(double value) {
088    setRawAxis(PS4Controller.Axis.kR2.value, value);
089  }
090
091  /**
092   * Change the value of the Square button on the controller.
093   *
094   * @param value the new value
095   */
096  public void setSquareButton(boolean value) {
097    setRawButton(PS4Controller.Button.kSquare.value, value);
098  }
099
100  /**
101   * Change the value of the Cross button on the controller.
102   *
103   * @param value the new value
104   */
105  public void setCrossButton(boolean value) {
106    setRawButton(PS4Controller.Button.kCross.value, value);
107  }
108
109  /**
110   * Change the value of the Circle button on the controller.
111   *
112   * @param value the new value
113   */
114  public void setCircleButton(boolean value) {
115    setRawButton(PS4Controller.Button.kCircle.value, value);
116  }
117
118  /**
119   * Change the value of the Triangle button on the controller.
120   *
121   * @param value the new value
122   */
123  public void setTriangleButton(boolean value) {
124    setRawButton(PS4Controller.Button.kTriangle.value, value);
125  }
126
127  /**
128   * Change the value of the L1 button on the controller.
129   *
130   * @param value the new value
131   */
132  public void setL1Button(boolean value) {
133    setRawButton(PS4Controller.Button.kL1.value, value);
134  }
135
136  /**
137   * Change the value of the R1 button on the controller.
138   *
139   * @param value the new value
140   */
141  public void setR1Button(boolean value) {
142    setRawButton(PS4Controller.Button.kR1.value, value);
143  }
144
145  /**
146   * Change the value of the L2 button on the controller.
147   *
148   * @param value the new value
149   */
150  public void setL2Button(boolean value) {
151    setRawButton(PS4Controller.Button.kL2.value, value);
152  }
153
154  /**
155   * Change the value of the R2 button on the controller.
156   *
157   * @param value the new value
158   */
159  public void setR2Button(boolean value) {
160    setRawButton(PS4Controller.Button.kR2.value, value);
161  }
162
163  /**
164   * Change the value of the Share button on the controller.
165   *
166   * @param value the new value
167   */
168  public void setShareButton(boolean value) {
169    setRawButton(PS4Controller.Button.kShare.value, value);
170  }
171
172  /**
173   * Change the value of the Options button on the controller.
174   *
175   * @param value the new value
176   */
177  public void setOptionsButton(boolean value) {
178    setRawButton(PS4Controller.Button.kOptions.value, value);
179  }
180
181  /**
182   * Change the value of the L3 (left stick) button on the controller.
183   *
184   * @param value the new value
185   */
186  public void setL3Button(boolean value) {
187    setRawButton(PS4Controller.Button.kL3.value, value);
188  }
189
190  /**
191   * Change the value of the R3 (right stick) button on the controller.
192   *
193   * @param value the new value
194   */
195  public void setR3Button(boolean value) {
196    setRawButton(PS4Controller.Button.kR3.value, value);
197  }
198
199  /**
200   * Change the value of the PS button on the controller.
201   *
202   * @param value the new value
203   */
204  public void setPSButton(boolean value) {
205    setRawButton(PS4Controller.Button.kPS.value, value);
206  }
207
208  /**
209   * Change the value of the touchpad button on the controller.
210   *
211   * @param value the new value
212   */
213  public void setTouchpad(boolean value) {
214    setRawButton(PS4Controller.Button.kTouchpad.value, value);
215  }
216}