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:
8:6fa15d4e31fb
--- a/glibr.h	Thu Mar 05 22:42:17 2015 +0000
+++ b/glibr.h	Fri Mar 06 02:06:15 2015 +0000
@@ -73,14 +73,14 @@
 #define APDS9960_GFIFO_R        0xFF
 
 /* Bit fields */
-#define APDS9960_PON            0b00000001
-#define APDS9960_AEN            0b00000010
-#define APDS9960_PEN            0b00000100
-#define APDS9960_WEN            0b00001000
-#define APSD9960_AIEN           0b00010000
-#define APDS9960_PIEN           0b00100000
-#define APDS9960_GEN            0b01000000
-#define APDS9960_GVALID         0b00000001
+#define APDS9960_PON            0x01
+#define APDS9960_AEN            0x02
+#define APDS9960_PEN            0x04
+#define APDS9960_WEN            0x08
+#define APSD9960_AIEN           0x10
+#define APDS9960_PIEN           0x20
+#define APDS9960_GEN            0x40
+#define APDS9960_GVALID         0x01
 
 /* On/Off definitions */
 #define OFF                     0
@@ -165,6 +165,37 @@
 #define DEFAULT_GCONF3          0       // All photodiodes active during gesture
 #define DEFAULT_GIEN            0       // Disable gesture interrupts
 
+/* Direction definitions */
+enum {
+  DIR_NONE,
+  DIR_LEFT,
+  DIR_RIGHT,
+  DIR_UP,
+  DIR_DOWN,
+  DIR_NEAR,
+  DIR_FAR,
+  DIR_ALL
+};
+
+/* State definitions */
+enum {
+  NA_STATE,
+  NEAR_STATE,
+  FAR_STATE,
+  ALL_STATE
+};
+
+/* Container for gesture data */
+typedef struct gesture_data_type {
+    uint8_t u_data[32];
+    uint8_t d_data[32];
+    uint8_t l_data[32];
+    uint8_t r_data[32];
+    uint8_t index;
+    uint8_t total_gestures;
+    uint8_t in_threshold;
+    uint8_t out_threshold;
+} gesture_data_type;
 
 
 class glibr{
@@ -177,31 +208,126 @@
 
     
     uint8_t ginit();
-    bool setMode(uint8_t mode, uint8_t enable);
+    /* Initialization methods */
+    
     uint8_t getMode();
-    bool setLEDDrive(uint8_t drive); 
-    bool setProximityGain(uint8_t drive);
-     uint8_t getProximityGain();
+    bool setMode(uint8_t mode, uint8_t enable);
+    
+    /* Turn the APDS-9960 on and off */
+    bool enablePower();
+    bool disablePower();
+    
+    /* Enable or disable specific sensors */
+    bool enableLightSensor(bool interrupts = false);
+    bool disableLightSensor();
+    bool enableProximitySensor(bool interrupts = false);
+    bool disableProximitySensor();
+    bool enableGestureSensor(bool interrupts = true);
+    bool disableGestureSensor();
+    
+    /* LED drive strength control */
+    uint8_t getLEDDrive();
+    bool setLEDDrive(uint8_t drive);
+    uint8_t getGestureLEDDrive();
+    bool setGestureLEDDrive(uint8_t drive);
+    
+    /* Gain control */
     uint8_t getAmbientLightGain();
-    bool setAmbientLightGain(uint8_t drive);
+    bool setAmbientLightGain(uint8_t gain);
+    uint8_t getProximityGain();
+    bool setProximityGain(uint8_t gain);
     uint8_t getGestureGain();
     bool setGestureGain(uint8_t gain);
     
-    bool enableLightSensor(bool interrupts);
-    bool disableLightSensor();
-    bool enableProximitySensor(bool interrupts);
-    bool disableProximitySensor();
+    /* Get and set light interrupt thresholds */
+    bool getLightIntLowThreshold(uint16_t &threshold);
+    bool setLightIntLowThreshold(uint16_t threshold);
+    bool getLightIntHighThreshold(uint16_t &threshold);
+    bool setLightIntHighThreshold(uint16_t threshold);
+    
+    /* Get and set proximity interrupt thresholds */
+    bool getProximityIntLowThreshold(uint8_t &threshold);
+    bool setProximityIntLowThreshold(uint8_t threshold);
+    bool getProximityIntHighThreshold(uint8_t &threshold);
+    bool setProximityIntHighThreshold(uint8_t threshold);
     
-    bool enableGestureSensor(bool interrupts);
-    bool disableGestureSensor();
+    /* Get and set interrupt enables */
+    uint8_t getAmbientLightIntEnable();
+    bool setAmbientLightIntEnable(uint8_t enable);
+    uint8_t getProximityIntEnable();
+    bool setProximityIntEnable(uint8_t enable);
+    uint8_t getGestureIntEnable();
+    bool setGestureIntEnable(uint8_t enable);
+    
+    /* Clear interrupts */
+    bool clearAmbientLightInt();
+    bool clearProximityInt();
+    
+    /* Ambient light methods */
+    bool readAmbientLight(uint16_t &val);
+    bool readRedLight(uint16_t &val);
+    bool readGreenLight(uint16_t &val);
+    bool readBlueLight(uint16_t &val);
+    
+    /* Proximity methods */
+    bool readProximity(uint8_t &val);
+    
+    /* Gesture methods */
     bool isGestureAvailable();
     int readGesture();
      
     private:  
+    /* Gesture processing */
+    void resetGestureParameters();
+    bool processGestureData();
+    bool decodeGesture();
+
+    /* Proximity Interrupt Threshold */
+    uint8_t getProxIntLowThresh();
+    bool setProxIntLowThresh(uint8_t threshold);
+    uint8_t getProxIntHighThresh();
+    bool setProxIntHighThresh(uint8_t threshold);
+    
+    /* LED Boost Control */
+    uint8_t getLEDBoost();
+    bool setLEDBoost(uint8_t boost);
+    
+    /* Proximity photodiode select */
+    uint8_t getProxGainCompEnable();
+    bool setProxGainCompEnable(uint8_t enable);
+    uint8_t getProxPhotoMask();
+    bool setProxPhotoMask(uint8_t mask);
+    
+    /* Gesture threshold control */
+    uint8_t getGestureEnterThresh();
+    bool setGestureEnterThresh(uint8_t threshold);
+    uint8_t getGestureExitThresh();
+    bool setGestureExitThresh(uint8_t threshold);
+    
+    /* Gesture LED, gain, and time control */
+    uint8_t getGestureWaitTime();
+    bool setGestureWaitTime(uint8_t time);
+    
+    /* Gesture mode */
+    uint8_t getGestureMode();
+    bool setGestureMode(uint8_t mode);
+    
+    /* Members */
+    gesture_data_type gesture_data_;  //instanciation from struct 
+    int gesture_ud_delta_;
+    int gesture_lr_delta_;
+    int gesture_ud_count_;
+    int gesture_lr_count_;
+    int gesture_near_count_;
+    int gesture_far_count_;
+    int gesture_state_;
+    int gesture_motion_;
+    
+    
+    
     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);
+    int I2CReadDataBlock(uint8_t reg, uint8_t *val, unsigned int len);
     I2C i2c;
     
 };