Skip to content

Commit c72c36f

Browse files
committed
remove thresholdsssss
1 parent 70c0058 commit c72c36f

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

adafruit_mpr121.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,12 @@ def raw_value(self):
9797
"""The raw touch measurement."""
9898
return self._mpr121.filtered_data(self._channel)
9999

100-
@property
101-
def thresholds(self):
102-
"""The touch / release thresholds."""
103-
buf = bytearray(2)
104-
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 2)
105-
return buf[0], buf[1]
106-
107-
@thresholds.setter
108-
def thresholds(self, value):
109-
touch, release = value
110-
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, touch)
111-
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, release)
112-
113100
@property
114101
def threshold(self):
115102
"""The touch threshold."""
116-
return self.thresholds[0]
103+
buf = bytearray(1)
104+
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 1)
105+
return buf[0]
117106

118107
@threshold.setter
119108
def threshold(self, value):
@@ -122,7 +111,9 @@ def threshold(self, value):
122111
@property
123112
def release_threshold(self):
124113
"""The release threshold."""
125-
return self.thresholds[1]
114+
buf = bytearray(1)
115+
self._mpr121._read_register_bytes(MPR121_RELEASETH_0 + 2*self._channel, buf, 1)
116+
return buf[0]
126117

127118
@release_threshold.setter
128119
def release_threshold(self, value):
@@ -186,7 +177,10 @@ def reset(self):
186177
self._read_register_bytes(MPR121_CONFIG2, self._buffer, 1)
187178
if self._buffer[0] != 0x24:
188179
raise RuntimeError('Failed to find MPR121 in expected config state!')
189-
self.set_thresholds(12, 6)
180+
# Default touch and release thresholds
181+
for i in range(12):
182+
self._write_register_byte(MPR121_TOUCHTH_0 + 2*i, 12)
183+
self._write_register_byte(MPR121_RELEASETH_0 + 2*i, 6)
190184
# Configure baseline filtering control registers.
191185
self._write_register_byte(MPR121_MHDR, 0x01)
192186
self._write_register_byte(MPR121_NHDR, 0x01)
@@ -206,18 +200,6 @@ def reset(self):
206200
# Enable all electrodes.
207201
self._write_register_byte(MPR121_ECR, 0x8F) # start with first 5 bits of baseline tracking
208202

209-
def set_thresholds(self, touch, release):
210-
"""Set the touch and release threshold for all inputs to the provided
211-
values. Both touch and release should be a value between 0 to 255
212-
(inclusive).
213-
"""
214-
if touch < 0 or touch > 255 or release < 0 or release > 255:
215-
raise ValueError('Touch/release must be a byte value 0-255.')
216-
# Set the touch and release register value for all the inputs.
217-
for i in range(12):
218-
self._write_register_byte(MPR121_TOUCHTH_0 + 2*i, touch)
219-
self._write_register_byte(MPR121_RELEASETH_0 + 2*i, release)
220-
221203
def filtered_data(self, pin):
222204
"""Return filtered data register value for the provided pin (0-11).
223205
Useful for debugging.

0 commit comments

Comments
 (0)