Skip to content

allow easy configuration of single or double tapping #26

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

Merged
merged 3 commits into from
Dec 27, 2017

Conversation

ladyada
Copy link
Member

@ladyada ladyada commented Dec 17, 2017

see below!

import time
from adafruit_circuitplayground.express import cpx

# Set up the accelerometer to detect tapping ('click')
cpx.detect_taps = 1

while True:
    if cpx.tapped:     # Look for a single tap
        print("Tapped", time.monotonic())
    time.sleep(0.01)

@ladyada ladyada requested review from tannewt and kattni December 17, 2017 22:00
Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is the sensitivity with single-tap. Same issue in the first demo example you sent me, I can't touch the board without setting it off. The threshold, time_limit and time_latency values for double-tap are apparently wrong for single-tap. I've linked an example of a way to address this issue.

Is there a reason why you decided to do detect_taps and tapped vs. single_tap and double_tap? I wrote up the code to have single and double separate, and tested it. In that version, I am able to tweak the set_tapvalues separately. It will take more testing to get it right, but here is what it looks like initially: https://github.com/kattni/Adafruit_CircuitPython_CircuitPlayground/blob/single-double-tap/adafruit_circuitplayground/express.py

My issue with having both single and double available are the same as before, that you can use single- and double-tap together (regardless of implementation type), and it returns mostly singletap. Seems like something we'd have to address in documentation or a guide so people aren't frustrated trying to use double-tap and single-tap together.

@@ -119,28 +119,53 @@ def __init__(self):
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

# Initialise tap:
self._last_tap = False
self._detect_taps = 1
self.detect_taps = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is detect_taps included twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one is the setter (detect_taps) and one is the variable that is set by the setter (_detect_taps)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you!

try:
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
self._lis3dh.set_tap(value, 18, time_limit=4, time_latency=17, time_window=110)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These numbers work for double-tapping, but it seems like they are not great for single-tap. Did you have issues with sensitivity? I can't touch the board without setting single-tap off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can tweak it for single/double, maybe set threshhold to 24 or so for single!

Copy link
Contributor

@kattni kattni Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to set single-tap threshold to 70 with them separated before single-tap wasn't going off constantly. I'll test some numbers and get back to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure sounds good, yeah with 8G its hard to get good numbers!

@kattni
Copy link
Contributor

kattni commented Dec 18, 2017

It looks like 80 is a good threshold.

When you said "tweak it for single/double" were you saying tweak the number in this implementation or did you want me to clean up the single_tap/double_tap implementation I linked?

@ladyada
Copy link
Member Author

ladyada commented Dec 18, 2017

yah i mean checking if you want 1 or 2 at this line
3a0c653
and then changing what you call self._lis3dh.set_tap with. i can commit late tonite when i get home, or you can take a go :)

@kattni
Copy link
Contributor

kattni commented Dec 18, 2017

I'm still curious though, why detect_taps and tapped, rather than single_tap and double_tap?

@kattni
Copy link
Contributor

kattni commented Dec 18, 2017

I'll commit it after the weekly :)

@ladyada
Copy link
Member Author

ladyada commented Dec 18, 2017

zoOOOOOoooM!

i think given you have to set up the filter differently, maybe less difficult to just say "hey you get single or double, your choice"?

@kattni
Copy link
Contributor

kattni commented Dec 18, 2017

It doesn't look much different on the code end. The library sets everything up and the code is basically:

if cpx.double_tap:
    blah
elif cpx.single_tap:
    etc

Even with detect_taps and tapped, you can do both, and it looks more like this:

cpx.detect_taps = 2
if cpx.tapped:
    blah
cpx.detect_taps = 1
if cpx.tapped:
    etc

Either way, double doesn't really work with single.

So sticking with this: Do we want to try to put in something that makes it fail if you try to use it twice? Or deal with it in documentation? Or something different?

(I had an issue with LIS3DH and 2 instances, but fixed that, it does work with set_tap twice in a while loop.)

Included fixes for travis ci build
@kattni
Copy link
Contributor

kattni commented Dec 19, 2017

I'd like to do some work on the documentation for these changes, update the explanations and add another example where you can delay between checking for single and double taps.

I went straight to trying to use both in a tight loop, so I assume others might too. So I thought if we explain more clearly that it's single OR double, and also have an example of being able to use both with a delay between checking for single and double, that we'll catch that well enough.

I'll merge this one and do another PR for the changes so I can work on them locally. Let me know if this works!

@kattni
Copy link
Contributor

kattni commented Dec 27, 2017

I'm going to merge this PR and do the next set of updates locally.

@kattni kattni merged commit 6fc77d3 into adafruit:master Dec 27, 2017
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants