|
| 1 | +// VCNL4010 code adapted from: |
| 2 | +// https://github.com/adafruit/Adafruit_VCNL4010 |
| 3 | +#ifndef ADAFRUIT_VCNL4010_H |
| 4 | +#define ADAFRUIT_VCNL4010_H |
| 5 | + |
| 6 | +// the i2c address |
| 7 | +#define VCNL4010_I2CADDR_DEFAULT 0x13 |
| 8 | + |
| 9 | +// commands and constants |
| 10 | +#define VCNL4010_COMMAND 0x80 |
| 11 | +#define VCNL4010_PRODUCTID 0x81 |
| 12 | +#define VCNL4010_PROXRATE 0x82 |
| 13 | +#define VCNL4010_IRLED 0x83 |
| 14 | +#define VCNL4010_AMBIENTPARAMETER 0x84 |
| 15 | +#define VCNL4010_AMBIENTDATA 0x85 |
| 16 | +#define VCNL4010_PROXIMITYDATA 0x87 |
| 17 | +#define VCNL4010_INTCONTROL 0x89 |
| 18 | +#define VCNL4010_PROXINITYADJUST 0x8A |
| 19 | +#define VCNL4010_INTSTAT 0x8E |
| 20 | +#define VCNL4010_MODTIMING 0x8F |
| 21 | + |
| 22 | +typedef enum |
| 23 | + { |
| 24 | + VCNL4010_3M125 = 3, |
| 25 | + VCNL4010_1M5625 = 2, |
| 26 | + VCNL4010_781K25 = 1, |
| 27 | + VCNL4010_390K625 = 0, |
| 28 | + } vcnl4010_freq; |
| 29 | + |
| 30 | +#define VCNL4010_MEASUREAMBIENT 0x10 |
| 31 | +#define VCNL4010_MEASUREPROXIMITY 0x08 |
| 32 | +#define VCNL4010_AMBIENTREADY 0x40 |
| 33 | +#define VCNL4010_PROXIMITYREADY 0x20 |
| 34 | + |
| 35 | +class Adafruit_VCNL4010 { |
| 36 | +public: |
| 37 | + Adafruit_VCNL4010() {} |
| 38 | + |
| 39 | + bool begin(uint8_t a = VCNL4010_I2CADDR_DEFAULT); |
| 40 | + uint16_t readProximity(); |
| 41 | + |
| 42 | +private: |
| 43 | + uint8_t read8(uint8_t address); |
| 44 | + uint16_t read16(uint8_t address); |
| 45 | + void write8(uint8_t address, uint8_t data); |
| 46 | + uint8_t _i2caddr; |
| 47 | + |
| 48 | +}; |
| 49 | + |
| 50 | +#endif |
0 commit comments