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:
Fri Mar 06 21:50:03 2015 +0000
Parent:
7:0564c6faf8aa
Child:
9:286d00d9db80
Commit message:
added/organized more.. getting Qualified name erro

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
--- a/glibr.cpp	Fri Mar 06 19:35:24 2015 +0000
+++ b/glibr.cpp	Fri Mar 06 21:50:03 2015 +0000
@@ -125,6 +125,7 @@
     
     return id;
 }
+
 #if 0
     /* Gesture config register dump */
     uint8_t reg;
@@ -151,14 +152,14 @@
 
     for(reg = 0xE4; reg <= 0xE7; reg++) {
         val= I2CreadByte(APDS9960_I2C_ADDR, reg);
-        Serial.print(reg, HEX);
+     /*   Serial.print(reg, HEX);
         Serial.print(": 0x");
-        Serial.println(val, HEX);
+        Serial.println(val, HEX);*/
     }
-#endif
+#endif 
 
-    return true;
-}
+  //  return true;
+//}
 
 
 
@@ -418,7 +419,8 @@
 int glibr::readGesture()
 {
     uint8_t fifo_level = 0;
-    uint8_t bytes_read = 0;
+   // uint8_t bytes_expected= 0;
+    int check;
     uint8_t fifo_data[128];
     uint8_t gstatus;
     int motion;
@@ -431,7 +433,7 @@
     
     /* 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);
         
@@ -445,10 +447,11 @@
         if( (gstatus & APDS9960_GVALID) == APDS9960_GVALID ) {
         
             /* Read the current FIFO level */
-            fifolevel=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GFLVL);
-            if( fifolevel==ERROR ) {
+            fifo_level=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GFLVL);
+            if( fifo_level==ERROR ) {
                 return ERROR;
             }
+            
 
 //#if DEBUG
 //            Serial.print("FIFO Level: ");
@@ -458,33 +461,34 @@
             /* If there's stuff in the FIFO, read it into our data block */                 //NEED TO FIGURE OUT WHAT THIS IS DOING.
         
             if( fifo_level > 0) {
-                bytes_read = I2CReadDataBlock(APDS9960_I2C_ADDR,APDS9960_GFIFO_U, 
+                check = I2CReadDataBlock(APDS9960_I2C_ADDR,APDS9960_GFIFO_U, 
                                                 (uint8_t*)fifo_data, 
                                                 (fifo_level * 4) );
-                if( bytes_read == -1 ) {
+                
+                if( check == -1 ) {
                     return ERROR;
                 }
 #if DEBUG
-                Serial.print("FIFO Dump: ");
-                for ( i = 0; i < bytes_read; i++ ) {
-                    Serial.print(fifo_data[i]);
-                    Serial.print(" ");
+                //Serial.print("FIFO Dump: ");
+                for ( i = 0; i < (fifo_level * 4); i++ ) {
+                 //   Serial.print(fifo_data[i]);
+                  //  Serial.print(" ");
                 }
-                Serial.println();
+                //Serial.println();
 #endif
 
                 /* If at least 1 set of data, sort the data into U/D/L/R */
-                if( bytes_read >= 4 ) {
-                    for( i = 0; i < bytes_read; i += 4 ) {
-                        gesture_data_.u_data[gesture_data_.index] = \
+                if((fifo_level * 4)  >= 4 ) {
+                    for( i = 0; i < (fifo_level * 4); i += 4 ) {
+                        gesture_data_.u_data[gesture_data_.sindex] = \
                                                             fifo_data[i + 0];
-                        gesture_data_.d_data[gesture_data_.index] = \
+                        gesture_data_.d_data[gesture_data_.sindex] = \
                                                             fifo_data[i + 1];
-                        gesture_data_.l_data[gesture_data_.index] = \
+                        gesture_data_.l_data[gesture_data_.sindex] = \
                                                             fifo_data[i + 2];
-                        gesture_data_.r_data[gesture_data_.index] = \
+                        gesture_data_.r_data[gesture_data_.sindex] = \
                                                             fifo_data[i + 3];
-                        gesture_data_.index++;
+                        gesture_data_.sindex++;
                         gesture_data_.total_gestures++;
                     }
                     
@@ -508,7 +512,7 @@
                     }
                     
                     /* Reset data */
-                    gesture_data_.index = 0;
+                    gesture_data_.sindex = 0;
                     gesture_data_.total_gestures = 0;
                 }
             }
@@ -572,7 +576,7 @@
     
     /* Read value from clear channel, low byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CDATAL);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     val = val_byte;
@@ -580,7 +584,7 @@
     /* Read value from clear channel, high byte register */
    
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CDATAH);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     val = val + ((uint16_t)val_byte << 8);
@@ -601,7 +605,7 @@
     
     /* Read value from clear channel, low byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_RDATAL);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     
@@ -609,7 +613,7 @@
     
     /* Read value from clear channel, high byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_RDATAH);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     val = val + ((uint16_t)val_byte << 8);
@@ -631,7 +635,7 @@
     
     /* Read value from clear channel, low byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GDATAL);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     
@@ -639,7 +643,7 @@
     
     /* Read value from clear channel, high byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GDATAH);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     val = val + ((uint16_t)val_byte << 8);
@@ -661,7 +665,7 @@
     
     /* Read value from clear channel, low byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_BDATAL);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     
@@ -669,7 +673,7 @@
     
     /* Read value from clear channel, high byte register */
     val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_BDATAH);
-    if( valbyte==ERROR) {
+    if( val_byte==ERROR) {
         return false;
     }
     val = val + ((uint16_t)val_byte << 8);
@@ -710,7 +714,7 @@
  */
 void glibr::resetGestureParameters()
 {
-    gesture_data_.index = 0;
+    gesture_data_.sindex = 0;
     gesture_data_.total_gestures = 0;
     
     gesture_ud_delta_ = 0;
@@ -928,7 +932,7 @@
  *
  * @return True if near/far event. False otherwise.
  */
-bool APDS9960::decodeGesture()
+bool glibr::decodeGesture()
 {
     /* Return if near or far event is detected */
     if( gesture_state_ == NEAR_STATE ) {
@@ -1105,9 +1109,6 @@
 }
 
 
-
-
-
 bool glibr::setLightIntLowThreshold(uint16_t threshold)
 {
     uint8_t val_low;
@@ -1164,19 +1165,23 @@
  * @param[in] len number of bytes to read
  * @return Number of bytes read. -1 on read error.
  */
-int glibr::I2CReadDataBlock(char address, char subAddress, unsigned int len)
+int glibr::I2CReadDataBlock(char address, char subAddress, uint8_t *val, unsigned int len)
 {
   //  unsigned char i = 0;
-    char *data
+
     /* Indicate which register we want to read from */
    
       if(i2c.write(address<<1, subAddress, 1, true)){
         return -1;   //7 bit   //not acked
-    } 
+      } 
     
     /* Read block data */
-    i2c.read(address<<1, &data, len);
+     
+    if(i2c.read(address<<1, &val, len)){
+        return -1;
+    }
     
+    return 1;
     //Wire.requestFrom(APDS9960_I2C_ADDR, len);
     /*while (Wire.available()) {
         if (i >= len) {
@@ -1185,6 +1190,4 @@
         val[i] = Wire.read();
         i++;
     }*/
-
-    return data;
 }
\ No newline at end of file
--- a/glibr.h	Fri Mar 06 19:35:24 2015 +0000
+++ b/glibr.h	Fri Mar 06 21:50:03 2015 +0000
@@ -191,7 +191,7 @@
     uint8_t d_data[32];
     uint8_t l_data[32];
     uint8_t r_data[32];
-    uint8_t index;
+    uint8_t sindex;
     uint8_t total_gestures;
     uint8_t in_threshold;
     uint8_t out_threshold;
@@ -327,7 +327,7 @@
     
     uint8_t I2CreadByte(char address, char subAddress);
     int I2CwriteByte(char address, char subAddress, char data); 
-    int I2CReadDataBlock(uint8_t reg, uint8_t *val, unsigned int len);
+    int I2CReadDataBlock(char address, char subAddress, uint8_t *val, unsigned int len);
     I2C i2c;
     
 };