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.wpilibj2.command.button;
006
007import edu.wpi.first.wpilibj.StadiaController;
008import edu.wpi.first.wpilibj.event.EventLoop;
009import edu.wpi.first.wpilibj2.command.CommandScheduler;
010
011/**
012 * A version of {@link StadiaController} with {@link Trigger} factories for command-based.
013 *
014 * @see StadiaController
015 */
016@SuppressWarnings("MethodName")
017public class CommandStadiaController extends CommandGenericHID {
018  private final StadiaController m_hid;
019
020  /**
021   * Construct an instance of a controller.
022   *
023   * @param port The port index on the Driver Station that the controller is plugged into.
024   */
025  public CommandStadiaController(int port) {
026    super(port);
027    m_hid = new StadiaController(port);
028  }
029
030  /**
031   * Get the underlying GenericHID object.
032   *
033   * @return the wrapped GenericHID object
034   */
035  @Override
036  public StadiaController getHID() {
037    return m_hid;
038  }
039
040  /**
041   * Constructs an event instance around the left bumper's digital signal.
042   *
043   * @return an event instance representing the left bumper's digital signal attached to the {@link
044   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
045   * @see #leftBumper(EventLoop)
046   */
047  public Trigger leftBumper() {
048    return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop());
049  }
050
051  /**
052   * Constructs an event instance around the left bumper's digital signal.
053   *
054   * @param loop the event loop instance to attach the event to.
055   * @return an event instance representing the right bumper's digital signal attached to the given
056   *     loop.
057   */
058  public Trigger leftBumper(EventLoop loop) {
059    return m_hid.leftBumper(loop).castTo(Trigger::new);
060  }
061
062  /**
063   * Constructs an event instance around the right bumper's digital signal.
064   *
065   * @return an event instance representing the right bumper's digital signal attached to the {@link
066   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
067   * @see #rightBumper(EventLoop)
068   */
069  public Trigger rightBumper() {
070    return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop());
071  }
072
073  /**
074   * Constructs an event instance around the right bumper's digital signal.
075   *
076   * @param loop the event loop instance to attach the event to.
077   * @return an event instance representing the left bumper's digital signal attached to the given
078   *     loop.
079   */
080  public Trigger rightBumper(EventLoop loop) {
081    return m_hid.rightBumper(loop).castTo(Trigger::new);
082  }
083
084  /**
085   * Constructs an event instance around the left stick button's digital signal.
086   *
087   * @return an event instance representing the left stick button's digital signal attached to the
088   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
089   * @see #leftStick(EventLoop)
090   */
091  public Trigger leftStick() {
092    return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop());
093  }
094
095  /**
096   * Constructs an event instance around the left stick button's digital signal.
097   *
098   * @param loop the event loop instance to attach the event to.
099   * @return an event instance representing the left stick button's digital signal attached to the
100   *     given loop.
101   */
102  public Trigger leftStick(EventLoop loop) {
103    return m_hid.leftStick(loop).castTo(Trigger::new);
104  }
105
106  /**
107   * Constructs an event instance around the right stick button's digital signal.
108   *
109   * @return an event instance representing the right stick button's digital signal attached to the
110   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
111   * @see #rightStick(EventLoop)
112   */
113  public Trigger rightStick() {
114    return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop());
115  }
116
117  /**
118   * Constructs an event instance around the right stick button's digital signal.
119   *
120   * @param loop the event loop instance to attach the event to.
121   * @return an event instance representing the right stick button's digital signal attached to the
122   *     given loop.
123   */
124  public Trigger rightStick(EventLoop loop) {
125    return m_hid.rightStick(loop).castTo(Trigger::new);
126  }
127
128  /**
129   * Constructs an event instance around the right trigger button's digital signal.
130   *
131   * @return an event instance representing the right trigger button's digital signal attached to
132   *     the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
133   * @see #rightTrigger(EventLoop)
134   */
135  public Trigger rightTrigger() {
136    return rightTrigger(CommandScheduler.getInstance().getDefaultButtonLoop());
137  }
138
139  /**
140   * Constructs an event instance around the right trigger button's digital signal.
141   *
142   * @param loop the event loop instance to attach the event to.
143   * @return an event instance representing the right trigger button's digital signal attached to
144   *     the given loop.
145   */
146  public Trigger rightTrigger(EventLoop loop) {
147    return m_hid.rightTrigger(loop).castTo(Trigger::new);
148  }
149
150  /**
151   * Constructs an event instance around the left trigger button's digital signal.
152   *
153   * @return an event instance representing the left trigger button's digital signal attached to the
154   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
155   * @see #leftTrigger(EventLoop)
156   */
157  public Trigger leftTrigger() {
158    return leftTrigger(CommandScheduler.getInstance().getDefaultButtonLoop());
159  }
160
161  /**
162   * Constructs an event instance around the left trigger button's digital signal.
163   *
164   * @param loop the event loop instance to attach the event to.
165   * @return an event instance representing the left trigger button's digital signal attached to the
166   *     given loop.
167   */
168  public Trigger leftTrigger(EventLoop loop) {
169    return m_hid.leftTrigger(loop).castTo(Trigger::new);
170  }
171
172  /**
173   * Constructs an event instance around the A button's digital signal.
174   *
175   * @return an event instance representing the A button's digital signal attached to the {@link
176   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
177   * @see #a(EventLoop)
178   */
179  public Trigger a() {
180    return a(CommandScheduler.getInstance().getDefaultButtonLoop());
181  }
182
183  /**
184   * Constructs an event instance around the A button's digital signal.
185   *
186   * @param loop the event loop instance to attach the event to.
187   * @return an event instance representing the A button's digital signal attached to the given
188   *     loop.
189   */
190  public Trigger a(EventLoop loop) {
191    return m_hid.a(loop).castTo(Trigger::new);
192  }
193
194  /**
195   * Constructs an event instance around the B button's digital signal.
196   *
197   * @return an event instance representing the B button's digital signal attached to the {@link
198   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
199   * @see #b(EventLoop)
200   */
201  public Trigger b() {
202    return b(CommandScheduler.getInstance().getDefaultButtonLoop());
203  }
204
205  /**
206   * Constructs an event instance around the B button's digital signal.
207   *
208   * @param loop the event loop instance to attach the event to.
209   * @return an event instance representing the B button's digital signal attached to the given
210   *     loop.
211   */
212  public Trigger b(EventLoop loop) {
213    return m_hid.b(loop).castTo(Trigger::new);
214  }
215
216  /**
217   * Constructs an event instance around the X button's digital signal.
218   *
219   * @return an event instance representing the X button's digital signal attached to the {@link
220   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
221   * @see #x(EventLoop)
222   */
223  public Trigger x() {
224    return x(CommandScheduler.getInstance().getDefaultButtonLoop());
225  }
226
227  /**
228   * Constructs an event instance around the X button's digital signal.
229   *
230   * @param loop the event loop instance to attach the event to.
231   * @return an event instance representing the X button's digital signal attached to the given
232   *     loop.
233   */
234  public Trigger x(EventLoop loop) {
235    return m_hid.x(loop).castTo(Trigger::new);
236  }
237
238  /**
239   * Constructs an event instance around the Y button's digital signal.
240   *
241   * @return an event instance representing the Y button's digital signal attached to the {@link
242   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
243   * @see #y(EventLoop)
244   */
245  public Trigger y() {
246    return y(CommandScheduler.getInstance().getDefaultButtonLoop());
247  }
248
249  /**
250   * Constructs an event instance around the Y button's digital signal.
251   *
252   * @param loop the event loop instance to attach the event to.
253   * @return an event instance representing the Y button's digital signal attached to the given
254   *     loop.
255   */
256  public Trigger y(EventLoop loop) {
257    return m_hid.y(loop).castTo(Trigger::new);
258  }
259
260  /**
261   * Constructs an event instance around the ellipses button's digital signal.
262   *
263   * @return an event instance representing the ellipses button's digital signal attached to the
264   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
265   * @see #ellipses(EventLoop)
266   */
267  public Trigger ellipses() {
268    return ellipses(CommandScheduler.getInstance().getDefaultButtonLoop());
269  }
270
271  /**
272   * Constructs an event instance around the ellipses button's digital signal.
273   *
274   * @param loop the event loop instance to attach the event to.
275   * @return an event instance representing the ellipses button's digital signal attached to the
276   *     given loop.
277   */
278  public Trigger ellipses(EventLoop loop) {
279    return m_hid.ellipses(loop).castTo(Trigger::new);
280  }
281
282  /**
283   * Constructs an event instance around the stadia button's digital signal.
284   *
285   * @return an event instance representing the stadia button's digital signal attached to the
286   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
287   * @see #stadia(EventLoop)
288   */
289  public Trigger stadia() {
290    return stadia(CommandScheduler.getInstance().getDefaultButtonLoop());
291  }
292
293  /**
294   * Constructs an event instance around the stadia button's digital signal.
295   *
296   * @param loop the event loop instance to attach the event to.
297   * @return an event instance representing the stadia button's digital signal attached to the given
298   *     loop.
299   */
300  public Trigger stadia(EventLoop loop) {
301    return m_hid.stadia(loop).castTo(Trigger::new);
302  }
303
304  /**
305   * Constructs an event instance around the google button's digital signal.
306   *
307   * @return an event instance representing the google button's digital signal attached to the
308   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
309   * @see #google(EventLoop)
310   */
311  public Trigger google() {
312    return google(CommandScheduler.getInstance().getDefaultButtonLoop());
313  }
314
315  /**
316   * Constructs an event instance around the google button's digital signal.
317   *
318   * @param loop the event loop instance to attach the event to.
319   * @return an event instance representing the google button's digital signal attached to the given
320   *     loop.
321   */
322  public Trigger google(EventLoop loop) {
323    return m_hid.google(loop).castTo(Trigger::new);
324  }
325
326  /**
327   * Constructs an event instance around the frame button's digital signal.
328   *
329   * @return an event instance representing the frame button's digital signal attached to the {@link
330   *     CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
331   * @see #frame(EventLoop)
332   */
333  public Trigger frame() {
334    return frame(CommandScheduler.getInstance().getDefaultButtonLoop());
335  }
336
337  /**
338   * Constructs an event instance around the frame button's digital signal.
339   *
340   * @param loop the event loop instance to attach the event to.
341   * @return an event instance representing the frame button's digital signal attached to the given
342   *     loop.
343   */
344  public Trigger frame(EventLoop loop) {
345    return m_hid.frame(loop).castTo(Trigger::new);
346  }
347
348  /**
349   * Constructs an event instance around the hamburger button's digital signal.
350   *
351   * @return an event instance representing the hamburger button's digital signal attached to the
352   *     {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
353   * @see #hamburger(EventLoop)
354   */
355  public Trigger hamburger() {
356    return hamburger(CommandScheduler.getInstance().getDefaultButtonLoop());
357  }
358
359  /**
360   * Constructs an event instance around the hamburger button's digital signal.
361   *
362   * @param loop the event loop instance to attach the event to.
363   * @return an event instance representing the hamburger button's digital signal attached to the
364   *     given loop.
365   */
366  public Trigger hamburger(EventLoop loop) {
367    return m_hid.hamburger(loop).castTo(Trigger::new);
368  }
369
370  /**
371   * Get the X axis value of left side of the controller.
372   *
373   * @return The axis value.
374   */
375  public double getLeftX() {
376    return m_hid.getLeftX();
377  }
378
379  /**
380   * Get the X axis value of right side of the controller.
381   *
382   * @return The axis value.
383   */
384  public double getRightX() {
385    return m_hid.getRightX();
386  }
387
388  /**
389   * Get the Y axis value of left side of the controller.
390   *
391   * @return The axis value.
392   */
393  public double getLeftY() {
394    return m_hid.getLeftY();
395  }
396
397  /**
398   * Get the Y axis value of right side of the controller.
399   *
400   * @return The axis value.
401   */
402  public double getRightY() {
403    return m_hid.getRightY();
404  }
405}