mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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.
|
||||
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
#include "frc2/command/button/CommandJoystick.h"
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandJoystick::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<class Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Trigger(frc::EventLoop* loop) const {
|
||||
return Joystick::Trigger(loop).CastTo<class Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Top(frc::EventLoop* loop) const {
|
||||
return Joystick::Top(loop).CastTo<class Trigger>();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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.
|
||||
|
||||
#include "frc2/command/button/CommandPS4Controller.h"
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandPS4Controller::Square(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Square(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Cross(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Cross(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Circle(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Circle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Triangle(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Triangle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L1(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R1(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L2(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R2(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Options(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Options(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L3(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R3(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::PS(frc::EventLoop* loop) const {
|
||||
return PS4Controller::PS(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Touchpad(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Touchpad(loop).CastTo<Trigger>();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// 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.
|
||||
|
||||
#include "frc2/command/button/CommandXboxController.h"
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const {
|
||||
return XboxController::LeftBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::RightBumper(frc::EventLoop* loop) const {
|
||||
return XboxController::RightBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::LeftStick(frc::EventLoop* loop) const {
|
||||
return XboxController::LeftStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::RightStick(frc::EventLoop* loop) const {
|
||||
return XboxController::RightStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::A(frc::EventLoop* loop) const {
|
||||
return XboxController::A(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::B(frc::EventLoop* loop) const {
|
||||
return XboxController::B(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::X(frc::EventLoop* loop) const {
|
||||
return XboxController::X(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Y(frc::EventLoop* loop) const {
|
||||
return XboxController::Y(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Back(frc::EventLoop* loop) const {
|
||||
return XboxController::Back(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Start(frc::EventLoop* loop) const {
|
||||
return XboxController::Start(loop).CastTo<Trigger>();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include <frc/GenericHID.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A subclass of {@link GenericHID} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
class CommandGenericHID : public frc::GenericHID {
|
||||
public:
|
||||
using GenericHID::GenericHID;
|
||||
|
||||
/**
|
||||
* 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. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include <frc/Joystick.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A subclass of {@link Joystick} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see Joystick
|
||||
*/
|
||||
class CommandJoystick : public frc::Joystick {
|
||||
public:
|
||||
using Joystick::Joystick;
|
||||
|
||||
/**
|
||||
* 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. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
*/
|
||||
class Trigger Button(
|
||||
int button, frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the trigger button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
class Trigger Trigger(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the top button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the top button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
class Trigger Top(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,165 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include <frc/PS4Controller.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A subclass of {@link PS4Controller} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see PS4Controller
|
||||
*/
|
||||
class CommandPS4Controller : public frc::PS4Controller {
|
||||
public:
|
||||
using PS4Controller::PS4Controller;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the square button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the square button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Square(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the cross button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the cross button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Cross(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the circle button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the circle button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Circle(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the triangle button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the triangle button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Triangle(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the L1 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the L1 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger L1(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the R1 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the R1 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger R1(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the L2 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the L2 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger L2(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the R2 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the R2 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger R2(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the options button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the options button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Options(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the L3 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the L3 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger L3(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the R3 button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the R3 button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger R3(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the PS button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the PS button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger PS(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the touchpad's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the touchpad's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -0,0 +1,132 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
#include <frc/XboxController.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A subclass of {@link XboxController} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see XboxController
|
||||
*/
|
||||
class CommandXboxController : public frc::XboxController {
|
||||
public:
|
||||
using XboxController::XboxController;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left bumper's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the left bumper's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger LeftBumper(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the right bumper's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the right bumper's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger RightBumper(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left stick's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the left stick's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger LeftStick(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the right stick's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the right stick's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger RightStick(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the A button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the A button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger A(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the B button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the B button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger B(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the X button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the X button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger X(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the Y button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the Y button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Y(frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the back button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the back button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Back(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the start button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the start button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
Trigger Start(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -30,6 +31,11 @@ bool GenericHID::GetRawButtonReleased(int button) {
|
||||
return DriverStation::GetStickButtonReleased(m_port, button);
|
||||
}
|
||||
|
||||
BooleanEvent GenericHID::Button(int button, EventLoop* loop) const {
|
||||
return BooleanEvent(loop,
|
||||
[this, button]() { return this->GetRawButton(button); });
|
||||
}
|
||||
|
||||
double GenericHID::GetRawAxis(int axis) const {
|
||||
return DriverStation::GetStickAxis(m_port, axis);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/numbers>
|
||||
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Joystick::Joystick(int port) : GenericHID(port) {
|
||||
@@ -93,6 +95,10 @@ bool Joystick::GetTriggerReleased() {
|
||||
return GetRawButtonReleased(Button::kTrigger);
|
||||
}
|
||||
|
||||
BooleanEvent Joystick::Trigger(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTrigger(); });
|
||||
}
|
||||
|
||||
bool Joystick::GetTop() const {
|
||||
return GetRawButton(Button::kTop);
|
||||
}
|
||||
@@ -105,6 +111,10 @@ bool Joystick::GetTopReleased() {
|
||||
return GetRawButtonReleased(Button::kTop);
|
||||
}
|
||||
|
||||
BooleanEvent Joystick::Top(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTop(); });
|
||||
}
|
||||
|
||||
double Joystick::GetMagnitude() const {
|
||||
return std::sqrt(std::pow(GetX(), 2) + std::pow(GetY(), 2));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
PS4Controller::PS4Controller(int port) : GenericHID(port) {
|
||||
@@ -48,6 +50,10 @@ bool PS4Controller::GetSquareButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kSquare);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Square(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetSquareButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetCrossButton() const {
|
||||
return GetRawButton(Button::kCross);
|
||||
}
|
||||
@@ -60,6 +66,10 @@ bool PS4Controller::GetCrossButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCross);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Cross(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetCrossButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetCircleButton() const {
|
||||
return GetRawButton(Button::kCircle);
|
||||
}
|
||||
@@ -72,6 +82,10 @@ bool PS4Controller::GetCircleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kCircle);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Circle(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetCircleButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetTriangleButton() const {
|
||||
return GetRawButton(Button::kTriangle);
|
||||
}
|
||||
@@ -84,6 +98,10 @@ bool PS4Controller::GetTriangleButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kTriangle);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Triangle(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTriangleButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetL1Button() const {
|
||||
return GetRawButton(Button::kL1);
|
||||
}
|
||||
@@ -96,6 +114,10 @@ bool PS4Controller::GetL1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL1);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::L1(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetL1Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetR1Button() const {
|
||||
return GetRawButton(Button::kR1);
|
||||
}
|
||||
@@ -108,6 +130,10 @@ bool PS4Controller::GetR1ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR1);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::R1(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetR1Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetL2Button() const {
|
||||
return GetRawButton(Button::kL2);
|
||||
}
|
||||
@@ -120,6 +146,10 @@ bool PS4Controller::GetL2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL2);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::L2(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetL2Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetR2Button() const {
|
||||
return GetRawButton(Button::kR2);
|
||||
}
|
||||
@@ -132,6 +162,10 @@ bool PS4Controller::GetR2ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR2);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::R2(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetR2Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetShareButton() const {
|
||||
return GetRawButton(Button::kShare);
|
||||
}
|
||||
@@ -144,6 +178,10 @@ bool PS4Controller::GetShareButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kShare);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Share(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetShareButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetOptionsButton() const {
|
||||
return GetRawButton(Button::kOptions);
|
||||
}
|
||||
@@ -156,6 +194,10 @@ bool PS4Controller::GetOptionsButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kOptions);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Options(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetOptionsButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetL3Button() const {
|
||||
return GetRawButton(Button::kL3);
|
||||
}
|
||||
@@ -168,6 +210,10 @@ bool PS4Controller::GetL3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kL3);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::L3(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetL3Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetR3Button() const {
|
||||
return GetRawButton(Button::kR3);
|
||||
}
|
||||
@@ -180,6 +226,10 @@ bool PS4Controller::GetR3ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kR3);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::R3(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetR3Button(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetPSButton() const {
|
||||
return GetRawButton(Button::kPS);
|
||||
}
|
||||
@@ -192,6 +242,10 @@ bool PS4Controller::GetPSButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kPS);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::PS(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetPSButton(); });
|
||||
}
|
||||
|
||||
bool PS4Controller::GetTouchpad() const {
|
||||
return GetRawButton(Button::kTouchpad);
|
||||
}
|
||||
@@ -203,3 +257,7 @@ bool PS4Controller::GetTouchpadPressed() {
|
||||
bool PS4Controller::GetTouchpadReleased() {
|
||||
return GetRawButtonReleased(Button::kTouchpad);
|
||||
}
|
||||
|
||||
BooleanEvent PS4Controller::Touchpad(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetTouchpad(); });
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
XboxController::XboxController(int port) : GenericHID(port) {
|
||||
@@ -60,6 +62,14 @@ bool XboxController::GetRightBumperReleased() {
|
||||
return GetRawButtonReleased(Button::kRightBumper);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::LeftBumper(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftBumper(); });
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::RightBumper(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightBumper(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetLeftStickButton() const {
|
||||
return GetRawButton(Button::kLeftStick);
|
||||
}
|
||||
@@ -84,6 +94,14 @@ bool XboxController::GetRightStickButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kRightStick);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::LeftStick(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); });
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::RightStick(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetAButton() const {
|
||||
return GetRawButton(Button::kA);
|
||||
}
|
||||
@@ -96,6 +114,10 @@ bool XboxController::GetAButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kA);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::A(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetAButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetBButton() const {
|
||||
return GetRawButton(Button::kB);
|
||||
}
|
||||
@@ -108,6 +130,10 @@ bool XboxController::GetBButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kB);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::B(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetBButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetXButton() const {
|
||||
return GetRawButton(Button::kX);
|
||||
}
|
||||
@@ -120,6 +146,10 @@ bool XboxController::GetXButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kX);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::X(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetXButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetYButton() const {
|
||||
return GetRawButton(Button::kY);
|
||||
}
|
||||
@@ -132,6 +162,10 @@ bool XboxController::GetYButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kY);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::Y(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetYButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetBackButton() const {
|
||||
return GetRawButton(Button::kBack);
|
||||
}
|
||||
@@ -144,6 +178,10 @@ bool XboxController::GetBackButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kBack);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::Back(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetBackButton(); });
|
||||
}
|
||||
|
||||
bool XboxController::GetStartButton() const {
|
||||
return GetRawButton(Button::kStart);
|
||||
}
|
||||
@@ -155,3 +193,7 @@ bool XboxController::GetStartButtonPressed() {
|
||||
bool XboxController::GetStartButtonReleased() {
|
||||
return GetRawButtonReleased(Button::kStart);
|
||||
}
|
||||
|
||||
BooleanEvent XboxController::Start(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->GetStartButton(); });
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
class DriverStation;
|
||||
class BooleanEvent;
|
||||
class EventLoop;
|
||||
|
||||
/**
|
||||
* Handle input from standard HID devices connected to the Driver Station.
|
||||
@@ -91,6 +92,16 @@ class GenericHID {
|
||||
*/
|
||||
bool GetRawButtonReleased(int 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.
|
||||
*/
|
||||
BooleanEvent Button(int button, EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Get the value of the axis.
|
||||
*
|
||||
|
||||
@@ -172,6 +172,15 @@ class Joystick : public GenericHID {
|
||||
*/
|
||||
bool GetTriggerReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Trigger(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the state of the top button on the joystick.
|
||||
*
|
||||
@@ -195,6 +204,15 @@ class Joystick : public GenericHID {
|
||||
*/
|
||||
bool GetTopReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Top(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Get the magnitude of the direction vector formed by the joystick's
|
||||
* current position relative to its origin.
|
||||
|
||||
@@ -98,6 +98,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetSquareButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Square(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Cross button on the controller.
|
||||
*
|
||||
@@ -119,6 +128,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetCrossButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Cross(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Circle button on the controller.
|
||||
*
|
||||
@@ -140,6 +158,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetCircleButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Circle(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Triangle button on the controller.
|
||||
*
|
||||
@@ -161,6 +188,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetTriangleButtonReleased();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the triangle button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance representing the triangle button's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
BooleanEvent Triangle(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the L1 button on the controller.
|
||||
*
|
||||
@@ -182,6 +218,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetL1ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent L1(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the R1 button on the controller.
|
||||
*
|
||||
@@ -203,6 +248,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetR1ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent R1(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the L2 button on the controller.
|
||||
*
|
||||
@@ -224,6 +278,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetL2ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent L2(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the R2 button on the controller.
|
||||
*
|
||||
@@ -245,6 +308,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetR2ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent R2(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Share button on the controller.
|
||||
*
|
||||
@@ -266,6 +338,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetShareButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Share(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Options button on the controller.
|
||||
*
|
||||
@@ -287,6 +368,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetOptionsButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Options(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the L3 button (pressing the left analog stick) on the
|
||||
* controller.
|
||||
@@ -309,6 +399,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetL3ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent L3(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the R3 button (pressing the right analog stick) on the
|
||||
* controller.
|
||||
@@ -331,6 +430,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetR3ButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent R3(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the PS button on the controller.
|
||||
*
|
||||
@@ -352,6 +460,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetPSButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent PS(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the touchpad button on the controller.
|
||||
*
|
||||
@@ -373,6 +490,15 @@ class PS4Controller : public GenericHID {
|
||||
*/
|
||||
bool GetTouchpadReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Touchpad(EventLoop* loop) const;
|
||||
|
||||
struct Button {
|
||||
static constexpr int kSquare = 1;
|
||||
static constexpr int kCross = 2;
|
||||
|
||||
@@ -96,6 +96,24 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetRightBumperReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent LeftBumper(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent RightBumper(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the left stick button (LSB) on the controller.
|
||||
*/
|
||||
@@ -126,6 +144,24 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetRightStickButtonReleased();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left stick's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance representing the left stick's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
BooleanEvent LeftStick(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the right stick's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance representing the right stick's digital signal
|
||||
* attached to the given loop.
|
||||
*/
|
||||
BooleanEvent RightStick(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the A button on the controller.
|
||||
*
|
||||
@@ -147,6 +183,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetAButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent A(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the B button on the controller.
|
||||
*
|
||||
@@ -168,6 +213,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetBButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent B(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the X button on the controller.
|
||||
*
|
||||
@@ -189,6 +243,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetXButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent X(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the Y button on the controller.
|
||||
*
|
||||
@@ -210,6 +273,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetYButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Y(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Whether the Y button was released since the last check.
|
||||
*
|
||||
@@ -231,6 +303,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetBackButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Back(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Read the value of the start button on the controller.
|
||||
*
|
||||
@@ -252,6 +333,15 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
bool GetStartButtonReleased();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
BooleanEvent Start(EventLoop* loop) const;
|
||||
|
||||
struct Button {
|
||||
static constexpr int kLeftBumper = 5;
|
||||
static constexpr int kRightBumper = 6;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user