Skip to content

Add property style access to thresholds #14

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 6 commits into from
Nov 19, 2018
Merged
Changes from 4 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
33 changes: 33 additions & 0 deletions adafruit_mpr121.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
# pylint: enable=bad-whitespace

class MPR121_Channel():
# pylint: disable=protected-access
"""Helper class to represent a touch channel on the MPR121. Not meant to
be used directly."""
def __init__(self, mpr121, channel):
Expand All @@ -96,6 +97,38 @@ def raw_value(self):
"""The raw touch measurement."""
return self._mpr121.filtered_data(self._channel)

@property
def thresholds(self):
"""The touch / release threholds."""
buf = bytearray(2)
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 2)
return buf[0], buf[1]

@thresholds.setter
def thresholds(self, value):
touch, release = value
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, touch)
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, release)

@property
def threshold(self):
"""The touch threhold."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""The touch threhold."""
"""The touch threshold."""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:faceplam: (sic)

return self.thresholds[0]

@threshold.setter
def threshold(self, value):
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, value)

@property
def release_threshold(self):
"""The release threhold."""
return self.thresholds[1]

@release_threshold.setter
def release_threshold(self, value):
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, value)


class MPR121:
"""Driver for the MPR121 capacitive touch breakout board."""

Expand Down