[wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)

This commit is contained in:
Starlight220
2022-06-14 08:48:16 +03:00
committed by GitHub
parent 9b1bf5c7f1
commit fd884581e4
24 changed files with 1717 additions and 1 deletions

View File

@@ -5,6 +5,8 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
import java.util.HashMap;
import java.util.Map;
@@ -119,6 +121,17 @@ public class GenericHID {
return DriverStation.getStickButtonReleased(m_port, button);
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the button's digital signal attached to the given loop.
*/
public BooleanEvent button(int button, EventLoop loop) {
return new BooleanEvent(loop, () -> getRawButton(button));
}
/**
* Get the value of the axis.
*

View File

@@ -6,6 +6,8 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from Flight Joysticks connected to the Driver Station.
@@ -233,6 +235,17 @@ public class Joystick extends GenericHID {
return getRawButtonReleased(ButtonType.kTrigger.value);
}
/**
* Constructs an event instance around the trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the trigger button's digital signal attached to the
* given loop.
*/
public BooleanEvent trigger(EventLoop loop) {
return new BooleanEvent(loop, this::getTrigger);
}
/**
* Read the state of the top button on the joystick.
*
@@ -260,6 +273,17 @@ public class Joystick extends GenericHID {
return getRawButtonReleased(ButtonType.kTop.value);
}
/**
* Constructs an event instance around the top button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the top button's digital signal attached to the given
* loop.
*/
public BooleanEvent top(EventLoop loop) {
return new BooleanEvent(loop, this::getTop);
}
/**
* Get the magnitude of the direction vector formed by the joystick's current position relative to
* its origin.

View File

@@ -6,6 +6,8 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from PS4 controllers connected to the Driver Station.
@@ -209,6 +211,30 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kR2.value);
}
/**
* Constructs an event instance around the L2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L2(EventLoop loop) {
return new BooleanEvent(loop, this::getL2Button);
}
/**
* Constructs an event instance around the R2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R2(EventLoop loop) {
return new BooleanEvent(loop, this::getR2Button);
}
/**
* Read the value of the L1 button on the controller.
*
@@ -263,6 +289,30 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kR1.value);
}
/**
* Constructs an event instance around the L1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L1(EventLoop loop) {
return new BooleanEvent(loop, this::getL1Button);
}
/**
* Constructs an event instance around the R1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R1(EventLoop loop) {
return new BooleanEvent(loop, this::getR1Button);
}
/**
* Read the value of the L3 button (pressing the left analog stick) on the controller.
*
@@ -317,6 +367,30 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kR3.value);
}
/**
* Constructs an event instance around the L3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L3(EventLoop loop) {
return new BooleanEvent(loop, this::getL3Button);
}
/**
* Constructs an event instance around the R3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R3(EventLoop loop) {
return new BooleanEvent(loop, this::getR3Button);
}
/**
* Read the value of the Square button on the controller.
*
@@ -344,6 +418,17 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kSquare.value);
}
/**
* Constructs an event instance around the square button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the square button's digital signal attached to the given
* loop.
*/
public BooleanEvent square(EventLoop loop) {
return new BooleanEvent(loop, this::getSquareButton);
}
/**
* Read the value of the Cross button on the controller.
*
@@ -371,6 +456,17 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kCross.value);
}
/**
* Constructs an event instance around the cross button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the cross button's digital signal attached to the given
* loop.
*/
public BooleanEvent cross(EventLoop loop) {
return new BooleanEvent(loop, this::getCrossButton);
}
/**
* Read the value of the Triangle button on the controller.
*
@@ -425,6 +521,17 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kCircle.value);
}
/**
* Constructs an event instance around the circle button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the circle button's digital signal attached to the given
* loop.
*/
public BooleanEvent circle(EventLoop loop) {
return new BooleanEvent(loop, this::getCircleButton);
}
/**
* Read the value of the share button on the controller.
*
@@ -452,6 +559,18 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kShare.value);
}
/**
* Constructs an event instance around the share button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the share button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent share(EventLoop loop) {
return new BooleanEvent(loop, this::getShareButton);
}
/**
* Read the value of the PS button on the controller.
*
@@ -479,6 +598,18 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kPS.value);
}
/**
* Constructs an event instance around the PS button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the PS button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent PS(EventLoop loop) {
return new BooleanEvent(loop, this::getPSButton);
}
/**
* Read the value of the options button on the controller.
*
@@ -506,6 +637,17 @@ public class PS4Controller extends GenericHID {
return getRawButtonReleased(Button.kOptions.value);
}
/**
* Constructs an event instance around the options button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the options button's digital signal attached to the
* given loop.
*/
public BooleanEvent options(EventLoop loop) {
return new BooleanEvent(loop, this::getOptionsButton);
}
/**
* Read the value of the touchpad on the controller.
*
@@ -532,4 +674,15 @@ public class PS4Controller extends GenericHID {
public boolean getTouchpadReleased() {
return getRawButtonReleased(Button.kTouchpad.value);
}
/**
* Constructs an event instance around the touchpad's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the touchpad's digital signal attached to the given
* loop.
*/
public BooleanEvent touchpad(EventLoop loop) {
return new BooleanEvent(loop, this::getTouchpad);
}
}

View File

@@ -6,6 +6,8 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station.
@@ -208,6 +210,28 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kRightBumper.value);
}
/**
* Constructs an event instance around the right bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent leftBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftBumper);
}
/**
* Constructs an event instance around the left bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent rightBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getRightBumper);
}
/**
* Read the value of the left stick button (LSB) on the controller.
*
@@ -262,6 +286,28 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kRightStick.value);
}
/**
* Constructs an event instance around the left stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent leftStick(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftStickButton);
}
/**
* Constructs an event instance around the right stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent rightStick(EventLoop loop) {
return new BooleanEvent(loop, this::getRightStickButton);
}
/**
* Read the value of the A button on the controller.
*
@@ -289,6 +335,18 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kA.value);
}
/**
* Constructs an event instance around the A button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the A button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent a(EventLoop loop) {
return new BooleanEvent(loop, this::getAButton);
}
/**
* Read the value of the B button on the controller.
*
@@ -316,6 +374,18 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kB.value);
}
/**
* Constructs an event instance around the B button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the B button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent b(EventLoop loop) {
return new BooleanEvent(loop, this::getBButton);
}
/**
* Read the value of the X button on the controller.
*
@@ -343,6 +413,18 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kX.value);
}
/**
* Constructs an event instance around the X button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the X button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent x(EventLoop loop) {
return new BooleanEvent(loop, this::getXButton);
}
/**
* Read the value of the Y button on the controller.
*
@@ -370,6 +452,18 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kY.value);
}
/**
* Constructs an event instance around the Y button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the Y button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent y(EventLoop loop) {
return new BooleanEvent(loop, this::getYButton);
}
/**
* Read the value of the back button on the controller.
*
@@ -397,6 +491,17 @@ public class XboxController extends GenericHID {
return getRawButtonReleased(Button.kBack.value);
}
/**
* Constructs an event instance around the back button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the back button's digital signal attached to the given
* loop.
*/
public BooleanEvent back(EventLoop loop) {
return new BooleanEvent(loop, this::getBackButton);
}
/**
* Read the value of the start button on the controller.
*
@@ -423,4 +528,15 @@ public class XboxController extends GenericHID {
public boolean getStartButtonReleased() {
return getRawButtonReleased(Button.kStart.value);
}
/**
* Constructs an event instance around the start button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the start button's digital signal attached to the given
* loop.
*/
public BooleanEvent start(EventLoop loop) {
return new BooleanEvent(loop, this::getStartButton);
}
}