Skip to content

Added non-blocking version of readGesture() #14

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
SparkFun APDS9960 RGB and Gesture Sensor Arduino Library
SparkFun APDS9960 RGB and Gesture Sensor Arduino Library (non blocking fork)
=========================================================

![Avago APDS-9960 Breakout Board - SEN-12787 ](https://cdn.sparkfun.com/r/92-92/assets/parts/9/6/0/3/12787-01.jpg)

[*Avago APDS-9960 Breakout Board (SEN-12787)*](https://www.sparkfun.com/products/12787)

This version has added apds.checkGesture() which, when repeatedly called, returns DIR_NONE most of the time but when a completed gesture is seen it returns that gesture. Updates were made with the ESP32 in mind, so the I2C uses a semaphore to prevent problems when e.g. calling apds.getProximity() from a different thread.
If this isn't required, or you're using an Arduino, the semaphore code is ifdef'd out, but that's not tested.

Getting Started
---------------

Expand Down
67 changes: 67 additions & 0 deletions examples/Non-blocking-gesture-test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <Arduino.h>
#include "SparkFun_APDS9960.h"

SparkFun_APDS9960 apds = SparkFun_APDS9960();

#define CHECK(f, msg) \
ar = f; \
Serial.print(msg); \
Serial.println((ar) ? " OK" : " failed")

const char *gestureName[] = {"Left", "Right", "Up", "Down"};

void setup() {
// Initialize Serial port
Serial.begin(115200);
Serial.println();
Serial.println(F("-----------------------"));
Serial.println(F("APDS-9960 - GestureTest"));
Serial.println(F("-----------------------"));

// Initialize APDS-9960 (configure I2C and initial values)
if (apds.init()) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}

// Start running the APDS-9960 gesture sensor engine
if (apds.enableGestureSensor(true)) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}

bool ar;
CHECK(apds.setGestureLEDDrive(2), "gesture LED drive");
CHECK(apds.setGestureIntEnable(0), "int en");
CHECK(apds.setGestureGain(GGAIN_4X), "gesture gain");
CHECK(apds.enableProximitySensor(false), "Prox sensor");
CHECK(apds.setProximityGain(PGAIN_4X), "Prox gain");
// CHECK(apds.setGestureTimeout(3000), "Gesture timeout");
}

void loop() {
Gesture gesture = apds.checkGesture();

switch (gesture) {
case DIR_UP:
case DIR_DOWN:
case DIR_LEFT:
case DIR_RIGHT:
Serial.println(gestureName[gesture - 1]);
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
case DIR_PENDING:
Serial.print("...");
default:
// Don't print, we'll be here a LOT!
// Serial.print("/");
break;
}
}
Loading