Skip to content

Commit

Permalink
add thresholds to triggerxboxcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Mar 2, 2024
1 parent 75140f8 commit aeb0416
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
26 changes: 26 additions & 0 deletions wombat/src/main/cpp/behaviour/TriggerXboxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "behaviour/TriggerXboxController.h"

#include "utils/Util.h"

using namespace behaviour;

TriggerXboxController::TriggerXboxController(int port) : m_hid{port} {}
Expand Down Expand Up @@ -136,6 +138,30 @@ Trigger* TriggerXboxController::RightBumperPressed() {
return new Trigger([this]() { return m_hid.GetRightBumperPressed(); }, "Right bumper pressed trigger");
}

Trigger* TriggerXboxController::RightTriggerThreshold(double threshold) {
return new Trigger([this]() { return GetRightTriggerAxis() > 0.05; }, "Right Trigger threshold trigger");
}

Trigger* TriggerXboxController::LeftTriggerThreshold(double threshold) {
return new Trigger([this]() { return GetLeftTriggerAxis() > 0.05; }, "Left Trigger threshold trigger");
}

Trigger* TriggerXboxController::RightJoystickXThreshold(double threshold) {
return new Trigger([this]() { return GetRightX() > 0.05; }, "Right Joystick X threshold trigger");
}

Trigger* TriggerXboxController::RightJoystickYThreshold(double threshold) {
return new Trigger([this]() { return GetRightY() > 0.05; }, "Right Joystick Y threshold trigger");
}

Trigger* TriggerXboxController::LeftJoystickXThreshold(double threshold) {
return new Trigger([this]() { return GetRightX() > 0.05; }, "Left Joystick X threshold trigger");
}

Trigger* TriggerXboxController::LeftJoystickYThreshold(double threshold) {
return new Trigger([this]() { return GetRightY() > 0.05; }, "Left Joystick Y threshold trigger");
}

double TriggerXboxController::GetRightTriggerAxis() {
return m_hid.GetRightTriggerAxis();
}
Expand Down
42 changes: 42 additions & 0 deletions wombat/src/main/include/behaviour/TriggerXboxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,48 @@ class TriggerXboxController {
*/
Trigger* StartButtonReleased();

/**
* Creates a new Trigger binded to the Right Trigger being over the threshold.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* RightTriggerThreshold(double threshold);

/**
* Creates a new Trigger binded to the Left Trigger being over the threshold.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* LeftTriggerThreshold(double threshold);

/**
* Creates a new Trigger binded to the Left Joystick being over the threshold on the X axis.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* LeftJoystickXThreshold(double threshold);

/**
* Creates a new Trigger binded to the Left Joystick being over the threshold on the Y axis.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* LeftJoystickYThreshold(double threshold);

/**
* Creates a new Trigger binded to the Right Joystick being over the threshold on the Y axis.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* RightJoystickXThreshold(double threshold);

/**
* Creates a new Trigger binded to the Right Joystick being over the threshold on the X axis.
*
* @param threshold The deadzone for the Trigger.
*/
Trigger* RightJoystickYThreshold(double threshold);

/**
* Get the right trigger (RT) axis value of the controller. Note that this
* axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
Expand Down

0 comments on commit aeb0416

Please sign in to comment.