mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)
This commit is contained in:
@@ -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(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user