Skip to content

Commit eaeb7fc

Browse files
committed
CP: more configuration options for the tap detection
1 parent a0692df commit eaeb7fc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

adafruit_circuitplayground/circuit_playground_base.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,34 @@ def detect_taps(self, value):
184184
value, 60, time_limit=10, time_latency=50, time_window=255
185185
)
186186

187+
def configure_taps(self, value, range = adafruit_lis3dh.RANGE_8_G, theshold = None, time_limit = None, time_latency = 50, time_window = 255):
188+
""" A way to customize the tap detection better. The default values don't work for all cases.
189+
Higher default thresholds for the CPB
190+
"""
191+
if value < 0 or value > 2:
192+
return
193+
194+
if range not in [ adafruit_lis3dh.RANGE_2_G, adafruit_lis3dh.RANGE_4_G, adafruit_lis3dh.RANGE_8_G, adafruit_lis3dh.RANGE_16_G ]:
195+
range = adafruit_lis3dh.RANGE_8_G
196+
self._lis3dh.range = range
197+
198+
if value == 1:
199+
if theshold == None or theshold < 0 or theshold > 127:
200+
theshold = 100 if "nRF52840" in os.uname().machine else 90
201+
if time_limit == None:
202+
time_limit = 4
203+
elif value == 2:
204+
if theshold == None or theshold < 0 or theshold > 127:
205+
theshold = 70 if "nRF52840" in os.uname().machine else 60
206+
if time_limit == None:
207+
time_limit = 10
208+
else:
209+
# sane values for turning the tap detection off
210+
theshold = 100
211+
time_limit = 1
212+
213+
self._lis3dh.set_tap(value, theshold, time_limit = time_limit, time_latency = time_latency, time_window = time_window)
214+
187215
@property
188216
def tapped(self):
189217
"""True once after a detecting a tap. Requires ``cp.detect_taps``.

0 commit comments

Comments
 (0)