Skip to content

Commit 9b16c8d

Browse files
committed
remove global threshold, add release threshold to channel
1 parent 28a84fa commit 9b16c8d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

adafruit_mpr121.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,31 @@ def thresholds(self):
102102
"""The touch / release threholds."""
103103
buf = bytearray(2)
104104
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 2)
105-
return (buf[0], buf[1])
105+
return buf[0], buf[1]
106106

107107
@thresholds.setter
108108
def thresholds(self, value):
109109
touch, release = value
110110
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, touch)
111111
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, release)
112112

113+
@property
114+
def threshold(self):
115+
return self.thresholds[0]
116+
117+
@threshold.setter
118+
def threshold(self, value):
119+
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, value)
120+
121+
@property
122+
def release_threshold(self):
123+
return self.thresholds[1]
124+
125+
@release_threshold.setter
126+
def release_threshold(self, value):
127+
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, value)
128+
129+
113130
class MPR121:
114131
"""Driver for the MPR121 capacitive touch breakout board."""
115132

@@ -132,18 +149,6 @@ def touched_pins(self):
132149
touched = self.touched()
133150
return tuple([bool(touched >> i & 0x01) for i in range(12)])
134151

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

0 commit comments

Comments
 (0)