Uses the APDS_9960 Digital Proximity, Ambient Light, RGB and Gesture Sensor library to play detected gesture sounds on a speaker from the SDcard

Dependencies:   mbed SDFileSystem wave_player

Files at this revision

API Documentation at this revision

Comitter:
kbhagat6
Date:
Mon Mar 09 21:17:34 2015 +0000
Parent:
9:286d00d9db80
Child:
11:ea43b0b83222
Commit message:
working gesture sensor. now we just need to write speaker sdcard... and led stuff

Changed in this revision

glibr.cpp Show annotated file Show diff for this revision Revisions of this file
glibr.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/glibr.cpp	Fri Mar 06 22:59:40 2015 +0000
+++ b/glibr.cpp	Mon Mar 09 21:17:34 2015 +0000
@@ -431,15 +431,16 @@
     if( !isGestureAvailable() || !(getMode() & 0x41) ) {
         return DIR_NONE;
     }
+
     
     /* Keep looping as long as gesture data is valid */
     while(1) {
-       
+      
         /* Wait some time to collect next batch of FIFO data */
         wait(FIFO_PAUSE_TIME);
         
         /* Get the contents of the STATUS register. Is data still valid? */
-        
+          
         gstatus=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GSTATUS);
         if( gstatus==ERROR ) {
             return ERROR;
@@ -453,7 +454,6 @@
                 return ERROR;
             }
             
-
 //#if DEBUG
 //            Serial.print("FIFO Level: ");
 //            Serial.println(fifo_level);
@@ -469,6 +469,7 @@
                 if( check == -1 ) {
                     return ERROR;
                 }
+                
 #if DEBUG
                 //Serial.print("FIFO Dump: ");
                 for ( i = 0; i < (fifo_level * 4); i++ ) {
--- a/glibr.h	Fri Mar 06 22:59:40 2015 +0000
+++ b/glibr.h	Mon Mar 09 21:17:34 2015 +0000
@@ -19,7 +19,7 @@
 #define APDS9960_ID_2           0x9C 
 
 /* Misc parameters */
-#define FIFO_PAUSE_TIME         30      // Wait period (ms) between FIFO reads
+#define FIFO_PAUSE_TIME         0.30      // Wait period (ms) between FIFO reads
 
 /* APDS-9960 register addresses */
 #define APDS9960_ENABLE         0x80
@@ -326,7 +326,7 @@
     
     
     uint8_t I2CreadByte(char address, char subAddress);
-    int I2CwriteByte(char address, char subAddress, char data); 
+    int I2CwriteByte(char address, char subAddress, char data);   //if return value is 1, then ack not sent
     int I2CReadDataBlock(char address, char subAddress, char *data, unsigned int len);
     I2C i2c;
     
--- a/main.cpp	Fri Mar 06 22:59:40 2015 +0000
+++ b/main.cpp	Mon Mar 09 21:17:34 2015 +0000
@@ -1,15 +1,73 @@
 #include "mbed.h"
 #include "glibr.h"
-//DigitalOut myled(LED1);
+//#include <Wire.h>
+//#include <SparkFun_APDS9960.h>
+
+// Pins
+//#define APDS9960_INT    2 // Needs to be an interrupt pin
+
+// Constants
+
+// Global Variables
+glibr test(p9,p10);
+//SparkFun_APDS9960 apds = SparkFun_APDS9960();
+int isr_flag = 0;
+DigitalOut myled(LED1);
+//InterruptIn interrupt(p11);
 Serial pc(USBTX, USBRX);
+bool ret;
+int val;
 
-glibr test(p9,p10);
+int main()
+{
+    myled = 0;
+    ret = 0;
+    val = 0;
+    if ( test.ginit() ) {
+        pc.printf("APDS-9960 initialization complete\n\r");
+    } else {
+        pc.printf("Something went wrong during APDS-9960 init\n\r");
+    }
 
-int main() {
+    // Start running the APDS-9960 gesture sensor engine
+    if ( test.enableGestureSensor(true) ) {
+        pc.printf("Gesture sensor is now running\n\r");
+    } else {
+        pc.printf("Something went wrong during gesture sensor init!\n\r");
+    }
 
+    while(1) {
+        /* ret = test.isGestureAvailable();
+         pc.printf("Is Gesture Available?: %d\n", ret);
+         myled = ret;
+         val = test.readGesture();
+         */
+        if ( test.isGestureAvailable() ) {
+            switch ( test.readGesture() ) {
+                case DIR_UP:
+                    pc.printf("UP\n");
+                    break;
+                case DIR_DOWN:
+                    pc.printf("DOWN\n");
+                    break;
+                case DIR_LEFT:
+                    pc.printf("LEFT\n");
+                    break;
+                case DIR_RIGHT:
+                    pc.printf("RIGHT\n");
+                    break;
+                case DIR_NEAR:
+                    pc.printf("NEAR\n");
+                    break;
+                case DIR_FAR:
+                    pc.printf("FAR\n");
+                    break;
+                default:
+                    pc.printf("NONE\n");
+            }
+        }
 
- uint8_t  cool;
-cool=test.ginit();
-//pc.printf("cool");
-pc.printf("%u", cool);
-}
+        wait(1);
+
+    }
+}
\ No newline at end of file