WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
Gamepad.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
10
11namespace wpi {
12
13/**
14 * Handle input from Gamepad controllers connected to the Driver Station.
15 *
16 * This class handles Gamepad input that comes from the Driver Station. Each
17 * time a value is requested the most recent value is returned. There is a
18 * single class instance for each controller and the mapping of ports to
19 * hardware buttons depends on the code in the Driver Station.
20 *
21 * Only first party controllers from Generic are guaranteed to have the
22 * correct mapping, and only through the official NI DS. Sim is not guaranteed
23 * to have the same mapping, as well as any 3rd party controllers.
24 */
25class Gamepad : public GenericHID,
27 public wpi::util::SendableHelper<Gamepad> {
28 public:
29 /** Represents a digital button on an Gamepad. */
30 enum class Button {
31 /// South Face button.
33 /// East Face button.
35 /// West Face button.
37 /// North Face button.
39 /// Back button.
40 BACK = 4,
41 /// Guide button.
42 GUIDE = 5,
43 /// Start button.
44 START = 6,
45 /// Left stick button.
47 /// Right stick button.
49 /// Left bumper button.
51 /// Right bumper button.
53 /// D-pad up button.
54 DPAD_UP = 11,
55 /// D-pad down button.
57 /// D-pad left button.
59 /// D-pad right button.
61 /// Miscellaneous 1 button.
62 MISC_1 = 15,
63 /// Right Paddle 1 button.
65 /// Left Paddle 1 button.
67 /// Right Paddle 2 button.
69 /// Left Paddle 2 button.
71 /// Touchpad button.
73 /// Miscellaneous 2 button.
74 MISC_2 = 21,
75 /// Miscellaneous 3 button.
76 MISC_3 = 22,
77 /// Miscellaneous 4 button.
78 MISC_4 = 23,
79 /// Miscellaneous 5 button.
80 MISC_5 = 24,
81 /// Miscellaneous 6 button.
82 MISC_6 = 25,
83 };
84
85 /** Represents an axis on an Gamepad. */
86 enum class Axis {
87 /// Left X axis.
88 LEFT_X = 0,
89 /// Left Y axis.
90 LEFT_Y = 1,
91 /// Right X axis.
93 /// Right Y axis.
95 /// Left trigger.
97 /// Right trigger.
99 };
100
101 /**
102 * Construct an instance of a controller.
103 *
104 * The controller index is the USB port on the Driver Station.
105 *
106 * @param port The port on the Driver Station that the controller is plugged
107 * into (0-5).
108 */
109 explicit Gamepad(int port);
110
111 ~Gamepad() override = default;
112
113 Gamepad(Gamepad&&) = default;
114 Gamepad& operator=(Gamepad&&) = default;
115
116 /**
117 * Get the X axis value of left side of the controller. Right is positive.
118 *
119 * @return the axis value.
120 */
121 double GetLeftX() const;
122
123 /**
124 * Get the Y axis value of left side of the controller. Back is positive.
125 *
126 * @return the axis value.
127 */
128 double GetLeftY() const;
129
130 /**
131 * Get the X axis value of right side of the controller. Right is positive.
132 *
133 * @return the axis value.
134 */
135 double GetRightX() const;
136
137 /**
138 * Get the Y axis value of right side of the controller. Back is positive.
139 *
140 * @return the axis value.
141 */
142 double GetRightY() const;
143
144 /**
145 * Get the left trigger axis value of the controller. Note that this axis
146 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
147 *
148 * @return the axis value.
149 */
150 double GetLeftTriggerAxis() const;
151
152 /**
153 * Constructs an event instance around the axis value of the left trigger.
154 * The returned trigger will be true when the axis value is greater than
155 * {@code threshold}.
156 * @param threshold the minimum axis value for the returned event to be true.
157 * This value should be in the range [0, 1] where 0 is the unpressed state of
158 * the axis.
159 * @param loop the event loop instance to attach the event to.
160 * @return an event instance that is true when the left trigger's axis
161 * exceeds the provided threshold, attached to the given event loop
162 */
163 BooleanEvent LeftTrigger(double threshold, EventLoop* loop) const;
164
165 /**
166 * Constructs an event instance around the axis value of the left trigger.
167 * The returned trigger will be true when the axis value is greater than 0.5.
168 * @param loop the event loop instance to attach the event to.
169 * @return an event instance that is true when the left trigger's axis
170 * exceeds 0.5, attached to the given event loop
171 */
173
174 /**
175 * Get the right trigger axis value of the controller. Note that this axis
176 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
177 *
178 * @return the axis value.
179 */
180 double GetRightTriggerAxis() const;
181
182 /**
183 * Constructs an event instance around the axis value of the right trigger.
184 * The returned trigger will be true when the axis value is greater than
185 * {@code threshold}.
186 * @param threshold the minimum axis value for the returned event to be true.
187 * This value should be in the range [0, 1] where 0 is the unpressed state of
188 * the axis.
189 * @param loop the event loop instance to attach the event to.
190 * @return an event instance that is true when the right trigger's axis
191 * exceeds the provided threshold, attached to the given event loop
192 */
193 BooleanEvent RightTrigger(double threshold, EventLoop* loop) const;
194
195 /**
196 * Constructs an event instance around the axis value of the right trigger.
197 * The returned trigger will be true when the axis value is greater than 0.5.
198 * @param loop the event loop instance to attach the event to.
199 * @return an event instance that is true when the right trigger's axis
200 * exceeds 0.5, attached to the given event loop
201 */
203
204 /**
205 * Read the value of the South Face button on the controller.
206 *
207 * @return The state of the button.
208 */
209 bool GetSouthFaceButton() const;
210
211 /**
212 * Whether the South Face button was pressed since the last check.
213 *
214 * @return Whether the button was pressed since the last check.
215 */
217
218 /**
219 * Whether the South Face button was released since the last check.
220 *
221 * @return Whether the button was released since the last check.
222 */
224
225 /**
226 * Constructs an event instance around the South Face button's
227 * digital signal.
228 *
229 * @param loop the event loop instance to attach the event to.
230 * @return an event instance representing the South Face button's
231 * digital signal attached to the given loop.
232 */
234
235 /**
236 * Read the value of the East Face button on the controller.
237 *
238 * @return The state of the button.
239 */
240 bool GetEastFaceButton() const;
241
242 /**
243 * Whether the East Face button was pressed since the last check.
244 *
245 * @return Whether the button was pressed since the last check.
246 */
248
249 /**
250 * Whether the East Face button was released since the last check.
251 *
252 * @return Whether the button was released since the last check.
253 */
255
256 /**
257 * Constructs an event instance around the East Face button's
258 * digital signal.
259 *
260 * @param loop the event loop instance to attach the event to.
261 * @return an event instance representing the East Face button's
262 * digital signal attached to the given loop.
263 */
265
266 /**
267 * Read the value of the West Face button on the controller.
268 *
269 * @return The state of the button.
270 */
271 bool GetWestFaceButton() const;
272
273 /**
274 * Whether the West Face button was pressed since the last check.
275 *
276 * @return Whether the button was pressed since the last check.
277 */
279
280 /**
281 * Whether the West Face button was released since the last check.
282 *
283 * @return Whether the button was released since the last check.
284 */
286
287 /**
288 * Constructs an event instance around the West Face button's
289 * digital signal.
290 *
291 * @param loop the event loop instance to attach the event to.
292 * @return an event instance representing the West Face button's
293 * digital signal attached to the given loop.
294 */
296
297 /**
298 * Read the value of the North Face button on the controller.
299 *
300 * @return The state of the button.
301 */
302 bool GetNorthFaceButton() const;
303
304 /**
305 * Whether the North Face button was pressed since the last check.
306 *
307 * @return Whether the button was pressed since the last check.
308 */
310
311 /**
312 * Whether the North Face button was released since the last check.
313 *
314 * @return Whether the button was released since the last check.
315 */
317
318 /**
319 * Constructs an event instance around the North Face button's
320 * digital signal.
321 *
322 * @param loop the event loop instance to attach the event to.
323 * @return an event instance representing the North Face button's
324 * digital signal attached to the given loop.
325 */
327
328 /**
329 * Read the value of the Back button on the controller.
330 *
331 * @return The state of the button.
332 */
333 bool GetBackButton() const;
334
335 /**
336 * Whether the Back button was pressed since the last check.
337 *
338 * @return Whether the button was pressed since the last check.
339 */
341
342 /**
343 * Whether the Back button was released since the last check.
344 *
345 * @return Whether the button was released since the last check.
346 */
348
349 /**
350 * Constructs an event instance around the Back button's
351 * digital signal.
352 *
353 * @param loop the event loop instance to attach the event to.
354 * @return an event instance representing the Back button's
355 * digital signal attached to the given loop.
356 */
358
359 /**
360 * Read the value of the Guide button on the controller.
361 *
362 * @return The state of the button.
363 */
364 bool GetGuideButton() const;
365
366 /**
367 * Whether the Guide button was pressed since the last check.
368 *
369 * @return Whether the button was pressed since the last check.
370 */
372
373 /**
374 * Whether the Guide button was released since the last check.
375 *
376 * @return Whether the button was released since the last check.
377 */
379
380 /**
381 * Constructs an event instance around the Guide button's
382 * digital signal.
383 *
384 * @param loop the event loop instance to attach the event to.
385 * @return an event instance representing the Guide button's
386 * digital signal attached to the given loop.
387 */
389
390 /**
391 * Read the value of the Start button on the controller.
392 *
393 * @return The state of the button.
394 */
395 bool GetStartButton() const;
396
397 /**
398 * Whether the Start button was pressed since the last check.
399 *
400 * @return Whether the button was pressed since the last check.
401 */
403
404 /**
405 * Whether the Start button was released since the last check.
406 *
407 * @return Whether the button was released since the last check.
408 */
410
411 /**
412 * Constructs an event instance around the Start button's
413 * digital signal.
414 *
415 * @param loop the event loop instance to attach the event to.
416 * @return an event instance representing the Start button's
417 * digital signal attached to the given loop.
418 */
420
421 /**
422 * Read the value of the left stick button on the controller.
423 *
424 * @return The state of the button.
425 */
426 bool GetLeftStickButton() const;
427
428 /**
429 * Whether the left stick button was pressed since the last check.
430 *
431 * @return Whether the button was pressed since the last check.
432 */
434
435 /**
436 * Whether the left stick button was released since the last check.
437 *
438 * @return Whether the button was released since the last check.
439 */
441
442 /**
443 * Constructs an event instance around the left stick button's
444 * digital signal.
445 *
446 * @param loop the event loop instance to attach the event to.
447 * @return an event instance representing the left stick button's
448 * digital signal attached to the given loop.
449 */
451
452 /**
453 * Read the value of the right stick button on the controller.
454 *
455 * @return The state of the button.
456 */
458
459 /**
460 * Whether the right stick button was pressed since the last check.
461 *
462 * @return Whether the button was pressed since the last check.
463 */
465
466 /**
467 * Whether the right stick button was released since the last check.
468 *
469 * @return Whether the button was released since the last check.
470 */
472
473 /**
474 * Constructs an event instance around the right stick button's
475 * digital signal.
476 *
477 * @param loop the event loop instance to attach the event to.
478 * @return an event instance representing the right stick button's
479 * digital signal attached to the given loop.
480 */
482
483 /**
484 * Read the value of the right bumper button on the controller.
485 *
486 * @return The state of the button.
487 */
489
490 /**
491 * Whether the right bumper button was pressed since the last check.
492 *
493 * @return Whether the button was pressed since the last check.
494 */
496
497 /**
498 * Whether the right bumper button was released since the last check.
499 *
500 * @return Whether the button was released since the last check.
501 */
503
504 /**
505 * Constructs an event instance around the right bumper button's
506 * digital signal.
507 *
508 * @param loop the event loop instance to attach the event to.
509 * @return an event instance representing the right bumper button's
510 * digital signal attached to the given loop.
511 */
513
514 /**
515 * Read the value of the right bumper button on the controller.
516 *
517 * @return The state of the button.
518 */
520
521 /**
522 * Whether the right bumper button was pressed since the last check.
523 *
524 * @return Whether the button was pressed since the last check.
525 */
527
528 /**
529 * Whether the right bumper button was released since the last check.
530 *
531 * @return Whether the button was released since the last check.
532 */
534
535 /**
536 * Constructs an event instance around the right bumper button's
537 * digital signal.
538 *
539 * @param loop the event loop instance to attach the event to.
540 * @return an event instance representing the right bumper button's
541 * digital signal attached to the given loop.
542 */
544
545 /**
546 * Read the value of the D-pad up button on the controller.
547 *
548 * @return The state of the button.
549 */
550 bool GetDpadUpButton() const;
551
552 /**
553 * Whether the D-pad up button was pressed since the last check.
554 *
555 * @return Whether the button was pressed since the last check.
556 */
558
559 /**
560 * Whether the D-pad up button was released since the last check.
561 *
562 * @return Whether the button was released since the last check.
563 */
565
566 /**
567 * Constructs an event instance around the D-pad up button's
568 * digital signal.
569 *
570 * @param loop the event loop instance to attach the event to.
571 * @return an event instance representing the D-pad up button's
572 * digital signal attached to the given loop.
573 */
575
576 /**
577 * Read the value of the D-pad down button on the controller.
578 *
579 * @return The state of the button.
580 */
581 bool GetDpadDownButton() const;
582
583 /**
584 * Whether the D-pad down button was pressed since the last check.
585 *
586 * @return Whether the button was pressed since the last check.
587 */
589
590 /**
591 * Whether the D-pad down button was released since the last check.
592 *
593 * @return Whether the button was released since the last check.
594 */
596
597 /**
598 * Constructs an event instance around the D-pad down button's
599 * digital signal.
600 *
601 * @param loop the event loop instance to attach the event to.
602 * @return an event instance representing the D-pad down button's
603 * digital signal attached to the given loop.
604 */
606
607 /**
608 * Read the value of the D-pad left button on the controller.
609 *
610 * @return The state of the button.
611 */
612 bool GetDpadLeftButton() const;
613
614 /**
615 * Whether the D-pad left button was pressed since the last check.
616 *
617 * @return Whether the button was pressed since the last check.
618 */
620
621 /**
622 * Whether the D-pad left button was released since the last check.
623 *
624 * @return Whether the button was released since the last check.
625 */
627
628 /**
629 * Constructs an event instance around the D-pad left button's
630 * digital signal.
631 *
632 * @param loop the event loop instance to attach the event to.
633 * @return an event instance representing the D-pad left button's
634 * digital signal attached to the given loop.
635 */
637
638 /**
639 * Read the value of the D-pad right button on the controller.
640 *
641 * @return The state of the button.
642 */
643 bool GetDpadRightButton() const;
644
645 /**
646 * Whether the D-pad right button was pressed since the last check.
647 *
648 * @return Whether the button was pressed since the last check.
649 */
651
652 /**
653 * Whether the D-pad right button was released since the last check.
654 *
655 * @return Whether the button was released since the last check.
656 */
658
659 /**
660 * Constructs an event instance around the D-pad right button's
661 * digital signal.
662 *
663 * @param loop the event loop instance to attach the event to.
664 * @return an event instance representing the D-pad right button's
665 * digital signal attached to the given loop.
666 */
668
669 /**
670 * Read the value of the Miscellaneous 1 button on the controller.
671 *
672 * @return The state of the button.
673 */
674 bool GetMisc1Button() const;
675
676 /**
677 * Whether the Miscellaneous 1 button was pressed since the last check.
678 *
679 * @return Whether the button was pressed since the last check.
680 */
682
683 /**
684 * Whether the Miscellaneous 1 button was released since the last check.
685 *
686 * @return Whether the button was released since the last check.
687 */
689
690 /**
691 * Constructs an event instance around the Miscellaneous 1 button's
692 * digital signal.
693 *
694 * @param loop the event loop instance to attach the event to.
695 * @return an event instance representing the Miscellaneous 1 button's
696 * digital signal attached to the given loop.
697 */
699
700 /**
701 * Read the value of the Right Paddle 1 button on the controller.
702 *
703 * @return The state of the button.
704 */
706
707 /**
708 * Whether the Right Paddle 1 button was pressed since the last check.
709 *
710 * @return Whether the button was pressed since the last check.
711 */
713
714 /**
715 * Whether the Right Paddle 1 button was released since the last check.
716 *
717 * @return Whether the button was released since the last check.
718 */
720
721 /**
722 * Constructs an event instance around the Right Paddle 1 button's
723 * digital signal.
724 *
725 * @param loop the event loop instance to attach the event to.
726 * @return an event instance representing the Right Paddle 1 button's
727 * digital signal attached to the given loop.
728 */
730
731 /**
732 * Read the value of the Left Paddle 1 button on the controller.
733 *
734 * @return The state of the button.
735 */
737
738 /**
739 * Whether the Left Paddle 1 button was pressed since the last check.
740 *
741 * @return Whether the button was pressed since the last check.
742 */
744
745 /**
746 * Whether the Left Paddle 1 button was released since the last check.
747 *
748 * @return Whether the button was released since the last check.
749 */
751
752 /**
753 * Constructs an event instance around the Left Paddle 1 button's
754 * digital signal.
755 *
756 * @param loop the event loop instance to attach the event to.
757 * @return an event instance representing the Left Paddle 1 button's
758 * digital signal attached to the given loop.
759 */
761
762 /**
763 * Read the value of the Right Paddle 2 button on the controller.
764 *
765 * @return The state of the button.
766 */
768
769 /**
770 * Whether the Right Paddle 2 button was pressed since the last check.
771 *
772 * @return Whether the button was pressed since the last check.
773 */
775
776 /**
777 * Whether the Right Paddle 2 button was released since the last check.
778 *
779 * @return Whether the button was released since the last check.
780 */
782
783 /**
784 * Constructs an event instance around the Right Paddle 2 button's
785 * digital signal.
786 *
787 * @param loop the event loop instance to attach the event to.
788 * @return an event instance representing the Right Paddle 2 button's
789 * digital signal attached to the given loop.
790 */
792
793 /**
794 * Read the value of the Left Paddle 2 button on the controller.
795 *
796 * @return The state of the button.
797 */
799
800 /**
801 * Whether the Left Paddle 2 button was pressed since the last check.
802 *
803 * @return Whether the button was pressed since the last check.
804 */
806
807 /**
808 * Whether the Left Paddle 2 button was released since the last check.
809 *
810 * @return Whether the button was released since the last check.
811 */
813
814 /**
815 * Constructs an event instance around the Left Paddle 2 button's
816 * digital signal.
817 *
818 * @param loop the event loop instance to attach the event to.
819 * @return an event instance representing the Left Paddle 2 button's
820 * digital signal attached to the given loop.
821 */
823
824 /**
825 * Read the value of the Touchpad button on the controller.
826 *
827 * @return The state of the button.
828 */
829 bool GetTouchpadButton() const;
830
831 /**
832 * Whether the Touchpad button was pressed since the last check.
833 *
834 * @return Whether the button was pressed since the last check.
835 */
837
838 /**
839 * Whether the Touchpad button was released since the last check.
840 *
841 * @return Whether the button was released since the last check.
842 */
844
845 /**
846 * Constructs an event instance around the Touchpad button's
847 * digital signal.
848 *
849 * @param loop the event loop instance to attach the event to.
850 * @return an event instance representing the Touchpad button's
851 * digital signal attached to the given loop.
852 */
854
855 /**
856 * Read the value of the Miscellaneous 2 button on the controller.
857 *
858 * @return The state of the button.
859 */
860 bool GetMisc2Button() const;
861
862 /**
863 * Whether the Miscellaneous 2 button was pressed since the last check.
864 *
865 * @return Whether the button was pressed since the last check.
866 */
868
869 /**
870 * Whether the Miscellaneous 2 button was released since the last check.
871 *
872 * @return Whether the button was released since the last check.
873 */
875
876 /**
877 * Constructs an event instance around the Miscellaneous 2 button's
878 * digital signal.
879 *
880 * @param loop the event loop instance to attach the event to.
881 * @return an event instance representing the Miscellaneous 2 button's
882 * digital signal attached to the given loop.
883 */
885
886 /**
887 * Read the value of the Miscellaneous 3 button on the controller.
888 *
889 * @return The state of the button.
890 */
891 bool GetMisc3Button() const;
892
893 /**
894 * Whether the Miscellaneous 3 button was pressed since the last check.
895 *
896 * @return Whether the button was pressed since the last check.
897 */
899
900 /**
901 * Whether the Miscellaneous 3 button was released since the last check.
902 *
903 * @return Whether the button was released since the last check.
904 */
906
907 /**
908 * Constructs an event instance around the Miscellaneous 3 button's
909 * digital signal.
910 *
911 * @param loop the event loop instance to attach the event to.
912 * @return an event instance representing the Miscellaneous 3 button's
913 * digital signal attached to the given loop.
914 */
916
917 /**
918 * Read the value of the Miscellaneous 4 button on the controller.
919 *
920 * @return The state of the button.
921 */
922 bool GetMisc4Button() const;
923
924 /**
925 * Whether the Miscellaneous 4 button was pressed since the last check.
926 *
927 * @return Whether the button was pressed since the last check.
928 */
930
931 /**
932 * Whether the Miscellaneous 4 button was released since the last check.
933 *
934 * @return Whether the button was released since the last check.
935 */
937
938 /**
939 * Constructs an event instance around the Miscellaneous 4 button's
940 * digital signal.
941 *
942 * @param loop the event loop instance to attach the event to.
943 * @return an event instance representing the Miscellaneous 4 button's
944 * digital signal attached to the given loop.
945 */
947
948 /**
949 * Read the value of the Miscellaneous 5 button on the controller.
950 *
951 * @return The state of the button.
952 */
953 bool GetMisc5Button() const;
954
955 /**
956 * Whether the Miscellaneous 5 button was pressed since the last check.
957 *
958 * @return Whether the button was pressed since the last check.
959 */
961
962 /**
963 * Whether the Miscellaneous 5 button was released since the last check.
964 *
965 * @return Whether the button was released since the last check.
966 */
968
969 /**
970 * Constructs an event instance around the Miscellaneous 5 button's
971 * digital signal.
972 *
973 * @param loop the event loop instance to attach the event to.
974 * @return an event instance representing the Miscellaneous 5 button's
975 * digital signal attached to the given loop.
976 */
978
979 /**
980 * Read the value of the Miscellaneous 6 button on the controller.
981 *
982 * @return The state of the button.
983 */
984 bool GetMisc6Button() const;
985
986 /**
987 * Whether the Miscellaneous 6 button was pressed since the last check.
988 *
989 * @return Whether the button was pressed since the last check.
990 */
992
993 /**
994 * Whether the Miscellaneous 6 button was released since the last check.
995 *
996 * @return Whether the button was released since the last check.
997 */
999
1000 /**
1001 * Constructs an event instance around the Miscellaneous 6 button's
1002 * digital signal.
1003 *
1004 * @param loop the event loop instance to attach the event to.
1005 * @return an event instance representing the Miscellaneous 6 button's
1006 * digital signal attached to the given loop.
1007 */
1009
1010 /**
1011 * Get the button value.
1012 *
1013 * This method returns true if the button is being held down at the time
1014 * that this method is being called.
1015 *
1016 * @param button The button
1017 * @return The state of the button.
1018 */
1019 bool GetButton(Button button) const;
1020
1021 /**
1022 * Whether the button was pressed since the last check.
1023 *
1024 * This method returns true if the button went from not pressed to held down
1025 * since the last time this method was called. This is useful if you only
1026 * want to call a function once when you press the button.
1027 *
1028 * @param button The button
1029 * @return Whether the button was pressed since the last check.
1030 */
1032
1033 /**
1034 * Whether the button was released since the last check.
1035 *
1036 * This method returns true if the button went from held down to not pressed
1037 * since the last time this method was called. This is useful if you only
1038 * want to call a function once when you release the button.
1039 *
1040 * @param button The button
1041 * @return Whether the button was released since the last check.
1042 */
1044
1045 /**
1046 * Constructs an event instance around this button's digital signal.
1047 *
1048 * @param button the button
1049 * @param loop the event loop instance to attach the event to.
1050 * @return an event instance representing the button's digital signal attached
1051 * to the given loop.
1052 */
1054
1055 /**
1056 * Get the value of the axis.
1057 *
1058 * @param axis The axis to read
1059 * @return The value of the axis.
1060 */
1061 double GetAxis(Axis axis) const;
1062
1063 /**
1064 * Constructs an event instance that is true when the axis value is less than
1065 * threshold
1066 *
1067 * @param axis The axis to read
1068 * @param threshold The value below which this trigger should return true.
1069 * @param loop the event loop instance to attach the event to.
1070 * @return an event instance that is true when the axis value is less than the
1071 * provided threshold.
1072 */
1073 BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop* loop) const;
1074
1075 /**
1076 * Constructs an event instance that is true when the axis value is greater
1077 * than threshold
1078 *
1079 * @param axis The axis to read
1080 * @param threshold The value above which this trigger should return true.
1081 * @param loop the event loop instance to attach the event to.
1082 * @return an event instance that is true when the axis value is greater than
1083 * the provided threshold.
1084 */
1085 BooleanEvent AxisGreaterThan(Axis axis, double threshold,
1086 EventLoop* loop) const;
1087
1089
1090 private:
1091 double GetAxisForSendable(Axis axis) const;
1092 bool GetButtonForSendable(Button button) const;
1093};
1094
1095} // namespace wpi
This class provides an easy way to link actions to active high logic signals.
Definition BooleanEvent.hpp:28
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.hpp:15
bool GetMisc5Button() const
Read the value of the Miscellaneous 5 button on the controller.
BooleanEvent RightBumper(EventLoop *loop) const
Constructs an event instance around the right bumper button's digital signal.
BooleanEvent RightPaddle1(EventLoop *loop) const
Constructs an event instance around the Right Paddle 1 button's digital signal.
Gamepad & operator=(Gamepad &&)=default
BooleanEvent RightStick(EventLoop *loop) const
Constructs an event instance around the right stick button's digital signal.
~Gamepad() override=default
BooleanEvent Guide(EventLoop *loop) const
Constructs an event instance around the Guide button's digital signal.
bool GetButtonPressed(Button button)
Whether the button was pressed since the last check.
BooleanEvent AxisGreaterThan(Axis axis, double threshold, EventLoop *loop) const
Constructs an event instance that is true when the axis value is greater than threshold.
bool GetStartButtonReleased()
Whether the Start button was released since the last check.
bool GetMisc5ButtonPressed()
Whether the Miscellaneous 5 button was pressed since the last check.
bool GetSouthFaceButton() const
Read the value of the South Face button on the controller.
BooleanEvent Misc1(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 1 button's digital signal.
BooleanEvent RightTrigger(double threshold, EventLoop *loop) const
Constructs an event instance around the axis value of the right trigger.
BooleanEvent Misc6(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 6 button's digital signal.
bool GetDpadLeftButtonPressed()
Whether the D-pad left button was pressed since the last check.
bool GetDpadLeftButton() const
Read the value of the D-pad left button on the controller.
double GetAxis(Axis axis) const
Get the value of the axis.
bool GetMisc4ButtonReleased()
Whether the Miscellaneous 4 button was released since the last check.
bool GetDpadDownButton() const
Read the value of the D-pad down button on the controller.
bool GetWestFaceButtonReleased()
Whether the West Face button was released since the last check.
bool GetDpadUpButtonPressed()
Whether the D-pad up button was pressed since the last check.
Gamepad(int port)
Construct an instance of a controller.
BooleanEvent LeftPaddle2(EventLoop *loop) const
Constructs an event instance around the Left Paddle 2 button's digital signal.
bool GetBackButton() const
Read the value of the Back button on the controller.
bool GetMisc2ButtonReleased()
Whether the Miscellaneous 2 button was released since the last check.
BooleanEvent NorthFace(EventLoop *loop) const
Constructs an event instance around the North Face button's digital signal.
bool GetMisc3Button() const
Read the value of the Miscellaneous 3 button on the controller.
bool GetBackButtonReleased()
Whether the Back button was released since the last check.
bool GetDpadRightButtonReleased()
Whether the D-pad right button was released since the last check.
bool GetRightStickButtonPressed()
Whether the right stick button was pressed since the last check.
BooleanEvent LeftPaddle1(EventLoop *loop) const
Constructs an event instance around the Left Paddle 1 button's digital signal.
bool GetRightPaddle2ButtonReleased()
Whether the Right Paddle 2 button was released since the last check.
bool GetSouthFaceButtonPressed()
Whether the South Face button was pressed since the last check.
bool GetRightPaddle1ButtonReleased()
Whether the Right Paddle 1 button was released since the last check.
double GetRightY() const
Get the Y axis value of right side of the controller.
BooleanEvent RightTrigger(EventLoop *loop) const
Constructs an event instance around the axis value of the right trigger.
double GetLeftTriggerAxis() const
Get the left trigger axis value of the controller.
BooleanEvent Misc4(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 4 button's digital signal.
BooleanEvent ButtonEvent(Button button, EventLoop *loop) const
Constructs an event instance around this button's digital signal.
bool GetEastFaceButton() const
Read the value of the East Face button on the controller.
BooleanEvent Back(EventLoop *loop) const
Constructs an event instance around the Back button's digital signal.
bool GetMisc1ButtonReleased()
Whether the Miscellaneous 1 button was released since the last check.
double GetLeftY() const
Get the Y axis value of left side of the controller.
bool GetDpadDownButtonReleased()
Whether the D-pad down button was released since the last check.
bool GetRightPaddle2Button() const
Read the value of the Right Paddle 2 button on the controller.
bool GetLeftPaddle2ButtonReleased()
Whether the Left Paddle 2 button was released since the last check.
BooleanEvent EastFace(EventLoop *loop) const
Constructs an event instance around the East Face button's digital signal.
BooleanEvent LeftTrigger(double threshold, EventLoop *loop) const
Constructs an event instance around the axis value of the left trigger.
bool GetRightBumperButtonPressed()
Whether the right bumper button was pressed since the last check.
bool GetButton(Button button) const
Get the button value.
bool GetDpadLeftButtonReleased()
Whether the D-pad left button was released since the last check.
bool GetWestFaceButtonPressed()
Whether the West Face button was pressed since the last check.
BooleanEvent Misc3(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 3 button's digital signal.
bool GetRightPaddle1Button() const
Read the value of the Right Paddle 1 button on the controller.
bool GetLeftBumperButtonPressed()
Whether the right bumper button was pressed since the last check.
bool GetGuideButton() const
Read the value of the Guide button on the controller.
bool GetMisc2ButtonPressed()
Whether the Miscellaneous 2 button was pressed since the last check.
bool GetDpadUpButton() const
Read the value of the D-pad up button on the controller.
bool GetTouchpadButtonReleased()
Whether the Touchpad button was released since the last check.
bool GetLeftPaddle1ButtonPressed()
Whether the Left Paddle 1 button was pressed since the last check.
bool GetLeftStickButton() const
Read the value of the left stick button on the controller.
bool GetLeftBumperButtonReleased()
Whether the right bumper button was released since the last check.
bool GetRightBumperButtonReleased()
Whether the right bumper button was released since the last check.
bool GetLeftStickButtonReleased()
Whether the left stick button was released since the last check.
bool GetSouthFaceButtonReleased()
Whether the South Face button was released since the last check.
BooleanEvent DpadRight(EventLoop *loop) const
Constructs an event instance around the D-pad right button's digital signal.
bool GetMisc6ButtonReleased()
Whether the Miscellaneous 6 button was released since the last check.
bool GetMisc3ButtonPressed()
Whether the Miscellaneous 3 button was pressed since the last check.
bool GetMisc6Button() const
Read the value of the Miscellaneous 6 button on the controller.
bool GetDpadUpButtonReleased()
Whether the D-pad up button was released since the last check.
bool GetDpadRightButton() const
Read the value of the D-pad right button on the controller.
bool GetGuideButtonReleased()
Whether the Guide button was released since the last check.
bool GetTouchpadButtonPressed()
Whether the Touchpad button was pressed since the last check.
Button
Represents a digital button on an Gamepad.
Definition Gamepad.hpp:30
@ LEFT_BUMPER
Left bumper button.
Definition Gamepad.hpp:50
@ BACK
Back button.
Definition Gamepad.hpp:40
@ DPAD_LEFT
D-pad left button.
Definition Gamepad.hpp:58
@ SOUTH_FACE
South Face button.
Definition Gamepad.hpp:32
@ MISC_1
Miscellaneous 1 button.
Definition Gamepad.hpp:62
@ WEST_FACE
West Face button.
Definition Gamepad.hpp:36
@ DPAD_UP
D-pad up button.
Definition Gamepad.hpp:54
@ DPAD_RIGHT
D-pad right button.
Definition Gamepad.hpp:60
@ RIGHT_BUMPER
Right bumper button.
Definition Gamepad.hpp:52
@ MISC_6
Miscellaneous 6 button.
Definition Gamepad.hpp:82
@ RIGHT_STICK
Right stick button.
Definition Gamepad.hpp:48
@ MISC_2
Miscellaneous 2 button.
Definition Gamepad.hpp:74
@ NORTH_FACE
North Face button.
Definition Gamepad.hpp:38
@ START
Start button.
Definition Gamepad.hpp:44
@ TOUCHPAD
Touchpad button.
Definition Gamepad.hpp:72
@ RIGHT_PADDLE_1
Right Paddle 1 button.
Definition Gamepad.hpp:64
@ MISC_3
Miscellaneous 3 button.
Definition Gamepad.hpp:76
@ MISC_5
Miscellaneous 5 button.
Definition Gamepad.hpp:80
@ LEFT_STICK
Left stick button.
Definition Gamepad.hpp:46
@ RIGHT_PADDLE_2
Right Paddle 2 button.
Definition Gamepad.hpp:68
@ MISC_4
Miscellaneous 4 button.
Definition Gamepad.hpp:78
@ LEFT_PADDLE_1
Left Paddle 1 button.
Definition Gamepad.hpp:66
@ EAST_FACE
East Face button.
Definition Gamepad.hpp:34
@ LEFT_PADDLE_2
Left Paddle 2 button.
Definition Gamepad.hpp:70
@ DPAD_DOWN
D-pad down button.
Definition Gamepad.hpp:56
@ GUIDE
Guide button.
Definition Gamepad.hpp:42
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
bool GetMisc4Button() const
Read the value of the Miscellaneous 4 button on the controller.
Gamepad(Gamepad &&)=default
bool GetMisc2Button() const
Read the value of the Miscellaneous 2 button on the controller.
bool GetLeftPaddle2Button() const
Read the value of the Left Paddle 2 button on the controller.
bool GetDpadDownButtonPressed()
Whether the D-pad down button was pressed since the last check.
BooleanEvent WestFace(EventLoop *loop) const
Constructs an event instance around the West Face button's digital signal.
bool GetRightPaddle2ButtonPressed()
Whether the Right Paddle 2 button was pressed since the last check.
BooleanEvent Touchpad(EventLoop *loop) const
Constructs an event instance around the Touchpad button's digital signal.
bool GetMisc6ButtonPressed()
Whether the Miscellaneous 6 button was pressed since the last check.
bool GetLeftBumperButton() const
Read the value of the right bumper button on the controller.
BooleanEvent LeftStick(EventLoop *loop) const
Constructs an event instance around the left stick button's digital signal.
bool GetMisc1Button() const
Read the value of the Miscellaneous 1 button on the controller.
BooleanEvent SouthFace(EventLoop *loop) const
Constructs an event instance around the South Face button's digital signal.
bool GetTouchpadButton() const
Read the value of the Touchpad button on the controller.
bool GetLeftPaddle2ButtonPressed()
Whether the Left Paddle 2 button was pressed since the last check.
bool GetDpadRightButtonPressed()
Whether the D-pad right button was pressed since the last check.
BooleanEvent DpadLeft(EventLoop *loop) const
Constructs an event instance around the D-pad left button's digital signal.
bool GetRightPaddle1ButtonPressed()
Whether the Right Paddle 1 button was pressed since the last check.
bool GetMisc3ButtonReleased()
Whether the Miscellaneous 3 button was released since the last check.
bool GetRightBumperButton() const
Read the value of the right bumper button on the controller.
bool GetRightStickButton() const
Read the value of the right stick button on the controller.
bool GetEastFaceButtonPressed()
Whether the East Face button was pressed since the last check.
bool GetLeftPaddle1Button() const
Read the value of the Left Paddle 1 button on the controller.
bool GetBackButtonPressed()
Whether the Back button was pressed since the last check.
BooleanEvent DpadDown(EventLoop *loop) const
Constructs an event instance around the D-pad down button's digital signal.
bool GetLeftPaddle1ButtonReleased()
Whether the Left Paddle 1 button was released since the last check.
BooleanEvent Misc5(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 5 button's digital signal.
BooleanEvent LeftTrigger(EventLoop *loop) const
Constructs an event instance around the axis value of the left trigger.
Axis
Represents an axis on an Gamepad.
Definition Gamepad.hpp:86
@ RIGHT_TRIGGER
Right trigger.
Definition Gamepad.hpp:98
@ LEFT_TRIGGER
Left trigger.
Definition Gamepad.hpp:96
@ RIGHT_Y
Right Y axis.
Definition Gamepad.hpp:94
@ LEFT_Y
Left Y axis.
Definition Gamepad.hpp:90
@ LEFT_X
Left X axis.
Definition Gamepad.hpp:88
@ RIGHT_X
Right X axis.
Definition Gamepad.hpp:92
double GetLeftX() const
Get the X axis value of left side of the controller.
double GetRightTriggerAxis() const
Get the right trigger axis value of the controller.
BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop *loop) const
Constructs an event instance that is true when the axis value is less than threshold.
BooleanEvent DpadUp(EventLoop *loop) const
Constructs an event instance around the D-pad up button's digital signal.
bool GetMisc1ButtonPressed()
Whether the Miscellaneous 1 button was pressed since the last check.
BooleanEvent LeftBumper(EventLoop *loop) const
Constructs an event instance around the right bumper button's digital signal.
double GetRightX() const
Get the X axis value of right side of the controller.
bool GetNorthFaceButton() const
Read the value of the North Face button on the controller.
bool GetEastFaceButtonReleased()
Whether the East Face button was released since the last check.
bool GetWestFaceButton() const
Read the value of the West Face button on the controller.
bool GetNorthFaceButtonReleased()
Whether the North Face button was released since the last check.
BooleanEvent RightPaddle2(EventLoop *loop) const
Constructs an event instance around the Right Paddle 2 button's digital signal.
BooleanEvent Misc2(EventLoop *loop) const
Constructs an event instance around the Miscellaneous 2 button's digital signal.
bool GetGuideButtonPressed()
Whether the Guide button was pressed since the last check.
bool GetMisc4ButtonPressed()
Whether the Miscellaneous 4 button was pressed since the last check.
bool GetMisc5ButtonReleased()
Whether the Miscellaneous 5 button was released since the last check.
bool GetLeftStickButtonPressed()
Whether the left stick button was pressed since the last check.
bool GetStartButtonPressed()
Whether the Start button was pressed since the last check.
bool GetButtonReleased(Button button)
Whether the button was released since the last check.
bool GetRightStickButtonReleased()
Whether the right stick button was released since the last check.
bool GetNorthFaceButtonPressed()
Whether the North Face button was pressed since the last check.
bool GetStartButton() const
Read the value of the Start button on the controller.
BooleanEvent Start(EventLoop *loop) const
Constructs an event instance around the Start button's digital signal.
GenericHID(int port)
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
Interface for Sendable objects.
Definition Sendable.hpp:16
Definition CvSource.hpp:15