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.command2.button; 006 007import org.wpilib.command2.CommandScheduler; 008import org.wpilib.driverstation.Gamepad; 009import org.wpilib.event.EventLoop; 010 011/** 012 * A version of {@link Gamepad} with {@link Trigger} factories for command-based. 013 * 014 * @see Gamepad 015 */ 016@SuppressWarnings("MethodName") 017public class CommandGamepad extends CommandGenericHID { 018 private final Gamepad 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 CommandGamepad(int port) { 026 super(port); 027 m_hid = new Gamepad(port); 028 } 029 030 /** 031 * Get the underlying GenericHID object. 032 * 033 * @return the wrapped GenericHID object 034 */ 035 @Override 036 public Gamepad getHID() { 037 return m_hid; 038 } 039 040 /** 041 * Constructs an event instance around this button's digital signal. 042 * 043 * @param button the button 044 * @return an event instance representing the button's digital signal attached to the {@link 045 * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 046 * @see #button(Gamepad.Button, EventLoop) 047 */ 048 public Trigger button(Gamepad.Button button) { 049 return super.button(button.value); 050 } 051 052 /** 053 * Constructs an event instance around this button's digital signal. 054 * 055 * @param button the button 056 * @param loop the event loop instance to attach the event to. 057 * @return an event instance representing the button's digital signal attached to the given loop. 058 */ 059 public Trigger button(Gamepad.Button button, EventLoop loop) { 060 return button(button.value, loop); 061 } 062 063 /** 064 * Constructs a Trigger instance around the South Face button's digital signal. 065 * 066 * @return a Trigger instance representing the South Face button's digital signal attached to the 067 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 068 * @see #southFace(EventLoop) 069 */ 070 public Trigger southFace() { 071 return southFace(CommandScheduler.getInstance().getDefaultButtonLoop()); 072 } 073 074 /** 075 * Constructs a Trigger instance around the South Face button's digital signal. 076 * 077 * @param loop the event loop instance to attach the event to. 078 * @return a Trigger instance representing the South Face button's digital signal attached to the 079 * given loop. 080 */ 081 public Trigger southFace(EventLoop loop) { 082 return button(Gamepad.Button.SOUTH_FACE, loop); 083 } 084 085 /** 086 * Constructs a Trigger instance around the East Face button's digital signal. 087 * 088 * @return a Trigger instance representing the East Face button's digital signal attached to the 089 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 090 * @see #eastFace(EventLoop) 091 */ 092 public Trigger eastFace() { 093 return eastFace(CommandScheduler.getInstance().getDefaultButtonLoop()); 094 } 095 096 /** 097 * Constructs a Trigger instance around the East Face button's digital signal. 098 * 099 * @param loop the event loop instance to attach the event to. 100 * @return a Trigger instance representing the East Face button's digital signal attached to the 101 * given loop. 102 */ 103 public Trigger eastFace(EventLoop loop) { 104 return button(Gamepad.Button.EAST_FACE, loop); 105 } 106 107 /** 108 * Constructs a Trigger instance around the West Face button's digital signal. 109 * 110 * @return a Trigger instance representing the West Face button's digital signal attached to the 111 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 112 * @see #westFace(EventLoop) 113 */ 114 public Trigger westFace() { 115 return westFace(CommandScheduler.getInstance().getDefaultButtonLoop()); 116 } 117 118 /** 119 * Constructs a Trigger instance around the West Face button's digital signal. 120 * 121 * @param loop the event loop instance to attach the event to. 122 * @return a Trigger instance representing the West Face button's digital signal attached to the 123 * given loop. 124 */ 125 public Trigger westFace(EventLoop loop) { 126 return button(Gamepad.Button.WEST_FACE, loop); 127 } 128 129 /** 130 * Constructs a Trigger instance around the North Face button's digital signal. 131 * 132 * @return a Trigger instance representing the North Face button's digital signal attached to the 133 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 134 * @see #northFace(EventLoop) 135 */ 136 public Trigger northFace() { 137 return northFace(CommandScheduler.getInstance().getDefaultButtonLoop()); 138 } 139 140 /** 141 * Constructs a Trigger instance around the North Face button's digital signal. 142 * 143 * @param loop the event loop instance to attach the event to. 144 * @return a Trigger instance representing the North Face button's digital signal attached to the 145 * given loop. 146 */ 147 public Trigger northFace(EventLoop loop) { 148 return button(Gamepad.Button.NORTH_FACE, loop); 149 } 150 151 /** 152 * Constructs a Trigger instance around the Back button's digital signal. 153 * 154 * @return a Trigger instance representing the Back button's digital signal attached to the {@link 155 * CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 156 * @see #back(EventLoop) 157 */ 158 public Trigger back() { 159 return back(CommandScheduler.getInstance().getDefaultButtonLoop()); 160 } 161 162 /** 163 * Constructs a Trigger instance around the Back button's digital signal. 164 * 165 * @param loop the event loop instance to attach the event to. 166 * @return a Trigger instance representing the Back button's digital signal attached to the given 167 * loop. 168 */ 169 public Trigger back(EventLoop loop) { 170 return button(Gamepad.Button.BACK, loop); 171 } 172 173 /** 174 * Constructs a Trigger instance around the Guide button's digital signal. 175 * 176 * @return a Trigger instance representing the Guide button's digital signal attached to the 177 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 178 * @see #guide(EventLoop) 179 */ 180 public Trigger guide() { 181 return guide(CommandScheduler.getInstance().getDefaultButtonLoop()); 182 } 183 184 /** 185 * Constructs a Trigger instance around the Guide button's digital signal. 186 * 187 * @param loop the event loop instance to attach the event to. 188 * @return a Trigger instance representing the Guide button's digital signal attached to the given 189 * loop. 190 */ 191 public Trigger guide(EventLoop loop) { 192 return button(Gamepad.Button.GUIDE, loop); 193 } 194 195 /** 196 * Constructs a Trigger instance around the Start button's digital signal. 197 * 198 * @return a Trigger instance representing the Start button's digital signal attached to the 199 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 200 * @see #start(EventLoop) 201 */ 202 public Trigger start() { 203 return start(CommandScheduler.getInstance().getDefaultButtonLoop()); 204 } 205 206 /** 207 * Constructs a Trigger instance around the Start button's digital signal. 208 * 209 * @param loop the event loop instance to attach the event to. 210 * @return a Trigger instance representing the Start button's digital signal attached to the given 211 * loop. 212 */ 213 public Trigger start(EventLoop loop) { 214 return button(Gamepad.Button.START, loop); 215 } 216 217 /** 218 * Constructs a Trigger instance around the left stick button's digital signal. 219 * 220 * @return a Trigger instance representing the left stick button's digital signal attached to the 221 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 222 * @see #leftStick(EventLoop) 223 */ 224 public Trigger leftStick() { 225 return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); 226 } 227 228 /** 229 * Constructs a Trigger instance around the left stick button's digital signal. 230 * 231 * @param loop the event loop instance to attach the event to. 232 * @return a Trigger instance representing the left stick button's digital signal attached to the 233 * given loop. 234 */ 235 public Trigger leftStick(EventLoop loop) { 236 return button(Gamepad.Button.LEFT_STICK, loop); 237 } 238 239 /** 240 * Constructs a Trigger instance around the right stick button's digital signal. 241 * 242 * @return a Trigger instance representing the right stick button's digital signal attached to the 243 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 244 * @see #rightStick(EventLoop) 245 */ 246 public Trigger rightStick() { 247 return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); 248 } 249 250 /** 251 * Constructs a Trigger instance around the right stick button's digital signal. 252 * 253 * @param loop the event loop instance to attach the event to. 254 * @return a Trigger instance representing the right stick button's digital signal attached to the 255 * given loop. 256 */ 257 public Trigger rightStick(EventLoop loop) { 258 return button(Gamepad.Button.RIGHT_STICK, loop); 259 } 260 261 /** 262 * Constructs a Trigger instance around the right bumper button's digital signal. 263 * 264 * @return a Trigger instance representing the right bumper button's digital signal attached to 265 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 266 * @see #leftBumper(EventLoop) 267 */ 268 public Trigger leftBumper() { 269 return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); 270 } 271 272 /** 273 * Constructs a Trigger instance around the right bumper button's digital signal. 274 * 275 * @param loop the event loop instance to attach the event to. 276 * @return a Trigger instance representing the right bumper button's digital signal attached to 277 * the given loop. 278 */ 279 public Trigger leftBumper(EventLoop loop) { 280 return button(Gamepad.Button.LEFT_BUMPER, loop); 281 } 282 283 /** 284 * Constructs a Trigger instance around the right bumper button's digital signal. 285 * 286 * @return a Trigger instance representing the right bumper button's digital signal attached to 287 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 288 * @see #rightBumper(EventLoop) 289 */ 290 public Trigger rightBumper() { 291 return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); 292 } 293 294 /** 295 * Constructs a Trigger instance around the right bumper button's digital signal. 296 * 297 * @param loop the event loop instance to attach the event to. 298 * @return a Trigger instance representing the right bumper button's digital signal attached to 299 * the given loop. 300 */ 301 public Trigger rightBumper(EventLoop loop) { 302 return button(Gamepad.Button.RIGHT_BUMPER, loop); 303 } 304 305 /** 306 * Constructs a Trigger instance around the D-pad up button's digital signal. 307 * 308 * @return a Trigger instance representing the D-pad up button's digital signal attached to the 309 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 310 * @see #dpadUp(EventLoop) 311 */ 312 public Trigger dpadUp() { 313 return dpadUp(CommandScheduler.getInstance().getDefaultButtonLoop()); 314 } 315 316 /** 317 * Constructs a Trigger instance around the D-pad up button's digital signal. 318 * 319 * @param loop the event loop instance to attach the event to. 320 * @return a Trigger instance representing the D-pad up button's digital signal attached to the 321 * given loop. 322 */ 323 public Trigger dpadUp(EventLoop loop) { 324 return button(Gamepad.Button.DPAD_UP, loop); 325 } 326 327 /** 328 * Constructs a Trigger instance around the D-pad down button's digital signal. 329 * 330 * @return a Trigger instance representing the D-pad down button's digital signal attached to the 331 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 332 * @see #dpadDown(EventLoop) 333 */ 334 public Trigger dpadDown() { 335 return dpadDown(CommandScheduler.getInstance().getDefaultButtonLoop()); 336 } 337 338 /** 339 * Constructs a Trigger instance around the D-pad down button's digital signal. 340 * 341 * @param loop the event loop instance to attach the event to. 342 * @return a Trigger instance representing the D-pad down button's digital signal attached to the 343 * given loop. 344 */ 345 public Trigger dpadDown(EventLoop loop) { 346 return button(Gamepad.Button.DPAD_DOWN, loop); 347 } 348 349 /** 350 * Constructs a Trigger instance around the D-pad left button's digital signal. 351 * 352 * @return a Trigger instance representing the D-pad left button's digital signal attached to the 353 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 354 * @see #dpadLeft(EventLoop) 355 */ 356 public Trigger dpadLeft() { 357 return dpadLeft(CommandScheduler.getInstance().getDefaultButtonLoop()); 358 } 359 360 /** 361 * Constructs a Trigger instance around the D-pad left button's digital signal. 362 * 363 * @param loop the event loop instance to attach the event to. 364 * @return a Trigger instance representing the D-pad left button's digital signal attached to the 365 * given loop. 366 */ 367 public Trigger dpadLeft(EventLoop loop) { 368 return button(Gamepad.Button.DPAD_LEFT, loop); 369 } 370 371 /** 372 * Constructs a Trigger instance around the D-pad right button's digital signal. 373 * 374 * @return a Trigger instance representing the D-pad right button's digital signal attached to the 375 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 376 * @see #dpadRight(EventLoop) 377 */ 378 public Trigger dpadRight() { 379 return dpadRight(CommandScheduler.getInstance().getDefaultButtonLoop()); 380 } 381 382 /** 383 * Constructs a Trigger instance around the D-pad right button's digital signal. 384 * 385 * @param loop the event loop instance to attach the event to. 386 * @return a Trigger instance representing the D-pad right button's digital signal attached to the 387 * given loop. 388 */ 389 public Trigger dpadRight(EventLoop loop) { 390 return button(Gamepad.Button.DPAD_RIGHT, loop); 391 } 392 393 /** 394 * Constructs a Trigger instance around the Miscellaneous 1 button's digital signal. 395 * 396 * @return a Trigger instance representing the Miscellaneous 1 button's digital signal attached to 397 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 398 * @see #misc1(EventLoop) 399 */ 400 public Trigger misc1() { 401 return misc1(CommandScheduler.getInstance().getDefaultButtonLoop()); 402 } 403 404 /** 405 * Constructs a Trigger instance around the Miscellaneous 1 button's digital signal. 406 * 407 * @param loop the event loop instance to attach the event to. 408 * @return a Trigger instance representing the Miscellaneous 1 button's digital signal attached to 409 * the given loop. 410 */ 411 public Trigger misc1(EventLoop loop) { 412 return button(Gamepad.Button.MISC_1, loop); 413 } 414 415 /** 416 * Constructs a Trigger instance around the Right Paddle 1 button's digital signal. 417 * 418 * @return a Trigger instance representing the Right Paddle 1 button's digital signal attached to 419 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 420 * @see #rightPaddle1(EventLoop) 421 */ 422 public Trigger rightPaddle1() { 423 return rightPaddle1(CommandScheduler.getInstance().getDefaultButtonLoop()); 424 } 425 426 /** 427 * Constructs a Trigger instance around the Right Paddle 1 button's digital signal. 428 * 429 * @param loop the event loop instance to attach the event to. 430 * @return a Trigger instance representing the Right Paddle 1 button's digital signal attached to 431 * the given loop. 432 */ 433 public Trigger rightPaddle1(EventLoop loop) { 434 return button(Gamepad.Button.RIGHT_PADDLE_1, loop); 435 } 436 437 /** 438 * Constructs a Trigger instance around the Left Paddle 1 button's digital signal. 439 * 440 * @return a Trigger instance representing the Left Paddle 1 button's digital signal attached to 441 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 442 * @see #leftPaddle1(EventLoop) 443 */ 444 public Trigger leftPaddle1() { 445 return leftPaddle1(CommandScheduler.getInstance().getDefaultButtonLoop()); 446 } 447 448 /** 449 * Constructs a Trigger instance around the Left Paddle 1 button's digital signal. 450 * 451 * @param loop the event loop instance to attach the event to. 452 * @return a Trigger instance representing the Left Paddle 1 button's digital signal attached to 453 * the given loop. 454 */ 455 public Trigger leftPaddle1(EventLoop loop) { 456 return button(Gamepad.Button.LEFT_PADDLE_1, loop); 457 } 458 459 /** 460 * Constructs a Trigger instance around the Right Paddle 2 button's digital signal. 461 * 462 * @return a Trigger instance representing the Right Paddle 2 button's digital signal attached to 463 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 464 * @see #rightPaddle2(EventLoop) 465 */ 466 public Trigger rightPaddle2() { 467 return rightPaddle2(CommandScheduler.getInstance().getDefaultButtonLoop()); 468 } 469 470 /** 471 * Constructs a Trigger instance around the Right Paddle 2 button's digital signal. 472 * 473 * @param loop the event loop instance to attach the event to. 474 * @return a Trigger instance representing the Right Paddle 2 button's digital signal attached to 475 * the given loop. 476 */ 477 public Trigger rightPaddle2(EventLoop loop) { 478 return button(Gamepad.Button.RIGHT_PADDLE_2, loop); 479 } 480 481 /** 482 * Constructs a Trigger instance around the Left Paddle 2 button's digital signal. 483 * 484 * @return a Trigger instance representing the Left Paddle 2 button's digital signal attached to 485 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 486 * @see #leftPaddle2(EventLoop) 487 */ 488 public Trigger leftPaddle2() { 489 return leftPaddle2(CommandScheduler.getInstance().getDefaultButtonLoop()); 490 } 491 492 /** 493 * Constructs a Trigger instance around the Left Paddle 2 button's digital signal. 494 * 495 * @param loop the event loop instance to attach the event to. 496 * @return a Trigger instance representing the Left Paddle 2 button's digital signal attached to 497 * the given loop. 498 */ 499 public Trigger leftPaddle2(EventLoop loop) { 500 return button(Gamepad.Button.LEFT_PADDLE_2, loop); 501 } 502 503 /** 504 * Constructs a Trigger instance around the Touchpad button's digital signal. 505 * 506 * @return a Trigger instance representing the Touchpad button's digital signal attached to the 507 * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 508 * @see #touchpad(EventLoop) 509 */ 510 public Trigger touchpad() { 511 return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop()); 512 } 513 514 /** 515 * Constructs a Trigger instance around the Touchpad button's digital signal. 516 * 517 * @param loop the event loop instance to attach the event to. 518 * @return a Trigger instance representing the Touchpad button's digital signal attached to the 519 * given loop. 520 */ 521 public Trigger touchpad(EventLoop loop) { 522 return button(Gamepad.Button.TOUCHPAD, loop); 523 } 524 525 /** 526 * Constructs a Trigger instance around the Miscellaneous 2 button's digital signal. 527 * 528 * @return a Trigger instance representing the Miscellaneous 2 button's digital signal attached to 529 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 530 * @see #misc2(EventLoop) 531 */ 532 public Trigger misc2() { 533 return misc2(CommandScheduler.getInstance().getDefaultButtonLoop()); 534 } 535 536 /** 537 * Constructs a Trigger instance around the Miscellaneous 2 button's digital signal. 538 * 539 * @param loop the event loop instance to attach the event to. 540 * @return a Trigger instance representing the Miscellaneous 2 button's digital signal attached to 541 * the given loop. 542 */ 543 public Trigger misc2(EventLoop loop) { 544 return button(Gamepad.Button.MISC_2, loop); 545 } 546 547 /** 548 * Constructs a Trigger instance around the Miscellaneous 3 button's digital signal. 549 * 550 * @return a Trigger instance representing the Miscellaneous 3 button's digital signal attached to 551 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 552 * @see #misc3(EventLoop) 553 */ 554 public Trigger misc3() { 555 return misc3(CommandScheduler.getInstance().getDefaultButtonLoop()); 556 } 557 558 /** 559 * Constructs a Trigger instance around the Miscellaneous 3 button's digital signal. 560 * 561 * @param loop the event loop instance to attach the event to. 562 * @return a Trigger instance representing the Miscellaneous 3 button's digital signal attached to 563 * the given loop. 564 */ 565 public Trigger misc3(EventLoop loop) { 566 return button(Gamepad.Button.MISC_3, loop); 567 } 568 569 /** 570 * Constructs a Trigger instance around the Miscellaneous 4 button's digital signal. 571 * 572 * @return a Trigger instance representing the Miscellaneous 4 button's digital signal attached to 573 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 574 * @see #misc4(EventLoop) 575 */ 576 public Trigger misc4() { 577 return misc4(CommandScheduler.getInstance().getDefaultButtonLoop()); 578 } 579 580 /** 581 * Constructs a Trigger instance around the Miscellaneous 4 button's digital signal. 582 * 583 * @param loop the event loop instance to attach the event to. 584 * @return a Trigger instance representing the Miscellaneous 4 button's digital signal attached to 585 * the given loop. 586 */ 587 public Trigger misc4(EventLoop loop) { 588 return button(Gamepad.Button.MISC_4, loop); 589 } 590 591 /** 592 * Constructs a Trigger instance around the Miscellaneous 5 button's digital signal. 593 * 594 * @return a Trigger instance representing the Miscellaneous 5 button's digital signal attached to 595 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 596 * @see #misc5(EventLoop) 597 */ 598 public Trigger misc5() { 599 return misc5(CommandScheduler.getInstance().getDefaultButtonLoop()); 600 } 601 602 /** 603 * Constructs a Trigger instance around the Miscellaneous 5 button's digital signal. 604 * 605 * @param loop the event loop instance to attach the event to. 606 * @return a Trigger instance representing the Miscellaneous 5 button's digital signal attached to 607 * the given loop. 608 */ 609 public Trigger misc5(EventLoop loop) { 610 return button(Gamepad.Button.MISC_5, loop); 611 } 612 613 /** 614 * Constructs a Trigger instance around the Miscellaneous 6 button's digital signal. 615 * 616 * @return a Trigger instance representing the Miscellaneous 6 button's digital signal attached to 617 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 618 * @see #misc6(EventLoop) 619 */ 620 public Trigger misc6() { 621 return misc6(CommandScheduler.getInstance().getDefaultButtonLoop()); 622 } 623 624 /** 625 * Constructs a Trigger instance around the Miscellaneous 6 button's digital signal. 626 * 627 * @param loop the event loop instance to attach the event to. 628 * @return a Trigger instance representing the Miscellaneous 6 button's digital signal attached to 629 * the given loop. 630 */ 631 public Trigger misc6(EventLoop loop) { 632 return button(Gamepad.Button.MISC_6, loop); 633 } 634 635 /** 636 * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger 637 * will be true when the axis value is greater than {@code threshold}. 638 * 639 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 640 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 641 * @param loop the event loop instance to attach the Trigger to. 642 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 643 * threshold, attached to the given event loop 644 */ 645 public Trigger leftTrigger(double threshold, EventLoop loop) { 646 return axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER, threshold, loop); 647 } 648 649 /** 650 * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger 651 * will be true when the axis value is greater than {@code threshold}. 652 * 653 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 654 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 655 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 656 * threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler 657 * button loop}. 658 */ 659 public Trigger leftTrigger(double threshold) { 660 return leftTrigger(threshold, CommandScheduler.getInstance().getDefaultButtonLoop()); 661 } 662 663 /** 664 * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger 665 * will be true when the axis value is greater than 0.5. 666 * 667 * @return a Trigger instance that is true when the left trigger's axis exceeds 0.5, attached to 668 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 669 */ 670 public Trigger leftTrigger() { 671 return leftTrigger(0.5); 672 } 673 674 /** 675 * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger 676 * will be true when the axis value is greater than {@code threshold}. 677 * 678 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 679 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 680 * @param loop the event loop instance to attach the Trigger to. 681 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 682 * threshold, attached to the given event loop 683 */ 684 public Trigger rightTrigger(double threshold, EventLoop loop) { 685 return axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER, threshold, loop); 686 } 687 688 /** 689 * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger 690 * will be true when the axis value is greater than {@code threshold}. 691 * 692 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 693 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 694 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 695 * threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler 696 * button loop}. 697 */ 698 public Trigger rightTrigger(double threshold) { 699 return rightTrigger(threshold, CommandScheduler.getInstance().getDefaultButtonLoop()); 700 } 701 702 /** 703 * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger 704 * will be true when the axis value is greater than 0.5. 705 * 706 * @return a Trigger instance that is true when the right trigger's axis exceeds 0.5, attached to 707 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 708 */ 709 public Trigger rightTrigger() { 710 return rightTrigger(0.5); 711 } 712 713 /** 714 * Constructs a Trigger instance that is true when the axis value is less than {@code threshold}, 715 * attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button 716 * loop}. 717 * 718 * @param axis The axis to read 719 * @param threshold The value below which this trigger should return true. 720 * @return a Trigger instance that is true when the axis value is less than the provided 721 * threshold. 722 */ 723 public Trigger axisLessThan(Gamepad.Axis axis, double threshold) { 724 return super.axisLessThan(axis.value, threshold); 725 } 726 727 /** 728 * Constructs a Trigger instance that is true when the axis value is less than {@code threshold}, 729 * attached to the given loop. 730 * 731 * @param axis The axis to read 732 * @param threshold The value below which this trigger should return true. 733 * @param loop the event loop instance to attach the trigger to 734 * @return a Trigger instance that is true when the axis value is less than the provided 735 * threshold. 736 */ 737 public Trigger axisLessThan(Gamepad.Axis axis, double threshold, EventLoop loop) { 738 return super.axisLessThan(axis.value, threshold, loop); 739 } 740 741 /** 742 * Constructs a Trigger instance that is true when the axis value is less than {@code threshold}, 743 * attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button 744 * loop}. 745 * 746 * @param axis The axis to read 747 * @param threshold The value above which this trigger should return true. 748 * @return a Trigger instance that is true when the axis value is greater than the provided 749 * threshold. 750 */ 751 public Trigger axisGreaterThan(Gamepad.Axis axis, double threshold) { 752 return super.axisGreaterThan(axis.value, threshold); 753 } 754 755 /** 756 * Constructs a Trigger instance that is true when the axis value is greater than {@code 757 * threshold}, attached to the given loop. 758 * 759 * @param axis The axis to read 760 * @param threshold The value above which this trigger should return true. 761 * @param loop the event loop instance to attach the trigger to. 762 * @return a Trigger instance that is true when the axis value is greater than the provided 763 * threshold. 764 */ 765 public Trigger axisGreaterThan(Gamepad.Axis axis, double threshold, EventLoop loop) { 766 return super.axisGreaterThan(axis.value, threshold, loop); 767 } 768 769 /** 770 * Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code 771 * threshold}, attached to the given loop. 772 * 773 * @param axis The axis to read 774 * @param threshold The value above which this trigger should return true. 775 * @param loop the event loop instance to attach the trigger to. 776 * @return a Trigger instance that is true when the axis magnitude value is greater than the 777 * provided threshold. 778 */ 779 public Trigger axisMagnitudeGreaterThan(Gamepad.Axis axis, double threshold, EventLoop loop) { 780 return super.axisMagnitudeGreaterThan(axis.value, threshold, loop); 781 } 782 783 /** 784 * Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code 785 * threshold}, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command 786 * scheduler button loop}. 787 * 788 * @param axis The axis to read 789 * @param threshold The value above which this trigger should return true. 790 * @return a Trigger instance that is true when the deadbanded axis value is active (non-zero). 791 */ 792 public Trigger axisMagnitudeGreaterThan(Gamepad.Axis axis, double threshold) { 793 return super.axisMagnitudeGreaterThan(axis.value, threshold); 794 } 795 796 /** 797 * Get the value of the axis. 798 * 799 * @param axis The axis to read 800 * @return The value of the axis. 801 */ 802 public double getAxis(Gamepad.Axis axis) { 803 return getRawAxis(axis.value); 804 } 805 806 /** 807 * Get the X axis value of left side of the controller. Right is positive. 808 * 809 * @return The axis value. 810 */ 811 public double getLeftX() { 812 return m_hid.getLeftX(); 813 } 814 815 /** 816 * Get the Y axis value of left side of the controller. Back is positive. 817 * 818 * @return The axis value. 819 */ 820 public double getLeftY() { 821 return m_hid.getLeftY(); 822 } 823 824 /** 825 * Get the X axis value of right side of the controller. Right is positive. 826 * 827 * @return The axis value. 828 */ 829 public double getRightX() { 830 return m_hid.getRightX(); 831 } 832 833 /** 834 * Get the Y axis value of right side of the controller. Back is positive. 835 * 836 * @return The axis value. 837 */ 838 public double getRightY() { 839 return m_hid.getRightY(); 840 } 841 842 /** 843 * Get the left trigger axis value of the controller. Note that this axis is bound to the range of 844 * [0, 1] as opposed to the usual [-1, 1]. 845 * 846 * @return The axis value. 847 */ 848 public double getLeftTriggerAxis() { 849 return m_hid.getLeftTriggerAxis(); 850 } 851 852 /** 853 * Get the right trigger axis value of the controller. Note that this axis is bound to the range 854 * of [0, 1] as opposed to the usual [-1, 1]. 855 * 856 * @return The axis value. 857 */ 858 public double getRightTriggerAxis() { 859 return m_hid.getRightTriggerAxis(); 860 } 861}