mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)
This commit is contained in:
@@ -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