-
Notifications
You must be signed in to change notification settings - Fork 63
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
base: master
Are you sure you want to change the base?
Conversation
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? |
I am sorry. I noticed it now.
Right before every line I changed there is a comment
// MarcFinns
From: Dean Blackketter <[email protected]>
Reply-To: sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library <[email protected]>
Date: Tuesday, 21 February 2017 at 00:42
To: sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library <[email protected]>
Cc: Marcello Fini <[email protected]>, Author <[email protected]>
Subject: Re: [sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library] Added timeout option (#5)
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#5 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AXPSLUCBEYr21WjsE0sqUiQoI2QSu69Uks5reiTtgaJpZM4MGpfM>.
|
Hi, 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); |
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:
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 |
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.