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
glibr.h@2:e31b7064efab, 2015-03-05 (annotated)
- Committer:
- kbhagat6
- Date:
- Thu Mar 05 21:52:01 2015 +0000
- Revision:
- 2:e31b7064efab
- Parent:
- 1:c7215f5f9a72
- Child:
- 3:26146a08bb22
added more functions in header file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kbhagat6 | 0:437ae08befe3 | 1 | #include "mbed.h" |
kbhagat6 | 0:437ae08befe3 | 2 | |
kbhagat6 | 0:437ae08befe3 | 3 | |
kbhagat6 | 0:437ae08befe3 | 4 | #define DEBUG 0 |
kbhagat6 | 0:437ae08befe3 | 5 | |
kbhagat6 | 0:437ae08befe3 | 6 | /* APDS-9960 I2C address */ |
kbhagat6 | 0:437ae08befe3 | 7 | #define APDS9960_I2C_ADDR 0x39 |
kbhagat6 | 0:437ae08befe3 | 8 | |
kbhagat6 | 0:437ae08befe3 | 9 | /* Gesture parameters */ |
kbhagat6 | 0:437ae08befe3 | 10 | #define GESTURE_THRESHOLD_OUT 10 |
kbhagat6 | 0:437ae08befe3 | 11 | #define GESTURE_SENSITIVITY_1 50 |
kbhagat6 | 0:437ae08befe3 | 12 | #define GESTURE_SENSITIVITY_2 20 |
kbhagat6 | 0:437ae08befe3 | 13 | |
kbhagat6 | 0:437ae08befe3 | 14 | /* Error code for returned values */ |
kbhagat6 | 0:437ae08befe3 | 15 | #define ERROR 0xFF |
kbhagat6 | 0:437ae08befe3 | 16 | |
kbhagat6 | 0:437ae08befe3 | 17 | /* Acceptable device IDs */ |
kbhagat6 | 0:437ae08befe3 | 18 | #define APDS9960_ID_1 0xAB |
kbhagat6 | 0:437ae08befe3 | 19 | #define APDS9960_ID_2 0x9C |
kbhagat6 | 0:437ae08befe3 | 20 | |
kbhagat6 | 0:437ae08befe3 | 21 | /* Misc parameters */ |
kbhagat6 | 0:437ae08befe3 | 22 | #define FIFO_PAUSE_TIME 30 // Wait period (ms) between FIFO reads |
kbhagat6 | 0:437ae08befe3 | 23 | |
kbhagat6 | 0:437ae08befe3 | 24 | /* APDS-9960 register addresses */ |
kbhagat6 | 0:437ae08befe3 | 25 | #define APDS9960_ENABLE 0x80 |
kbhagat6 | 0:437ae08befe3 | 26 | #define APDS9960_ATIME 0x81 |
kbhagat6 | 0:437ae08befe3 | 27 | #define APDS9960_WTIME 0x83 |
kbhagat6 | 0:437ae08befe3 | 28 | #define APDS9960_AILTL 0x84 |
kbhagat6 | 0:437ae08befe3 | 29 | #define APDS9960_AILTH 0x85 |
kbhagat6 | 0:437ae08befe3 | 30 | #define APDS9960_AIHTL 0x86 |
kbhagat6 | 0:437ae08befe3 | 31 | #define APDS9960_AIHTH 0x87 |
kbhagat6 | 0:437ae08befe3 | 32 | #define APDS9960_PILT 0x89 |
kbhagat6 | 0:437ae08befe3 | 33 | #define APDS9960_PIHT 0x8B |
kbhagat6 | 0:437ae08befe3 | 34 | #define APDS9960_PERS 0x8C |
kbhagat6 | 0:437ae08befe3 | 35 | #define APDS9960_CONFIG1 0x8D |
kbhagat6 | 0:437ae08befe3 | 36 | #define APDS9960_PPULSE 0x8E |
kbhagat6 | 0:437ae08befe3 | 37 | #define APDS9960_CONTROL 0x8F |
kbhagat6 | 0:437ae08befe3 | 38 | #define APDS9960_CONFIG2 0x90 |
kbhagat6 | 0:437ae08befe3 | 39 | #define APDS9960_ID 0x92 |
kbhagat6 | 0:437ae08befe3 | 40 | #define APDS9960_STATUS 0x93 |
kbhagat6 | 0:437ae08befe3 | 41 | #define APDS9960_CDATAL 0x94 |
kbhagat6 | 0:437ae08befe3 | 42 | #define APDS9960_CDATAH 0x95 |
kbhagat6 | 0:437ae08befe3 | 43 | #define APDS9960_RDATAL 0x96 |
kbhagat6 | 0:437ae08befe3 | 44 | #define APDS9960_RDATAH 0x97 |
kbhagat6 | 0:437ae08befe3 | 45 | #define APDS9960_GDATAL 0x98 |
kbhagat6 | 0:437ae08befe3 | 46 | #define APDS9960_GDATAH 0x99 |
kbhagat6 | 0:437ae08befe3 | 47 | #define APDS9960_BDATAL 0x9A |
kbhagat6 | 0:437ae08befe3 | 48 | #define APDS9960_BDATAH 0x9B |
kbhagat6 | 0:437ae08befe3 | 49 | #define APDS9960_PDATA 0x9C |
kbhagat6 | 0:437ae08befe3 | 50 | #define APDS9960_POFFSET_UR 0x9D |
kbhagat6 | 0:437ae08befe3 | 51 | #define APDS9960_POFFSET_DL 0x9E |
kbhagat6 | 0:437ae08befe3 | 52 | #define APDS9960_CONFIG3 0x9F |
kbhagat6 | 0:437ae08befe3 | 53 | #define APDS9960_GPENTH 0xA0 |
kbhagat6 | 0:437ae08befe3 | 54 | #define APDS9960_GEXTH 0xA1 |
kbhagat6 | 0:437ae08befe3 | 55 | #define APDS9960_GCONF1 0xA2 |
kbhagat6 | 0:437ae08befe3 | 56 | #define APDS9960_GCONF2 0xA3 |
kbhagat6 | 0:437ae08befe3 | 57 | #define APDS9960_GOFFSET_U 0xA4 |
kbhagat6 | 0:437ae08befe3 | 58 | #define APDS9960_GOFFSET_D 0xA5 |
kbhagat6 | 0:437ae08befe3 | 59 | #define APDS9960_GOFFSET_L 0xA7 |
kbhagat6 | 0:437ae08befe3 | 60 | #define APDS9960_GOFFSET_R 0xA9 |
kbhagat6 | 0:437ae08befe3 | 61 | #define APDS9960_GPULSE 0xA6 |
kbhagat6 | 0:437ae08befe3 | 62 | #define APDS9960_GCONF3 0xAA |
kbhagat6 | 0:437ae08befe3 | 63 | #define APDS9960_GCONF4 0xAB |
kbhagat6 | 0:437ae08befe3 | 64 | #define APDS9960_GFLVL 0xAE |
kbhagat6 | 0:437ae08befe3 | 65 | #define APDS9960_GSTATUS 0xAF |
kbhagat6 | 0:437ae08befe3 | 66 | #define APDS9960_IFORCE 0xE4 |
kbhagat6 | 0:437ae08befe3 | 67 | #define APDS9960_PICLEAR 0xE5 |
kbhagat6 | 0:437ae08befe3 | 68 | #define APDS9960_CICLEAR 0xE6 |
kbhagat6 | 0:437ae08befe3 | 69 | #define APDS9960_AICLEAR 0xE7 |
kbhagat6 | 0:437ae08befe3 | 70 | #define APDS9960_GFIFO_U 0xFC |
kbhagat6 | 0:437ae08befe3 | 71 | #define APDS9960_GFIFO_D 0xFD |
kbhagat6 | 0:437ae08befe3 | 72 | #define APDS9960_GFIFO_L 0xFE |
kbhagat6 | 0:437ae08befe3 | 73 | #define APDS9960_GFIFO_R 0xFF |
kbhagat6 | 0:437ae08befe3 | 74 | |
kbhagat6 | 0:437ae08befe3 | 75 | /* Bit fields */ |
kbhagat6 | 0:437ae08befe3 | 76 | #define APDS9960_PON 0b00000001 |
kbhagat6 | 0:437ae08befe3 | 77 | #define APDS9960_AEN 0b00000010 |
kbhagat6 | 0:437ae08befe3 | 78 | #define APDS9960_PEN 0b00000100 |
kbhagat6 | 0:437ae08befe3 | 79 | #define APDS9960_WEN 0b00001000 |
kbhagat6 | 0:437ae08befe3 | 80 | #define APSD9960_AIEN 0b00010000 |
kbhagat6 | 0:437ae08befe3 | 81 | #define APDS9960_PIEN 0b00100000 |
kbhagat6 | 0:437ae08befe3 | 82 | #define APDS9960_GEN 0b01000000 |
kbhagat6 | 0:437ae08befe3 | 83 | #define APDS9960_GVALID 0b00000001 |
kbhagat6 | 0:437ae08befe3 | 84 | |
kbhagat6 | 0:437ae08befe3 | 85 | /* On/Off definitions */ |
kbhagat6 | 0:437ae08befe3 | 86 | #define OFF 0 |
kbhagat6 | 0:437ae08befe3 | 87 | #define ON 1 |
kbhagat6 | 0:437ae08befe3 | 88 | |
kbhagat6 | 0:437ae08befe3 | 89 | /* Acceptable parameters for setMode */ |
kbhagat6 | 0:437ae08befe3 | 90 | #define POWER 0 |
kbhagat6 | 0:437ae08befe3 | 91 | #define AMBIENT_LIGHT 1 |
kbhagat6 | 0:437ae08befe3 | 92 | #define PROXIMITY 2 |
kbhagat6 | 0:437ae08befe3 | 93 | #define WAIT 3 |
kbhagat6 | 0:437ae08befe3 | 94 | #define AMBIENT_LIGHT_INT 4 |
kbhagat6 | 0:437ae08befe3 | 95 | #define PROXIMITY_INT 5 |
kbhagat6 | 0:437ae08befe3 | 96 | #define GESTURE 6 |
kbhagat6 | 0:437ae08befe3 | 97 | #define ALL 7 |
kbhagat6 | 0:437ae08befe3 | 98 | |
kbhagat6 | 0:437ae08befe3 | 99 | /* LED Drive values */ |
kbhagat6 | 0:437ae08befe3 | 100 | #define LED_DRIVE_100MA 0 |
kbhagat6 | 0:437ae08befe3 | 101 | #define LED_DRIVE_50MA 1 |
kbhagat6 | 0:437ae08befe3 | 102 | #define LED_DRIVE_25MA 2 |
kbhagat6 | 0:437ae08befe3 | 103 | #define LED_DRIVE_12_5MA 3 |
kbhagat6 | 0:437ae08befe3 | 104 | |
kbhagat6 | 0:437ae08befe3 | 105 | /* Proximity Gain (PGAIN) values */ |
kbhagat6 | 0:437ae08befe3 | 106 | #define PGAIN_1X 0 |
kbhagat6 | 0:437ae08befe3 | 107 | #define PGAIN_2X 1 |
kbhagat6 | 0:437ae08befe3 | 108 | #define PGAIN_4X 2 |
kbhagat6 | 0:437ae08befe3 | 109 | #define PGAIN_8X 3 |
kbhagat6 | 0:437ae08befe3 | 110 | |
kbhagat6 | 0:437ae08befe3 | 111 | /* ALS Gain (AGAIN) values */ |
kbhagat6 | 0:437ae08befe3 | 112 | #define AGAIN_1X 0 |
kbhagat6 | 0:437ae08befe3 | 113 | #define AGAIN_4X 1 |
kbhagat6 | 0:437ae08befe3 | 114 | #define AGAIN_16X 2 |
kbhagat6 | 0:437ae08befe3 | 115 | #define AGAIN_64X 3 |
kbhagat6 | 0:437ae08befe3 | 116 | |
kbhagat6 | 0:437ae08befe3 | 117 | /* Gesture Gain (GGAIN) values */ |
kbhagat6 | 0:437ae08befe3 | 118 | #define GGAIN_1X 0 |
kbhagat6 | 0:437ae08befe3 | 119 | #define GGAIN_2X 1 |
kbhagat6 | 0:437ae08befe3 | 120 | #define GGAIN_4X 2 |
kbhagat6 | 0:437ae08befe3 | 121 | #define GGAIN_8X 3 |
kbhagat6 | 0:437ae08befe3 | 122 | |
kbhagat6 | 0:437ae08befe3 | 123 | /* LED Boost values */ |
kbhagat6 | 0:437ae08befe3 | 124 | #define LED_BOOST_100 0 |
kbhagat6 | 0:437ae08befe3 | 125 | #define LED_BOOST_150 1 |
kbhagat6 | 0:437ae08befe3 | 126 | #define LED_BOOST_200 2 |
kbhagat6 | 0:437ae08befe3 | 127 | #define LED_BOOST_300 3 |
kbhagat6 | 0:437ae08befe3 | 128 | |
kbhagat6 | 0:437ae08befe3 | 129 | /* Gesture wait time values */ |
kbhagat6 | 0:437ae08befe3 | 130 | #define GWTIME_0MS 0 |
kbhagat6 | 0:437ae08befe3 | 131 | #define GWTIME_2_8MS 1 |
kbhagat6 | 0:437ae08befe3 | 132 | #define GWTIME_5_6MS 2 |
kbhagat6 | 0:437ae08befe3 | 133 | #define GWTIME_8_4MS 3 |
kbhagat6 | 0:437ae08befe3 | 134 | #define GWTIME_14_0MS 4 |
kbhagat6 | 0:437ae08befe3 | 135 | #define GWTIME_22_4MS 5 |
kbhagat6 | 0:437ae08befe3 | 136 | #define GWTIME_30_8MS 6 |
kbhagat6 | 0:437ae08befe3 | 137 | #define GWTIME_39_2MS 7 |
kbhagat6 | 0:437ae08befe3 | 138 | |
kbhagat6 | 0:437ae08befe3 | 139 | /* Default values */ |
kbhagat6 | 0:437ae08befe3 | 140 | #define DEFAULT_ATIME 219 // 103ms |
kbhagat6 | 0:437ae08befe3 | 141 | #define DEFAULT_WTIME 246 // 27ms |
kbhagat6 | 0:437ae08befe3 | 142 | #define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses |
kbhagat6 | 0:437ae08befe3 | 143 | #define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses |
kbhagat6 | 0:437ae08befe3 | 144 | #define DEFAULT_POFFSET_UR 0 // 0 offset |
kbhagat6 | 0:437ae08befe3 | 145 | #define DEFAULT_POFFSET_DL 0 // 0 offset |
kbhagat6 | 0:437ae08befe3 | 146 | #define DEFAULT_CONFIG1 0x60 // No 12x wait (WTIME) factor |
kbhagat6 | 0:437ae08befe3 | 147 | #define DEFAULT_LDRIVE LED_DRIVE_100MA |
kbhagat6 | 0:437ae08befe3 | 148 | #define DEFAULT_PGAIN PGAIN_4X |
kbhagat6 | 0:437ae08befe3 | 149 | #define DEFAULT_AGAIN AGAIN_4X |
kbhagat6 | 0:437ae08befe3 | 150 | #define DEFAULT_PILT 0 // Low proximity threshold |
kbhagat6 | 0:437ae08befe3 | 151 | #define DEFAULT_PIHT 50 // High proximity threshold |
kbhagat6 | 0:437ae08befe3 | 152 | #define DEFAULT_AILT 0xFFFF // Force interrupt for calibration |
kbhagat6 | 0:437ae08befe3 | 153 | #define DEFAULT_AIHT 0 |
kbhagat6 | 0:437ae08befe3 | 154 | #define DEFAULT_PERS 0x11 // 2 consecutive prox or ALS for int. |
kbhagat6 | 0:437ae08befe3 | 155 | #define DEFAULT_CONFIG2 0x01 // No saturation interrupts or LED boost |
kbhagat6 | 0:437ae08befe3 | 156 | #define DEFAULT_CONFIG3 0 // Enable all photodiodes, no SAI |
kbhagat6 | 0:437ae08befe3 | 157 | #define DEFAULT_GPENTH 40 // Threshold for entering gesture mode |
kbhagat6 | 0:437ae08befe3 | 158 | #define DEFAULT_GEXTH 30 // Threshold for exiting gesture mode |
kbhagat6 | 0:437ae08befe3 | 159 | #define DEFAULT_GCONF1 0x40 // 4 gesture events for int., 1 for exit |
kbhagat6 | 0:437ae08befe3 | 160 | #define DEFAULT_GGAIN GGAIN_4X |
kbhagat6 | 0:437ae08befe3 | 161 | #define DEFAULT_GLDRIVE LED_DRIVE_100MA |
kbhagat6 | 0:437ae08befe3 | 162 | #define DEFAULT_GWTIME GWTIME_2_8MS |
kbhagat6 | 0:437ae08befe3 | 163 | #define DEFAULT_GOFFSET 0 // No offset scaling for gesture mode |
kbhagat6 | 0:437ae08befe3 | 164 | #define DEFAULT_GPULSE 0xC9 // 32us, 10 pulses |
kbhagat6 | 0:437ae08befe3 | 165 | #define DEFAULT_GCONF3 0 // All photodiodes active during gesture |
kbhagat6 | 0:437ae08befe3 | 166 | #define DEFAULT_GIEN 0 // Disable gesture interrupts |
kbhagat6 | 0:437ae08befe3 | 167 | |
kbhagat6 | 0:437ae08befe3 | 168 | |
kbhagat6 | 0:437ae08befe3 | 169 | |
kbhagat6 | 0:437ae08befe3 | 170 | class glibr{ |
kbhagat6 | 0:437ae08befe3 | 171 | |
kbhagat6 | 0:437ae08befe3 | 172 | public: |
kbhagat6 | 0:437ae08befe3 | 173 | |
kbhagat6 | 0:437ae08befe3 | 174 | |
kbhagat6 | 0:437ae08befe3 | 175 | glibr(PinName sda, PinName scl); //constructor |
kbhagat6 | 0:437ae08befe3 | 176 | ~glibr(); |
kbhagat6 | 0:437ae08befe3 | 177 | |
kbhagat6 | 0:437ae08befe3 | 178 | |
kbhagat6 | 0:437ae08befe3 | 179 | uint8_t ginit(); |
kbhagat6 | 0:437ae08befe3 | 180 | bool setMode(uint8_t mode, uint8_t enable); |
kbhagat6 | 0:437ae08befe3 | 181 | uint8_t getMode(); |
kbhagat6 | 2:e31b7064efab | 182 | bool setLEDDrive(uint8_t drive); |
kbhagat6 | 0:437ae08befe3 | 183 | bool setProximityGain(uint8_t drive); |
kbhagat6 | 2:e31b7064efab | 184 | uint8_t getProximityGain(); |
kbhagat6 | 2:e31b7064efab | 185 | uint8_t getAmbientLightGain(); |
kbhagat6 | 1:c7215f5f9a72 | 186 | bool setAmbientLightGain(uint8_t drive); |
kbhagat6 | 2:e31b7064efab | 187 | uint8_t getGestureGain(); |
kbhagat6 | 2:e31b7064efab | 188 | bool setGestureGain(uint8_t gain); |
kbhagat6 | 0:437ae08befe3 | 189 | |
kbhagat6 | 0:437ae08befe3 | 190 | private: |
kbhagat6 | 0:437ae08befe3 | 191 | uint8_t I2CreadByte(char address, char subAddress); |
kbhagat6 | 0:437ae08befe3 | 192 | int I2CwriteByte(char address, char subAddress, char data); |
kbhagat6 | 1:c7215f5f9a72 | 193 | bool setProxIntLowThresh(uint8_t threshold); |
kbhagat6 | 1:c7215f5f9a72 | 194 | bool setProxIntHighThresh(uint8_t threshold); |
kbhagat6 | 0:437ae08befe3 | 195 | I2C i2c; |
kbhagat6 | 0:437ae08befe3 | 196 | |
kbhagat6 | 0:437ae08befe3 | 197 | }; |