Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Add deadband trigger methods to CommandGenericHID #72

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions commands2/button/commandgenerichid.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ def axisGreaterThan(
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
return Trigger(loop, lambda: self._hid.getRawAxis(axis) > threshold)

def axisMagnitudeGreaterThan(
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
) -> Trigger:
"""
Constructs a Trigger instance that is true when the axis magnitude is greater than
``threshold``, attached to the given loop.

: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 trigger to.

:returns: a Trigger instance that is true when the axis magnitude is greater than the provided
threshold.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
return Trigger(loop, lambda: abs(self._hid.getRawAxis(axis)) > threshold)

def getRawAxis(self, axis: int) -> float:
"""
Expand Down