[commands] Add functions to HID classes to allow use of axes as BooleanEvents/Triggers (#4762)

This commit is contained in:
Ryan Blue
2022-12-26 14:29:14 -05:00
committed by GitHub
parent 87a34af367
commit 176fddeb4c
12 changed files with 413 additions and 0 deletions

View File

@@ -89,6 +89,20 @@ BooleanEvent GenericHID::POVCenter(EventLoop* loop) const {
return POV(360, loop);
}
BooleanEvent GenericHID::AxisLessThan(int axis, double threshold,
EventLoop* loop) const {
return BooleanEvent(loop, [this, axis, threshold]() {
return this->GetRawAxis(axis) < threshold;
});
}
BooleanEvent GenericHID::AxisGreaterThan(int axis, double threshold,
EventLoop* loop) const {
return BooleanEvent(loop, [this, axis, threshold]() {
return this->GetRawAxis(axis) > threshold;
});
}
int GenericHID::GetAxisCount() const {
return DriverStation::GetStickAxisCount(m_port);
}

View File

@@ -197,3 +197,25 @@ bool XboxController::GetStartButtonReleased() {
BooleanEvent XboxController::Start(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetStartButton(); });
}
BooleanEvent XboxController::LeftTrigger(double threshold,
EventLoop* loop) const {
return BooleanEvent(loop, [this, threshold]() {
return this->GetLeftTriggerAxis() > threshold;
});
}
BooleanEvent XboxController::LeftTrigger(EventLoop* loop) const {
return this->LeftTrigger(0.5, loop);
}
BooleanEvent XboxController::RightTrigger(double threshold,
EventLoop* loop) const {
return BooleanEvent(loop, [this, threshold]() {
return this->GetRightTriggerAxis() > threshold;
});
}
BooleanEvent XboxController::RightTrigger(EventLoop* loop) const {
return this->RightTrigger(0.5, loop);
}