SparkFun_APDS-9960_Sensor_Arduino_Library icon indicating copy to clipboard operation
SparkFun_APDS-9960_Sensor_Arduino_Library copied to clipboard

Added timeout option

Open MarcFinns opened this issue 7 years ago • 4 comments

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.

MarcFinns avatar Feb 20 '17 21:02 MarcFinns

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?

blackketter avatar Feb 20 '17 23:02 blackketter

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 GitHubhttps://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library/pull/5#issuecomment-281207064, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AXPSLUCBEYr21WjsE0sqUiQoI2QSu69Uks5reiTtgaJpZM4MGpfM.

MarcFinns avatar Feb 20 '17 23:02 MarcFinns

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 avatar Jan 07 '18 13:01 yesyesuk

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

yesyesuk avatar Jan 07 '18 14:01 yesyesuk