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:
Thu Mar 05 06:44:27 2015 +0000
Parent:
0:437ae08befe3
Child:
2:e31b7064efab
Commit message:
still working in bool init function, and adding the functions it calls.

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	Thu Mar 05 04:53:07 2015 +0000
+++ b/glibr.cpp	Thu Mar 05 06:44:27 2015 +0000
@@ -58,8 +58,58 @@
     if( !setProxIntLowThresh(DEFAULT_PILT) ) {
         return false;
     }
-
-
+    if( !setProxIntHighThresh(DEFAULT_PIHT) ) {
+        return false;
+    }
+    if( !setLightIntLowThreshold(DEFAULT_AILT) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONFIG2, DEFAULT_CONFIG2) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONFIG3, DEFAULT_CONFIG3) ) {
+        return false;
+    }
+    
+    if( !setGestureEnterThresh(DEFAULT_GPENTH) ) {
+        return false;
+    }
+    if( !setGestureExitThresh(DEFAULT_GEXTH) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GCONF1, DEFAULT_GCONF1) ) {
+        return false;
+    }
+    if( !setGestureGain(DEFAULT_GGAIN) ) {
+        return false;
+    }
+    if( !setGestureLEDDrive(DEFAULT_GLDRIVE) ) {
+        return false;
+    }
+    if( !setGestureWaitTime(DEFAULT_GWTIME) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_U, DEFAULT_GOFFSET) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_D, DEFAULT_GOFFSET) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_L, DEFAULT_GOFFSET) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_R, DEFAULT_GOFFSET) ) {
+        return false;
+    }
+    if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GPULSE, DEFAULT_GPULSE) ) {
+        return false;
+    }
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GCONF3, DEFAULT_GCONF3) ) {
+        return false;
+    }
+    if( !setGestureIntEnable(DEFAULT_GIEN) ) {
+        return false;
+    }
     
     
     
@@ -147,26 +197,71 @@
     uint8_t val;
     
     /* Read value from CONTROL register */
-    if( !wireReadDataByte(APDS9960_CONTROL, val) ) {
-        return false;
-    }
+   
+    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val);
     
+    if(val==ERROR){
+        return false;   
+    }
     /* Set bits in register to given value */
-    drive &= 0b00000011;
+    //drive &= 0b00000011;
+    drive &=0x03;
     drive = drive << 2;
-    val &= 0b11110011;
+    val &= 0xF3;
     val |= drive;
     
     /* Write register value back into CONTROL register */
-    if( !wireWriteDataByte(APDS9960_CONTROL, val) ) {
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val) ) {
+        return false;
+    }
+    return true;
+}
+
+
+bool glibr::setAmbientLightGain(uint8_t drive){
+{
+    uint8_t val;
+    
+    /* Read value from CONTROL register */
+   
+    val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val);
+    
+    if(val==ERROR){
+        return false;   
+    }
+    /* Set bits in register to given value */
+    //drive &= 0b00000011;
+    drive &=0x03;
+    drive = drive << 2;
+    val &= 0xF3;
+    val |= drive;
+    
+    /* Write register value back into CONTROL register */
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val) ) {
+        return false;
+    }
+    return true;
+}
+
+
+bool glibr::setProxIntLowThresh(uint8_t threshold)
+{
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PILT, threshold) ) {
         return false;
     }
     
     return true;
 }
 
-
-
+bool glibr::setProxIntHighThresh(uint8_t threshold)
+{
+   
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PIHT, threshold) ) {
+        return false;
+    }
+    
+    return true;
+}
 
 int glibr::I2CwriteByte(char address, char subAddress, char data)
 {   
@@ -176,6 +271,29 @@
     return ret;
 }
 
+
+bool glibr::setLightIntLowThreshold(uint16_t threshold)
+{
+    uint8_t val_low;
+    uint8_t val_high;
+    
+    /* Break 16-bit threshold into 2 8-bit values */
+    val_low = threshold & 0x00FF;
+    val_high = (threshold & 0xFF00) >> 8;
+    
+    /* Write low byte */
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_AILTL, val_low) ) {
+        return false;
+    }
+    
+    /* Write high byte */
+    if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_AILTH, val_high) ) {
+        return false;
+    }
+    
+    return true;
+}
+
 uint8_t glibr::I2CreadByte(char address, char subAddress)
 {
     char data; // store the register data
--- a/glibr.h	Thu Mar 05 04:53:07 2015 +0000
+++ b/glibr.h	Thu Mar 05 06:44:27 2015 +0000
@@ -181,11 +181,14 @@
     uint8_t getMode();
     bool setLEDDrive(uint8_t drive);
     bool setProximityGain(uint8_t drive);
-    
+    bool setAmbientLightGain(uint8_t drive);
+ 
     
     private:  
     uint8_t I2CreadByte(char address, char subAddress);
     int I2CwriteByte(char address, char subAddress, char data); 
+    bool setProxIntLowThresh(uint8_t threshold);
+    bool setProxIntHighThresh(uint8_t threshold);
     I2C i2c;
     
 };