[wpilib] Add BooleanEvent/Trigger factories on HID classes (#4247)

This commit is contained in:
Starlight220
2022-06-14 08:48:16 +03:00
committed by GitHub
parent 9b1bf5c7f1
commit fd884581e4
24 changed files with 1717 additions and 1 deletions

View File

@@ -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));
}