Skip to content

Add support for checking maximum force sensed #117

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

Merged
merged 3 commits into from
Mar 17, 2022
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
11 changes: 10 additions & 1 deletion buildhat/force.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ForceSensor(Device):
"""
def __init__(self, port, threshold_force=1):
super().__init__(port)
self.mode([(0,0),(1,0)])
self.mode([(0,0),(1,0),(3,0)])
self._when_pressed = None
self._when_released = None
self._fired_pressed = False
Expand Down Expand Up @@ -54,6 +54,15 @@ def get_force(self):
"""
return self.get()[0]

def get_peak_force(self):
"""Gets the maximum force registered since the sensor was reset
(The sensor gets reset when the firmware is reloaded)

:return: 0 - 100
:rtype: int
"""
return self.get()[2]

def is_pressed(self):
"""Gets whether the button is pressed

Expand Down