Skip to content

Commit ebd72cb

Browse files
committed
add property style access to thresholds
1 parent 29716cb commit ebd72cb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

adafruit_mpr121.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ def raw_value(self):
9696
"""The raw touch measurement."""
9797
return self._mpr121.filtered_data(self._channel)
9898

99+
@property
100+
def thresholds(self):
101+
"""The touch / release threholds."""
102+
buf = bytearray(2)
103+
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 2)
104+
return (buf[0], buf[1])
105+
106+
@thresholds.setter
107+
def thresholds(self, value):
108+
touch, release = value
109+
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, touch)
110+
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, release)
111+
99112
class MPR121:
100113
"""Driver for the MPR121 capacitive touch breakout board."""
101114

@@ -118,6 +131,18 @@ def touched_pins(self):
118131
touched = self.touched()
119132
return tuple([bool(touched >> i & 0x01) for i in range(12)])
120133

134+
@property
135+
def thresholds(self):
136+
"""The touch / release threholds for all channels."""
137+
buf = bytearray(24)
138+
self._read_register_bytes(MPR121_TOUCHTH_0, buf, 24)
139+
return tuple( [ (buf[2*i], buf[2*i+1]) for i in range(12) ] )
140+
141+
@thresholds.setter
142+
def thresholds(self, value):
143+
touch, release = value
144+
self.set_thresholds(touch, release)
145+
121146
def _write_register_byte(self, register, value):
122147
# Write a byte value to the specifier register address.
123148
# MPR121 must be put in Stop Mode to write to most registers

0 commit comments

Comments
 (0)