APDS9960 gesture sensor library for use with mbed. Ported from Justin Woodman's RPI APDS9960 library.
APDS9960_I2C.h@0:49ae62548910, 2015-05-19 (annotated)
- Committer:
- chiggayeuh
- Date:
- Tue May 19 11:00:23 2015 +0000
- Revision:
- 0:49ae62548910
Initial release of APDS9960 library for mBed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chiggayeuh | 0:49ae62548910 | 1 | /** |
chiggayeuh | 0:49ae62548910 | 2 | * @file APDS9960_RPi.h |
chiggayeuh | 0:49ae62548910 | 3 | * @brief Raspberry Pi library for the SparkFun APDS-9960 breakout board |
chiggayeuh | 0:49ae62548910 | 4 | * @author Shawn Hymel (SparkFun Electronics), Modified for Raspberry Pi by Justin Woodman |
chiggayeuh | 0:49ae62548910 | 5 | * |
chiggayeuh | 0:49ae62548910 | 6 | * @copyright This code is public domain but you buy me a beer if you use |
chiggayeuh | 0:49ae62548910 | 7 | * this and we meet someday (Beerware license). |
chiggayeuh | 0:49ae62548910 | 8 | * |
chiggayeuh | 0:49ae62548910 | 9 | * This library interfaces the Avago APDS-9960 to Raspberry Pi over I2C. The library |
chiggayeuh | 0:49ae62548910 | 10 | * relies on the wiringPi library. to use the library, instantiate an |
chiggayeuh | 0:49ae62548910 | 11 | * APDS9960 object, call init(), and call the appropriate functions. |
chiggayeuh | 0:49ae62548910 | 12 | * |
chiggayeuh | 0:49ae62548910 | 13 | * APDS-9960 current draw tests (default parameters): |
chiggayeuh | 0:49ae62548910 | 14 | * Off: 1mA |
chiggayeuh | 0:49ae62548910 | 15 | * Waiting for gesture: 14mA |
chiggayeuh | 0:49ae62548910 | 16 | * Gesture in progress: 35mA |
chiggayeuh | 0:49ae62548910 | 17 | */ |
chiggayeuh | 0:49ae62548910 | 18 | |
chiggayeuh | 0:49ae62548910 | 19 | #ifndef APDS9960_I2C_H |
chiggayeuh | 0:49ae62548910 | 20 | #define APDS9960_I2C_H |
chiggayeuh | 0:49ae62548910 | 21 | #include "mbed.h" |
chiggayeuh | 0:49ae62548910 | 22 | |
chiggayeuh | 0:49ae62548910 | 23 | #include <stdint.h> |
chiggayeuh | 0:49ae62548910 | 24 | #include <stdlib.h> |
chiggayeuh | 0:49ae62548910 | 25 | |
chiggayeuh | 0:49ae62548910 | 26 | /* Debug */ |
chiggayeuh | 0:49ae62548910 | 27 | #define DEBUG 0 |
chiggayeuh | 0:49ae62548910 | 28 | |
chiggayeuh | 0:49ae62548910 | 29 | /* APDS-9960 I2C address */ |
chiggayeuh | 0:49ae62548910 | 30 | #define APDS9960_I2C_ADDR 0x39 |
chiggayeuh | 0:49ae62548910 | 31 | |
chiggayeuh | 0:49ae62548910 | 32 | /* Gesture parameters */ |
chiggayeuh | 0:49ae62548910 | 33 | #define GESTURE_THRESHOLD_OUT 10 |
chiggayeuh | 0:49ae62548910 | 34 | #define GESTURE_SENSITIVITY_1 50 |
chiggayeuh | 0:49ae62548910 | 35 | #define GESTURE_SENSITIVITY_2 20 |
chiggayeuh | 0:49ae62548910 | 36 | |
chiggayeuh | 0:49ae62548910 | 37 | /* Error code for returned values */ |
chiggayeuh | 0:49ae62548910 | 38 | #define ERROR 0xFF |
chiggayeuh | 0:49ae62548910 | 39 | |
chiggayeuh | 0:49ae62548910 | 40 | /* Acceptable device IDs */ |
chiggayeuh | 0:49ae62548910 | 41 | #define APDS9960_ID_1 0xAB |
chiggayeuh | 0:49ae62548910 | 42 | #define APDS9960_ID_2 0x9C |
chiggayeuh | 0:49ae62548910 | 43 | |
chiggayeuh | 0:49ae62548910 | 44 | /* Misc parameters */ |
chiggayeuh | 0:49ae62548910 | 45 | #define FIFO_PAUSE_TIME 30 // Wait period (ms) between FIFO reads |
chiggayeuh | 0:49ae62548910 | 46 | |
chiggayeuh | 0:49ae62548910 | 47 | /* APDS-9960 register addresses */ |
chiggayeuh | 0:49ae62548910 | 48 | #define APDS9960_ENABLE 0x80 |
chiggayeuh | 0:49ae62548910 | 49 | #define APDS9960_ATIME 0x81 |
chiggayeuh | 0:49ae62548910 | 50 | #define APDS9960_WTIME 0x83 |
chiggayeuh | 0:49ae62548910 | 51 | #define APDS9960_AILTL 0x84 |
chiggayeuh | 0:49ae62548910 | 52 | #define APDS9960_AILTH 0x85 |
chiggayeuh | 0:49ae62548910 | 53 | #define APDS9960_AIHTL 0x86 |
chiggayeuh | 0:49ae62548910 | 54 | #define APDS9960_AIHTH 0x87 |
chiggayeuh | 0:49ae62548910 | 55 | #define APDS9960_PILT 0x89 |
chiggayeuh | 0:49ae62548910 | 56 | #define APDS9960_PIHT 0x8B |
chiggayeuh | 0:49ae62548910 | 57 | #define APDS9960_PERS 0x8C |
chiggayeuh | 0:49ae62548910 | 58 | #define APDS9960_CONFIG1 0x8D |
chiggayeuh | 0:49ae62548910 | 59 | #define APDS9960_PPULSE 0x8E |
chiggayeuh | 0:49ae62548910 | 60 | #define APDS9960_CONTROL 0x8F |
chiggayeuh | 0:49ae62548910 | 61 | #define APDS9960_CONFIG2 0x90 |
chiggayeuh | 0:49ae62548910 | 62 | #define APDS9960_ID 0x92 |
chiggayeuh | 0:49ae62548910 | 63 | #define APDS9960_STATUS 0x93 |
chiggayeuh | 0:49ae62548910 | 64 | #define APDS9960_CDATAL 0x94 |
chiggayeuh | 0:49ae62548910 | 65 | #define APDS9960_CDATAH 0x95 |
chiggayeuh | 0:49ae62548910 | 66 | #define APDS9960_RDATAL 0x96 |
chiggayeuh | 0:49ae62548910 | 67 | #define APDS9960_RDATAH 0x97 |
chiggayeuh | 0:49ae62548910 | 68 | #define APDS9960_GDATAL 0x98 |
chiggayeuh | 0:49ae62548910 | 69 | #define APDS9960_GDATAH 0x99 |
chiggayeuh | 0:49ae62548910 | 70 | #define APDS9960_BDATAL 0x9A |
chiggayeuh | 0:49ae62548910 | 71 | #define APDS9960_BDATAH 0x9B |
chiggayeuh | 0:49ae62548910 | 72 | #define APDS9960_PDATA 0x9C |
chiggayeuh | 0:49ae62548910 | 73 | #define APDS9960_POFFSET_UR 0x9D |
chiggayeuh | 0:49ae62548910 | 74 | #define APDS9960_POFFSET_DL 0x9E |
chiggayeuh | 0:49ae62548910 | 75 | #define APDS9960_CONFIG3 0x9F |
chiggayeuh | 0:49ae62548910 | 76 | #define APDS9960_GPENTH 0xA0 |
chiggayeuh | 0:49ae62548910 | 77 | #define APDS9960_GEXTH 0xA1 |
chiggayeuh | 0:49ae62548910 | 78 | #define APDS9960_GCONF1 0xA2 |
chiggayeuh | 0:49ae62548910 | 79 | #define APDS9960_GCONF2 0xA3 |
chiggayeuh | 0:49ae62548910 | 80 | #define APDS9960_GOFFSET_U 0xA4 |
chiggayeuh | 0:49ae62548910 | 81 | #define APDS9960_GOFFSET_D 0xA5 |
chiggayeuh | 0:49ae62548910 | 82 | #define APDS9960_GOFFSET_L 0xA7 |
chiggayeuh | 0:49ae62548910 | 83 | #define APDS9960_GOFFSET_R 0xA9 |
chiggayeuh | 0:49ae62548910 | 84 | #define APDS9960_GPULSE 0xA6 |
chiggayeuh | 0:49ae62548910 | 85 | #define APDS9960_GCONF3 0xAA |
chiggayeuh | 0:49ae62548910 | 86 | #define APDS9960_GCONF4 0xAB |
chiggayeuh | 0:49ae62548910 | 87 | #define APDS9960_GFLVL 0xAE |
chiggayeuh | 0:49ae62548910 | 88 | #define APDS9960_GSTATUS 0xAF |
chiggayeuh | 0:49ae62548910 | 89 | #define APDS9960_IFORCE 0xE4 |
chiggayeuh | 0:49ae62548910 | 90 | #define APDS9960_PICLEAR 0xE5 |
chiggayeuh | 0:49ae62548910 | 91 | #define APDS9960_CICLEAR 0xE6 |
chiggayeuh | 0:49ae62548910 | 92 | #define APDS9960_AICLEAR 0xE7 |
chiggayeuh | 0:49ae62548910 | 93 | #define APDS9960_GFIFO_U 0xFC |
chiggayeuh | 0:49ae62548910 | 94 | #define APDS9960_GFIFO_D 0xFD |
chiggayeuh | 0:49ae62548910 | 95 | #define APDS9960_GFIFO_L 0xFE |
chiggayeuh | 0:49ae62548910 | 96 | #define APDS9960_GFIFO_R 0xFF |
chiggayeuh | 0:49ae62548910 | 97 | |
chiggayeuh | 0:49ae62548910 | 98 | /* Bit fields */ |
chiggayeuh | 0:49ae62548910 | 99 | #define APDS9960_PON 00000001 |
chiggayeuh | 0:49ae62548910 | 100 | #define APDS9960_AEN 00000010 |
chiggayeuh | 0:49ae62548910 | 101 | #define APDS9960_PEN 00000100 |
chiggayeuh | 0:49ae62548910 | 102 | #define APDS9960_WEN 00001000 |
chiggayeuh | 0:49ae62548910 | 103 | #define APSD9960_AIEN 00010000 |
chiggayeuh | 0:49ae62548910 | 104 | #define APDS9960_PIEN 00100000 |
chiggayeuh | 0:49ae62548910 | 105 | #define APDS9960_GEN 01000000 |
chiggayeuh | 0:49ae62548910 | 106 | #define APDS9960_GVALID 00000001 |
chiggayeuh | 0:49ae62548910 | 107 | |
chiggayeuh | 0:49ae62548910 | 108 | /* On/Off definitions */ |
chiggayeuh | 0:49ae62548910 | 109 | #define OFF 0 |
chiggayeuh | 0:49ae62548910 | 110 | #define ON 1 |
chiggayeuh | 0:49ae62548910 | 111 | |
chiggayeuh | 0:49ae62548910 | 112 | /* Acceptable parameters for setMode */ |
chiggayeuh | 0:49ae62548910 | 113 | #define POWER 0 |
chiggayeuh | 0:49ae62548910 | 114 | #define AMBIENT_LIGHT 1 |
chiggayeuh | 0:49ae62548910 | 115 | #define PROXIMITY 2 |
chiggayeuh | 0:49ae62548910 | 116 | #define WAIT 3 |
chiggayeuh | 0:49ae62548910 | 117 | #define AMBIENT_LIGHT_INT 4 |
chiggayeuh | 0:49ae62548910 | 118 | #define PROXIMITY_INT 5 |
chiggayeuh | 0:49ae62548910 | 119 | #define GESTURE 6 |
chiggayeuh | 0:49ae62548910 | 120 | #define ALL 7 |
chiggayeuh | 0:49ae62548910 | 121 | |
chiggayeuh | 0:49ae62548910 | 122 | /* LED Drive values */ |
chiggayeuh | 0:49ae62548910 | 123 | #define LED_DRIVE_100MA 0 |
chiggayeuh | 0:49ae62548910 | 124 | #define LED_DRIVE_50MA 1 |
chiggayeuh | 0:49ae62548910 | 125 | #define LED_DRIVE_25MA 2 |
chiggayeuh | 0:49ae62548910 | 126 | #define LED_DRIVE_12_5MA 3 |
chiggayeuh | 0:49ae62548910 | 127 | |
chiggayeuh | 0:49ae62548910 | 128 | /* Proximity Gain (PGAIN) values */ |
chiggayeuh | 0:49ae62548910 | 129 | #define PGAIN_1X 0 |
chiggayeuh | 0:49ae62548910 | 130 | #define PGAIN_2X 1 |
chiggayeuh | 0:49ae62548910 | 131 | #define PGAIN_4X 2 |
chiggayeuh | 0:49ae62548910 | 132 | #define PGAIN_8X 3 |
chiggayeuh | 0:49ae62548910 | 133 | |
chiggayeuh | 0:49ae62548910 | 134 | /* ALS Gain (AGAIN) values */ |
chiggayeuh | 0:49ae62548910 | 135 | #define AGAIN_1X 0 |
chiggayeuh | 0:49ae62548910 | 136 | #define AGAIN_4X 1 |
chiggayeuh | 0:49ae62548910 | 137 | #define AGAIN_16X 2 |
chiggayeuh | 0:49ae62548910 | 138 | #define AGAIN_64X 3 |
chiggayeuh | 0:49ae62548910 | 139 | |
chiggayeuh | 0:49ae62548910 | 140 | /* Gesture Gain (GGAIN) values */ |
chiggayeuh | 0:49ae62548910 | 141 | #define GGAIN_1X 0 |
chiggayeuh | 0:49ae62548910 | 142 | #define GGAIN_2X 1 |
chiggayeuh | 0:49ae62548910 | 143 | #define GGAIN_4X 2 |
chiggayeuh | 0:49ae62548910 | 144 | #define GGAIN_8X 3 |
chiggayeuh | 0:49ae62548910 | 145 | |
chiggayeuh | 0:49ae62548910 | 146 | /* LED Boost values */ |
chiggayeuh | 0:49ae62548910 | 147 | #define LED_BOOST_100 0 |
chiggayeuh | 0:49ae62548910 | 148 | #define LED_BOOST_150 1 |
chiggayeuh | 0:49ae62548910 | 149 | #define LED_BOOST_200 2 |
chiggayeuh | 0:49ae62548910 | 150 | #define LED_BOOST_300 3 |
chiggayeuh | 0:49ae62548910 | 151 | |
chiggayeuh | 0:49ae62548910 | 152 | /* Gesture wait time values */ |
chiggayeuh | 0:49ae62548910 | 153 | #define GWTIME_0MS 0 |
chiggayeuh | 0:49ae62548910 | 154 | #define GWTIME_2_8MS 1 |
chiggayeuh | 0:49ae62548910 | 155 | #define GWTIME_5_6MS 2 |
chiggayeuh | 0:49ae62548910 | 156 | #define GWTIME_8_4MS 3 |
chiggayeuh | 0:49ae62548910 | 157 | #define GWTIME_14_0MS 4 |
chiggayeuh | 0:49ae62548910 | 158 | #define GWTIME_22_4MS 5 |
chiggayeuh | 0:49ae62548910 | 159 | #define GWTIME_30_8MS 6 |
chiggayeuh | 0:49ae62548910 | 160 | #define GWTIME_39_2MS 7 |
chiggayeuh | 0:49ae62548910 | 161 | |
chiggayeuh | 0:49ae62548910 | 162 | /* Default values */ |
chiggayeuh | 0:49ae62548910 | 163 | #define DEFAULT_ATIME 219 // 103ms |
chiggayeuh | 0:49ae62548910 | 164 | #define DEFAULT_WTIME 246 // 27ms |
chiggayeuh | 0:49ae62548910 | 165 | #define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses |
chiggayeuh | 0:49ae62548910 | 166 | #define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses |
chiggayeuh | 0:49ae62548910 | 167 | #define DEFAULT_POFFSET_UR 0 // 0 offset |
chiggayeuh | 0:49ae62548910 | 168 | #define DEFAULT_POFFSET_DL 0 // 0 offset |
chiggayeuh | 0:49ae62548910 | 169 | #define DEFAULT_CONFIG1 0x60 // No 12x wait (WTIME) factor |
chiggayeuh | 0:49ae62548910 | 170 | #define DEFAULT_LDRIVE LED_DRIVE_100MA |
chiggayeuh | 0:49ae62548910 | 171 | #define DEFAULT_PGAIN PGAIN_4X |
chiggayeuh | 0:49ae62548910 | 172 | #define DEFAULT_AGAIN AGAIN_4X |
chiggayeuh | 0:49ae62548910 | 173 | #define DEFAULT_PILT 0 // Low proximity threshold |
chiggayeuh | 0:49ae62548910 | 174 | #define DEFAULT_PIHT 50 // High proximity threshold |
chiggayeuh | 0:49ae62548910 | 175 | #define DEFAULT_AILT 0xFFFF // Force interrupt for calibration |
chiggayeuh | 0:49ae62548910 | 176 | #define DEFAULT_AIHT 0 |
chiggayeuh | 0:49ae62548910 | 177 | #define DEFAULT_PERS 0x11 // 2 consecutive prox or ALS for int. |
chiggayeuh | 0:49ae62548910 | 178 | #define DEFAULT_CONFIG2 0x01 // No saturation interrupts or LED boost |
chiggayeuh | 0:49ae62548910 | 179 | #define DEFAULT_CONFIG3 0 // Enable all photodiodes, no SAI |
chiggayeuh | 0:49ae62548910 | 180 | #define DEFAULT_GPENTH 40 // Threshold for entering gesture mode |
chiggayeuh | 0:49ae62548910 | 181 | #define DEFAULT_GEXTH 30 // Threshold for exiting gesture mode |
chiggayeuh | 0:49ae62548910 | 182 | #define DEFAULT_GCONF1 0x40 // 4 gesture events for int., 1 for exit |
chiggayeuh | 0:49ae62548910 | 183 | #define DEFAULT_GGAIN GGAIN_4X |
chiggayeuh | 0:49ae62548910 | 184 | #define DEFAULT_GLDRIVE LED_DRIVE_100MA |
chiggayeuh | 0:49ae62548910 | 185 | #define DEFAULT_GWTIME GWTIME_2_8MS |
chiggayeuh | 0:49ae62548910 | 186 | #define DEFAULT_GOFFSET 0 // No offset scaling for gesture mode |
chiggayeuh | 0:49ae62548910 | 187 | #define DEFAULT_GPULSE 0xC9 // 32us, 10 pulses |
chiggayeuh | 0:49ae62548910 | 188 | #define DEFAULT_GCONF3 0 // All photodiodes active during gesture |
chiggayeuh | 0:49ae62548910 | 189 | #define DEFAULT_GIEN 0 // Disable gesture interrupts |
chiggayeuh | 0:49ae62548910 | 190 | |
chiggayeuh | 0:49ae62548910 | 191 | /* Direction definitions */ |
chiggayeuh | 0:49ae62548910 | 192 | enum { |
chiggayeuh | 0:49ae62548910 | 193 | DIR_NONE, |
chiggayeuh | 0:49ae62548910 | 194 | DIR_LEFT, |
chiggayeuh | 0:49ae62548910 | 195 | DIR_RIGHT, |
chiggayeuh | 0:49ae62548910 | 196 | DIR_UP, |
chiggayeuh | 0:49ae62548910 | 197 | DIR_DOWN, |
chiggayeuh | 0:49ae62548910 | 198 | DIR_NEAR, |
chiggayeuh | 0:49ae62548910 | 199 | DIR_FAR, |
chiggayeuh | 0:49ae62548910 | 200 | DIR_ALL |
chiggayeuh | 0:49ae62548910 | 201 | }; |
chiggayeuh | 0:49ae62548910 | 202 | |
chiggayeuh | 0:49ae62548910 | 203 | /* State definitions */ |
chiggayeuh | 0:49ae62548910 | 204 | enum { |
chiggayeuh | 0:49ae62548910 | 205 | NA_STATE, |
chiggayeuh | 0:49ae62548910 | 206 | NEAR_STATE, |
chiggayeuh | 0:49ae62548910 | 207 | FAR_STATE, |
chiggayeuh | 0:49ae62548910 | 208 | ALL_STATE |
chiggayeuh | 0:49ae62548910 | 209 | }; |
chiggayeuh | 0:49ae62548910 | 210 | |
chiggayeuh | 0:49ae62548910 | 211 | /* Container for gesture data */ |
chiggayeuh | 0:49ae62548910 | 212 | typedef struct gesture_data_type { |
chiggayeuh | 0:49ae62548910 | 213 | uint8_t u_data[32]; |
chiggayeuh | 0:49ae62548910 | 214 | uint8_t d_data[32]; |
chiggayeuh | 0:49ae62548910 | 215 | uint8_t l_data[32]; |
chiggayeuh | 0:49ae62548910 | 216 | uint8_t r_data[32]; |
chiggayeuh | 0:49ae62548910 | 217 | uint8_t index; |
chiggayeuh | 0:49ae62548910 | 218 | uint8_t total_gestures; |
chiggayeuh | 0:49ae62548910 | 219 | uint8_t in_threshold; |
chiggayeuh | 0:49ae62548910 | 220 | uint8_t out_threshold; |
chiggayeuh | 0:49ae62548910 | 221 | } gesture_data_type; |
chiggayeuh | 0:49ae62548910 | 222 | |
chiggayeuh | 0:49ae62548910 | 223 | /* APDS9960 Class */ |
chiggayeuh | 0:49ae62548910 | 224 | class APDS9960_I2C { |
chiggayeuh | 0:49ae62548910 | 225 | public: |
chiggayeuh | 0:49ae62548910 | 226 | |
chiggayeuh | 0:49ae62548910 | 227 | /* Initialization methods */ |
chiggayeuh | 0:49ae62548910 | 228 | APDS9960_I2C( PinName sda, PinName scl ); |
chiggayeuh | 0:49ae62548910 | 229 | //~APDS9960(); |
chiggayeuh | 0:49ae62548910 | 230 | bool init(); |
chiggayeuh | 0:49ae62548910 | 231 | uint8_t read_this(); |
chiggayeuh | 0:49ae62548910 | 232 | uint8_t getMode(); |
chiggayeuh | 0:49ae62548910 | 233 | int write_this(); |
chiggayeuh | 0:49ae62548910 | 234 | bool setMode(uint8_t mode, uint8_t enable); |
chiggayeuh | 0:49ae62548910 | 235 | |
chiggayeuh | 0:49ae62548910 | 236 | /* Turn the APDS-9960 on and off */ |
chiggayeuh | 0:49ae62548910 | 237 | bool enablePower(); |
chiggayeuh | 0:49ae62548910 | 238 | bool disablePower(); |
chiggayeuh | 0:49ae62548910 | 239 | |
chiggayeuh | 0:49ae62548910 | 240 | /* Enable or disable specific sensors */ |
chiggayeuh | 0:49ae62548910 | 241 | bool enableLightSensor(bool interrupts = false); |
chiggayeuh | 0:49ae62548910 | 242 | bool disableLightSensor(); |
chiggayeuh | 0:49ae62548910 | 243 | bool enableProximitySensor(bool interrupts = false); |
chiggayeuh | 0:49ae62548910 | 244 | bool disableProximitySensor(); |
chiggayeuh | 0:49ae62548910 | 245 | bool enableGestureSensor(bool interrupts = true); |
chiggayeuh | 0:49ae62548910 | 246 | bool disableGestureSensor(); |
chiggayeuh | 0:49ae62548910 | 247 | |
chiggayeuh | 0:49ae62548910 | 248 | /* LED drive strength control */ |
chiggayeuh | 0:49ae62548910 | 249 | uint8_t getLEDDrive(); |
chiggayeuh | 0:49ae62548910 | 250 | bool setLEDDrive(uint8_t drive); |
chiggayeuh | 0:49ae62548910 | 251 | uint8_t getGestureLEDDrive(); |
chiggayeuh | 0:49ae62548910 | 252 | bool setGestureLEDDrive(uint8_t drive); |
chiggayeuh | 0:49ae62548910 | 253 | |
chiggayeuh | 0:49ae62548910 | 254 | /* Gain control */ |
chiggayeuh | 0:49ae62548910 | 255 | uint8_t getAmbientLightGain(); |
chiggayeuh | 0:49ae62548910 | 256 | bool setAmbientLightGain(uint8_t gain); |
chiggayeuh | 0:49ae62548910 | 257 | uint8_t getProximityGain(); |
chiggayeuh | 0:49ae62548910 | 258 | bool setProximityGain(uint8_t gain); |
chiggayeuh | 0:49ae62548910 | 259 | uint8_t getGestureGain(); |
chiggayeuh | 0:49ae62548910 | 260 | bool setGestureGain(uint8_t gain); |
chiggayeuh | 0:49ae62548910 | 261 | |
chiggayeuh | 0:49ae62548910 | 262 | /* Get and set light interrupt thresholds */ |
chiggayeuh | 0:49ae62548910 | 263 | bool getLightIntLowThreshold(uint16_t &threshold); |
chiggayeuh | 0:49ae62548910 | 264 | bool setLightIntLowThreshold(uint16_t threshold); |
chiggayeuh | 0:49ae62548910 | 265 | bool getLightIntHighThreshold(uint16_t &threshold); |
chiggayeuh | 0:49ae62548910 | 266 | bool setLightIntHighThreshold(uint16_t threshold); |
chiggayeuh | 0:49ae62548910 | 267 | |
chiggayeuh | 0:49ae62548910 | 268 | /* Get and set proximity interrupt thresholds */ |
chiggayeuh | 0:49ae62548910 | 269 | bool getProximityIntLowThreshold(uint8_t &threshold); |
chiggayeuh | 0:49ae62548910 | 270 | bool setProximityIntLowThreshold(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 271 | bool getProximityIntHighThreshold(uint8_t &threshold); |
chiggayeuh | 0:49ae62548910 | 272 | bool setProximityIntHighThreshold(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 273 | |
chiggayeuh | 0:49ae62548910 | 274 | /* Get and set interrupt enables */ |
chiggayeuh | 0:49ae62548910 | 275 | uint8_t getAmbientLightIntEnable(); |
chiggayeuh | 0:49ae62548910 | 276 | bool setAmbientLightIntEnable(uint8_t enable); |
chiggayeuh | 0:49ae62548910 | 277 | uint8_t getProximityIntEnable(); |
chiggayeuh | 0:49ae62548910 | 278 | bool setProximityIntEnable(uint8_t enable); |
chiggayeuh | 0:49ae62548910 | 279 | uint8_t getGestureIntEnable(); |
chiggayeuh | 0:49ae62548910 | 280 | bool setGestureIntEnable(uint8_t enable); |
chiggayeuh | 0:49ae62548910 | 281 | |
chiggayeuh | 0:49ae62548910 | 282 | /* Clear interrupts */ |
chiggayeuh | 0:49ae62548910 | 283 | bool clearAmbientLightInt(); |
chiggayeuh | 0:49ae62548910 | 284 | bool clearProximityInt(); |
chiggayeuh | 0:49ae62548910 | 285 | |
chiggayeuh | 0:49ae62548910 | 286 | /* Ambient light methods */ |
chiggayeuh | 0:49ae62548910 | 287 | bool readAmbientLight(uint16_t &val); |
chiggayeuh | 0:49ae62548910 | 288 | bool readRedLight(uint16_t &val); |
chiggayeuh | 0:49ae62548910 | 289 | bool readGreenLight(uint16_t &val); |
chiggayeuh | 0:49ae62548910 | 290 | bool readBlueLight(uint16_t &val); |
chiggayeuh | 0:49ae62548910 | 291 | |
chiggayeuh | 0:49ae62548910 | 292 | /* Proximity methods */ |
chiggayeuh | 0:49ae62548910 | 293 | bool readProximity(uint8_t &val); |
chiggayeuh | 0:49ae62548910 | 294 | |
chiggayeuh | 0:49ae62548910 | 295 | /* Gesture methods */ |
chiggayeuh | 0:49ae62548910 | 296 | bool isGestureAvailable(); |
chiggayeuh | 0:49ae62548910 | 297 | int readGesture(); |
chiggayeuh | 0:49ae62548910 | 298 | |
chiggayeuh | 0:49ae62548910 | 299 | private: |
chiggayeuh | 0:49ae62548910 | 300 | I2C i2c; |
chiggayeuh | 0:49ae62548910 | 301 | |
chiggayeuh | 0:49ae62548910 | 302 | /* Gesture processing */ |
chiggayeuh | 0:49ae62548910 | 303 | void resetGestureParameters(); |
chiggayeuh | 0:49ae62548910 | 304 | bool processGestureData(); |
chiggayeuh | 0:49ae62548910 | 305 | bool decodeGesture(); |
chiggayeuh | 0:49ae62548910 | 306 | |
chiggayeuh | 0:49ae62548910 | 307 | /* Proximity Interrupt Threshold */ |
chiggayeuh | 0:49ae62548910 | 308 | uint8_t getProxIntLowThresh(); |
chiggayeuh | 0:49ae62548910 | 309 | bool setProxIntLowThresh(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 310 | uint8_t getProxIntHighThresh(); |
chiggayeuh | 0:49ae62548910 | 311 | bool setProxIntHighThresh(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 312 | |
chiggayeuh | 0:49ae62548910 | 313 | /* LED Boost Control */ |
chiggayeuh | 0:49ae62548910 | 314 | uint8_t getLEDBoost(); |
chiggayeuh | 0:49ae62548910 | 315 | bool setLEDBoost(uint8_t boost); |
chiggayeuh | 0:49ae62548910 | 316 | |
chiggayeuh | 0:49ae62548910 | 317 | /* Proximity photodiode select */ |
chiggayeuh | 0:49ae62548910 | 318 | uint8_t getProxGainCompEnable(); |
chiggayeuh | 0:49ae62548910 | 319 | bool setProxGainCompEnable(uint8_t enable); |
chiggayeuh | 0:49ae62548910 | 320 | uint8_t getProxPhotoMask(); |
chiggayeuh | 0:49ae62548910 | 321 | bool setProxPhotoMask(uint8_t mask); |
chiggayeuh | 0:49ae62548910 | 322 | |
chiggayeuh | 0:49ae62548910 | 323 | /* Gesture threshold control */ |
chiggayeuh | 0:49ae62548910 | 324 | uint8_t getGestureEnterThresh(); |
chiggayeuh | 0:49ae62548910 | 325 | bool setGestureEnterThresh(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 326 | uint8_t getGestureExitThresh(); |
chiggayeuh | 0:49ae62548910 | 327 | bool setGestureExitThresh(uint8_t threshold); |
chiggayeuh | 0:49ae62548910 | 328 | |
chiggayeuh | 0:49ae62548910 | 329 | /* Gesture LED, gain, and time control */ |
chiggayeuh | 0:49ae62548910 | 330 | uint8_t getGestureWaitTime(); |
chiggayeuh | 0:49ae62548910 | 331 | bool setGestureWaitTime(uint8_t time); |
chiggayeuh | 0:49ae62548910 | 332 | |
chiggayeuh | 0:49ae62548910 | 333 | /* Gesture mode */ |
chiggayeuh | 0:49ae62548910 | 334 | uint8_t getGestureMode(); |
chiggayeuh | 0:49ae62548910 | 335 | bool setGestureMode(uint8_t mode); |
chiggayeuh | 0:49ae62548910 | 336 | |
chiggayeuh | 0:49ae62548910 | 337 | /* Raw I2C Commands */ |
chiggayeuh | 0:49ae62548910 | 338 | //bool wireWriteByte(uint8_t val); |
chiggayeuh | 0:49ae62548910 | 339 | int wireWriteDataByte(uint8_t reg, uint8_t val); |
chiggayeuh | 0:49ae62548910 | 340 | int wireWriteDataBlock(uint8_t reg, uint8_t *val, unsigned int len); |
chiggayeuh | 0:49ae62548910 | 341 | int wireReadDataByte(uint8_t reg, uint8_t &val); |
chiggayeuh | 0:49ae62548910 | 342 | int wireReadDataBlock(uint8_t reg, uint8_t *val, unsigned int len); |
chiggayeuh | 0:49ae62548910 | 343 | |
chiggayeuh | 0:49ae62548910 | 344 | /* Members */ |
chiggayeuh | 0:49ae62548910 | 345 | gesture_data_type gesture_data_; |
chiggayeuh | 0:49ae62548910 | 346 | int gesture_ud_delta_; |
chiggayeuh | 0:49ae62548910 | 347 | int gesture_lr_delta_; |
chiggayeuh | 0:49ae62548910 | 348 | int gesture_ud_count_; |
chiggayeuh | 0:49ae62548910 | 349 | int gesture_lr_count_; |
chiggayeuh | 0:49ae62548910 | 350 | int gesture_near_count_; |
chiggayeuh | 0:49ae62548910 | 351 | int gesture_far_count_; |
chiggayeuh | 0:49ae62548910 | 352 | int gesture_state_; |
chiggayeuh | 0:49ae62548910 | 353 | int gesture_motion_; |
chiggayeuh | 0:49ae62548910 | 354 | int fd_; |
chiggayeuh | 0:49ae62548910 | 355 | }; |
chiggayeuh | 0:49ae62548910 | 356 | |
chiggayeuh | 0:49ae62548910 | 357 | #endif |