Skip to content

Commit

Permalink
Merge pull request #72 from narmstro2020/CommandHID
Browse files Browse the repository at this point in the history
[cmd] Add deadband trigger methods to CommandGenericHID
  • Loading branch information
virtuald authored Oct 19, 2024
2 parents 125788e + 0014b48 commit 81f6129
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 81f6129

Please sign in to comment.