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
005// THIS FILE WAS AUTO-GENERATED BY ./commandsv3/generate_files.py. DO NOT MODIFY
006
007package org.wpilib.commands3.button;
008
009import edu.wpi.first.wpilibj.PS4Controller;
010import edu.wpi.first.wpilibj.event.EventLoop;
011import org.wpilib.commands3.Scheduler;
012import org.wpilib.commands3.Trigger;
013
014/**
015 * A version of {@link PS4Controller} with {@link Trigger} factories for command-based.
016 *
017 * @see PS4Controller
018 */
019@SuppressWarnings("MethodName")
020public class CommandPS4Controller extends CommandGenericHID {
021  private final PS4Controller m_hid;
022
023  /**
024   * Construct an instance of a controller. Commands bound to buttons on the controller will be
025   * scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop.
026   *
027   * @param port The port index on the Driver Station that the controller is plugged into.
028   */
029  public CommandPS4Controller(int port) {
030    super(port);
031    m_hid = new PS4Controller(port);
032  }
033
034  /**
035   * Construct an instance of a controller. Commands bound to buttons on the controller will be
036   * scheduled on the given scheduler using its default event loop.
037   *
038   * @param scheduler The scheduler that should execute the triggered commands.
039   * @param port The port index on the Driver Station that the controller is plugged into.
040   */
041  public CommandPS4Controller(Scheduler scheduler, int port) {
042    super(scheduler, port);
043    m_hid = new PS4Controller(port);
044  }
045
046  /**
047   * Get the underlying GenericHID object.
048   *
049   * @return the wrapped GenericHID object
050   */
051  @Override
052  public PS4Controller getHID() {
053    return m_hid;
054  }
055
056  /**
057   * Constructs a Trigger instance around the square button's digital signal.
058   *
059   * @return a Trigger instance representing the square button's digital signal attached
060   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
061   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
062   *     default scheduler} if a scheduler was not explicitly provided.
063   * @see #square(EventLoop)
064   */
065  public Trigger square() {
066    return square(getScheduler().getDefaultEventLoop());
067  }
068
069  /**
070   * Constructs a Trigger instance around the square button's digital signal.
071   *
072   * @param loop the event loop instance to attach the event to.
073   * @return a Trigger instance representing the square button's digital signal attached
074   *     to the given loop.
075   */
076  public Trigger square(EventLoop loop) {
077    return button(PS4Controller.Button.kSquare.value, loop);
078  }
079
080  /**
081   * Constructs a Trigger instance around the cross button's digital signal.
082   *
083   * @return a Trigger instance representing the cross button's digital signal attached
084   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
085   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
086   *     default scheduler} if a scheduler was not explicitly provided.
087   * @see #cross(EventLoop)
088   */
089  public Trigger cross() {
090    return cross(getScheduler().getDefaultEventLoop());
091  }
092
093  /**
094   * Constructs a Trigger instance around the cross button's digital signal.
095   *
096   * @param loop the event loop instance to attach the event to.
097   * @return a Trigger instance representing the cross button's digital signal attached
098   *     to the given loop.
099   */
100  public Trigger cross(EventLoop loop) {
101    return button(PS4Controller.Button.kCross.value, loop);
102  }
103
104  /**
105   * Constructs a Trigger instance around the circle button's digital signal.
106   *
107   * @return a Trigger instance representing the circle button's digital signal attached
108   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
109   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
110   *     default scheduler} if a scheduler was not explicitly provided.
111   * @see #circle(EventLoop)
112   */
113  public Trigger circle() {
114    return circle(getScheduler().getDefaultEventLoop());
115  }
116
117  /**
118   * Constructs a Trigger instance around the circle button's digital signal.
119   *
120   * @param loop the event loop instance to attach the event to.
121   * @return a Trigger instance representing the circle button's digital signal attached
122   *     to the given loop.
123   */
124  public Trigger circle(EventLoop loop) {
125    return button(PS4Controller.Button.kCircle.value, loop);
126  }
127
128  /**
129   * Constructs a Trigger instance around the triangle button's digital signal.
130   *
131   * @return a Trigger instance representing the triangle button's digital signal attached
132   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
133   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
134   *     default scheduler} if a scheduler was not explicitly provided.
135   * @see #triangle(EventLoop)
136   */
137  public Trigger triangle() {
138    return triangle(getScheduler().getDefaultEventLoop());
139  }
140
141  /**
142   * Constructs a Trigger instance around the triangle button's digital signal.
143   *
144   * @param loop the event loop instance to attach the event to.
145   * @return a Trigger instance representing the triangle button's digital signal attached
146   *     to the given loop.
147   */
148  public Trigger triangle(EventLoop loop) {
149    return button(PS4Controller.Button.kTriangle.value, loop);
150  }
151
152  /**
153   * Constructs a Trigger instance around the left trigger 1 button's digital signal.
154   *
155   * @return a Trigger instance representing the left trigger 1 button's digital signal attached
156   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
157   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
158   *     default scheduler} if a scheduler was not explicitly provided.
159   * @see #L1(EventLoop)
160   */
161  public Trigger L1() {
162    return L1(getScheduler().getDefaultEventLoop());
163  }
164
165  /**
166   * Constructs a Trigger instance around the left trigger 1 button's digital signal.
167   *
168   * @param loop the event loop instance to attach the event to.
169   * @return a Trigger instance representing the left trigger 1 button's digital signal attached
170   *     to the given loop.
171   */
172  public Trigger L1(EventLoop loop) {
173    return button(PS4Controller.Button.kL1.value, loop);
174  }
175
176  /**
177   * Constructs a Trigger instance around the right trigger 1 button's digital signal.
178   *
179   * @return a Trigger instance representing the right trigger 1 button's digital signal attached
180   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
181   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
182   *     default scheduler} if a scheduler was not explicitly provided.
183   * @see #R1(EventLoop)
184   */
185  public Trigger R1() {
186    return R1(getScheduler().getDefaultEventLoop());
187  }
188
189  /**
190   * Constructs a Trigger instance around the right trigger 1 button's digital signal.
191   *
192   * @param loop the event loop instance to attach the event to.
193   * @return a Trigger instance representing the right trigger 1 button's digital signal attached
194   *     to the given loop.
195   */
196  public Trigger R1(EventLoop loop) {
197    return button(PS4Controller.Button.kR1.value, loop);
198  }
199
200  /**
201   * Constructs a Trigger instance around the left trigger 2 button's digital signal.
202   *
203   * @return a Trigger instance representing the left trigger 2 button's digital signal attached
204   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
205   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
206   *     default scheduler} if a scheduler was not explicitly provided.
207   * @see #L2(EventLoop)
208   */
209  public Trigger L2() {
210    return L2(getScheduler().getDefaultEventLoop());
211  }
212
213  /**
214   * Constructs a Trigger instance around the left trigger 2 button's digital signal.
215   *
216   * @param loop the event loop instance to attach the event to.
217   * @return a Trigger instance representing the left trigger 2 button's digital signal attached
218   *     to the given loop.
219   */
220  public Trigger L2(EventLoop loop) {
221    return button(PS4Controller.Button.kL2.value, loop);
222  }
223
224  /**
225   * Constructs a Trigger instance around the right trigger 2 button's digital signal.
226   *
227   * @return a Trigger instance representing the right trigger 2 button's digital signal attached
228   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
229   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
230   *     default scheduler} if a scheduler was not explicitly provided.
231   * @see #R2(EventLoop)
232   */
233  public Trigger R2() {
234    return R2(getScheduler().getDefaultEventLoop());
235  }
236
237  /**
238   * Constructs a Trigger instance around the right trigger 2 button's digital signal.
239   *
240   * @param loop the event loop instance to attach the event to.
241   * @return a Trigger instance representing the right trigger 2 button's digital signal attached
242   *     to the given loop.
243   */
244  public Trigger R2(EventLoop loop) {
245    return button(PS4Controller.Button.kR2.value, loop);
246  }
247
248  /**
249   * Constructs a Trigger instance around the share button's digital signal.
250   *
251   * @return a Trigger instance representing the share button's digital signal attached
252   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
253   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
254   *     default scheduler} if a scheduler was not explicitly provided.
255   * @see #share(EventLoop)
256   */
257  public Trigger share() {
258    return share(getScheduler().getDefaultEventLoop());
259  }
260
261  /**
262   * Constructs a Trigger instance around the share button's digital signal.
263   *
264   * @param loop the event loop instance to attach the event to.
265   * @return a Trigger instance representing the share button's digital signal attached
266   *     to the given loop.
267   */
268  public Trigger share(EventLoop loop) {
269    return button(PS4Controller.Button.kShare.value, loop);
270  }
271
272  /**
273   * Constructs a Trigger instance around the options button's digital signal.
274   *
275   * @return a Trigger instance representing the options button's digital signal attached
276   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
277   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
278   *     default scheduler} if a scheduler was not explicitly provided.
279   * @see #options(EventLoop)
280   */
281  public Trigger options() {
282    return options(getScheduler().getDefaultEventLoop());
283  }
284
285  /**
286   * Constructs a Trigger instance around the options button's digital signal.
287   *
288   * @param loop the event loop instance to attach the event to.
289   * @return a Trigger instance representing the options button's digital signal attached
290   *     to the given loop.
291   */
292  public Trigger options(EventLoop loop) {
293    return button(PS4Controller.Button.kOptions.value, loop);
294  }
295
296  /**
297   * Constructs a Trigger instance around the L3 (left stick) button's digital signal.
298   *
299   * @return a Trigger instance representing the L3 (left stick) button's digital signal attached
300   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
301   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
302   *     default scheduler} if a scheduler was not explicitly provided.
303   * @see #L3(EventLoop)
304   */
305  public Trigger L3() {
306    return L3(getScheduler().getDefaultEventLoop());
307  }
308
309  /**
310   * Constructs a Trigger instance around the L3 (left stick) button's digital signal.
311   *
312   * @param loop the event loop instance to attach the event to.
313   * @return a Trigger instance representing the L3 (left stick) button's digital signal attached
314   *     to the given loop.
315   */
316  public Trigger L3(EventLoop loop) {
317    return button(PS4Controller.Button.kL3.value, loop);
318  }
319
320  /**
321   * Constructs a Trigger instance around the R3 (right stick) button's digital signal.
322   *
323   * @return a Trigger instance representing the R3 (right stick) button's digital signal attached
324   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
325   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
326   *     default scheduler} if a scheduler was not explicitly provided.
327   * @see #R3(EventLoop)
328   */
329  public Trigger R3() {
330    return R3(getScheduler().getDefaultEventLoop());
331  }
332
333  /**
334   * Constructs a Trigger instance around the R3 (right stick) button's digital signal.
335   *
336   * @param loop the event loop instance to attach the event to.
337   * @return a Trigger instance representing the R3 (right stick) button's digital signal attached
338   *     to the given loop.
339   */
340  public Trigger R3(EventLoop loop) {
341    return button(PS4Controller.Button.kR3.value, loop);
342  }
343
344  /**
345   * Constructs a Trigger instance around the PlayStation button's digital signal.
346   *
347   * @return a Trigger instance representing the PlayStation button's digital signal attached
348   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
349   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
350   *     default scheduler} if a scheduler was not explicitly provided.
351   * @see #PS(EventLoop)
352   */
353  public Trigger PS() {
354    return PS(getScheduler().getDefaultEventLoop());
355  }
356
357  /**
358   * Constructs a Trigger instance around the PlayStation button's digital signal.
359   *
360   * @param loop the event loop instance to attach the event to.
361   * @return a Trigger instance representing the PlayStation button's digital signal attached
362   *     to the given loop.
363   */
364  public Trigger PS(EventLoop loop) {
365    return button(PS4Controller.Button.kPS.value, loop);
366  }
367
368  /**
369   * Constructs a Trigger instance around the touchpad button's digital signal.
370   *
371   * @return a Trigger instance representing the touchpad button's digital signal attached
372   *     to the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the
373   *     scheduler passed to the controller's constructor, or the {@link Scheduler#getDefault
374   *     default scheduler} if a scheduler was not explicitly provided.
375   * @see #touchpad(EventLoop)
376   */
377  public Trigger touchpad() {
378    return touchpad(getScheduler().getDefaultEventLoop());
379  }
380
381  /**
382   * Constructs a Trigger instance around the touchpad button's digital signal.
383   *
384   * @param loop the event loop instance to attach the event to.
385   * @return a Trigger instance representing the touchpad button's digital signal attached
386   *     to the given loop.
387   */
388  public Trigger touchpad(EventLoop loop) {
389    return button(PS4Controller.Button.kTouchpad.value, loop);
390  }
391
392  /**
393   * Get the X axis value of left side of the controller. Right is positive.
394   *
395   * @return The axis value.
396   */
397  public double getLeftX() {
398    return m_hid.getLeftX();
399  }
400
401  /**
402   * Get the Y axis value of left side of the controller. Back is positive.
403   *
404   * @return The axis value.
405   */
406  public double getLeftY() {
407    return m_hid.getLeftY();
408  }
409
410  /**
411   * Get the X axis value of right side of the controller. Right is positive.
412   *
413   * @return The axis value.
414   */
415  public double getRightX() {
416    return m_hid.getRightX();
417  }
418
419  /**
420   * Get the Y axis value of right side of the controller. Back is positive.
421   *
422   * @return The axis value.
423   */
424  public double getRightY() {
425    return m_hid.getRightY();
426  }
427
428  /**
429   * Get the left trigger 2 axis value of the controller. Note that this axis is bound to the
430   * range of [0, 1] as opposed to the usual [-1, 1].
431   *
432   * @return The axis value.
433   */
434  public double getL2Axis() {
435    return m_hid.getL2Axis();
436  }
437
438  /**
439   * Get the right trigger 2 axis value of the controller. Note that this axis is bound to the
440   * range of [0, 1] as opposed to the usual [-1, 1].
441   *
442   * @return The axis value.
443   */
444  public double getR2Axis() {
445    return m_hid.getR2Axis();
446  }
447}