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

Revision:
5:3eb4f3091bd8
Parent:
4:84545b0e63a9
Child:
6:687dff16904e
diff -r 84545b0e63a9 -r 3eb4f3091bd8 glibr.cpp
--- a/glibr.cpp	Thu Mar 05 22:42:17 2015 +0000
+++ b/glibr.cpp	Fri Mar 06 02:06:15 2015 +0000
@@ -375,7 +375,7 @@
     
     /* Read value from GSTATUS register */
     val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GSTATUS);
-    if( val==ERROR) ) {
+    if( val==ERROR) {
         return ERROR;
     }
     
@@ -408,7 +408,7 @@
     while(1) {
     
         /* Wait some time to collect next batch of FIFO data */
-        delay(FIFO_PAUSE_TIME);
+        wait(FIFO_PAUSE_TIME);
         
         /* Get the contents of the STATUS register. Is data still valid? */
         
@@ -431,8 +431,9 @@
 //#endif
 
             /* 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 = wireReadDataBlock(  APDS9960_GFIFO_U, 
+                bytes_read = I2CReadDataBlock(APDS9960_I2C_ADDR,APDS9960_GFIFO_U, 
                                                 (uint8_t*)fifo_data, 
                                                 (fifo_level * 4) );
                 if( bytes_read == -1 ) {
@@ -463,12 +464,12 @@
                     }
                     
 #if DEBUG
-                Serial.print("Up Data: ");
+               // Serial.print("Up Data: ");
                 for ( i = 0; i < gesture_data_.total_gestures; i++ ) {
-                    Serial.print(gesture_data_.u_data[i]);
-                    Serial.print(" ");
+                 //   Serial.print(gesture_data_.u_data[i]);
+                  //  Serial.print(" ");
                 }
-                Serial.println();
+              //  Serial.println();
 #endif
 
                     /* Filter and process gesture data. Decode near/far state */
@@ -489,12 +490,12 @@
         } else {
     
             /* Determine best guessed gesture and clean up */
-            delay(FIFO_PAUSE_TIME);
+            wait(FIFO_PAUSE_TIME);
             decodeGesture();
             motion = gesture_motion_;
 #if DEBUG
-            Serial.print("END: ");
-            Serial.println(gesture_motion_);
+        //    Serial.print("END: ");
+        //    Serial.println(gesture_motion_);
 #endif
             resetGestureParameters();
             return motion;
@@ -508,7 +509,7 @@
     
     /* Read value from CONTROL register */
    
-    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val);
+    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL);
     
     if(val==ERROR){
         return false;   
@@ -534,7 +535,7 @@
     
     /* Read value from CONTROL register */
    
-    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val);
+    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL);
     
     if(val==ERROR){
         return false;   
@@ -554,7 +555,7 @@
 }
 
 
-bool glibr::setProxIntLowThresh(uint8_t threshold)
+bool setProxIntLowThresh(uint8_t threshold)
 {
     if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PILT, threshold) ) {
         return false;
@@ -577,18 +578,6 @@
 
 
 
-
-
-
-int glibr::I2CwriteByte(char address, char subAddress, char data)
-{   
-    int ret;
-    char cmd[2] = {subAddress, data};
-    ret=i2c.write(address<<1, cmd, 2);  //if ret is 1, then not acked.
-    return ret;
-}
-
-
 bool glibr::setLightIntLowThreshold(uint16_t threshold)
 {
     uint8_t val_low;
@@ -611,6 +600,20 @@
     return true;
 }
 
+
+
+
+
+int glibr::I2CwriteByte(char address, char subAddress, char data)
+{   
+    int ret;
+    char cmd[2] = {subAddress, data};
+    ret=i2c.write(address<<1, cmd, 2);  //if ret is 1, then not acked.
+    return ret;
+}
+
+
+
 uint8_t glibr::I2CreadByte(char address, char subAddress)
 {
     char data; // store the register data
@@ -622,3 +625,36 @@
     return data;
 
 }
+
+/**
+ * @brief Reads a block (array) of bytes from the I2C device and register
+ *
+ * @param[in] reg the register to read from
+ * @param[out] val pointer to the beginning of the data
+ * @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)
+{
+  //  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);
+    
+    //Wire.requestFrom(APDS9960_I2C_ADDR, len);
+    /*while (Wire.available()) {
+        if (i >= len) {
+            return -1;
+        }
+        val[i] = Wire.read();
+        i++;
+    }*/
+
+    return data;
+}
\ No newline at end of file