Skip to content
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

CP: more configuration options for the tap detection #99

Merged
merged 8 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
52 changes: 52 additions & 0 deletions adafruit_circuitplayground/circuit_playground_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,58 @@ def detect_taps(self, value):
value, 60, time_limit=10, time_latency=50, time_window=255
)

# pylint: disable-msg=too-many-arguments
# Many default arguments which will probably not need changing in most cases
def configure_taps(
self,
value,
accel_range=adafruit_lis3dh.RANGE_8_G,
theshold=None,
time_limit=None,
time_latency=50,
time_window=255,
):
""" A way to customize the tap detection better. The default values don't work
for all cases.
Higher default thresholds for the CPB
"""
if value < 0 or value > 2:
return

if accel_range not in [
adafruit_lis3dh.RANGE_2_G,
adafruit_lis3dh.RANGE_4_G,
adafruit_lis3dh.RANGE_8_G,
adafruit_lis3dh.RANGE_16_G,
]:
accel_range = adafruit_lis3dh.RANGE_8_G
self._lis3dh.range = accel_range

if value == 1:
if theshold is None or theshold < 0 or theshold > 127:
theshold = 100 if "nRF52840" in os.uname().machine else 90
if time_limit is None:
time_limit = 4
elif value == 2:
if theshold is None or theshold < 0 or theshold > 127:
theshold = 70 if "nRF52840" in os.uname().machine else 60
if time_limit is None:
time_limit = 10
else:
# sane values for turning the tap detection off
theshold = 100
time_limit = 1

self._lis3dh.set_tap(
value,
theshold,
time_limit=time_limit,
time_latency=time_latency,
time_window=time_window,
)

# pylint: enable-msg=too-many-arguments

@property
def tapped(self):
"""True once after a detecting a tap. Requires ``cp.detect_taps``.
Expand Down
4 changes: 2 additions & 2 deletions examples/circuitplayground_ir_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# Create a 'pulseio' input, to listen to infrared signals on the IR receiver
try:
pulsein = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
except AttributeError:
except AttributeError as e:
raise NotImplementedError(
"This example does not work with Circuit Playground Bluefruti!"
)
) from e
# Create a decoder that will take pulses and turn them into numbers
decoder = adafruit_irremote.GenericDecode()

Expand Down
4 changes: 2 additions & 2 deletions examples/circuitplayground_ir_transmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# Create a 'pulseio' output, to send infrared signals from the IR transmitter
try:
pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
except AttributeError:
except AttributeError as e:
raise NotImplementedError(
"This example does not work with Circuit Playground Bluefruit!"
)
) from e
pulseout = pulseio.PulseOut(pwm) # pylint: disable=no-member
# Create an encoder that will take numbers and turn them into NEC IR pulses
encoder = adafruit_irremote.GenericTransmit(
Expand Down