mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[commands] Add functions to HID classes to allow use of axes as BooleanEvents/Triggers (#4762)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -231,6 +231,31 @@ class GenericHID {
|
||||
*/
|
||||
BooleanEvent POVCenter(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance that is true when the axis value is less than
|
||||
* threshold
|
||||
*
|
||||
* @param axis The axis to read, starting at 0.
|
||||
* @param threshold The value below which this trigger should return true.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the axis value is less than the
|
||||
* provided threshold.
|
||||
*/
|
||||
BooleanEvent AxisLessThan(int axis, double threshold, EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance that is true when the axis value is greater
|
||||
* than threshold
|
||||
*
|
||||
* @param axis The axis to read, starting at 0.
|
||||
* @param threshold The value above which this trigger should return true.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the axis value is greater than
|
||||
* the provided threshold.
|
||||
*/
|
||||
BooleanEvent AxisGreaterThan(int axis, double threshold,
|
||||
EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Get the number of axes for the HID.
|
||||
*
|
||||
|
||||
@@ -342,6 +342,50 @@ class XboxController : public GenericHID {
|
||||
*/
|
||||
BooleanEvent Start(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the axis value of the left trigger. The
|
||||
* returned trigger will be true when the axis value is greater than {@code
|
||||
* threshold}.
|
||||
* @param threshold the minimum axis value for the returned event to be true.
|
||||
* This value should be in the range [0, 1] where 0 is the unpressed state of
|
||||
* the axis.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the left trigger's axis exceeds
|
||||
* the provided threshold, attached to the given event loop
|
||||
*/
|
||||
BooleanEvent LeftTrigger(double threshold, EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the axis value of the left trigger.
|
||||
* The returned trigger will be true when the axis value is greater than 0.5.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the right trigger's axis
|
||||
* exceeds 0.5, attached to the given event loop
|
||||
*/
|
||||
BooleanEvent LeftTrigger(EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the axis value of the right trigger.
|
||||
* The returned trigger will be true when the axis value is greater than
|
||||
* {@code threshold}.
|
||||
* @param threshold the minimum axis value for the returned event to be true.
|
||||
* This value should be in the range [0, 1] where 0 is the unpressed state of
|
||||
* the axis.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the right trigger's axis
|
||||
* exceeds the provided threshold, attached to the given event loop
|
||||
*/
|
||||
BooleanEvent RightTrigger(double threshold, EventLoop* loop) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the axis value of the right trigger.
|
||||
* The returned trigger will be true when the axis value is greater than 0.5.
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return an event instance that is true when the right trigger's axis
|
||||
* exceeds 0.5, attached to the given event loop
|
||||
*/
|
||||
BooleanEvent RightTrigger(EventLoop* loop) const;
|
||||
|
||||
struct Button {
|
||||
static constexpr int kLeftBumper = 5;
|
||||
static constexpr int kRightBumper = 6;
|
||||
|
||||
Reference in New Issue
Block a user