[wpilib] Add StadiaController and command wrapper (#6083)

This commit is contained in:
NC GEARS FRC 1918
2023-12-23 11:15:05 -05:00
committed by GitHub
parent 4e4a468d4d
commit c1178d5add
6 changed files with 2209 additions and 0 deletions

View File

@@ -0,0 +1,405 @@
// 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.StadiaController;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
/**
* A version of {@link StadiaController} with {@link Trigger} factories for command-based.
*
* @see StadiaController
*/
@SuppressWarnings("MethodName")
public class CommandStadiaController extends CommandGenericHID {
private final StadiaController m_hid;
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public CommandStadiaController(int port) {
super(port);
m_hid = new StadiaController(port);
}
/**
* Get the underlying GenericHID object.
*
* @return the wrapped GenericHID object
*/
@Override
public StadiaController getHID() {
return m_hid;
}
/**
* 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());
}
/**
* 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 right bumper's digital signal attached to the given
* loop.
*/
public Trigger leftBumper(EventLoop loop) {
return m_hid.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());
}
/**
* 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 left bumper's digital signal attached to the given
* loop.
*/
public Trigger rightBumper(EventLoop loop) {
return m_hid.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());
}
/**
* 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 Trigger leftStick(EventLoop loop) {
return m_hid.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());
}
/**
* 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 Trigger rightStick(EventLoop loop) {
return m_hid.rightStick(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the right trigger button's digital signal.
*
* @return an event instance representing the right trigger button's digital signal attached to
* the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #rightTrigger(EventLoop)
*/
public Trigger rightTrigger() {
return rightTrigger(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the right trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger button's digital signal attached to
* the given loop.
*/
public Trigger rightTrigger(EventLoop loop) {
return m_hid.rightTrigger(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the left trigger button's digital signal.
*
* @return an event instance representing the left trigger button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #leftTrigger(EventLoop)
*/
public Trigger leftTrigger() {
return leftTrigger(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the left trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger button's digital signal attached to the
* given loop.
*/
public Trigger leftTrigger(EventLoop loop) {
return m_hid.leftTrigger(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());
}
/**
* 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.
*/
public Trigger a(EventLoop loop) {
return m_hid.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());
}
/**
* 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.
*/
public Trigger b(EventLoop loop) {
return m_hid.b(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());
}
/**
* 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.
*/
public Trigger x(EventLoop loop) {
return m_hid.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());
}
/**
* 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.
*/
public Trigger y(EventLoop loop) {
return m_hid.y(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the ellipses button's digital signal.
*
* @return an event instance representing the ellipses button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #ellipses(EventLoop)
*/
public Trigger ellipses() {
return ellipses(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the ellipses button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the ellipses button's digital signal attached to the
* given loop.
*/
public Trigger ellipses(EventLoop loop) {
return m_hid.ellipses(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the stadia button's digital signal.
*
* @return an event instance representing the stadia button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #stadia(EventLoop)
*/
public Trigger stadia() {
return stadia(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the stadia button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the stadia button's digital signal attached to the given
* loop.
*/
public Trigger stadia(EventLoop loop) {
return m_hid.stadia(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the google button's digital signal.
*
* @return an event instance representing the google button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #google(EventLoop)
*/
public Trigger google() {
return google(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the google button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the google button's digital signal attached to the given
* loop.
*/
public Trigger google(EventLoop loop) {
return m_hid.google(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the frame button's digital signal.
*
* @return an event instance representing the frame button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #frame(EventLoop)
*/
public Trigger frame() {
return frame(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the frame button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the frame button's digital signal attached to the given
* loop.
*/
public Trigger frame(EventLoop loop) {
return m_hid.frame(loop).castTo(Trigger::new);
}
/**
* Constructs an event instance around the hamburger button's digital signal.
*
* @return an event instance representing the hamburger button's digital signal attached to the
* {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #hamburger(EventLoop)
*/
public Trigger hamburger() {
return hamburger(CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around the hamburger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the hamburger button's digital signal attached to the
* given loop.
*/
public Trigger hamburger(EventLoop loop) {
return m_hid.hamburger(loop).castTo(Trigger::new);
}
/**
* Get the X axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftX() {
return m_hid.getLeftX();
}
/**
* Get the X axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightX() {
return m_hid.getRightX();
}
/**
* Get the Y axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftY() {
return m_hid.getLeftY();
}
/**
* Get the Y axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightY() {
return m_hid.getRightY();
}
}

View File

@@ -0,0 +1,72 @@
// 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/CommandStadiaController.h"
using namespace frc2;
Trigger CommandStadiaController::Button(int button,
frc::EventLoop* loop) const {
return GenericHID::Button(button, loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::LeftBumper(frc::EventLoop* loop) const {
return StadiaController::LeftBumper(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::RightBumper(frc::EventLoop* loop) const {
return StadiaController::RightBumper(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::LeftStick(frc::EventLoop* loop) const {
return StadiaController::LeftStick(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::RightStick(frc::EventLoop* loop) const {
return StadiaController::RightStick(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::A(frc::EventLoop* loop) const {
return StadiaController::A(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::B(frc::EventLoop* loop) const {
return StadiaController::B(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::X(frc::EventLoop* loop) const {
return StadiaController::X(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Y(frc::EventLoop* loop) const {
return StadiaController::Y(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Ellipses(frc::EventLoop* loop) const {
return StadiaController::Ellipses(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Hamburger(frc::EventLoop* loop) const {
return StadiaController::Hamburger(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Stadia(frc::EventLoop* loop) const {
return StadiaController::Stadia(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Google(frc::EventLoop* loop) const {
return StadiaController::Google(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::Frame(frc::EventLoop* loop) const {
return StadiaController::Frame(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::LeftTrigger(frc::EventLoop* loop) const {
return StadiaController::LeftTrigger(loop).CastTo<Trigger>();
}
Trigger CommandStadiaController::RightTrigger(frc::EventLoop* loop) const {
return StadiaController::RightTrigger(loop).CastTo<Trigger>();
}

View File

@@ -0,0 +1,201 @@
// 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/StadiaController.h>
#include "Trigger.h"
#include "frc2/command/CommandScheduler.h"
namespace frc2 {
/**
* A version of {@link StadiaController} with {@link Trigger} factories for
* command-based.
*
* @see StadiaController
*/
class CommandStadiaController : public frc::StadiaController {
public:
using StadiaController::StadiaController;
/**
* 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;
/**
* 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 ellipses 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 ellipses button's digital signal
* attached to the given loop.
*/
Trigger Ellipses(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the hamburger 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 hamburger button's digital
* signal attached to the given loop.
*/
Trigger Hamburger(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the stadia 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 stadia button's digital signal
* attached to the given loop.
*/
Trigger Stadia(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the google 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 google button's digital signal
* attached to the given loop.
*/
Trigger Google(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the frame 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 frame button's digital signal
* attached to the given loop.
*/
Trigger Frame(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the left trigger'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 trigger's digital signal
* attached to the given loop.
*/
Trigger LeftTrigger(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs an event instance around the right trigger'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 trigger's digital signal
* attached to the given loop.
*/
Trigger RightTrigger(
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
};
} // namespace frc2

View File

@@ -0,0 +1,272 @@
// 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 "frc/StadiaController.h"
#include <hal/FRCUsageReporting.h>
#include "frc/event/BooleanEvent.h"
using namespace frc;
StadiaController::StadiaController(int port) : GenericHID(port) {
// re-enable when StadiaController is added to Usage Reporting
// HAL_Report(HALUsageReporting::kResourceType_StadiaController, port + 1);
}
double StadiaController::GetLeftX() const {
return GetRawAxis(Axis::kLeftX);
}
double StadiaController::GetRightX() const {
return GetRawAxis(Axis::kRightX);
}
double StadiaController::GetLeftY() const {
return GetRawAxis(Axis::kLeftY);
}
double StadiaController::GetRightY() const {
return GetRawAxis(Axis::kRightY);
}
bool StadiaController::GetLeftBumper() const {
return GetRawButton(Button::kLeftBumper);
}
bool StadiaController::GetRightBumper() const {
return GetRawButton(Button::kRightBumper);
}
bool StadiaController::GetLeftBumperPressed() {
return GetRawButtonPressed(Button::kLeftBumper);
}
bool StadiaController::GetRightBumperPressed() {
return GetRawButtonPressed(Button::kRightBumper);
}
bool StadiaController::GetLeftBumperReleased() {
return GetRawButtonReleased(Button::kLeftBumper);
}
bool StadiaController::GetRightBumperReleased() {
return GetRawButtonReleased(Button::kRightBumper);
}
BooleanEvent StadiaController::LeftBumper(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetLeftBumper(); });
}
BooleanEvent StadiaController::RightBumper(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetRightBumper(); });
}
bool StadiaController::GetLeftStickButton() const {
return GetRawButton(Button::kLeftStick);
}
bool StadiaController::GetRightStickButton() const {
return GetRawButton(Button::kRightStick);
}
bool StadiaController::GetLeftStickButtonPressed() {
return GetRawButtonPressed(Button::kLeftStick);
}
bool StadiaController::GetRightStickButtonPressed() {
return GetRawButtonPressed(Button::kRightStick);
}
bool StadiaController::GetLeftStickButtonReleased() {
return GetRawButtonReleased(Button::kLeftStick);
}
bool StadiaController::GetRightStickButtonReleased() {
return GetRawButtonReleased(Button::kRightStick);
}
BooleanEvent StadiaController::LeftStick(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetLeftStickButton(); });
}
BooleanEvent StadiaController::RightStick(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetRightStickButton(); });
}
bool StadiaController::GetAButton() const {
return GetRawButton(Button::kA);
}
bool StadiaController::GetAButtonPressed() {
return GetRawButtonPressed(Button::kA);
}
bool StadiaController::GetAButtonReleased() {
return GetRawButtonReleased(Button::kA);
}
BooleanEvent StadiaController::A(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetAButton(); });
}
bool StadiaController::GetBButton() const {
return GetRawButton(Button::kB);
}
bool StadiaController::GetBButtonPressed() {
return GetRawButtonPressed(Button::kB);
}
bool StadiaController::GetBButtonReleased() {
return GetRawButtonReleased(Button::kB);
}
BooleanEvent StadiaController::B(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetBButton(); });
}
bool StadiaController::GetXButton() const {
return GetRawButton(Button::kX);
}
bool StadiaController::GetXButtonPressed() {
return GetRawButtonPressed(Button::kX);
}
bool StadiaController::GetXButtonReleased() {
return GetRawButtonReleased(Button::kX);
}
BooleanEvent StadiaController::X(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetXButton(); });
}
bool StadiaController::GetYButton() const {
return GetRawButton(Button::kY);
}
bool StadiaController::GetYButtonPressed() {
return GetRawButtonPressed(Button::kY);
}
bool StadiaController::GetYButtonReleased() {
return GetRawButtonReleased(Button::kY);
}
BooleanEvent StadiaController::Y(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetYButton(); });
}
bool StadiaController::GetEllipsesButton() const {
return GetRawButton(Button::kEllipses);
}
bool StadiaController::GetEllipsesButtonPressed() {
return GetRawButtonPressed(Button::kEllipses);
}
bool StadiaController::GetEllipsesButtonReleased() {
return GetRawButtonReleased(Button::kEllipses);
}
BooleanEvent StadiaController::Ellipses(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetEllipsesButton(); });
}
bool StadiaController::GetHamburgerButton() const {
return GetRawButton(Button::kHamburger);
}
bool StadiaController::GetHamburgerButtonPressed() {
return GetRawButtonPressed(Button::kHamburger);
}
bool StadiaController::GetHamburgerButtonReleased() {
return GetRawButtonReleased(Button::kHamburger);
}
BooleanEvent StadiaController::Hamburger(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetHamburgerButton(); });
}
bool StadiaController::GetStadiaButton() const {
return GetRawButton(Button::kStadia);
}
bool StadiaController::GetStadiaButtonPressed() {
return GetRawButtonPressed(Button::kStadia);
}
bool StadiaController::GetStadiaButtonReleased() {
return GetRawButtonReleased(Button::kStadia);
}
BooleanEvent StadiaController::Stadia(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetStadiaButton(); });
}
bool StadiaController::GetGoogleButton() const {
return GetRawButton(Button::kGoogle);
}
bool StadiaController::GetGoogleButtonPressed() {
return GetRawButtonPressed(Button::kGoogle);
}
bool StadiaController::GetGoogleButtonReleased() {
return GetRawButtonReleased(Button::kGoogle);
}
BooleanEvent StadiaController::Google(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetGoogleButton(); });
}
bool StadiaController::GetFrameButton() const {
return GetRawButton(Button::kFrame);
}
bool StadiaController::GetFrameButtonPressed() {
return GetRawButtonPressed(Button::kFrame);
}
bool StadiaController::GetFrameButtonReleased() {
return GetRawButtonReleased(Button::kFrame);
}
BooleanEvent StadiaController::Frame(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetFrameButton(); });
}
bool StadiaController::GetLeftTriggerButton() const {
return GetRawButton(Button::kLeftTrigger);
}
bool StadiaController::GetLeftTriggerButtonPressed() {
return GetRawButtonPressed(Button::kLeftTrigger);
}
bool StadiaController::GetLeftTriggerButtonReleased() {
return GetRawButtonReleased(Button::kLeftTrigger);
}
BooleanEvent StadiaController::LeftTrigger(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetLeftTriggerButton(); });
}
bool StadiaController::GetRightTriggerButton() const {
return GetRawButton(Button::kRightTrigger);
}
bool StadiaController::GetRightTriggerButtonPressed() {
return GetRawButtonPressed(Button::kRightTrigger);
}
bool StadiaController::GetRightTriggerButtonReleased() {
return GetRawButtonReleased(Button::kRightTrigger);
}
BooleanEvent StadiaController::RightTrigger(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetRightTriggerButton(); });
}

View File

@@ -0,0 +1,543 @@
// 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"
namespace frc {
/**
* Handle input from Stadia controllers connected to the Driver
* Station.
*
* This class handles Stadia input that comes from the Driver Station. Each time
* a value is requested the most recent value is returned. There is a single
* class instance for each controller and the mapping of ports to hardware
* buttons depends on the code in the Driver Station.
*/
class StadiaController : public GenericHID {
public:
/**
* Construct an instance of a Stadia controller.
*
* The controller index is the USB port on the Driver Station.
*
* @param port The port on the Driver Station that the controller is plugged
* into (0-5).
*/
explicit StadiaController(int port);
~StadiaController() override = default;
StadiaController(StadiaController&&) = default;
StadiaController& operator=(StadiaController&&) = default;
/**
* Get the X axis value of left side of the controller.
*
* @return the axis value
*/
double GetLeftX() const;
/**
* Get the X axis value of right side of the controller.
*
* @return the axis value
*/
double GetRightX() const;
/**
* Get the Y axis value of left side of the controller.
*
* @return the axis value
*/
double GetLeftY() const;
/**
* Get the Y axis value of right side of the controller.
*
* @return the axis value
*/
double GetRightY() const;
/**
* Read the value of the left bumper (LB) button on the controller.
*
* @return the state of the button
*/
bool GetLeftBumper() const;
/**
* Read the value of the right bumper (RB) button on the controller.
*
* @return the state of the button
*/
bool GetRightBumper() const;
/**
* Whether the left bumper (LB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check
*/
bool GetLeftBumperPressed();
/**
* Whether the right bumper (RB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check
*/
bool GetRightBumperPressed();
/**
* Whether the left bumper (LB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetLeftBumperReleased();
/**
* Whether the right bumper (RB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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.
*
* @return the state of the button
*/
bool GetLeftStickButton() const;
/**
* Read the value of the right stick button (RSB) on the controller.
*
* @return the state of the button
*/
bool GetRightStickButton() const;
/**
* Whether the left stick button (LSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetLeftStickButtonPressed();
/**
* Whether the right stick button (RSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check
*/
bool GetRightStickButtonPressed();
/**
* Whether the left stick button (LSB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetLeftStickButtonReleased();
/**
* Whether the right stick button (RSB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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.
*
* @return The state of the button.
*/
bool GetAButton() const;
/**
* Whether the A button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetAButtonPressed();
/**
* Whether the A button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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.
*
* @return The state of the button.
*/
bool GetBButton() const;
/**
* Whether the B button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetBButtonPressed();
/**
* Whether the B button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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.
*
* @return The state of the button.
*/
bool GetXButton() const;
/**
* Whether the X button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetXButtonPressed();
/**
* Whether the X button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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.
*
* @return The state of the button.
*/
bool GetYButton() const;
/**
* Whether the Y button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetYButtonPressed();
/**
* Whether the Y button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
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;
/**
* Read the value of the ellipses button on the controller.
*
* @return The state of the button.
*/
bool GetEllipsesButton() const;
/**
* Whether the ellipses button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetEllipsesButtonPressed();
/**
* Whether the ellipses button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetEllipsesButtonReleased();
/**
* Constructs an event instance around the ellipses button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the ellipses button's digital signal
* attached to the given loop.
*/
BooleanEvent Ellipses(EventLoop* loop) const;
/**
* Read the value of the hamburger button on the controller.
*
* @return The state of the button.
*/
bool GetHamburgerButton() const;
/**
* Whether the hamburger button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetHamburgerButtonPressed();
/**
* Whether the hamburger button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetHamburgerButtonReleased();
/**
* Constructs an event instance around the hamburger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the hamburger button's digital
* signal attached to the given loop.
*/
BooleanEvent Hamburger(EventLoop* loop) const;
/**
* Read the value of the stadia button on the controller.
*
* @return The state of the button.
*/
bool GetStadiaButton() const;
/**
* Whether the stadia button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetStadiaButtonPressed();
/**
* Whether the stadia button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetStadiaButtonReleased();
/**
* Constructs an event instance around the stadia button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the stadia button's digital signal
* attached to the given loop.
*/
BooleanEvent Stadia(EventLoop* loop) const;
/**
* Read the value of the google button on the controller.
*
* @return The state of the button.
*/
bool GetGoogleButton() const;
/**
* Whether the google button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetGoogleButtonPressed();
/**
* Whether the google button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetGoogleButtonReleased();
/**
* Constructs an event instance around the google button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the google button's digital signal
* attached to the given loop.
*/
BooleanEvent Google(EventLoop* loop) const;
/**
* Read the value of the frame button on the controller.
*
* @return The state of the button.
*/
bool GetFrameButton() const;
/**
* Whether the frame button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetFrameButtonPressed();
/**
* Whether the frame button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetFrameButtonReleased();
/**
* Constructs an event instance around the frame button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the frame button's digital signal
* attached to the given loop.
*/
BooleanEvent Frame(EventLoop* loop) const;
/**
* Read the value of the left trigger button on the controller.
*
* @return The state of the button.
*/
bool GetLeftTriggerButton() const;
/**
* Whether the left trigger button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetLeftTriggerButtonPressed();
/**
* Whether the left trigger button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetLeftTriggerButtonReleased();
/**
* Constructs an event instance around the left trigger button's digital
* signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger button's digital
* signal attached to the given loop.
*/
BooleanEvent LeftTrigger(EventLoop* loop) const;
/**
* Read the value of the right trigger button on the controller.
*
* @return The state of the button.
*/
bool GetRightTriggerButton() const;
/**
* Whether the right trigger button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetRightTriggerButtonPressed();
/**
* Whether the right trigger button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetRightTriggerButtonReleased();
/**
* Constructs an event instance around the right trigger button's digital
* signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger button's digital
* signal attached to the given loop.
*/
BooleanEvent RightTrigger(EventLoop* loop) const;
struct Button {
static constexpr int kA = 1;
static constexpr int kB = 2;
static constexpr int kX = 3;
static constexpr int kY = 4;
static constexpr int kLeftBumper = 5;
static constexpr int kRightBumper = 6;
static constexpr int kLeftStick = 7;
static constexpr int kRightStick = 8;
static constexpr int kEllipses = 9;
static constexpr int kHamburger = 10;
static constexpr int kStadia = 11;
static constexpr int kRightTrigger = 12;
static constexpr int kLeftTrigger = 13;
static constexpr int kGoogle = 14;
static constexpr int kFrame = 15;
};
struct Axis {
static constexpr int kLeftX = 0;
static constexpr int kRightX = 4;
static constexpr int kLeftY = 1;
static constexpr int kRightY = 5;
};
};
} // namespace frc

View File

@@ -0,0 +1,716 @@
// 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.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 Stadia controllers connected to the Driver Station.
*
* <p>This class handles Stadia input that comes from the Driver Station. Each time a value is
* requested the most recent value is returned. There is a single class instance for each controller
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
*/
public class StadiaController extends GenericHID {
/** Represents a digital button on a StadiaController. */
public enum Button {
kA(1),
kB(2),
kX(3),
kY(4),
kLeftBumper(5),
kRightBumper(6),
kLeftStick(7),
kRightStick(8),
kEllipses(9),
kHamburger(10),
kStadia(11),
kRightTrigger(12),
kLeftTrigger(13),
kGoogle(14),
kFrame(15);
public final int value;
Button(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the button, matching the relevant methods. This is done by
* stripping the leading `k`, and if not a Bumper button append `Button`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the button.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Bumper")) {
return name;
}
return name + "Button";
}
}
/** Represents an axis on a StadiaController. */
public enum Axis {
kLeftX(0),
kRightX(3),
kLeftY(1),
kRightY(4);
public final int value;
Axis(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the axis, matching the relevant methods. This is done by
* stripping the leading `k`, and if a trigger axis append `Axis`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Trigger")) {
return name + "Axis";
}
return name;
}
}
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public StadiaController(final int port) {
super(port);
// re-enable when StadiaController is added to Usage Reporting
// HAL.report(tResourceType.kResourceType_Joystick, port + 1);
}
/**
* Get the X axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftX() {
return getRawAxis(Axis.kLeftX.value);
}
/**
* Get the X axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightX() {
return getRawAxis(Axis.kRightX.value);
}
/**
* Get the Y axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftY() {
return getRawAxis(Axis.kLeftY.value);
}
/**
* Get the Y axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightY() {
return getRawAxis(Axis.kRightY.value);
}
/**
* Read the value of the left bumper (LB) button on the controller.
*
* @return The state of the button.
*/
public boolean getLeftBumper() {
return getRawButton(Button.kLeftBumper.value);
}
/**
* Read the value of the right bumper (RB) button on the controller.
*
* @return The state of the button.
*/
public boolean getRightBumper() {
return getRawButton(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftBumperPressed() {
return getRawButtonPressed(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightBumperPressed() {
return getRawButtonPressed(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftBumperReleased() {
return getRawButtonReleased(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightBumperReleased() {
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.
*
* @return The state of the button.
*/
public boolean getLeftStickButton() {
return getRawButton(Button.kLeftStick.value);
}
/**
* Read the value of the right stick button (RSB) on the controller.
*
* @return The state of the button.
*/
public boolean getRightStickButton() {
return getRawButton(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftStickButtonPressed() {
return getRawButtonPressed(Button.kLeftStick.value);
}
/**
* Whether the right stick button (RSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightStickButtonPressed() {
return getRawButtonPressed(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftStickButtonReleased() {
return getRawButtonReleased(Button.kLeftStick.value);
}
/**
* Whether the right stick (RSB) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightStickButtonReleased() {
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 left trigger button (LTB) on the controller.
*
* @return The state of the button.
*/
public boolean getLeftTriggerButton() {
return getRawButton(Button.kLeftTrigger.value);
}
/**
* Read the value of the right trigger button (RTB) on the controller.
*
* @return The state of the button.
*/
public boolean getRightTriggerButton() {
return getRawButton(Button.kRightTrigger.value);
}
/**
* Whether the left trigger button (LTB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftTriggerButtonPressed() {
return getRawButtonPressed(Button.kLeftTrigger.value);
}
/**
* Whether the right trigger button (RTB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightTriggerButtonPressed() {
return getRawButtonPressed(Button.kRightTrigger.value);
}
/**
* Whether the left trigger button (LTB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftTriggerButtonReleased() {
return getRawButtonReleased(Button.kLeftTrigger.value);
}
/**
* Whether the right trigger (RTB) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightTriggerButtonReleased() {
return getRawButtonReleased(Button.kRightTrigger.value);
}
/**
* Constructs an event instance around the left trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger button's digital signal attached to the
* given loop.
*/
public BooleanEvent leftTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftTriggerButton);
}
/**
* Constructs an event instance around the right trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger button's digital signal attached to
* the given loop.
*/
public BooleanEvent rightTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getRightTriggerButton);
}
/**
* Read the value of the A button on the controller.
*
* @return The state of the button.
*/
public boolean getAButton() {
return getRawButton(Button.kA.value);
}
/**
* Whether the A button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getAButtonPressed() {
return getRawButtonPressed(Button.kA.value);
}
/**
* Whether the A button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getAButtonReleased() {
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.
*
* @return The state of the button.
*/
public boolean getBButton() {
return getRawButton(Button.kB.value);
}
/**
* Whether the B button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getBButtonPressed() {
return getRawButtonPressed(Button.kB.value);
}
/**
* Whether the B button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getBButtonReleased() {
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.
*
* @return The state of the button.
*/
public boolean getXButton() {
return getRawButton(Button.kX.value);
}
/**
* Whether the X button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getXButtonPressed() {
return getRawButtonPressed(Button.kX.value);
}
/**
* Whether the X button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getXButtonReleased() {
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.
*
* @return The state of the button.
*/
public boolean getYButton() {
return getRawButton(Button.kY.value);
}
/**
* Whether the Y button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getYButtonPressed() {
return getRawButtonPressed(Button.kY.value);
}
/**
* Whether the Y button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getYButtonReleased() {
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 ellipses button on the controller.
*
* @return The state of the button.
*/
public boolean getEllipsesButton() {
return getRawButton(Button.kEllipses.value);
}
/**
* Whether the ellipses button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getEllipsesButtonPressed() {
return getRawButtonPressed(Button.kEllipses.value);
}
/**
* Whether the ellipses button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getEllipsesButtonReleased() {
return getRawButtonReleased(Button.kEllipses.value);
}
/**
* Constructs an event instance around the ellipses button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the ellipses button's digital signal attached to the
* given loop.
*/
public BooleanEvent ellipses(EventLoop loop) {
return new BooleanEvent(loop, this::getEllipsesButton);
}
/**
* Read the value of the hamburger button on the controller.
*
* @return The state of the button.
*/
public boolean getHamburgerButton() {
return getRawButton(Button.kHamburger.value);
}
/**
* Whether the hamburger button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getHamburgerButtonPressed() {
return getRawButtonPressed(Button.kHamburger.value);
}
/**
* Whether the hamburger button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getHamburgerButtonReleased() {
return getRawButtonReleased(Button.kHamburger.value);
}
/**
* Constructs an event instance around the hamburger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the hamburger button's digital signal attached to the
* given loop.
*/
public BooleanEvent hamburger(EventLoop loop) {
return new BooleanEvent(loop, this::getHamburgerButton);
}
/**
* Read the value of the stadia button on the controller.
*
* @return The state of the button.
*/
public boolean getStadiaButton() {
return getRawButton(Button.kStadia.value);
}
/**
* Whether the stadia button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getStadiaButtonPressed() {
return getRawButtonPressed(Button.kStadia.value);
}
/**
* Whether the stadia button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getStadiaButtonReleased() {
return getRawButtonReleased(Button.kStadia.value);
}
/**
* Constructs an event instance around the stadia button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the stadia button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent stadia(EventLoop loop) {
return new BooleanEvent(loop, this::getStadiaButton);
}
/**
* Read the value of the google button on the controller.
*
* @return The state of the button.
*/
public boolean getGoogleButton() {
return getRawButton(Button.kGoogle.value);
}
/**
* Whether the google button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getGoogleButtonPressed() {
return getRawButtonPressed(Button.kGoogle.value);
}
/**
* Whether the google button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getGoogleButtonReleased() {
return getRawButtonReleased(Button.kGoogle.value);
}
/**
* Constructs an event instance around the google button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the google button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent google(EventLoop loop) {
return new BooleanEvent(loop, this::getGoogleButton);
}
/**
* Read the value of the frame button on the controller.
*
* @return The state of the button.
*/
public boolean getFrameButton() {
return getRawButton(Button.kFrame.value);
}
/**
* Whether the frame button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getFrameButtonPressed() {
return getRawButtonPressed(Button.kFrame.value);
}
/**
* Whether the frame button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getFrameButtonReleased() {
return getRawButtonReleased(Button.kFrame.value);
}
/**
* Constructs an event instance around the frame button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the frame button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent frame(EventLoop loop) {
return new BooleanEvent(loop, this::getFrameButton);
}
}