[wpilib, commands] Cache controller BooleanEvents/Triggers and directly construct Triggers (#6738)

This has been a common footgun for teams, due to calling the factory functions in periodic loops.
This commit is contained in:
Gold856
2024-07-29 10:58:23 -04:00
committed by GitHub
parent 073192d513
commit 3c2bdafd57
21 changed files with 235 additions and 187 deletions

View File

@@ -219,7 +219,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent square(EventLoop loop) {
return new BooleanEvent(loop, this::getSquareButton);
return button(Button.kSquare.value, loop);
}
/**
@@ -257,7 +257,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent cross(EventLoop loop) {
return new BooleanEvent(loop, this::getCrossButton);
return button(Button.kCross.value, loop);
}
/**
@@ -295,7 +295,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent circle(EventLoop loop) {
return new BooleanEvent(loop, this::getCircleButton);
return button(Button.kCircle.value, loop);
}
/**
@@ -333,7 +333,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent triangle(EventLoop loop) {
return new BooleanEvent(loop, this::getTriangleButton);
return button(Button.kTriangle.value, loop);
}
/**
@@ -371,7 +371,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L1(EventLoop loop) {
return new BooleanEvent(loop, this::getL1Button);
return button(Button.kL1.value, loop);
}
/**
@@ -409,7 +409,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R1(EventLoop loop) {
return new BooleanEvent(loop, this::getR1Button);
return button(Button.kR1.value, loop);
}
/**
@@ -447,7 +447,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L2(EventLoop loop) {
return new BooleanEvent(loop, this::getL2Button);
return button(Button.kL2.value, loop);
}
/**
@@ -485,7 +485,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R2(EventLoop loop) {
return new BooleanEvent(loop, this::getR2Button);
return button(Button.kR2.value, loop);
}
/**
@@ -523,7 +523,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent share(EventLoop loop) {
return new BooleanEvent(loop, this::getShareButton);
return button(Button.kShare.value, loop);
}
/**
@@ -561,7 +561,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent options(EventLoop loop) {
return new BooleanEvent(loop, this::getOptionsButton);
return button(Button.kOptions.value, loop);
}
/**
@@ -599,7 +599,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L3(EventLoop loop) {
return new BooleanEvent(loop, this::getL3Button);
return button(Button.kL3.value, loop);
}
/**
@@ -637,7 +637,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R3(EventLoop loop) {
return new BooleanEvent(loop, this::getR3Button);
return button(Button.kR3.value, loop);
}
/**
@@ -675,7 +675,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent PS(EventLoop loop) {
return new BooleanEvent(loop, this::getPSButton);
return button(Button.kPS.value, loop);
}
/**
@@ -713,7 +713,7 @@ public class PS4Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent touchpad(EventLoop loop) {
return new BooleanEvent(loop, this::getTouchpadButton);
return button(Button.kTouchpad.value, loop);
}
/**

View File

@@ -219,7 +219,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent square(EventLoop loop) {
return new BooleanEvent(loop, this::getSquareButton);
return button(Button.kSquare.value, loop);
}
/**
@@ -257,7 +257,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent cross(EventLoop loop) {
return new BooleanEvent(loop, this::getCrossButton);
return button(Button.kCross.value, loop);
}
/**
@@ -295,7 +295,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent circle(EventLoop loop) {
return new BooleanEvent(loop, this::getCircleButton);
return button(Button.kCircle.value, loop);
}
/**
@@ -333,7 +333,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent triangle(EventLoop loop) {
return new BooleanEvent(loop, this::getTriangleButton);
return button(Button.kTriangle.value, loop);
}
/**
@@ -371,7 +371,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L1(EventLoop loop) {
return new BooleanEvent(loop, this::getL1Button);
return button(Button.kL1.value, loop);
}
/**
@@ -409,7 +409,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R1(EventLoop loop) {
return new BooleanEvent(loop, this::getR1Button);
return button(Button.kR1.value, loop);
}
/**
@@ -447,7 +447,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L2(EventLoop loop) {
return new BooleanEvent(loop, this::getL2Button);
return button(Button.kL2.value, loop);
}
/**
@@ -485,7 +485,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R2(EventLoop loop) {
return new BooleanEvent(loop, this::getR2Button);
return button(Button.kR2.value, loop);
}
/**
@@ -523,7 +523,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent create(EventLoop loop) {
return new BooleanEvent(loop, this::getCreateButton);
return button(Button.kCreate.value, loop);
}
/**
@@ -561,7 +561,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent options(EventLoop loop) {
return new BooleanEvent(loop, this::getOptionsButton);
return button(Button.kOptions.value, loop);
}
/**
@@ -599,7 +599,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent L3(EventLoop loop) {
return new BooleanEvent(loop, this::getL3Button);
return button(Button.kL3.value, loop);
}
/**
@@ -637,7 +637,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent R3(EventLoop loop) {
return new BooleanEvent(loop, this::getR3Button);
return button(Button.kR3.value, loop);
}
/**
@@ -675,7 +675,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent PS(EventLoop loop) {
return new BooleanEvent(loop, this::getPSButton);
return button(Button.kPS.value, loop);
}
/**
@@ -713,7 +713,7 @@ public class PS5Controller extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent touchpad(EventLoop loop) {
return new BooleanEvent(loop, this::getTouchpadButton);
return button(Button.kTouchpad.value, loop);
}
/**

View File

@@ -197,7 +197,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent a(EventLoop loop) {
return new BooleanEvent(loop, this::getAButton);
return button(Button.kA.value, loop);
}
/**
@@ -235,7 +235,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent b(EventLoop loop) {
return new BooleanEvent(loop, this::getBButton);
return button(Button.kB.value, loop);
}
/**
@@ -273,7 +273,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent x(EventLoop loop) {
return new BooleanEvent(loop, this::getXButton);
return button(Button.kX.value, loop);
}
/**
@@ -311,7 +311,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent y(EventLoop loop) {
return new BooleanEvent(loop, this::getYButton);
return button(Button.kY.value, loop);
}
/**
@@ -349,7 +349,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent leftBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftBumperButton);
return button(Button.kLeftBumper.value, loop);
}
/**
@@ -387,7 +387,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent rightBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getRightBumperButton);
return button(Button.kRightBumper.value, loop);
}
/**
@@ -425,7 +425,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent leftStick(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftStickButton);
return button(Button.kLeftStick.value, loop);
}
/**
@@ -463,7 +463,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent rightStick(EventLoop loop) {
return new BooleanEvent(loop, this::getRightStickButton);
return button(Button.kRightStick.value, loop);
}
/**
@@ -501,7 +501,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent ellipses(EventLoop loop) {
return new BooleanEvent(loop, this::getEllipsesButton);
return button(Button.kEllipses.value, loop);
}
/**
@@ -539,7 +539,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent hamburger(EventLoop loop) {
return new BooleanEvent(loop, this::getHamburgerButton);
return button(Button.kHamburger.value, loop);
}
/**
@@ -577,7 +577,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent stadia(EventLoop loop) {
return new BooleanEvent(loop, this::getStadiaButton);
return button(Button.kStadia.value, loop);
}
/**
@@ -615,7 +615,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent rightTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getRightTriggerButton);
return button(Button.kRightTrigger.value, loop);
}
/**
@@ -653,7 +653,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent leftTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftTriggerButton);
return button(Button.kLeftTrigger.value, loop);
}
/**
@@ -691,7 +691,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent google(EventLoop loop) {
return new BooleanEvent(loop, this::getGoogleButton);
return button(Button.kGoogle.value, loop);
}
/**
@@ -729,7 +729,7 @@ public class StadiaController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent frame(EventLoop loop) {
return new BooleanEvent(loop, this::getFrameButton);
return button(Button.kFrame.value, loop);
}
/**

View File

@@ -177,7 +177,7 @@ public class XboxController extends GenericHID implements Sendable {
* threshold, attached to the given event loop
*/
public BooleanEvent leftTrigger(double threshold, EventLoop loop) {
return new BooleanEvent(loop, () -> getLeftTriggerAxis() > threshold);
return axisGreaterThan(Axis.kLeftTrigger.value, threshold, loop);
}
/**
@@ -213,7 +213,7 @@ public class XboxController extends GenericHID implements Sendable {
* threshold, attached to the given event loop
*/
public BooleanEvent rightTrigger(double threshold, EventLoop loop) {
return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold);
return axisGreaterThan(Axis.kRightTrigger.value, threshold, loop);
}
/**
@@ -263,7 +263,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent a(EventLoop loop) {
return new BooleanEvent(loop, this::getAButton);
return button(Button.kA.value, loop);
}
/**
@@ -301,7 +301,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent b(EventLoop loop) {
return new BooleanEvent(loop, this::getBButton);
return button(Button.kB.value, loop);
}
/**
@@ -339,7 +339,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent x(EventLoop loop) {
return new BooleanEvent(loop, this::getXButton);
return button(Button.kX.value, loop);
}
/**
@@ -377,7 +377,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent y(EventLoop loop) {
return new BooleanEvent(loop, this::getYButton);
return button(Button.kY.value, loop);
}
/**
@@ -415,7 +415,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent leftBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftBumperButton);
return button(Button.kLeftBumper.value, loop);
}
/**
@@ -453,7 +453,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent rightBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getRightBumperButton);
return button(Button.kRightBumper.value, loop);
}
/**
@@ -491,7 +491,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent back(EventLoop loop) {
return new BooleanEvent(loop, this::getBackButton);
return button(Button.kBack.value, loop);
}
/**
@@ -529,7 +529,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent start(EventLoop loop) {
return new BooleanEvent(loop, this::getStartButton);
return button(Button.kStart.value, loop);
}
/**
@@ -567,7 +567,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent leftStick(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftStickButton);
return button(Button.kLeftStick.value, loop);
}
/**
@@ -605,7 +605,7 @@ public class XboxController extends GenericHID implements Sendable {
* attached to the given loop.
*/
public BooleanEvent rightStick(EventLoop loop) {
return new BooleanEvent(loop, this::getRightStickButton);
return button(Button.kRightStick.value, loop);
}
/**