[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

@@ -0,0 +1,42 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* A subclass of {@link GenericHID} with {@link Trigger} factories for command-based.
*
* @see GenericHID
*/
public class CommandGenericHID extends GenericHID {
/**
* Construct an instance of a device.
*
* @param port The port index on the Driver Station that the device is plugged into.
*/
public CommandGenericHID(int port) {
super(port);
}
@Override
public Trigger button(int button, EventLoop loop) {
return super.button(button, loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @return an event instance representing the button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #button(int, EventLoop)
*/
public Trigger button(int button) {
return button(button, CommandScheduler.getInstance().getDefaultButtonLoop());
}
}

View File

@@ -0,0 +1,74 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* A subclass of {@link Joystick} with {@link Trigger} factories for command-based.
*
* @see Joystick
*/
public class CommandJoystick extends Joystick {
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public CommandJoystick(int port) {
super(port);
}
@Override
public Trigger button(int button, EventLoop loop) {
return super.button(button, loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @return an event instance representing the button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #button(int, EventLoop)
*/
public Trigger button(int button) {
return button(button, CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the trigger button's digital signal.
*
* @return an event instance representing the trigger button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #trigger(EventLoop)
*/
public Trigger trigger() {
return trigger(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger trigger(EventLoop loop) {
return super.trigger(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the top button's digital signal.
*
* @return an event instance representing the top button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #top(EventLoop)
*/
public Trigger top() {
return top(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger top(EventLoop loop) {
return super.top(loop).castTo(Trigger::new);
}
}

View File

@@ -0,0 +1,221 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.wpilibj.PS4Controller;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* A subclass of {@link PS4Controller} with {@link Trigger} factories for command-based.
*
* @see PS4Controller
*/
@SuppressWarnings("MethodName")
public class CommandPS4Controller extends PS4Controller {
/**
* Construct an instance of a device.
*
* @param port The port index on the Driver Station that the device is plugged into.
*/
public CommandPS4Controller(int port) {
super(port);
}
/**
* Constructs an event instance around the L2 button's digital signal.
*
* @return an event instance representing the L2 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger L2() {
return L2(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger L2(EventLoop loop) {
return super.L2(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the R2 button's digital signal.
*
* @return an event instance representing the R2 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger R2() {
return R2(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger R2(EventLoop loop) {
return super.R2(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the L1 button's digital signal.
*
* @return an event instance representing the L1 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger L1() {
return L1(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger L1(EventLoop loop) {
return super.L1(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the R1 button's digital signal.
*
* @return an event instance representing the R1 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger R1() {
return R1(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger R1(EventLoop loop) {
return super.R1(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the L3 button's digital signal.
*
* @return an event instance representing the L3 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger L3() {
return L3(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger L3(EventLoop loop) {
return super.L3(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the R3 button's digital signal.
*
* @return an event instance representing the R3 button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger R3() {
return R3(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger R3(EventLoop loop) {
return super.R3(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the square button's digital signal.
*
* @return an event instance representing the square button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger square() {
return square(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger square(EventLoop loop) {
return super.square(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the cross button's digital signal.
*
* @return an event instance representing the cross button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger cross() {
return cross(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger cross(EventLoop loop) {
return super.cross(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the circle button's digital signal.
*
* @return an event instance representing the circle button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger circle() {
return circle(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger circle(EventLoop loop) {
return super.circle(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the share button's digital signal.
*
* @return an event instance representing the share button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger share() {
return share(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger share(EventLoop loop) {
return super.share(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the PS button's digital signal.
*
* @return an event instance representing the PS button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger PS() {
return PS(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger PS(EventLoop loop) {
return super.PS(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the options button's digital signal.
*
* @return an event instance representing the options button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger options() {
return options(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger options(EventLoop loop) {
return super.options(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the touchpad's digital signal.
*
* @return an event instance representing the touchpad's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
*/
public Trigger touchpad() {
return touchpad(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger touchpad(EventLoop loop) {
return super.touchpad(loop).castTo(Trigger::new);
}
}

View File

@@ -0,0 +1,186 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* A subclass of {@link XboxController} with {@link Trigger} factories for command-based.
*
* @see XboxController
*/
@SuppressWarnings("MethodName")
public class CommandXboxController extends XboxController {
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public CommandXboxController(int port) {
super(port);
}
/**
* Constructs an event instance around the left bumper's digital signal.
*
* @return an event instance representing the left bumper's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #leftBumper(EventLoop)
*/
public Trigger leftBumper() {
return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger leftBumper(EventLoop loop) {
return super.leftBumper(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the right bumper's digital signal.
*
* @return an event instance representing the right bumper's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #rightBumper(EventLoop)
*/
public Trigger rightBumper() {
return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger rightBumper(EventLoop loop) {
return super.rightBumper(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the left stick button's digital signal.
*
* @return an event instance representing the left stick button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #leftStick(EventLoop)
*/
public Trigger leftStick() {
return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger leftStick(EventLoop loop) {
return super.leftStick(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the right stick button's digital signal.
*
* @return an event instance representing the right stick button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #rightStick(EventLoop)
*/
public Trigger rightStick() {
return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger rightStick(EventLoop loop) {
return super.rightStick(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the X button's digital signal.
*
* @return an event instance representing the X button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #x(EventLoop)
*/
public Trigger x() {
return x(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger x(EventLoop loop) {
return super.x(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the Y button's digital signal.
*
* @return an event instance representing the Y button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #y(EventLoop)
*/
public Trigger y() {
return y(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger y(EventLoop loop) {
return super.y(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the A button's digital signal.
*
* @return an event instance representing the A button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #a(EventLoop)
*/
public Trigger a() {
return a(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger a(EventLoop loop) {
return super.a(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the B button's digital signal.
*
* @return an event instance representing the B button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #b(EventLoop)
*/
public Trigger b() {
return b(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger b(EventLoop loop) {
return super.b(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the start button's digital signal.
*
* @return an event instance representing the start button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #start(EventLoop)
*/
public Trigger start() {
return start(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger start(EventLoop loop) {
return super.start(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the back button's digital signal.
*
* @return an event instance representing the back button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #back(EventLoop)
*/
public Trigger back() {
return back(CommandScheduler.getInstance().getDefaultButtonLoop());
}
@Override
public Trigger back(EventLoop loop) {
return super.back(loop).castTo(Trigger::new);
}
}