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 org.wpilib.simulation;
006
007import org.wpilib.driverstation.Gamepad;
008
009/** Class to control a simulated Gamepad controller. */
010public class GamepadSim extends GenericHIDSim {
011  /**
012   * Constructs from a Gamepad object.
013   *
014   * @param joystick controller to simulate
015   */
016  @SuppressWarnings("this-escape")
017  public GamepadSim(Gamepad joystick) {
018    super(joystick);
019    setAxesMaximumIndex(6);
020    setButtonsMaximumIndex(26);
021    setPOVsMaximumIndex(1);
022  }
023
024  /**
025   * Constructs from a joystick port number.
026   *
027   * @param port port number
028   */
029  @SuppressWarnings("this-escape")
030  public GamepadSim(int port) {
031    super(port);
032    setAxesMaximumIndex(6);
033    setButtonsMaximumIndex(26);
034    setPOVsMaximumIndex(1);
035  }
036
037  /**
038   * Set the value of a given button.
039   *
040   * @param button the button to set
041   * @param value the new value
042   */
043  public void setButton(Gamepad.Button button, boolean value) {
044    setRawButton(button.value, value);
045  }
046
047  /**
048   * Set the value of a given axis.
049   *
050   * @param axis the axis to set
051   * @param value the new value
052   */
053  public void setAxis(Gamepad.Axis axis, double value) {
054    setRawAxis(axis.value, value);
055  }
056
057  /**
058   * Change the left X value of the controller's joystick.
059   *
060   * @param value the new value
061   */
062  public void setLeftX(double value) {
063    setAxis(Gamepad.Axis.LEFT_X, value);
064  }
065
066  /**
067   * Change the left Y value of the controller's joystick.
068   *
069   * @param value the new value
070   */
071  public void setLeftY(double value) {
072    setAxis(Gamepad.Axis.LEFT_Y, value);
073  }
074
075  /**
076   * Change the right X value of the controller's joystick.
077   *
078   * @param value the new value
079   */
080  public void setRightX(double value) {
081    setAxis(Gamepad.Axis.RIGHT_X, value);
082  }
083
084  /**
085   * Change the right Y value of the controller's joystick.
086   *
087   * @param value the new value
088   */
089  public void setRightY(double value) {
090    setAxis(Gamepad.Axis.RIGHT_Y, value);
091  }
092
093  /**
094   * Change the value of the left trigger axis on the controller.
095   *
096   * @param value the new value
097   */
098  public void setLeftTriggerAxis(double value) {
099    setAxis(Gamepad.Axis.LEFT_TRIGGER, value);
100  }
101
102  /**
103   * Change the value of the right trigger axis on the controller.
104   *
105   * @param value the new value
106   */
107  public void setRightTriggerAxis(double value) {
108    setAxis(Gamepad.Axis.RIGHT_TRIGGER, value);
109  }
110
111  /**
112   * Change the value of the South Face button on the controller.
113   *
114   * @param value the new value
115   */
116  public void setSouthFaceButton(boolean value) {
117    setButton(Gamepad.Button.SOUTH_FACE, value);
118  }
119
120  /**
121   * Change the value of the East Face button on the controller.
122   *
123   * @param value the new value
124   */
125  public void setEastFaceButton(boolean value) {
126    setButton(Gamepad.Button.EAST_FACE, value);
127  }
128
129  /**
130   * Change the value of the West Face button on the controller.
131   *
132   * @param value the new value
133   */
134  public void setWestFaceButton(boolean value) {
135    setButton(Gamepad.Button.WEST_FACE, value);
136  }
137
138  /**
139   * Change the value of the North Face button on the controller.
140   *
141   * @param value the new value
142   */
143  public void setNorthFaceButton(boolean value) {
144    setButton(Gamepad.Button.NORTH_FACE, value);
145  }
146
147  /**
148   * Change the value of the Back button on the controller.
149   *
150   * @param value the new value
151   */
152  public void setBackButton(boolean value) {
153    setButton(Gamepad.Button.BACK, value);
154  }
155
156  /**
157   * Change the value of the Guide button on the controller.
158   *
159   * @param value the new value
160   */
161  public void setGuideButton(boolean value) {
162    setButton(Gamepad.Button.GUIDE, value);
163  }
164
165  /**
166   * Change the value of the Start button on the controller.
167   *
168   * @param value the new value
169   */
170  public void setStartButton(boolean value) {
171    setButton(Gamepad.Button.START, value);
172  }
173
174  /**
175   * Change the value of the left stick button on the controller.
176   *
177   * @param value the new value
178   */
179  public void setLeftStickButton(boolean value) {
180    setButton(Gamepad.Button.LEFT_STICK, value);
181  }
182
183  /**
184   * Change the value of the right stick button on the controller.
185   *
186   * @param value the new value
187   */
188  public void setRightStickButton(boolean value) {
189    setButton(Gamepad.Button.RIGHT_STICK, value);
190  }
191
192  /**
193   * Change the value of the right bumper button on the controller.
194   *
195   * @param value the new value
196   */
197  public void setLeftBumperButton(boolean value) {
198    setButton(Gamepad.Button.LEFT_BUMPER, value);
199  }
200
201  /**
202   * Change the value of the right bumper button on the controller.
203   *
204   * @param value the new value
205   */
206  public void setRightBumperButton(boolean value) {
207    setButton(Gamepad.Button.RIGHT_BUMPER, value);
208  }
209
210  /**
211   * Change the value of the D-pad up button on the controller.
212   *
213   * @param value the new value
214   */
215  public void setDpadUpButton(boolean value) {
216    setButton(Gamepad.Button.DPAD_UP, value);
217  }
218
219  /**
220   * Change the value of the D-pad down button on the controller.
221   *
222   * @param value the new value
223   */
224  public void setDpadDownButton(boolean value) {
225    setButton(Gamepad.Button.DPAD_DOWN, value);
226  }
227
228  /**
229   * Change the value of the D-pad left button on the controller.
230   *
231   * @param value the new value
232   */
233  public void setDpadLeftButton(boolean value) {
234    setButton(Gamepad.Button.DPAD_LEFT, value);
235  }
236
237  /**
238   * Change the value of the D-pad right button on the controller.
239   *
240   * @param value the new value
241   */
242  public void setDpadRightButton(boolean value) {
243    setButton(Gamepad.Button.DPAD_RIGHT, value);
244  }
245
246  /**
247   * Change the value of the Miscellaneous 1 button on the controller.
248   *
249   * @param value the new value
250   */
251  public void setMisc1Button(boolean value) {
252    setButton(Gamepad.Button.MISC_1, value);
253  }
254
255  /**
256   * Change the value of the Right Paddle 1 button on the controller.
257   *
258   * @param value the new value
259   */
260  public void setRightPaddle1Button(boolean value) {
261    setButton(Gamepad.Button.RIGHT_PADDLE_1, value);
262  }
263
264  /**
265   * Change the value of the Left Paddle 1 button on the controller.
266   *
267   * @param value the new value
268   */
269  public void setLeftPaddle1Button(boolean value) {
270    setButton(Gamepad.Button.LEFT_PADDLE_1, value);
271  }
272
273  /**
274   * Change the value of the Right Paddle 2 button on the controller.
275   *
276   * @param value the new value
277   */
278  public void setRightPaddle2Button(boolean value) {
279    setButton(Gamepad.Button.RIGHT_PADDLE_2, value);
280  }
281
282  /**
283   * Change the value of the Left Paddle 2 button on the controller.
284   *
285   * @param value the new value
286   */
287  public void setLeftPaddle2Button(boolean value) {
288    setButton(Gamepad.Button.LEFT_PADDLE_2, value);
289  }
290
291  /**
292   * Change the value of the Touchpad button on the controller.
293   *
294   * @param value the new value
295   */
296  public void setTouchpadButton(boolean value) {
297    setButton(Gamepad.Button.TOUCHPAD, value);
298  }
299
300  /**
301   * Change the value of the Miscellaneous 2 button on the controller.
302   *
303   * @param value the new value
304   */
305  public void setMisc2Button(boolean value) {
306    setButton(Gamepad.Button.MISC_2, value);
307  }
308
309  /**
310   * Change the value of the Miscellaneous 3 button on the controller.
311   *
312   * @param value the new value
313   */
314  public void setMisc3Button(boolean value) {
315    setButton(Gamepad.Button.MISC_3, value);
316  }
317
318  /**
319   * Change the value of the Miscellaneous 4 button on the controller.
320   *
321   * @param value the new value
322   */
323  public void setMisc4Button(boolean value) {
324    setButton(Gamepad.Button.MISC_4, value);
325  }
326
327  /**
328   * Change the value of the Miscellaneous 5 button on the controller.
329   *
330   * @param value the new value
331   */
332  public void setMisc5Button(boolean value) {
333    setButton(Gamepad.Button.MISC_5, value);
334  }
335
336  /**
337   * Change the value of the Miscellaneous 6 button on the controller.
338   *
339   * @param value the new value
340   */
341  public void setMisc6Button(boolean value) {
342    setButton(Gamepad.Button.MISC_6, value);
343  }
344}