![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.cpp@6:687dff16904e, 2015-03-06 (annotated)
- Committer:
- kbhagat6
- Date:
- Fri Mar 06 07:20:24 2015 +0000
- Revision:
- 6:687dff16904e
- Parent:
- 5:3eb4f3091bd8
- Child:
- 7:0564c6faf8aa
more functions.. still need to look at readgesture()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kbhagat6 | 0:437ae08befe3 | 1 | #include "glibr.h" |
kbhagat6 | 0:437ae08befe3 | 2 | #include "mbed.h" |
kbhagat6 | 0:437ae08befe3 | 3 | |
kbhagat6 | 0:437ae08befe3 | 4 | |
kbhagat6 | 0:437ae08befe3 | 5 | |
kbhagat6 | 0:437ae08befe3 | 6 | |
kbhagat6 | 0:437ae08befe3 | 7 | glibr::glibr(PinName sda, PinName scl):i2c(sda, scl){ |
kbhagat6 | 6:687dff16904e | 8 | gesture_ud_delta_ = 0; |
kbhagat6 | 6:687dff16904e | 9 | gesture_lr_delta_ = 0; |
kbhagat6 | 6:687dff16904e | 10 | |
kbhagat6 | 6:687dff16904e | 11 | gesture_ud_count_ = 0; |
kbhagat6 | 6:687dff16904e | 12 | gesture_lr_count_ = 0; |
kbhagat6 | 6:687dff16904e | 13 | |
kbhagat6 | 6:687dff16904e | 14 | gesture_near_count_ = 0; |
kbhagat6 | 6:687dff16904e | 15 | gesture_far_count_ = 0; |
kbhagat6 | 6:687dff16904e | 16 | |
kbhagat6 | 6:687dff16904e | 17 | gesture_state_ = 0; |
kbhagat6 | 6:687dff16904e | 18 | gesture_motion_ = DIR_NONE; |
kbhagat6 | 0:437ae08befe3 | 19 | } |
kbhagat6 | 0:437ae08befe3 | 20 | |
kbhagat6 | 0:437ae08befe3 | 21 | glibr::~glibr(){ |
kbhagat6 | 0:437ae08befe3 | 22 | |
kbhagat6 | 0:437ae08befe3 | 23 | } |
kbhagat6 | 0:437ae08befe3 | 24 | |
kbhagat6 | 0:437ae08befe3 | 25 | uint8_t glibr::ginit(){ |
kbhagat6 | 0:437ae08befe3 | 26 | uint8_t id; |
kbhagat6 | 0:437ae08befe3 | 27 | |
kbhagat6 | 0:437ae08befe3 | 28 | // if( !wireReadDataByte(APDS9960_ID, id) ) { |
kbhagat6 | 0:437ae08befe3 | 29 | |
kbhagat6 | 0:437ae08befe3 | 30 | id=I2CreadByte(APDS9960_I2C_ADDR, APDS9960_ID); |
kbhagat6 | 0:437ae08befe3 | 31 | |
kbhagat6 | 0:437ae08befe3 | 32 | if( (!(id == APDS9960_ID_1 || id == APDS9960_ID_2))||id==ERROR) { |
kbhagat6 | 0:437ae08befe3 | 33 | return false; |
kbhagat6 | 0:437ae08befe3 | 34 | } |
kbhagat6 | 0:437ae08befe3 | 35 | |
kbhagat6 | 0:437ae08befe3 | 36 | if(!setMode(ALL, OFF)) { |
kbhagat6 | 0:437ae08befe3 | 37 | return false; |
kbhagat6 | 0:437ae08befe3 | 38 | } |
kbhagat6 | 0:437ae08befe3 | 39 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_ATIME, DEFAULT_ATIME)){ |
kbhagat6 | 0:437ae08befe3 | 40 | return false; |
kbhagat6 | 0:437ae08befe3 | 41 | } |
kbhagat6 | 0:437ae08befe3 | 42 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_WTIME, DEFAULT_WTIME)){ |
kbhagat6 | 0:437ae08befe3 | 43 | return false; |
kbhagat6 | 0:437ae08befe3 | 44 | } |
kbhagat6 | 0:437ae08befe3 | 45 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PPULSE, DEFAULT_PROX_PPULSE)){ |
kbhagat6 | 0:437ae08befe3 | 46 | return false; |
kbhagat6 | 0:437ae08befe3 | 47 | } |
kbhagat6 | 0:437ae08befe3 | 48 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_POFFSET_UR, DEFAULT_POFFSET_UR)){ |
kbhagat6 | 0:437ae08befe3 | 49 | return false; |
kbhagat6 | 0:437ae08befe3 | 50 | } |
kbhagat6 | 0:437ae08befe3 | 51 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_POFFSET_DL, DEFAULT_POFFSET_DL)){ |
kbhagat6 | 0:437ae08befe3 | 52 | return false; |
kbhagat6 | 0:437ae08befe3 | 53 | } |
kbhagat6 | 0:437ae08befe3 | 54 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONFIG1, DEFAULT_CONFIG1)){ |
kbhagat6 | 0:437ae08befe3 | 55 | return false; |
kbhagat6 | 0:437ae08befe3 | 56 | } |
kbhagat6 | 0:437ae08befe3 | 57 | |
kbhagat6 | 0:437ae08befe3 | 58 | if( !setLEDDrive(DEFAULT_LDRIVE) ) { |
kbhagat6 | 0:437ae08befe3 | 59 | return false; |
kbhagat6 | 0:437ae08befe3 | 60 | } |
kbhagat6 | 0:437ae08befe3 | 61 | |
kbhagat6 | 0:437ae08befe3 | 62 | if( !setProximityGain(DEFAULT_PGAIN) ) { |
kbhagat6 | 0:437ae08befe3 | 63 | return false; |
kbhagat6 | 0:437ae08befe3 | 64 | } |
kbhagat6 | 0:437ae08befe3 | 65 | if( !setAmbientLightGain(DEFAULT_AGAIN) ) { |
kbhagat6 | 0:437ae08befe3 | 66 | return false; |
kbhagat6 | 0:437ae08befe3 | 67 | } |
kbhagat6 | 0:437ae08befe3 | 68 | if( !setProxIntLowThresh(DEFAULT_PILT) ) { |
kbhagat6 | 0:437ae08befe3 | 69 | return false; |
kbhagat6 | 0:437ae08befe3 | 70 | } |
kbhagat6 | 1:c7215f5f9a72 | 71 | if( !setProxIntHighThresh(DEFAULT_PIHT) ) { |
kbhagat6 | 1:c7215f5f9a72 | 72 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 73 | } |
kbhagat6 | 1:c7215f5f9a72 | 74 | if( !setLightIntLowThreshold(DEFAULT_AILT) ) { |
kbhagat6 | 1:c7215f5f9a72 | 75 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 76 | } |
kbhagat6 | 1:c7215f5f9a72 | 77 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONFIG2, DEFAULT_CONFIG2) ) { |
kbhagat6 | 1:c7215f5f9a72 | 78 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 79 | } |
kbhagat6 | 1:c7215f5f9a72 | 80 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONFIG3, DEFAULT_CONFIG3) ) { |
kbhagat6 | 1:c7215f5f9a72 | 81 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 82 | } |
kbhagat6 | 1:c7215f5f9a72 | 83 | |
kbhagat6 | 1:c7215f5f9a72 | 84 | if( !setGestureEnterThresh(DEFAULT_GPENTH) ) { |
kbhagat6 | 1:c7215f5f9a72 | 85 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 86 | } |
kbhagat6 | 1:c7215f5f9a72 | 87 | if( !setGestureExitThresh(DEFAULT_GEXTH) ) { |
kbhagat6 | 1:c7215f5f9a72 | 88 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 89 | } |
kbhagat6 | 1:c7215f5f9a72 | 90 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GCONF1, DEFAULT_GCONF1) ) { |
kbhagat6 | 1:c7215f5f9a72 | 91 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 92 | } |
kbhagat6 | 1:c7215f5f9a72 | 93 | if( !setGestureGain(DEFAULT_GGAIN) ) { |
kbhagat6 | 1:c7215f5f9a72 | 94 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 95 | } |
kbhagat6 | 1:c7215f5f9a72 | 96 | if( !setGestureLEDDrive(DEFAULT_GLDRIVE) ) { |
kbhagat6 | 1:c7215f5f9a72 | 97 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 98 | } |
kbhagat6 | 1:c7215f5f9a72 | 99 | if( !setGestureWaitTime(DEFAULT_GWTIME) ) { |
kbhagat6 | 1:c7215f5f9a72 | 100 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 101 | } |
kbhagat6 | 1:c7215f5f9a72 | 102 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_U, DEFAULT_GOFFSET) ) { |
kbhagat6 | 1:c7215f5f9a72 | 103 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 104 | } |
kbhagat6 | 1:c7215f5f9a72 | 105 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_D, DEFAULT_GOFFSET) ) { |
kbhagat6 | 1:c7215f5f9a72 | 106 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 107 | } |
kbhagat6 | 1:c7215f5f9a72 | 108 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_L, DEFAULT_GOFFSET) ) { |
kbhagat6 | 1:c7215f5f9a72 | 109 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 110 | } |
kbhagat6 | 1:c7215f5f9a72 | 111 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GOFFSET_R, DEFAULT_GOFFSET) ) { |
kbhagat6 | 1:c7215f5f9a72 | 112 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 113 | } |
kbhagat6 | 1:c7215f5f9a72 | 114 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GPULSE, DEFAULT_GPULSE) ) { |
kbhagat6 | 1:c7215f5f9a72 | 115 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 116 | } |
kbhagat6 | 1:c7215f5f9a72 | 117 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_GCONF3, DEFAULT_GCONF3) ) { |
kbhagat6 | 1:c7215f5f9a72 | 118 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 119 | } |
kbhagat6 | 1:c7215f5f9a72 | 120 | if( !setGestureIntEnable(DEFAULT_GIEN) ) { |
kbhagat6 | 1:c7215f5f9a72 | 121 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 122 | } |
kbhagat6 | 0:437ae08befe3 | 123 | |
kbhagat6 | 0:437ae08befe3 | 124 | |
kbhagat6 | 0:437ae08befe3 | 125 | |
kbhagat6 | 0:437ae08befe3 | 126 | return id; |
kbhagat6 | 0:437ae08befe3 | 127 | } |
kbhagat6 | 0:437ae08befe3 | 128 | |
kbhagat6 | 0:437ae08befe3 | 129 | |
kbhagat6 | 0:437ae08befe3 | 130 | |
kbhagat6 | 0:437ae08befe3 | 131 | |
kbhagat6 | 0:437ae08befe3 | 132 | /** |
kbhagat6 | 0:437ae08befe3 | 133 | * @brief Enables or disables a feature in the APDS-9960 |
kbhagat6 | 0:437ae08befe3 | 134 | * |
kbhagat6 | 0:437ae08befe3 | 135 | * @param[in] mode which feature to enable |
kbhagat6 | 0:437ae08befe3 | 136 | * @param[in] enable ON (1) or OFF (0) |
kbhagat6 | 0:437ae08befe3 | 137 | * @return True if operation success. False otherwise. |
kbhagat6 | 0:437ae08befe3 | 138 | */ |
kbhagat6 | 0:437ae08befe3 | 139 | bool glibr::setMode(uint8_t mode, uint8_t enable) |
kbhagat6 | 0:437ae08befe3 | 140 | { |
kbhagat6 | 0:437ae08befe3 | 141 | uint8_t reg_val; |
kbhagat6 | 0:437ae08befe3 | 142 | |
kbhagat6 | 0:437ae08befe3 | 143 | /* Read current ENABLE register */ |
kbhagat6 | 0:437ae08befe3 | 144 | reg_val = getMode(); |
kbhagat6 | 0:437ae08befe3 | 145 | if( reg_val == ERROR ) { |
kbhagat6 | 0:437ae08befe3 | 146 | return false; |
kbhagat6 | 0:437ae08befe3 | 147 | } |
kbhagat6 | 0:437ae08befe3 | 148 | |
kbhagat6 | 0:437ae08befe3 | 149 | /* Change bit(s) in ENABLE register */ |
kbhagat6 | 0:437ae08befe3 | 150 | enable = enable & 0x01; |
kbhagat6 | 0:437ae08befe3 | 151 | if( mode >= 0 && mode <= 6 ) { |
kbhagat6 | 0:437ae08befe3 | 152 | if (enable) { |
kbhagat6 | 0:437ae08befe3 | 153 | reg_val |= (1 << mode); |
kbhagat6 | 0:437ae08befe3 | 154 | } else { |
kbhagat6 | 0:437ae08befe3 | 155 | reg_val &= ~(1 << mode); |
kbhagat6 | 0:437ae08befe3 | 156 | } |
kbhagat6 | 0:437ae08befe3 | 157 | } else if( mode == ALL ) { |
kbhagat6 | 0:437ae08befe3 | 158 | if (enable) { |
kbhagat6 | 0:437ae08befe3 | 159 | reg_val = 0x7F; |
kbhagat6 | 0:437ae08befe3 | 160 | } else { |
kbhagat6 | 0:437ae08befe3 | 161 | reg_val = 0x00; |
kbhagat6 | 0:437ae08befe3 | 162 | } |
kbhagat6 | 0:437ae08befe3 | 163 | } |
kbhagat6 | 0:437ae08befe3 | 164 | |
kbhagat6 | 0:437ae08befe3 | 165 | /* Write value back to ENABLE register */ |
kbhagat6 | 0:437ae08befe3 | 166 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_ENABLE, reg_val)){ |
kbhagat6 | 0:437ae08befe3 | 167 | return false; |
kbhagat6 | 0:437ae08befe3 | 168 | } |
kbhagat6 | 0:437ae08befe3 | 169 | |
kbhagat6 | 0:437ae08befe3 | 170 | |
kbhagat6 | 0:437ae08befe3 | 171 | |
kbhagat6 | 0:437ae08befe3 | 172 | return true; |
kbhagat6 | 0:437ae08befe3 | 173 | } |
kbhagat6 | 0:437ae08befe3 | 174 | |
kbhagat6 | 0:437ae08befe3 | 175 | uint8_t glibr::getMode() |
kbhagat6 | 0:437ae08befe3 | 176 | { |
kbhagat6 | 6:687dff16904e | 177 | uint8_t val; |
kbhagat6 | 6:687dff16904e | 178 | val= I2CreadByte(APDS9960_I2C_ADDR, APDS9960_ENABLE); |
kbhagat6 | 6:687dff16904e | 179 | if(val==ERROR){ |
kbhagat6 | 6:687dff16904e | 180 | return ERROR; |
kbhagat6 | 6:687dff16904e | 181 | } |
kbhagat6 | 6:687dff16904e | 182 | return val; |
kbhagat6 | 0:437ae08befe3 | 183 | } |
kbhagat6 | 0:437ae08befe3 | 184 | |
kbhagat6 | 0:437ae08befe3 | 185 | bool glibr::setLEDDrive(uint8_t drive) |
kbhagat6 | 0:437ae08befe3 | 186 | { |
kbhagat6 | 0:437ae08befe3 | 187 | uint8_t val; |
kbhagat6 | 0:437ae08befe3 | 188 | |
kbhagat6 | 0:437ae08befe3 | 189 | /* Read value from CONTROL register */ |
kbhagat6 | 0:437ae08befe3 | 190 | |
kbhagat6 | 0:437ae08befe3 | 191 | val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL); |
kbhagat6 | 0:437ae08befe3 | 192 | if(val==ERROR){ |
kbhagat6 | 0:437ae08befe3 | 193 | return false; |
kbhagat6 | 0:437ae08befe3 | 194 | } |
kbhagat6 | 0:437ae08befe3 | 195 | /* Set bits in register to given value */ |
kbhagat6 | 0:437ae08befe3 | 196 | drive &= 0x03; |
kbhagat6 | 0:437ae08befe3 | 197 | drive = drive << 6; |
kbhagat6 | 0:437ae08befe3 | 198 | //val &= 0b00111111; |
kbhagat6 | 0:437ae08befe3 | 199 | val &= 0x3F; |
kbhagat6 | 0:437ae08befe3 | 200 | val |= drive; |
kbhagat6 | 0:437ae08befe3 | 201 | |
kbhagat6 | 0:437ae08befe3 | 202 | /* Write register value back into CONTROL register */ |
kbhagat6 | 0:437ae08befe3 | 203 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val) ) { |
kbhagat6 | 0:437ae08befe3 | 204 | return false; |
kbhagat6 | 0:437ae08befe3 | 205 | } |
kbhagat6 | 0:437ae08befe3 | 206 | |
kbhagat6 | 0:437ae08befe3 | 207 | return true; |
kbhagat6 | 0:437ae08befe3 | 208 | } |
kbhagat6 | 0:437ae08befe3 | 209 | |
kbhagat6 | 3:26146a08bb22 | 210 | bool glibr::enableLightSensor(bool interrupts) |
kbhagat6 | 3:26146a08bb22 | 211 | { |
kbhagat6 | 3:26146a08bb22 | 212 | |
kbhagat6 | 3:26146a08bb22 | 213 | /* Set default gain, interrupts, enable power, and enable sensor */ |
kbhagat6 | 3:26146a08bb22 | 214 | if( !setAmbientLightGain(DEFAULT_AGAIN) ) { |
kbhagat6 | 3:26146a08bb22 | 215 | return false; |
kbhagat6 | 3:26146a08bb22 | 216 | } |
kbhagat6 | 3:26146a08bb22 | 217 | if( interrupts ) { |
kbhagat6 | 3:26146a08bb22 | 218 | if( !setAmbientLightIntEnable(1) ) { |
kbhagat6 | 3:26146a08bb22 | 219 | return false; |
kbhagat6 | 3:26146a08bb22 | 220 | } |
kbhagat6 | 3:26146a08bb22 | 221 | } else { |
kbhagat6 | 3:26146a08bb22 | 222 | if( !setAmbientLightIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 223 | return false; |
kbhagat6 | 3:26146a08bb22 | 224 | } |
kbhagat6 | 3:26146a08bb22 | 225 | } |
kbhagat6 | 3:26146a08bb22 | 226 | if( !enablePower() ){ |
kbhagat6 | 3:26146a08bb22 | 227 | return false; |
kbhagat6 | 3:26146a08bb22 | 228 | } |
kbhagat6 | 3:26146a08bb22 | 229 | if( !setMode(AMBIENT_LIGHT, 1) ) { |
kbhagat6 | 3:26146a08bb22 | 230 | return false; |
kbhagat6 | 3:26146a08bb22 | 231 | } |
kbhagat6 | 3:26146a08bb22 | 232 | |
kbhagat6 | 3:26146a08bb22 | 233 | return true; |
kbhagat6 | 3:26146a08bb22 | 234 | |
kbhagat6 | 3:26146a08bb22 | 235 | } |
kbhagat6 | 3:26146a08bb22 | 236 | |
kbhagat6 | 3:26146a08bb22 | 237 | /** |
kbhagat6 | 3:26146a08bb22 | 238 | * @brief Ends the light sensor on the APDS-9960 |
kbhagat6 | 3:26146a08bb22 | 239 | * |
kbhagat6 | 3:26146a08bb22 | 240 | * @return True if sensor disabled correctly. False on error. |
kbhagat6 | 3:26146a08bb22 | 241 | */ |
kbhagat6 | 3:26146a08bb22 | 242 | bool glibr::disableLightSensor() |
kbhagat6 | 3:26146a08bb22 | 243 | { |
kbhagat6 | 3:26146a08bb22 | 244 | if( !setAmbientLightIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 245 | return false; |
kbhagat6 | 3:26146a08bb22 | 246 | } |
kbhagat6 | 3:26146a08bb22 | 247 | if( !setMode(AMBIENT_LIGHT, 0) ) { |
kbhagat6 | 3:26146a08bb22 | 248 | return false; |
kbhagat6 | 3:26146a08bb22 | 249 | } |
kbhagat6 | 3:26146a08bb22 | 250 | |
kbhagat6 | 3:26146a08bb22 | 251 | return true; |
kbhagat6 | 3:26146a08bb22 | 252 | } |
kbhagat6 | 3:26146a08bb22 | 253 | |
kbhagat6 | 3:26146a08bb22 | 254 | /** |
kbhagat6 | 3:26146a08bb22 | 255 | * @brief Starts the proximity sensor on the APDS-9960 |
kbhagat6 | 3:26146a08bb22 | 256 | * |
kbhagat6 | 3:26146a08bb22 | 257 | * @param[in] interrupts true to enable hardware external interrupt on proximity |
kbhagat6 | 3:26146a08bb22 | 258 | * @return True if sensor enabled correctly. False on error. |
kbhagat6 | 3:26146a08bb22 | 259 | */ |
kbhagat6 | 3:26146a08bb22 | 260 | bool glibr::enableProximitySensor(bool interrupts) |
kbhagat6 | 3:26146a08bb22 | 261 | { |
kbhagat6 | 3:26146a08bb22 | 262 | /* Set default gain, LED, interrupts, enable power, and enable sensor */ |
kbhagat6 | 3:26146a08bb22 | 263 | if( !setProximityGain(DEFAULT_PGAIN) ) { |
kbhagat6 | 3:26146a08bb22 | 264 | return false; |
kbhagat6 | 3:26146a08bb22 | 265 | } |
kbhagat6 | 3:26146a08bb22 | 266 | if( !setLEDDrive(DEFAULT_LDRIVE) ) { |
kbhagat6 | 3:26146a08bb22 | 267 | return false; |
kbhagat6 | 3:26146a08bb22 | 268 | } |
kbhagat6 | 3:26146a08bb22 | 269 | if( interrupts ) { |
kbhagat6 | 3:26146a08bb22 | 270 | if( !setProximityIntEnable(1) ) { |
kbhagat6 | 3:26146a08bb22 | 271 | return false; |
kbhagat6 | 3:26146a08bb22 | 272 | } |
kbhagat6 | 3:26146a08bb22 | 273 | } else { |
kbhagat6 | 3:26146a08bb22 | 274 | if( !setProximityIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 275 | return false; |
kbhagat6 | 3:26146a08bb22 | 276 | } |
kbhagat6 | 3:26146a08bb22 | 277 | } |
kbhagat6 | 3:26146a08bb22 | 278 | if( !enablePower() ){ |
kbhagat6 | 3:26146a08bb22 | 279 | return false; |
kbhagat6 | 3:26146a08bb22 | 280 | } |
kbhagat6 | 3:26146a08bb22 | 281 | if( !setMode(PROXIMITY, 1) ) { |
kbhagat6 | 3:26146a08bb22 | 282 | return false; |
kbhagat6 | 3:26146a08bb22 | 283 | } |
kbhagat6 | 3:26146a08bb22 | 284 | |
kbhagat6 | 3:26146a08bb22 | 285 | return true; |
kbhagat6 | 3:26146a08bb22 | 286 | } |
kbhagat6 | 3:26146a08bb22 | 287 | |
kbhagat6 | 3:26146a08bb22 | 288 | /** |
kbhagat6 | 3:26146a08bb22 | 289 | * @brief Ends the proximity sensor on the APDS-9960 |
kbhagat6 | 3:26146a08bb22 | 290 | * |
kbhagat6 | 3:26146a08bb22 | 291 | * @return True if sensor disabled correctly. False on error. |
kbhagat6 | 3:26146a08bb22 | 292 | */ |
kbhagat6 | 3:26146a08bb22 | 293 | bool glibr::disableProximitySensor() |
kbhagat6 | 3:26146a08bb22 | 294 | { |
kbhagat6 | 3:26146a08bb22 | 295 | if( !setProximityIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 296 | return false; |
kbhagat6 | 3:26146a08bb22 | 297 | } |
kbhagat6 | 3:26146a08bb22 | 298 | if( !setMode(PROXIMITY, 0) ) { |
kbhagat6 | 3:26146a08bb22 | 299 | return false; |
kbhagat6 | 3:26146a08bb22 | 300 | } |
kbhagat6 | 3:26146a08bb22 | 301 | |
kbhagat6 | 3:26146a08bb22 | 302 | return true; |
kbhagat6 | 3:26146a08bb22 | 303 | } |
kbhagat6 | 3:26146a08bb22 | 304 | |
kbhagat6 | 3:26146a08bb22 | 305 | |
kbhagat6 | 3:26146a08bb22 | 306 | /** |
kbhagat6 | 3:26146a08bb22 | 307 | * @brief Starts the gesture recognition engine on the APDS-9960 |
kbhagat6 | 3:26146a08bb22 | 308 | * |
kbhagat6 | 3:26146a08bb22 | 309 | * @param[in] interrupts true to enable hardware external interrupt on gesture |
kbhagat6 | 3:26146a08bb22 | 310 | * @return True if engine enabled correctly. False on error. |
kbhagat6 | 3:26146a08bb22 | 311 | */ |
kbhagat6 | 3:26146a08bb22 | 312 | bool glibr::enableGestureSensor(bool interrupts) |
kbhagat6 | 3:26146a08bb22 | 313 | { |
kbhagat6 | 3:26146a08bb22 | 314 | |
kbhagat6 | 3:26146a08bb22 | 315 | /* Enable gesture mode |
kbhagat6 | 3:26146a08bb22 | 316 | Set ENABLE to 0 (power off) |
kbhagat6 | 3:26146a08bb22 | 317 | Set WTIME to 0xFF |
kbhagat6 | 3:26146a08bb22 | 318 | Set AUX to LED_BOOST_300 |
kbhagat6 | 3:26146a08bb22 | 319 | Enable PON, WEN, PEN, GEN in ENABLE |
kbhagat6 | 3:26146a08bb22 | 320 | */ |
kbhagat6 | 3:26146a08bb22 | 321 | |
kbhagat6 | 3:26146a08bb22 | 322 | resetGestureParameters(); |
kbhagat6 | 3:26146a08bb22 | 323 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_WTIME, 0xFF) ) { |
kbhagat6 | 3:26146a08bb22 | 324 | return false; |
kbhagat6 | 3:26146a08bb22 | 325 | } |
kbhagat6 | 3:26146a08bb22 | 326 | if(I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE) ) { |
kbhagat6 | 3:26146a08bb22 | 327 | return false; |
kbhagat6 | 3:26146a08bb22 | 328 | } |
kbhagat6 | 3:26146a08bb22 | 329 | if( !setLEDBoost(LED_BOOST_300) ) { |
kbhagat6 | 3:26146a08bb22 | 330 | return false; |
kbhagat6 | 3:26146a08bb22 | 331 | } |
kbhagat6 | 3:26146a08bb22 | 332 | if( interrupts ) { |
kbhagat6 | 3:26146a08bb22 | 333 | if( !setGestureIntEnable(1) ) { |
kbhagat6 | 3:26146a08bb22 | 334 | return false; |
kbhagat6 | 3:26146a08bb22 | 335 | } |
kbhagat6 | 3:26146a08bb22 | 336 | } else { |
kbhagat6 | 3:26146a08bb22 | 337 | if( !setGestureIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 338 | return false; |
kbhagat6 | 3:26146a08bb22 | 339 | } |
kbhagat6 | 3:26146a08bb22 | 340 | } |
kbhagat6 | 3:26146a08bb22 | 341 | if( !setGestureMode(1) ) { |
kbhagat6 | 3:26146a08bb22 | 342 | return false; |
kbhagat6 | 3:26146a08bb22 | 343 | } |
kbhagat6 | 3:26146a08bb22 | 344 | if( !enablePower() ){ |
kbhagat6 | 3:26146a08bb22 | 345 | return false; |
kbhagat6 | 3:26146a08bb22 | 346 | } |
kbhagat6 | 3:26146a08bb22 | 347 | if( !setMode(WAIT, 1) ) { |
kbhagat6 | 3:26146a08bb22 | 348 | return false; |
kbhagat6 | 3:26146a08bb22 | 349 | } |
kbhagat6 | 3:26146a08bb22 | 350 | if( !setMode(PROXIMITY, 1) ) { |
kbhagat6 | 3:26146a08bb22 | 351 | return false; |
kbhagat6 | 3:26146a08bb22 | 352 | } |
kbhagat6 | 3:26146a08bb22 | 353 | if( !setMode(GESTURE, 1) ) { |
kbhagat6 | 3:26146a08bb22 | 354 | return false; |
kbhagat6 | 3:26146a08bb22 | 355 | } |
kbhagat6 | 3:26146a08bb22 | 356 | |
kbhagat6 | 3:26146a08bb22 | 357 | return true; |
kbhagat6 | 3:26146a08bb22 | 358 | } |
kbhagat6 | 3:26146a08bb22 | 359 | |
kbhagat6 | 3:26146a08bb22 | 360 | /** |
kbhagat6 | 3:26146a08bb22 | 361 | * @brief Ends the gesture recognition engine on the APDS-9960 |
kbhagat6 | 3:26146a08bb22 | 362 | * |
kbhagat6 | 3:26146a08bb22 | 363 | * @return True if engine disabled correctly. False on error. |
kbhagat6 | 3:26146a08bb22 | 364 | */ |
kbhagat6 | 3:26146a08bb22 | 365 | bool glibr::disableGestureSensor() |
kbhagat6 | 3:26146a08bb22 | 366 | { |
kbhagat6 | 3:26146a08bb22 | 367 | resetGestureParameters(); |
kbhagat6 | 3:26146a08bb22 | 368 | if( !setGestureIntEnable(0) ) { |
kbhagat6 | 3:26146a08bb22 | 369 | return false; |
kbhagat6 | 3:26146a08bb22 | 370 | } |
kbhagat6 | 3:26146a08bb22 | 371 | if( !setGestureMode(0) ) { |
kbhagat6 | 3:26146a08bb22 | 372 | return false; |
kbhagat6 | 3:26146a08bb22 | 373 | } |
kbhagat6 | 3:26146a08bb22 | 374 | if( !setMode(GESTURE, 0) ) { |
kbhagat6 | 3:26146a08bb22 | 375 | return false; |
kbhagat6 | 3:26146a08bb22 | 376 | } |
kbhagat6 | 3:26146a08bb22 | 377 | |
kbhagat6 | 3:26146a08bb22 | 378 | return true; |
kbhagat6 | 3:26146a08bb22 | 379 | } |
kbhagat6 | 3:26146a08bb22 | 380 | |
kbhagat6 | 3:26146a08bb22 | 381 | |
kbhagat6 | 3:26146a08bb22 | 382 | /** |
kbhagat6 | 3:26146a08bb22 | 383 | * @brief Determines if there is a gesture available for reading |
kbhagat6 | 3:26146a08bb22 | 384 | * |
kbhagat6 | 3:26146a08bb22 | 385 | * @return True if gesture available. False otherwise. |
kbhagat6 | 3:26146a08bb22 | 386 | */ |
kbhagat6 | 3:26146a08bb22 | 387 | bool glibr::isGestureAvailable() |
kbhagat6 | 3:26146a08bb22 | 388 | { |
kbhagat6 | 3:26146a08bb22 | 389 | uint8_t val; |
kbhagat6 | 3:26146a08bb22 | 390 | |
kbhagat6 | 3:26146a08bb22 | 391 | /* Read value from GSTATUS register */ |
kbhagat6 | 4:84545b0e63a9 | 392 | val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GSTATUS); |
kbhagat6 | 5:3eb4f3091bd8 | 393 | if( val==ERROR) { |
kbhagat6 | 3:26146a08bb22 | 394 | return ERROR; |
kbhagat6 | 3:26146a08bb22 | 395 | } |
kbhagat6 | 3:26146a08bb22 | 396 | |
kbhagat6 | 3:26146a08bb22 | 397 | /* Shift and mask out GVALID bit */ |
kbhagat6 | 3:26146a08bb22 | 398 | val &= APDS9960_GVALID; |
kbhagat6 | 3:26146a08bb22 | 399 | |
kbhagat6 | 3:26146a08bb22 | 400 | /* Return true/false based on GVALID bit */ |
kbhagat6 | 3:26146a08bb22 | 401 | if( val == 1) { |
kbhagat6 | 3:26146a08bb22 | 402 | return true; |
kbhagat6 | 3:26146a08bb22 | 403 | } else { |
kbhagat6 | 3:26146a08bb22 | 404 | return false; |
kbhagat6 | 3:26146a08bb22 | 405 | } |
kbhagat6 | 3:26146a08bb22 | 406 | } |
kbhagat6 | 3:26146a08bb22 | 407 | |
kbhagat6 | 4:84545b0e63a9 | 408 | int glibr::readGesture() |
kbhagat6 | 4:84545b0e63a9 | 409 | { |
kbhagat6 | 4:84545b0e63a9 | 410 | uint8_t fifo_level = 0; |
kbhagat6 | 4:84545b0e63a9 | 411 | uint8_t bytes_read = 0; |
kbhagat6 | 4:84545b0e63a9 | 412 | uint8_t fifo_data[128]; |
kbhagat6 | 4:84545b0e63a9 | 413 | uint8_t gstatus; |
kbhagat6 | 4:84545b0e63a9 | 414 | int motion; |
kbhagat6 | 4:84545b0e63a9 | 415 | int i; |
kbhagat6 | 4:84545b0e63a9 | 416 | |
kbhagat6 | 4:84545b0e63a9 | 417 | /* Make sure that power and gesture is on and data is valid */ |
kbhagat6 | 4:84545b0e63a9 | 418 | if( !isGestureAvailable() || !(getMode() & 0x41) ) { |
kbhagat6 | 4:84545b0e63a9 | 419 | return DIR_NONE; |
kbhagat6 | 4:84545b0e63a9 | 420 | } |
kbhagat6 | 4:84545b0e63a9 | 421 | |
kbhagat6 | 4:84545b0e63a9 | 422 | /* Keep looping as long as gesture data is valid */ |
kbhagat6 | 4:84545b0e63a9 | 423 | while(1) { |
kbhagat6 | 4:84545b0e63a9 | 424 | |
kbhagat6 | 4:84545b0e63a9 | 425 | /* Wait some time to collect next batch of FIFO data */ |
kbhagat6 | 5:3eb4f3091bd8 | 426 | wait(FIFO_PAUSE_TIME); |
kbhagat6 | 4:84545b0e63a9 | 427 | |
kbhagat6 | 4:84545b0e63a9 | 428 | /* Get the contents of the STATUS register. Is data still valid? */ |
kbhagat6 | 4:84545b0e63a9 | 429 | |
kbhagat6 | 4:84545b0e63a9 | 430 | gstatus=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GSTATUS); |
kbhagat6 | 4:84545b0e63a9 | 431 | if( gstatus==ERROR ) { |
kbhagat6 | 4:84545b0e63a9 | 432 | return ERROR; |
kbhagat6 | 4:84545b0e63a9 | 433 | } |
kbhagat6 | 4:84545b0e63a9 | 434 | /* If we have valid data, read in FIFO */ |
kbhagat6 | 4:84545b0e63a9 | 435 | if( (gstatus & APDS9960_GVALID) == APDS9960_GVALID ) { |
kbhagat6 | 4:84545b0e63a9 | 436 | |
kbhagat6 | 4:84545b0e63a9 | 437 | /* Read the current FIFO level */ |
kbhagat6 | 4:84545b0e63a9 | 438 | fifolevel=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GFLVL); |
kbhagat6 | 4:84545b0e63a9 | 439 | if( fifolevel==ERROR ) { |
kbhagat6 | 4:84545b0e63a9 | 440 | return ERROR; |
kbhagat6 | 4:84545b0e63a9 | 441 | } |
kbhagat6 | 4:84545b0e63a9 | 442 | |
kbhagat6 | 4:84545b0e63a9 | 443 | //#if DEBUG |
kbhagat6 | 4:84545b0e63a9 | 444 | // Serial.print("FIFO Level: "); |
kbhagat6 | 4:84545b0e63a9 | 445 | // Serial.println(fifo_level); |
kbhagat6 | 4:84545b0e63a9 | 446 | //#endif |
kbhagat6 | 4:84545b0e63a9 | 447 | |
kbhagat6 | 4:84545b0e63a9 | 448 | /* If there's stuff in the FIFO, read it into our data block */ //NEED TO FIGURE OUT WHAT THIS IS DOING. |
kbhagat6 | 5:3eb4f3091bd8 | 449 | |
kbhagat6 | 4:84545b0e63a9 | 450 | if( fifo_level > 0) { |
kbhagat6 | 5:3eb4f3091bd8 | 451 | bytes_read = I2CReadDataBlock(APDS9960_I2C_ADDR,APDS9960_GFIFO_U, |
kbhagat6 | 4:84545b0e63a9 | 452 | (uint8_t*)fifo_data, |
kbhagat6 | 4:84545b0e63a9 | 453 | (fifo_level * 4) ); |
kbhagat6 | 4:84545b0e63a9 | 454 | if( bytes_read == -1 ) { |
kbhagat6 | 4:84545b0e63a9 | 455 | return ERROR; |
kbhagat6 | 4:84545b0e63a9 | 456 | } |
kbhagat6 | 4:84545b0e63a9 | 457 | #if DEBUG |
kbhagat6 | 4:84545b0e63a9 | 458 | Serial.print("FIFO Dump: "); |
kbhagat6 | 4:84545b0e63a9 | 459 | for ( i = 0; i < bytes_read; i++ ) { |
kbhagat6 | 4:84545b0e63a9 | 460 | Serial.print(fifo_data[i]); |
kbhagat6 | 4:84545b0e63a9 | 461 | Serial.print(" "); |
kbhagat6 | 4:84545b0e63a9 | 462 | } |
kbhagat6 | 4:84545b0e63a9 | 463 | Serial.println(); |
kbhagat6 | 4:84545b0e63a9 | 464 | #endif |
kbhagat6 | 4:84545b0e63a9 | 465 | |
kbhagat6 | 4:84545b0e63a9 | 466 | /* If at least 1 set of data, sort the data into U/D/L/R */ |
kbhagat6 | 4:84545b0e63a9 | 467 | if( bytes_read >= 4 ) { |
kbhagat6 | 4:84545b0e63a9 | 468 | for( i = 0; i < bytes_read; i += 4 ) { |
kbhagat6 | 4:84545b0e63a9 | 469 | gesture_data_.u_data[gesture_data_.index] = \ |
kbhagat6 | 4:84545b0e63a9 | 470 | fifo_data[i + 0]; |
kbhagat6 | 4:84545b0e63a9 | 471 | gesture_data_.d_data[gesture_data_.index] = \ |
kbhagat6 | 4:84545b0e63a9 | 472 | fifo_data[i + 1]; |
kbhagat6 | 4:84545b0e63a9 | 473 | gesture_data_.l_data[gesture_data_.index] = \ |
kbhagat6 | 4:84545b0e63a9 | 474 | fifo_data[i + 2]; |
kbhagat6 | 4:84545b0e63a9 | 475 | gesture_data_.r_data[gesture_data_.index] = \ |
kbhagat6 | 4:84545b0e63a9 | 476 | fifo_data[i + 3]; |
kbhagat6 | 4:84545b0e63a9 | 477 | gesture_data_.index++; |
kbhagat6 | 4:84545b0e63a9 | 478 | gesture_data_.total_gestures++; |
kbhagat6 | 4:84545b0e63a9 | 479 | } |
kbhagat6 | 4:84545b0e63a9 | 480 | |
kbhagat6 | 4:84545b0e63a9 | 481 | #if DEBUG |
kbhagat6 | 5:3eb4f3091bd8 | 482 | // Serial.print("Up Data: "); |
kbhagat6 | 4:84545b0e63a9 | 483 | for ( i = 0; i < gesture_data_.total_gestures; i++ ) { |
kbhagat6 | 5:3eb4f3091bd8 | 484 | // Serial.print(gesture_data_.u_data[i]); |
kbhagat6 | 5:3eb4f3091bd8 | 485 | // Serial.print(" "); |
kbhagat6 | 4:84545b0e63a9 | 486 | } |
kbhagat6 | 5:3eb4f3091bd8 | 487 | // Serial.println(); |
kbhagat6 | 4:84545b0e63a9 | 488 | #endif |
kbhagat6 | 4:84545b0e63a9 | 489 | |
kbhagat6 | 4:84545b0e63a9 | 490 | /* Filter and process gesture data. Decode near/far state */ |
kbhagat6 | 4:84545b0e63a9 | 491 | if( processGestureData() ) { |
kbhagat6 | 4:84545b0e63a9 | 492 | if( decodeGesture() ) { |
kbhagat6 | 4:84545b0e63a9 | 493 | //***TODO: U-Turn Gestures |
kbhagat6 | 4:84545b0e63a9 | 494 | #if DEBUG |
kbhagat6 | 4:84545b0e63a9 | 495 | //Serial.println(gesture_motion_); |
kbhagat6 | 4:84545b0e63a9 | 496 | #endif |
kbhagat6 | 4:84545b0e63a9 | 497 | } |
kbhagat6 | 4:84545b0e63a9 | 498 | } |
kbhagat6 | 4:84545b0e63a9 | 499 | |
kbhagat6 | 4:84545b0e63a9 | 500 | /* Reset data */ |
kbhagat6 | 4:84545b0e63a9 | 501 | gesture_data_.index = 0; |
kbhagat6 | 4:84545b0e63a9 | 502 | gesture_data_.total_gestures = 0; |
kbhagat6 | 4:84545b0e63a9 | 503 | } |
kbhagat6 | 4:84545b0e63a9 | 504 | } |
kbhagat6 | 4:84545b0e63a9 | 505 | } else { |
kbhagat6 | 4:84545b0e63a9 | 506 | |
kbhagat6 | 4:84545b0e63a9 | 507 | /* Determine best guessed gesture and clean up */ |
kbhagat6 | 5:3eb4f3091bd8 | 508 | wait(FIFO_PAUSE_TIME); |
kbhagat6 | 4:84545b0e63a9 | 509 | decodeGesture(); |
kbhagat6 | 4:84545b0e63a9 | 510 | motion = gesture_motion_; |
kbhagat6 | 4:84545b0e63a9 | 511 | #if DEBUG |
kbhagat6 | 5:3eb4f3091bd8 | 512 | // Serial.print("END: "); |
kbhagat6 | 5:3eb4f3091bd8 | 513 | // Serial.println(gesture_motion_); |
kbhagat6 | 4:84545b0e63a9 | 514 | #endif |
kbhagat6 | 4:84545b0e63a9 | 515 | resetGestureParameters(); |
kbhagat6 | 4:84545b0e63a9 | 516 | return motion; |
kbhagat6 | 4:84545b0e63a9 | 517 | } |
kbhagat6 | 4:84545b0e63a9 | 518 | } |
kbhagat6 | 4:84545b0e63a9 | 519 | } |
kbhagat6 | 6:687dff16904e | 520 | /** |
kbhagat6 | 6:687dff16904e | 521 | * Turn the APDS-9960 on |
kbhagat6 | 6:687dff16904e | 522 | * |
kbhagat6 | 6:687dff16904e | 523 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 524 | */ |
kbhagat6 | 6:687dff16904e | 525 | bool glibr::enablePower() |
kbhagat6 | 6:687dff16904e | 526 | { |
kbhagat6 | 6:687dff16904e | 527 | if( !setMode(POWER, 1) ) { |
kbhagat6 | 6:687dff16904e | 528 | return false; |
kbhagat6 | 6:687dff16904e | 529 | } |
kbhagat6 | 6:687dff16904e | 530 | |
kbhagat6 | 6:687dff16904e | 531 | return true; |
kbhagat6 | 6:687dff16904e | 532 | } |
kbhagat6 | 6:687dff16904e | 533 | |
kbhagat6 | 6:687dff16904e | 534 | /** |
kbhagat6 | 6:687dff16904e | 535 | * Turn the APDS-9960 off |
kbhagat6 | 6:687dff16904e | 536 | * |
kbhagat6 | 6:687dff16904e | 537 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 538 | */ |
kbhagat6 | 6:687dff16904e | 539 | bool glibr::disablePower() |
kbhagat6 | 6:687dff16904e | 540 | { |
kbhagat6 | 6:687dff16904e | 541 | if( !setMode(POWER, 0) ) { |
kbhagat6 | 6:687dff16904e | 542 | return false; |
kbhagat6 | 6:687dff16904e | 543 | } |
kbhagat6 | 6:687dff16904e | 544 | |
kbhagat6 | 6:687dff16904e | 545 | return true; |
kbhagat6 | 6:687dff16904e | 546 | } |
kbhagat6 | 6:687dff16904e | 547 | |
kbhagat6 | 6:687dff16904e | 548 | /******************************************************************************* |
kbhagat6 | 6:687dff16904e | 549 | * Ambient light and color sensor controls |
kbhagat6 | 6:687dff16904e | 550 | ******************************************************************************/ |
kbhagat6 | 6:687dff16904e | 551 | |
kbhagat6 | 6:687dff16904e | 552 | /** |
kbhagat6 | 6:687dff16904e | 553 | * @brief Reads the ambient (clear) light level as a 16-bit value |
kbhagat6 | 6:687dff16904e | 554 | * |
kbhagat6 | 6:687dff16904e | 555 | * @param[out] val value of the light sensor. |
kbhagat6 | 6:687dff16904e | 556 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 557 | */ |
kbhagat6 | 6:687dff16904e | 558 | bool glibr::readAmbientLight(uint16_t &val) |
kbhagat6 | 6:687dff16904e | 559 | { |
kbhagat6 | 6:687dff16904e | 560 | uint8_t val_byte; |
kbhagat6 | 6:687dff16904e | 561 | val = 0; |
kbhagat6 | 6:687dff16904e | 562 | |
kbhagat6 | 6:687dff16904e | 563 | /* Read value from clear channel, low byte register */ |
kbhagat6 | 6:687dff16904e | 564 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CDATAL); |
kbhagat6 | 6:687dff16904e | 565 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 566 | return false; |
kbhagat6 | 6:687dff16904e | 567 | } |
kbhagat6 | 6:687dff16904e | 568 | val = val_byte; |
kbhagat6 | 6:687dff16904e | 569 | |
kbhagat6 | 6:687dff16904e | 570 | /* Read value from clear channel, high byte register */ |
kbhagat6 | 6:687dff16904e | 571 | |
kbhagat6 | 6:687dff16904e | 572 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CDATAH); |
kbhagat6 | 6:687dff16904e | 573 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 574 | return false; |
kbhagat6 | 6:687dff16904e | 575 | } |
kbhagat6 | 6:687dff16904e | 576 | val = val + ((uint16_t)val_byte << 8); |
kbhagat6 | 6:687dff16904e | 577 | |
kbhagat6 | 6:687dff16904e | 578 | return true; |
kbhagat6 | 6:687dff16904e | 579 | } |
kbhagat6 | 6:687dff16904e | 580 | |
kbhagat6 | 6:687dff16904e | 581 | /** |
kbhagat6 | 6:687dff16904e | 582 | * @brief Reads the red light level as a 16-bit value |
kbhagat6 | 6:687dff16904e | 583 | * |
kbhagat6 | 6:687dff16904e | 584 | * @param[out] val value of the light sensor. |
kbhagat6 | 6:687dff16904e | 585 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 586 | */ |
kbhagat6 | 6:687dff16904e | 587 | bool glibr::readRedLight(uint16_t &val) |
kbhagat6 | 6:687dff16904e | 588 | { |
kbhagat6 | 6:687dff16904e | 589 | uint8_t val_byte; |
kbhagat6 | 6:687dff16904e | 590 | val = 0; |
kbhagat6 | 6:687dff16904e | 591 | |
kbhagat6 | 6:687dff16904e | 592 | /* Read value from clear channel, low byte register */ |
kbhagat6 | 6:687dff16904e | 593 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_RDATAL); |
kbhagat6 | 6:687dff16904e | 594 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 595 | return false; |
kbhagat6 | 6:687dff16904e | 596 | } |
kbhagat6 | 6:687dff16904e | 597 | |
kbhagat6 | 6:687dff16904e | 598 | val = val_byte; |
kbhagat6 | 6:687dff16904e | 599 | |
kbhagat6 | 6:687dff16904e | 600 | /* Read value from clear channel, high byte register */ |
kbhagat6 | 6:687dff16904e | 601 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_RDATAH); |
kbhagat6 | 6:687dff16904e | 602 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 603 | return false; |
kbhagat6 | 6:687dff16904e | 604 | } |
kbhagat6 | 6:687dff16904e | 605 | val = val + ((uint16_t)val_byte << 8); |
kbhagat6 | 6:687dff16904e | 606 | |
kbhagat6 | 6:687dff16904e | 607 | return true; |
kbhagat6 | 6:687dff16904e | 608 | } |
kbhagat6 | 6:687dff16904e | 609 | |
kbhagat6 | 6:687dff16904e | 610 | /** |
kbhagat6 | 6:687dff16904e | 611 | * @brief Reads the green light level as a 16-bit value |
kbhagat6 | 6:687dff16904e | 612 | * |
kbhagat6 | 6:687dff16904e | 613 | * @param[out] val value of the light sensor. |
kbhagat6 | 6:687dff16904e | 614 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 615 | */ |
kbhagat6 | 6:687dff16904e | 616 | |
kbhagat6 | 6:687dff16904e | 617 | bool glibr::readGreenLight(uint16_t &val) |
kbhagat6 | 6:687dff16904e | 618 | { |
kbhagat6 | 6:687dff16904e | 619 | uint8_t val_byte; |
kbhagat6 | 6:687dff16904e | 620 | val = 0; |
kbhagat6 | 6:687dff16904e | 621 | |
kbhagat6 | 6:687dff16904e | 622 | /* Read value from clear channel, low byte register */ |
kbhagat6 | 6:687dff16904e | 623 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GDATAL); |
kbhagat6 | 6:687dff16904e | 624 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 625 | return false; |
kbhagat6 | 6:687dff16904e | 626 | } |
kbhagat6 | 6:687dff16904e | 627 | |
kbhagat6 | 6:687dff16904e | 628 | val = val_byte; |
kbhagat6 | 6:687dff16904e | 629 | |
kbhagat6 | 6:687dff16904e | 630 | /* Read value from clear channel, high byte register */ |
kbhagat6 | 6:687dff16904e | 631 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_GDATAH); |
kbhagat6 | 6:687dff16904e | 632 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 633 | return false; |
kbhagat6 | 6:687dff16904e | 634 | } |
kbhagat6 | 6:687dff16904e | 635 | val = val + ((uint16_t)val_byte << 8); |
kbhagat6 | 6:687dff16904e | 636 | |
kbhagat6 | 6:687dff16904e | 637 | return true; |
kbhagat6 | 6:687dff16904e | 638 | } |
kbhagat6 | 6:687dff16904e | 639 | |
kbhagat6 | 6:687dff16904e | 640 | /** |
kbhagat6 | 6:687dff16904e | 641 | * @brief Reads the red light level as a 16-bit value |
kbhagat6 | 6:687dff16904e | 642 | * |
kbhagat6 | 6:687dff16904e | 643 | * @param[out] val value of the light sensor. |
kbhagat6 | 6:687dff16904e | 644 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 645 | */ |
kbhagat6 | 6:687dff16904e | 646 | |
kbhagat6 | 6:687dff16904e | 647 | bool glibr::readBlueLight(uint16_t &val) |
kbhagat6 | 6:687dff16904e | 648 | { |
kbhagat6 | 6:687dff16904e | 649 | uint8_t val_byte; |
kbhagat6 | 6:687dff16904e | 650 | val = 0; |
kbhagat6 | 6:687dff16904e | 651 | |
kbhagat6 | 6:687dff16904e | 652 | /* Read value from clear channel, low byte register */ |
kbhagat6 | 6:687dff16904e | 653 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_BDATAL); |
kbhagat6 | 6:687dff16904e | 654 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 655 | return false; |
kbhagat6 | 6:687dff16904e | 656 | } |
kbhagat6 | 6:687dff16904e | 657 | |
kbhagat6 | 6:687dff16904e | 658 | val = val_byte; |
kbhagat6 | 6:687dff16904e | 659 | |
kbhagat6 | 6:687dff16904e | 660 | /* Read value from clear channel, high byte register */ |
kbhagat6 | 6:687dff16904e | 661 | val_byte=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_BDATAH); |
kbhagat6 | 6:687dff16904e | 662 | if( valbyte==ERROR) { |
kbhagat6 | 6:687dff16904e | 663 | return false; |
kbhagat6 | 6:687dff16904e | 664 | } |
kbhagat6 | 6:687dff16904e | 665 | val = val + ((uint16_t)val_byte << 8); |
kbhagat6 | 6:687dff16904e | 666 | |
kbhagat6 | 6:687dff16904e | 667 | return true; |
kbhagat6 | 6:687dff16904e | 668 | } |
kbhagat6 | 6:687dff16904e | 669 | |
kbhagat6 | 6:687dff16904e | 670 | /******************************************************************************* |
kbhagat6 | 6:687dff16904e | 671 | * Proximity sensor controls |
kbhagat6 | 6:687dff16904e | 672 | ******************************************************************************/ |
kbhagat6 | 6:687dff16904e | 673 | |
kbhagat6 | 6:687dff16904e | 674 | /** |
kbhagat6 | 6:687dff16904e | 675 | * @brief Reads the proximity level as an 8-bit value |
kbhagat6 | 6:687dff16904e | 676 | * |
kbhagat6 | 6:687dff16904e | 677 | * @param[out] val value of the proximity sensor. |
kbhagat6 | 6:687dff16904e | 678 | * @return True if operation successful. False otherwise. |
kbhagat6 | 6:687dff16904e | 679 | */ |
kbhagat6 | 6:687dff16904e | 680 | bool glibr::readProximity(uint8_t &val) |
kbhagat6 | 6:687dff16904e | 681 | { |
kbhagat6 | 6:687dff16904e | 682 | val = 0; |
kbhagat6 | 6:687dff16904e | 683 | |
kbhagat6 | 6:687dff16904e | 684 | /* Read value from proximity data register */ |
kbhagat6 | 6:687dff16904e | 685 | val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_PDATA); |
kbhagat6 | 6:687dff16904e | 686 | |
kbhagat6 | 6:687dff16904e | 687 | if(val==ERROR){ |
kbhagat6 | 6:687dff16904e | 688 | return false; |
kbhagat6 | 6:687dff16904e | 689 | } |
kbhagat6 | 6:687dff16904e | 690 | |
kbhagat6 | 6:687dff16904e | 691 | return true; |
kbhagat6 | 6:687dff16904e | 692 | } |
kbhagat6 | 6:687dff16904e | 693 | |
kbhagat6 | 6:687dff16904e | 694 | /******************************************************************************* |
kbhagat6 | 6:687dff16904e | 695 | * High-level gesture controls |
kbhagat6 | 6:687dff16904e | 696 | ******************************************************************************/ |
kbhagat6 | 6:687dff16904e | 697 | |
kbhagat6 | 6:687dff16904e | 698 | /** |
kbhagat6 | 6:687dff16904e | 699 | * @brief Resets all the parameters in the gesture data member |
kbhagat6 | 6:687dff16904e | 700 | */ |
kbhagat6 | 6:687dff16904e | 701 | void glibr::resetGestureParameters() |
kbhagat6 | 6:687dff16904e | 702 | { |
kbhagat6 | 6:687dff16904e | 703 | gesture_data_.index = 0; |
kbhagat6 | 6:687dff16904e | 704 | gesture_data_.total_gestures = 0; |
kbhagat6 | 6:687dff16904e | 705 | |
kbhagat6 | 6:687dff16904e | 706 | gesture_ud_delta_ = 0; |
kbhagat6 | 6:687dff16904e | 707 | gesture_lr_delta_ = 0; |
kbhagat6 | 6:687dff16904e | 708 | |
kbhagat6 | 6:687dff16904e | 709 | gesture_ud_count_ = 0; |
kbhagat6 | 6:687dff16904e | 710 | gesture_lr_count_ = 0; |
kbhagat6 | 6:687dff16904e | 711 | |
kbhagat6 | 6:687dff16904e | 712 | gesture_near_count_ = 0; |
kbhagat6 | 6:687dff16904e | 713 | gesture_far_count_ = 0; |
kbhagat6 | 6:687dff16904e | 714 | |
kbhagat6 | 6:687dff16904e | 715 | gesture_state_ = 0; |
kbhagat6 | 6:687dff16904e | 716 | gesture_motion_ = DIR_NONE; |
kbhagat6 | 6:687dff16904e | 717 | } |
kbhagat6 | 6:687dff16904e | 718 | |
kbhagat6 | 6:687dff16904e | 719 | |
kbhagat6 | 4:84545b0e63a9 | 720 | |
kbhagat6 | 0:437ae08befe3 | 721 | bool glibr::setProximityGain(uint8_t drive) |
kbhagat6 | 0:437ae08befe3 | 722 | { |
kbhagat6 | 0:437ae08befe3 | 723 | uint8_t val; |
kbhagat6 | 0:437ae08befe3 | 724 | |
kbhagat6 | 0:437ae08befe3 | 725 | /* Read value from CONTROL register */ |
kbhagat6 | 1:c7215f5f9a72 | 726 | |
kbhagat6 | 5:3eb4f3091bd8 | 727 | val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL); |
kbhagat6 | 0:437ae08befe3 | 728 | |
kbhagat6 | 1:c7215f5f9a72 | 729 | if(val==ERROR){ |
kbhagat6 | 1:c7215f5f9a72 | 730 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 731 | } |
kbhagat6 | 0:437ae08befe3 | 732 | /* Set bits in register to given value */ |
kbhagat6 | 1:c7215f5f9a72 | 733 | //drive &= 0b00000011; |
kbhagat6 | 1:c7215f5f9a72 | 734 | drive &=0x03; |
kbhagat6 | 0:437ae08befe3 | 735 | drive = drive << 2; |
kbhagat6 | 1:c7215f5f9a72 | 736 | val &= 0xF3; |
kbhagat6 | 0:437ae08befe3 | 737 | val |= drive; |
kbhagat6 | 0:437ae08befe3 | 738 | |
kbhagat6 | 0:437ae08befe3 | 739 | /* Write register value back into CONTROL register */ |
kbhagat6 | 1:c7215f5f9a72 | 740 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val) ) { |
kbhagat6 | 1:c7215f5f9a72 | 741 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 742 | } |
kbhagat6 | 1:c7215f5f9a72 | 743 | return true; |
kbhagat6 | 1:c7215f5f9a72 | 744 | } |
kbhagat6 | 1:c7215f5f9a72 | 745 | |
kbhagat6 | 1:c7215f5f9a72 | 746 | |
kbhagat6 | 1:c7215f5f9a72 | 747 | bool glibr::setAmbientLightGain(uint8_t drive){ |
kbhagat6 | 1:c7215f5f9a72 | 748 | { |
kbhagat6 | 1:c7215f5f9a72 | 749 | uint8_t val; |
kbhagat6 | 1:c7215f5f9a72 | 750 | |
kbhagat6 | 1:c7215f5f9a72 | 751 | /* Read value from CONTROL register */ |
kbhagat6 | 1:c7215f5f9a72 | 752 | |
kbhagat6 | 5:3eb4f3091bd8 | 753 | val=I2CreadByte(APDS9960_I2C_ADDR,APDS9960_CONTROL); |
kbhagat6 | 1:c7215f5f9a72 | 754 | |
kbhagat6 | 1:c7215f5f9a72 | 755 | if(val==ERROR){ |
kbhagat6 | 1:c7215f5f9a72 | 756 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 757 | } |
kbhagat6 | 1:c7215f5f9a72 | 758 | /* Set bits in register to given value */ |
kbhagat6 | 1:c7215f5f9a72 | 759 | //drive &= 0b00000011; |
kbhagat6 | 1:c7215f5f9a72 | 760 | drive &=0x03; |
kbhagat6 | 1:c7215f5f9a72 | 761 | drive = drive << 2; |
kbhagat6 | 1:c7215f5f9a72 | 762 | val &= 0xF3; |
kbhagat6 | 1:c7215f5f9a72 | 763 | val |= drive; |
kbhagat6 | 1:c7215f5f9a72 | 764 | |
kbhagat6 | 1:c7215f5f9a72 | 765 | /* Write register value back into CONTROL register */ |
kbhagat6 | 1:c7215f5f9a72 | 766 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_CONTROL, val) ) { |
kbhagat6 | 1:c7215f5f9a72 | 767 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 768 | } |
kbhagat6 | 1:c7215f5f9a72 | 769 | return true; |
kbhagat6 | 1:c7215f5f9a72 | 770 | } |
kbhagat6 | 1:c7215f5f9a72 | 771 | |
kbhagat6 | 1:c7215f5f9a72 | 772 | |
kbhagat6 | 5:3eb4f3091bd8 | 773 | bool setProxIntLowThresh(uint8_t threshold) |
kbhagat6 | 1:c7215f5f9a72 | 774 | { |
kbhagat6 | 1:c7215f5f9a72 | 775 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PILT, threshold) ) { |
kbhagat6 | 0:437ae08befe3 | 776 | return false; |
kbhagat6 | 0:437ae08befe3 | 777 | } |
kbhagat6 | 0:437ae08befe3 | 778 | |
kbhagat6 | 0:437ae08befe3 | 779 | return true; |
kbhagat6 | 0:437ae08befe3 | 780 | } |
kbhagat6 | 0:437ae08befe3 | 781 | |
kbhagat6 | 1:c7215f5f9a72 | 782 | bool glibr::setProxIntHighThresh(uint8_t threshold) |
kbhagat6 | 1:c7215f5f9a72 | 783 | { |
kbhagat6 | 1:c7215f5f9a72 | 784 | |
kbhagat6 | 1:c7215f5f9a72 | 785 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_PIHT, threshold) ) { |
kbhagat6 | 1:c7215f5f9a72 | 786 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 787 | } |
kbhagat6 | 1:c7215f5f9a72 | 788 | |
kbhagat6 | 1:c7215f5f9a72 | 789 | return true; |
kbhagat6 | 1:c7215f5f9a72 | 790 | } |
kbhagat6 | 0:437ae08befe3 | 791 | |
kbhagat6 | 3:26146a08bb22 | 792 | |
kbhagat6 | 3:26146a08bb22 | 793 | |
kbhagat6 | 3:26146a08bb22 | 794 | |
kbhagat6 | 3:26146a08bb22 | 795 | |
kbhagat6 | 1:c7215f5f9a72 | 796 | bool glibr::setLightIntLowThreshold(uint16_t threshold) |
kbhagat6 | 1:c7215f5f9a72 | 797 | { |
kbhagat6 | 1:c7215f5f9a72 | 798 | uint8_t val_low; |
kbhagat6 | 1:c7215f5f9a72 | 799 | uint8_t val_high; |
kbhagat6 | 1:c7215f5f9a72 | 800 | |
kbhagat6 | 1:c7215f5f9a72 | 801 | /* Break 16-bit threshold into 2 8-bit values */ |
kbhagat6 | 1:c7215f5f9a72 | 802 | val_low = threshold & 0x00FF; |
kbhagat6 | 1:c7215f5f9a72 | 803 | val_high = (threshold & 0xFF00) >> 8; |
kbhagat6 | 1:c7215f5f9a72 | 804 | |
kbhagat6 | 1:c7215f5f9a72 | 805 | /* Write low byte */ |
kbhagat6 | 1:c7215f5f9a72 | 806 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_AILTL, val_low) ) { |
kbhagat6 | 1:c7215f5f9a72 | 807 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 808 | } |
kbhagat6 | 1:c7215f5f9a72 | 809 | |
kbhagat6 | 1:c7215f5f9a72 | 810 | /* Write high byte */ |
kbhagat6 | 1:c7215f5f9a72 | 811 | if( I2CwriteByte(APDS9960_I2C_ADDR,APDS9960_AILTH, val_high) ) { |
kbhagat6 | 1:c7215f5f9a72 | 812 | return false; |
kbhagat6 | 1:c7215f5f9a72 | 813 | } |
kbhagat6 | 1:c7215f5f9a72 | 814 | |
kbhagat6 | 1:c7215f5f9a72 | 815 | return true; |
kbhagat6 | 1:c7215f5f9a72 | 816 | } |
kbhagat6 | 1:c7215f5f9a72 | 817 | |
kbhagat6 | 5:3eb4f3091bd8 | 818 | |
kbhagat6 | 5:3eb4f3091bd8 | 819 | |
kbhagat6 | 5:3eb4f3091bd8 | 820 | |
kbhagat6 | 5:3eb4f3091bd8 | 821 | |
kbhagat6 | 5:3eb4f3091bd8 | 822 | int glibr::I2CwriteByte(char address, char subAddress, char data) |
kbhagat6 | 5:3eb4f3091bd8 | 823 | { |
kbhagat6 | 5:3eb4f3091bd8 | 824 | int ret; |
kbhagat6 | 5:3eb4f3091bd8 | 825 | char cmd[2] = {subAddress, data}; |
kbhagat6 | 5:3eb4f3091bd8 | 826 | ret=i2c.write(address<<1, cmd, 2); //if ret is 1, then not acked. |
kbhagat6 | 5:3eb4f3091bd8 | 827 | return ret; |
kbhagat6 | 5:3eb4f3091bd8 | 828 | } |
kbhagat6 | 5:3eb4f3091bd8 | 829 | |
kbhagat6 | 5:3eb4f3091bd8 | 830 | |
kbhagat6 | 5:3eb4f3091bd8 | 831 | |
kbhagat6 | 0:437ae08befe3 | 832 | uint8_t glibr::I2CreadByte(char address, char subAddress) |
kbhagat6 | 0:437ae08befe3 | 833 | { |
kbhagat6 | 0:437ae08befe3 | 834 | char data; // store the register data |
kbhagat6 | 0:437ae08befe3 | 835 | |
kbhagat6 | 0:437ae08befe3 | 836 | if(i2c.write(address<<1, &subAddress, 1, true)){ |
kbhagat6 | 0:437ae08befe3 | 837 | return ERROR; //7 bit //not acked |
kbhagat6 | 0:437ae08befe3 | 838 | } |
kbhagat6 | 0:437ae08befe3 | 839 | i2c.read(address<<1, &data, 1); |
kbhagat6 | 0:437ae08befe3 | 840 | return data; |
kbhagat6 | 0:437ae08befe3 | 841 | |
kbhagat6 | 0:437ae08befe3 | 842 | } |
kbhagat6 | 5:3eb4f3091bd8 | 843 | |
kbhagat6 | 5:3eb4f3091bd8 | 844 | /** |
kbhagat6 | 5:3eb4f3091bd8 | 845 | * @brief Reads a block (array) of bytes from the I2C device and register |
kbhagat6 | 5:3eb4f3091bd8 | 846 | * |
kbhagat6 | 5:3eb4f3091bd8 | 847 | * @param[in] reg the register to read from |
kbhagat6 | 5:3eb4f3091bd8 | 848 | * @param[out] val pointer to the beginning of the data |
kbhagat6 | 5:3eb4f3091bd8 | 849 | * @param[in] len number of bytes to read |
kbhagat6 | 5:3eb4f3091bd8 | 850 | * @return Number of bytes read. -1 on read error. |
kbhagat6 | 5:3eb4f3091bd8 | 851 | */ |
kbhagat6 | 5:3eb4f3091bd8 | 852 | int glibr::I2CReadDataBlock(char address, char subAddress, unsigned int len) |
kbhagat6 | 5:3eb4f3091bd8 | 853 | { |
kbhagat6 | 5:3eb4f3091bd8 | 854 | // unsigned char i = 0; |
kbhagat6 | 5:3eb4f3091bd8 | 855 | char *data |
kbhagat6 | 5:3eb4f3091bd8 | 856 | /* Indicate which register we want to read from */ |
kbhagat6 | 5:3eb4f3091bd8 | 857 | |
kbhagat6 | 5:3eb4f3091bd8 | 858 | if(i2c.write(address<<1, subAddress, 1, true)){ |
kbhagat6 | 5:3eb4f3091bd8 | 859 | return -1; //7 bit //not acked |
kbhagat6 | 5:3eb4f3091bd8 | 860 | } |
kbhagat6 | 5:3eb4f3091bd8 | 861 | |
kbhagat6 | 5:3eb4f3091bd8 | 862 | /* Read block data */ |
kbhagat6 | 5:3eb4f3091bd8 | 863 | i2c.read(address<<1, &data, len); |
kbhagat6 | 5:3eb4f3091bd8 | 864 | |
kbhagat6 | 5:3eb4f3091bd8 | 865 | //Wire.requestFrom(APDS9960_I2C_ADDR, len); |
kbhagat6 | 5:3eb4f3091bd8 | 866 | /*while (Wire.available()) { |
kbhagat6 | 5:3eb4f3091bd8 | 867 | if (i >= len) { |
kbhagat6 | 5:3eb4f3091bd8 | 868 | return -1; |
kbhagat6 | 5:3eb4f3091bd8 | 869 | } |
kbhagat6 | 5:3eb4f3091bd8 | 870 | val[i] = Wire.read(); |
kbhagat6 | 5:3eb4f3091bd8 | 871 | i++; |
kbhagat6 | 5:3eb4f3091bd8 | 872 | }*/ |
kbhagat6 | 5:3eb4f3091bd8 | 873 | |
kbhagat6 | 5:3eb4f3091bd8 | 874 | return data; |
kbhagat6 | 5:3eb4f3091bd8 | 875 | } |