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

Added timeout option #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

MarcFinns
Copy link

In the original version the readGesture() API does not return if there is something in front of the sensor. This blocks the execution flow indefinitely if the sensor view is not clear, e.g. if an object is in front of the sensor. This is a big issue for small CPUs such as Arduino / ESP8266 that are not multithreaded.
The issue is addressed by adding a setGestureTimeout() API that accepts a timeout in milliseconds. If the readGesture() API returns because of a timeout, the returned event is set to DIR_NONE.
The original blocking behavior is retained as the default timeout value is set to DEFAULT_GWAIT_FOREVER upon initialization.

@blackketter
Copy link

This looks really interesting, and I think I can try it out and use it, but the patch is really hard to read due to the massive whitespace changes. Any chance you can separate those into a separate merge request?

@MarcFinns
Copy link
Author

MarcFinns commented Feb 20, 2017 via email

@yesyesuk
Copy link

yesyesuk commented Jan 7, 2018

Hi,
what happened to this very useful addition to the library? It would be very useful to merge this into the master.

However, I do seem to have a problem with it. I have downloaded and used the modified library from MarcFinns/SparkFun_APDS-9960_Sensor_Arduino_Library. I want to use the APDS-9960 as a gesture and ambient light sensor. With the original library I sometimes get "stuck" gestures when readGesture() does not return. The same happens when I put an object in front of the sensor. With Marc's version I set the gesture timeout to 1 sec with apds.setGestureTimeout(1000); Then in both cases readGesture() returns. However, from that point on the sensor reports no more gestures. The ambient light readings continue normally.

I use the GestureTest demo with only apds.setGestureTimeout(1000); added in setup() after apds.enableGestureSensor(true);

@yesyesuk
Copy link

yesyesuk commented Jan 7, 2018

Some further investigation shows that it seems that the sensor doesn't get "reset" properly after the timeout.

I found a workaround. I added DIR_TOUT to the direction definitions enum. Then in readGesture() I return DIR_TOUT instead of DIR_NONE. In handleGesture() in the demo sketch I added the following to the switch:

case DIR_TOUT:
   Serial.println("gesture TOUT");
   apds.disableGestureSensor();
   apds.enableGestureSensor(true);
   break;

This restarts the gesture engine and I do get gestures reported again. In case there is an object in front of the sensor I immediately get an interrupt after enabling the sensor again, but that is something I can handle. When the object is removed from the front of the sensor everything is working normally again.

Also, I enabled the library DEBUG to get more info printed. It seems that when the object is in front of the sensor, the sensor continuously reports "valid" data until the object is removed. This is probably why the original readGesture() never returns. I hope there is a way to cancel a gesture in the sensor. Will have a look at the datasheet.

Chris

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.

3 participants