Skip to content

Commit 715ad07

Browse files
committed
add thresholds to triggerxboxcontroller
1 parent 05d78bc commit 715ad07

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

wombat/src/main/cpp/behaviour/TriggerXboxController.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "behaviour/TriggerXboxController.h"
66

7+
#include "utils/Util.h"
8+
79
using namespace behaviour;
810

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

141+
Trigger* TriggerXboxController::RightTriggerThreshold(double threshold) {
142+
return new Trigger([this]() { return GetRightTriggerAxis() > 0.05; }, "Right Trigger threshold trigger");
143+
}
144+
145+
Trigger* TriggerXboxController::LeftTriggerThreshold(double threshold) {
146+
return new Trigger([this]() { return GetLeftTriggerAxis() > 0.05; }, "Left Trigger threshold trigger");
147+
}
148+
149+
Trigger* TriggerXboxController::RightJoystickXThreshold(double threshold) {
150+
return new Trigger([this]() { return GetRightX() > 0.05; }, "Right Joystick X threshold trigger");
151+
}
152+
153+
Trigger* TriggerXboxController::RightJoystickYThreshold(double threshold) {
154+
return new Trigger([this]() { return GetRightY() > 0.05; }, "Right Joystick Y threshold trigger");
155+
}
156+
157+
Trigger* TriggerXboxController::LeftJoystickXThreshold(double threshold) {
158+
return new Trigger([this]() { return GetRightX() > 0.05; }, "Left Joystick X threshold trigger");
159+
}
160+
161+
Trigger* TriggerXboxController::LeftJoystickYThreshold(double threshold) {
162+
return new Trigger([this]() { return GetRightY() > 0.05; }, "Left Joystick Y threshold trigger");
163+
}
164+
139165
double TriggerXboxController::GetRightTriggerAxis() {
140166
return m_hid.GetRightTriggerAxis();
141167
}

wombat/src/main/include/behaviour/TriggerXboxController.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,48 @@ class TriggerXboxController {
181181
*/
182182
Trigger* StartButtonReleased();
183183

184+
/**
185+
* Creates a new Trigger binded to the Right Trigger being over the threshold.
186+
*
187+
* @param threshold The deadzone for the Trigger.
188+
*/
189+
Trigger* RightTriggerThreshold(double threshold);
190+
191+
/**
192+
* Creates a new Trigger binded to the Left Trigger being over the threshold.
193+
*
194+
* @param threshold The deadzone for the Trigger.
195+
*/
196+
Trigger* LeftTriggerThreshold(double threshold);
197+
198+
/**
199+
* Creates a new Trigger binded to the Left Joystick being over the threshold on the X axis.
200+
*
201+
* @param threshold The deadzone for the Trigger.
202+
*/
203+
Trigger* LeftJoystickXThreshold(double threshold);
204+
205+
/**
206+
* Creates a new Trigger binded to the Left Joystick being over the threshold on the Y axis.
207+
*
208+
* @param threshold The deadzone for the Trigger.
209+
*/
210+
Trigger* LeftJoystickYThreshold(double threshold);
211+
212+
/**
213+
* Creates a new Trigger binded to the Right Joystick being over the threshold on the Y axis.
214+
*
215+
* @param threshold The deadzone for the Trigger.
216+
*/
217+
Trigger* RightJoystickXThreshold(double threshold);
218+
219+
/**
220+
* Creates a new Trigger binded to the Right Joystick being over the threshold on the X axis.
221+
*
222+
* @param threshold The deadzone for the Trigger.
223+
*/
224+
Trigger* RightJoystickYThreshold(double threshold);
225+
184226
/**
185227
* Get the right trigger (RT) axis value of the controller. Note that this
186228
* axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].

0 commit comments

Comments
 (0)