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 22:23:50 2015 +0000
Parent:
2:e31b7064efab
Child:
4:84545b0e63a9
Commit message:
more functions

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 21:52:01 2015 +0000
+++ b/glibr.cpp	Thu Mar 05 22:23:50 2015 +0000
@@ -192,6 +192,203 @@
     return true;
 }
 
+bool glibr::enableLightSensor(bool interrupts)
+{
+    
+    /* Set default gain, interrupts, enable power, and enable sensor */
+    if( !setAmbientLightGain(DEFAULT_AGAIN) ) {
+        return false;
+    }
+    if( interrupts ) {
+        if( !setAmbientLightIntEnable(1) ) {
+            return false;
+        }
+    } else {
+        if( !setAmbientLightIntEnable(0) ) {
+            return false;
+        }
+    }
+    if( !enablePower() ){
+        return false;
+    }
+    if( !setMode(AMBIENT_LIGHT, 1) ) {
+        return false;
+    }
+    
+    return true;
+
+}
+
+/**
+ * @brief Ends the light sensor on the APDS-9960
+ *
+ * @return True if sensor disabled correctly. False on error.
+ */
+bool glibr::disableLightSensor()
+{
+    if( !setAmbientLightIntEnable(0) ) {
+        return false;
+    }
+    if( !setMode(AMBIENT_LIGHT, 0) ) {
+        return false;
+    }
+    
+    return true;
+}
+
+/**
+ * @brief Starts the proximity sensor on the APDS-9960
+ *
+ * @param[in] interrupts true to enable hardware external interrupt on proximity
+ * @return True if sensor enabled correctly. False on error.
+ */
+bool glibr::enableProximitySensor(bool interrupts)
+{
+    /* Set default gain, LED, interrupts, enable power, and enable sensor */
+    if( !setProximityGain(DEFAULT_PGAIN) ) {
+        return false;
+    }
+    if( !setLEDDrive(DEFAULT_LDRIVE) ) {
+        return false;
+    }
+    if( interrupts ) {
+        if( !setProximityIntEnable(1) ) {
+            return false;
+        }
+    } else {
+        if( !setProximityIntEnable(0) ) {
+            return false;
+        }
+    }
+    if( !enablePower() ){
+        return false;
+    }
+    if( !setMode(PROXIMITY, 1) ) {
+        return false;
+    }
+    
+    return true;
+}
+
+/**
+ * @brief Ends the proximity sensor on the APDS-9960
+ *
+ * @return True if sensor disabled correctly. False on error.
+ */
+bool glibr::disableProximitySensor()
+{
+    if( !setProximityIntEnable(0) ) {
+        return false;
+    }
+    if( !setMode(PROXIMITY, 0) ) {
+        return false;
+    }
+
+    return true;
+}
+
+
+/**
+ * @brief Starts the gesture recognition engine on the APDS-9960
+ *
+ * @param[in] interrupts true to enable hardware external interrupt on gesture
+ * @return True if engine enabled correctly. False on error.
+ */
+bool glibr::enableGestureSensor(bool interrupts)
+{
+    
+    /* Enable gesture mode
+       Set ENABLE to 0 (power off)
+       Set WTIME to 0xFF
+       Set AUX to LED_BOOST_300
+       Enable PON, WEN, PEN, GEN in ENABLE 
+    */
+
+    resetGestureParameters();
+    if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_WTIME, 0xFF) ) {
+        return false;
+    }
+    if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE) ) {
+        return false;
+    }
+    if( !setLEDBoost(LED_BOOST_300) ) {
+        return false;
+    }
+    if( interrupts ) {
+        if( !setGestureIntEnable(1) ) {
+            return false;
+        }
+    } else {
+        if( !setGestureIntEnable(0) ) {
+            return false;
+        }
+    }
+    if( !setGestureMode(1) ) {
+        return false;
+    }
+    if( !enablePower() ){
+        return false;
+    }
+    if( !setMode(WAIT, 1) ) {
+        return false;
+    }
+    if( !setMode(PROXIMITY, 1) ) {
+        return false;
+    }
+    if( !setMode(GESTURE, 1) ) {
+        return false;
+    }
+    
+    return true;
+}
+
+/**
+ * @brief Ends the gesture recognition engine on the APDS-9960
+ *
+ * @return True if engine disabled correctly. False on error.
+ */
+bool glibr::disableGestureSensor()
+{
+    resetGestureParameters();
+    if( !setGestureIntEnable(0) ) {
+        return false;
+    }
+    if( !setGestureMode(0) ) {
+        return false;
+    }
+    if( !setMode(GESTURE, 0) ) {
+        return false;
+    }
+    
+    return true;
+}
+
+
+/**
+ * @brief Determines if there is a gesture available for reading
+ *
+ * @return True if gesture available. False otherwise.
+ */
+bool glibr::isGestureAvailable()
+{
+    uint8_t val;
+    
+    /* Read value from GSTATUS register */
+    if( !wireReadDataByte(APDS9960_GSTATUS, val) ) {
+        return ERROR;
+    }
+    
+    /* Shift and mask out GVALID bit */
+    val &= APDS9960_GVALID;
+    
+    /* Return true/false based on GVALID bit */
+    if( val == 1) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
 bool glibr::setProximityGain(uint8_t drive)
 {
     uint8_t val;
@@ -263,6 +460,13 @@
     return true;
 }
 
+
+
+
+
+
+
+
 int glibr::I2CwriteByte(char address, char subAddress, char data)
 {   
     int ret;
--- a/glibr.h	Thu Mar 05 21:52:01 2015 +0000
+++ b/glibr.h	Thu Mar 05 22:23:50 2015 +0000
@@ -187,6 +187,16 @@
     uint8_t getGestureGain();
     bool setGestureGain(uint8_t gain);
     
+    bool enableLightSensor(bool interrupts);
+    bool disableLightSensor();
+    bool enableProximitySensor(bool interrupts);
+    bool disableProximitySensor();
+    
+    bool enableGestureSensor(bool interrupts);
+    bool disableGestureSensor();
+    bool isGestureAvailable();
+
+    
     private:  
     uint8_t I2CreadByte(char address, char subAddress);
     int I2CwriteByte(char address, char subAddress, char data);