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:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user