sdsd
Revision 4:aab6582c7456, committed 2020-04-03
- Comitter:
- maazshaikh
- Date:
- Fri Apr 03 15:38:03 2020 +0000
- Parent:
- 3:5d61f202b1bd
- Commit message:
- sds
Changed in this revision
VL6180.cpp | Show annotated file Show diff for this revision Revisions of this file |
VL6180.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/VL6180.cpp Mon Oct 19 21:58:52 2015 +0000 +++ b/VL6180.cpp Fri Apr 03 15:38:03 2020 +0000 @@ -1,100 +1,281 @@ -#include "VL6180.h" -#include "mbed.h" +/****************************************************************************** + * SFE_VL6180.cpp + * Library for VL6180 time of flight range finder. + * Casey Kuhns @ SparkFun Electronics + * 10/29/2014 + * https://github.com/sparkfun/ + * + * The VL6180 by ST micro is a time of flight range finder that + * uses pulsed IR light to determine distances from object at close + * range. The average range of a sensor is between 0-200mm + * + * In this file are the functions in the VL6180 class + * + * Resources: + * This library uses the Arduino Wire.h to complete I2C transactions. + * + * Development environment specifics: + * IDE: Arduino 1.0.5 + * Hardware Platform: Arduino Pro 3.3V/8MHz + * VL6180 Breakout Version: 1.0 + * + * + * This code is beerware. If you see me (or any other SparkFun employee) at the + * local pub, and you've found our code helpful, please buy us a round! + * + * Distributed as-is; no warranty is given. + ******************************************************************************/ -VL6180::VL6180(PinName sda, PinName scl) : _i2c(sda, scl) { - char poweron; - poweron = readI2C(0x16); - if(poweron == 1) { - //mandatory initialization - writeI2C(0x0207,0x01); - writeI2C(0x0208,0x01); - writeI2C(0x0096,0x00); - writeI2C(0x0097,0xfd); - writeI2C(0x00e3,0x00); - writeI2C(0x00e4,0x04); - writeI2C(0x00e5,0x02); - writeI2C(0x00e6,0x01); - writeI2C(0x00e7,0x03); - writeI2C(0x00f5,0x02); - writeI2C(0x00d9,0x05); - writeI2C(0x00db,0xce); - writeI2C(0x00dc,0x03); - writeI2C(0x00dd,0xf8); - writeI2C(0x009f,0x00); - writeI2C(0x00a3,0x3c); - writeI2C(0x00b7,0x00); - writeI2C(0x00bb,0x3c); - writeI2C(0x00b2,0x09); - writeI2C(0x00ca,0x09); - writeI2C(0x0198,0x01); - writeI2C(0x01b0,0x17); - writeI2C(0x01ad,0x00); - writeI2C(0x00ff,0x05); - writeI2C(0x0100,0x05); - writeI2C(0x0199,0x05); - writeI2C(0x01a6,0x1b); - writeI2C(0x01ac,0x3e); - writeI2C(0x01a7,0x1f); - writeI2C(0x0030,0x00); - //recommended initialization - writeI2C(0x0011,0x10);// Enables polling for ‘New Sample ready’ when measurement completes - writeI2C(0x010a,0x30);// Set the averaging sample period (compromise between lower noise and increased execution time) - writeI2C(0x003f,0x46);// Sets the light and dark gain (upper nibble). Dark gain should not be changed. - writeI2C(0x0031,0xFF);// sets the # of range measurements after which auto calibration of system is performed - writeI2C(0x0040,0x63);// Set ALS integration time to 100ms - writeI2C(0x002e,0x01);// perform a single temperature calibration of the ranging sensor - //optional initialization - writeI2C(0x001b,0x09);// Set default ranging inter-measurement period to 100ms - writeI2C(0x003e,0x31);// Set default ALS inter-measurement period to 500ms - writeI2C(0x0014,0x24);// Configures interrupt on ‘New Sample Ready threshold event’ - - writeI2C(0x016,0x00);//change fresh out of set status to 0 - } +#include "VL6180.h" + +// +// Constructors +// +VL6180::VL6180(PinName sda, PinName scl) : i2c(sda, scl) +{ + VL6180_i2cAddress = VL6180_DEF_ADDR; +} + +VL6180::VL6180(PinName sda, PinName scl, int i2cAddress) : i2c(sda, scl) +{ + VL6180_i2cAddress = i2cAddress; + VL6180_error_no = 0; +} +// +// destructor +// +VL6180::~VL6180() +{ } -float VL6180::read() { - char status; - char retn; - - writeI2C(0x18, 0x01); - - status = readI2C(0x4F); - while((status & 0x7) != 4) { - status = readI2C(0x4F); - } - - retn = readI2C(0x62); - - writeI2C(0x15, 0x07); - - return (float)retn / 10.0; +int8_t VL6180::VL6180_Init(void) +{ + uint8_t data; //for temp data storage + + data = VL6180_getRegister(VL6180_SYSTEM_FRESH_OUT_OF_RESET); + + if(data != 1) return VL6180_FAILURE_RESET; + + //Required by datasheet + //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf + VL6180_setRegister(0x0207, 0x01); + VL6180_setRegister(0x0208, 0x01); + VL6180_setRegister(0x0096, 0x00); + VL6180_setRegister(0x0097, 0xfd); + VL6180_setRegister(0x00e3, 0x00); + VL6180_setRegister(0x00e4, 0x04); + VL6180_setRegister(0x00e5, 0x02); + VL6180_setRegister(0x00e6, 0x01); + VL6180_setRegister(0x00e7, 0x03); + VL6180_setRegister(0x00f5, 0x02); + VL6180_setRegister(0x00d9, 0x05); + VL6180_setRegister(0x00db, 0xce); + VL6180_setRegister(0x00dc, 0x03); + VL6180_setRegister(0x00dd, 0xf8); + VL6180_setRegister(0x009f, 0x00); + VL6180_setRegister(0x00a3, 0x3c); + VL6180_setRegister(0x00b7, 0x00); + VL6180_setRegister(0x00bb, 0x3c); + VL6180_setRegister(0x00b2, 0x09); + VL6180_setRegister(0x00ca, 0x09); + VL6180_setRegister(0x0198, 0x01); + VL6180_setRegister(0x01b0, 0x17); + VL6180_setRegister(0x01ad, 0x00); + VL6180_setRegister(0x00ff, 0x05); + VL6180_setRegister(0x0100, 0x05); + VL6180_setRegister(0x0199, 0x05); + VL6180_setRegister(0x01a6, 0x1b); + VL6180_setRegister(0x01ac, 0x3e); + VL6180_setRegister(0x01a7, 0x1f); + VL6180_setRegister(0x0030, 0x00); + + return 0; } -VL6180::operator float() { - return read(); +void VL6180::VL6180_DefautSettings(void) +{ + //Recommended settings from datasheet + //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf + + //Enable Interrupts on Conversion Complete (any source) + VL6180_setRegister(VL6180_SYSTEM_INTERRUPT_CONFIG_GPIO, (4 << 3)|(4) ); // Set GPIO1 high when sample complete + + + VL6180_setRegister(VL6180_SYSTEM_MODE_GPIO1, 0x10); // Set GPIO1 high when sample complete + VL6180_setRegister(VL6180_READOUT_AVERAGING_SAMPLE_PERIOD, 0x30); //Set Avg sample period + VL6180_setRegister(VL6180_SYSALS_ANALOGUE_GAIN, 0x46); // Set the ALS gain + VL6180_setRegister(VL6180_SYSRANGE_VHV_REPEAT_RATE, 0xFF); // Set auto calibration period (Max = 255)/(OFF = 0) + VL6180_setRegister(VL6180_SYSALS_INTEGRATION_PERIOD, 0x63); // Set ALS integration time to 100ms + VL6180_setRegister(VL6180_SYSRANGE_VHV_RECALIBRATE, 0x01); // perform a single temperature calibration + //Optional settings from datasheet + //http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf + VL6180_setRegister(VL6180_SYSRANGE_INTERMEASUREMENT_PERIOD, 0x09); // Set default ranging inter-measurement period to 100ms + VL6180_setRegister(VL6180_SYSALS_INTERMEASUREMENT_PERIOD, 0x0A); // Set default ALS inter-measurement period to 100ms + VL6180_setRegister(VL6180_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x24); // Configures interrupt on ‘New Sample Ready threshold event’ + //Additional settings defaults from community + VL6180_setRegister(VL6180_SYSRANGE_MAX_CONVERGENCE_TIME, 0x32); + VL6180_setRegister(VL6180_SYSRANGE_RANGE_CHECK_ENABLES, 0x10 | 0x01); + VL6180_setRegister16bit(VL6180_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, 0x7B ); + VL6180_setRegister16bit(VL6180_SYSALS_INTEGRATION_PERIOD, 0x64); + + VL6180_setRegister(VL6180_READOUT_AVERAGING_SAMPLE_PERIOD,0x30); + VL6180_setRegister(VL6180_SYSALS_ANALOGUE_GAIN,0x40); + VL6180_setRegister(VL6180_FIRMWARE_RESULT_SCALER,0x01); +} +void VL6180::getIdentification(struct VL6180Identification *temp) +{ + + temp->idModel = VL6180_getRegister(VL6180_IDENTIFICATION_MODEL_ID); + temp->idModelRevMajor = VL6180_getRegister(VL6180_IDENTIFICATION_MODEL_REV_MAJOR); + temp->idModelRevMinor = VL6180_getRegister(VL6180_IDENTIFICATION_MODEL_REV_MINOR); + temp->idModuleRevMajor = VL6180_getRegister(VL6180_IDENTIFICATION_MODULE_REV_MAJOR); + temp->idModuleRevMinor = VL6180_getRegister(VL6180_IDENTIFICATION_MODULE_REV_MINOR); + + temp->idDate = VL6180_getRegister16bit(VL6180_IDENTIFICATION_DATE); + temp->idTime = VL6180_getRegister16bit(VL6180_IDENTIFICATION_TIME); } -void VL6180::writeI2C(int reg, char data) { - char dataout[3]; - - dataout[0] = (reg >> 8) & 0xFF; - dataout[1] = reg & 0xFF; - dataout[2] = data & 0xFF; - - _i2c.write(_addr, dataout, 3); +uint8_t VL6180::changeAddress(uint8_t old_address, uint8_t new_address) +{ + + //NOTICE: IT APPEARS THAT CHANGING THE ADDRESS IS NOT STORED IN NON-VOLATILE MEMORY + // POWER CYCLING THE DEVICE REVERTS ADDRESS BACK TO 0X29 + + if( old_address == new_address) return old_address; + if( new_address > 127) return old_address; + + VL6180_setRegister(VL6180_I2C_SLAVE_DEVICE_ADDRESS, new_address); + + return VL6180_getRegister(VL6180_I2C_SLAVE_DEVICE_ADDRESS); +} + + + +uint8_t VL6180::getDistance() +{ + VL6180_setRegister(VL6180_SYSRANGE_START, 0x01); //Start Single shot mode + wait(0.01); // 10mS + return VL6180_getRegister(VL6180_RESULT_RANGE_VAL); +// VL6180_setRegister(VL6180_SYSTEM_INTERRUPT_CLEAR, 0x07); +// return distance; } -char VL6180::readI2C(int reg) { - char dataout[2]; - char datain[1]; - - dataout[0] = (reg >> 8) & 0xFF; - dataout[1] = reg & 0xFF; - - _i2c.write(_addr, dataout, 2); - _i2c.read(_addr, datain, 1); - - return datain[0]; +float VL6180::getAmbientLight(VL6180_als_gain VL6180_ALS_GAIN) +{ + //First load in Gain we are using, do it everytime incase someone changes it on us. + //Note: Upper nibble shoudl be set to 0x4 i.e. for ALS gain of 1.0 write 0x46 + VL6180_setRegister(VL6180_SYSALS_ANALOGUE_GAIN, (0x40 | VL6180_ALS_GAIN)); // Set the ALS gain + + //Start ALS Measurement + VL6180_setRegister(VL6180_SYSALS_START, 0x01); + + wait(0.1); //100Ms + + VL6180_setRegister(VL6180_SYSTEM_INTERRUPT_CLEAR, 0x07); + + //Retrieve the Raw ALS value from the sensoe + unsigned int alsRaw = VL6180_getRegister16bit(VL6180_RESULT_ALS_VAL); + + //Get Integration Period for calculation, we do this everytime incase someone changes it on us. + unsigned int alsIntegrationPeriodRaw = VL6180_getRegister16bit(VL6180_SYSALS_INTEGRATION_PERIOD); + + float alsIntegrationPeriod = 100.0 / alsIntegrationPeriodRaw ; + + //Calculate actual LUX from Appnotes + + float alsGain = 0.0; + + switch (VL6180_ALS_GAIN) { + case GAIN_20: + alsGain = 20.0; + break; + case GAIN_10: + alsGain = 10.32; + break; + case GAIN_5: + alsGain = 5.21; + break; + case GAIN_2_5: + alsGain = 2.60; + break; + case GAIN_1_67: + alsGain = 1.72; + break; + case GAIN_1_25: + alsGain = 1.28; + break; + case GAIN_1: + alsGain = 1.01; + break; + case GAIN_40: + alsGain = 40.0; + break; + } + +//Calculate LUX from formula in AppNotes + + float alsCalculated = (float)0.32 * ((float)alsRaw / alsGain) * alsIntegrationPeriod; + + return alsCalculated; +} + +// --- Private Functions --- // + +uint8_t VL6180::VL6180_getRegister(uint16_t reg_address) +{ + char data[2]; + + data[0] = (reg_address >> 8) & 0xFF; //MSB of register address + data[1] = reg_address & 0xFF; //LSB of register address + VL6180_error_no = i2c.write(VL6180_i2cAddress, data, 2); + VL6180_error_no = i2c.read(VL6180_i2cAddress, data, 1, false); + return data[0]; +} + +uint16_t VL6180::VL6180_getRegister16bit(uint16_t reg_address) +{ + char data[2]; + + data[0] = (reg_address >> 8) & 0xFF; //MSB of register address + data[1] = reg_address & 0xFF; //LSB of register address + VL6180_error_no = i2c.write(VL6180_i2cAddress, data, 2); + VL6180_error_no = i2c.read(VL6180_i2cAddress, data, 2, false); + return (data[0] + ((data[1] << 8) & 0xFF00)); +} + +void VL6180::VL6180_setRegister(uint16_t reg_address, uint8_t value) +{ + char data[3]; + + data[0] = (reg_address >> 8) & 0xFF; //MSB of register address + data[1] = reg_address & 0xFF; //LSB of register address + data[2] = value; + VL6180_error_no = VL6180_error_no = i2c.write(VL6180_i2cAddress, data, 3); +} + +void VL6180::VL6180_setRegister16bit(uint16_t reg_address, uint16_t value) +{ + char data[4]; + + data[0] = (reg_address >> 8) & 0xFF; //MSB of register address + data[1] = reg_address & 0xFF; //LSB of register address + data[2] = value & 0xFF; + data[3] = ((value >> 8) & 0xFF); + VL6180_error_no = VL6180_error_no = i2c.write(VL6180_i2cAddress, data, 4); +} + +int VL6180::writeSingleRegister( uint16_t reg_address, uint8_t data ) +{ + + char data_write[3]; + data_write[0] = (reg_address >> 8) & 0xFF; //MSB of register address + data_write[1] = reg_address & 0xFF; //LSB of register address + data_write[2] = data & 0xFF; + return i2c.write(VL6180_DEF_ADDR, data_write, 3); + +// char tx[2] = { address | 160, data }; //0d160 = 0b10100000 +// int ack = i2c.write( SLAVE_ADDRESS << 1, tx, 2 ); +// return ack; } \ No newline at end of file
--- a/VL6180.h Mon Oct 19 21:58:52 2015 +0000 +++ b/VL6180.h Fri Apr 03 15:38:03 2020 +0000 @@ -1,52 +1,202 @@ -#ifndef MBED_VL6180_H -#define MBED_VL6180_H +/****************************************************************************** + * SFE_VL6180.h + * Library for VL6180 time of flight range finder. + * Casey Kuhns @ SparkFun Electronics + * 10/29/2014 + * https://github.com/sparkfun/ + * + * The VL6180 by ST micro is a time of flight range finder that + * uses pulsed IR light to determine distances from object at close + * range. The average range of a sensor is between 0-200mm + * + * In this file are the function prototypes in the VL6180 class + * + * Resources: + * This library uses the Arduino Wire.h to complete I2C transactions. + * + * Development environment specifics: + * IDE: Arduino 1.0.5 + * Hardware Platform: Arduino Pro 3.3V/8MHz + * VL6180 Breakout Version: 1.0 + * + * Some settings and initial values come from code written by Kris Winer + * VL6180_t3 Basic Example Code + * by: Kris Winer + * date: September 1, 2014 + * license: Beerware - Use this code however you'd like. If you + * find it useful you can buy me a beer some time. + * + * This code is beerware. If you see me (or any other SparkFun employee) at the + * local pub, and you've found our code helpful, please buy us a round! + * + * Distributed as-is; no warranty is given. + ******************************************************************************/ + +#ifndef SFE_VL6180_h +#define SFE_VL6180_h #include "mbed.h" -/** VL6180 control class. - * - * Example: - * @code - * //Update pc terminal every half second with range reading - * #include "VL6180.h" - * #include "mbed.h" - * - * VL6180 rf(p9, p10); //I2C sda and scl - * Serial pc(USBTX, USBRX); //USB serial - * - * int main() { - * float reading; - * while(1) { - * reading = rf; - * pc.printf("Read %4.1f cm\n", reading); - * wait(0.5); - * } - * } - * @endcode - */ -class VL6180 { +#include "stdint.h" + +#define VL6180_DEF_ADDR 0x52 + +#define VL6180_FAILURE_RESET -1 + +#define VL6180_IDENTIFICATION_MODEL_ID 0x0000 +#define VL6180_IDENTIFICATION_MODEL_REV_MAJOR 0x0001 +#define VL6180_IDENTIFICATION_MODEL_REV_MINOR 0x0002 +#define VL6180_IDENTIFICATION_MODULE_REV_MAJOR 0x0003 +#define VL6180_IDENTIFICATION_MODULE_REV_MINOR 0x0004 +#define VL6180_IDENTIFICATION_DATE 0x0006 //16bit value +#define VL6180_IDENTIFICATION_TIME 0x0008 //16bit value + +#define VL6180_SYSTEM_MODE_GPIO0 0x0010 +#define VL6180_SYSTEM_MODE_GPIO1 0x0011 +#define VL6180_SYSTEM_HISTORY_CTRL 0x0012 +#define VL6180_SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014 +#define VL6180_SYSTEM_INTERRUPT_CLEAR 0x0015 +#define VL6180_SYSTEM_FRESH_OUT_OF_RESET 0x0016 +#define VL6180_SYSTEM_GROUPED_PARAMETER_HOLD 0x0017 + +#define VL6180_SYSRANGE_START 0x0018 +#define VL6180_SYSRANGE_THRESH_HIGH 0x0019 +#define VL6180_SYSRANGE_THRESH_LOW 0x001A +#define VL6180_SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B +#define VL6180_SYSRANGE_MAX_CONVERGENCE_TIME 0x001C +#define VL6180_SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E +#define VL6180_SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021 +#define VL6180_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022 +#define VL6180_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024 +#define VL6180_SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025 +#define VL6180_SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026 +#define VL6180_SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C +#define VL6180_SYSRANGE_RANGE_CHECK_ENABLES 0x002D +#define VL6180_SYSRANGE_VHV_RECALIBRATE 0x002E +#define VL6180_SYSRANGE_VHV_REPEAT_RATE 0x0031 + +#define VL6180_SYSALS_START 0x0038 +#define VL6180_SYSALS_THRESH_HIGH 0x003A +#define VL6180_SYSALS_THRESH_LOW 0x003C +#define VL6180_SYSALS_INTERMEASUREMENT_PERIOD 0x003E +#define VL6180_SYSALS_ANALOGUE_GAIN 0x003F +#define VL6180_SYSALS_INTEGRATION_PERIOD 0x0040 + +#define VL6180_RESULT_RANGE_STATUS 0x004D +#define VL6180_RESULT_ALS_STATUS 0x004E +#define VL6180_RESULT_INTERRUPT_STATUS_GPIO 0x004F +#define VL6180_RESULT_ALS_VAL 0x0050 +#define VL6180_RESULT_HISTORY_BUFFER 0x0052 +#define VL6180_RESULT_RANGE_VAL 0x0062 +#define VL6180_RESULT_RANGE_RAW 0x0064 +#define VL6180_RESULT_RANGE_RETURN_RATE 0x0066 +#define VL6180_RESULT_RANGE_REFERENCE_RATE 0x0068 +#define VL6180_RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C +#define VL6180_RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070 +#define VL6180_RESULT_RANGE_RETURN_AMB_COUNT 0x0074 +#define VL6180_RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078 +#define VL6180_RESULT_RANGE_RETURN_CONV_TIME 0x007C +#define VL6180_RESULT_RANGE_REFERENCE_CONV_TIME 0x0080 + +#define VL6180_READOUT_AVERAGING_SAMPLE_PERIOD 0x010A +#define VL6180_FIRMWARE_BOOTUP 0x0119 +#define VL6180_FIRMWARE_RESULT_SCALER 0x0120 +#define VL6180_I2C_SLAVE_DEVICE_ADDRESS 0x0212 +#define VL6180_INTERLEAVED_MODE_ENABLE 0x02A3 + + +enum VL6180_als_gain { //Data sheet shows gain values as binary list + + GAIN_20 = 0, // Actual ALS Gain of 20 + GAIN_10, // Actual ALS Gain of 10.32 + GAIN_5, // Actual ALS Gain of 5.21 + GAIN_2_5, // Actual ALS Gain of 2.60 + GAIN_1_67, // Actual ALS Gain of 1.72 + GAIN_1_25, // Actual ALS Gain of 1.28 + GAIN_1 , // Actual ALS Gain of 1.01 + GAIN_40, // Actual ALS Gain of 40 + +}; + +struct VL6180Identification { + uint8_t idModel; + uint8_t idModelRevMajor; + uint8_t idModelRevMinor; + uint8_t idModuleRevMajor; + uint8_t idModuleRevMinor; + uint16_t idDate; + uint16_t idTime; +}; + + +class VL6180 +{ public: - /** Create a VL6180 object at I2C address 0x29 (7 bit). - * - * @param sda I2C sda pin number - * @param scl I2C scl pin number + /** Create VL6180 instance + * + * @param sda sda pin for I2C + * @param scl scl pin for I2C */ - VL6180(PinName sda, PinName scl); + VL6180( PinName sda, PinName scl ); + VL6180( PinName sda, PinName scl , int i2c_address); - /** Make a range reading. - * - * @param return Distance to target in cm. Approx 0.0 cm to 20.0 cm. + /** Destructor + */ + ~VL6180(); + + /** Read red, green, blue and clear values into array + * + * @param readings Array of four integers to store the read data */ - float read(); + //Initalize library with default address +// VL6180(uint8_t address); + //Send manditory settings as stated in ST datasheet. + // http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf (Section 1.3) + int8_t VL6180_Init(void); + // Use default settings from ST data sheet section 9. + // http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf + void VL6180_DefautSettings(void); + + // Get Range distance in (mm) + uint8_t getDistance(); + // Get ALS level in Lux + float getAmbientLight(VL6180_als_gain VL6180_ALS_GAIN); + + //Load structure provided by the user with identification info + //Structure example: + // struct VL6180Identification + // { + // uint8_t idModel; + // uint8_t idModelRevMajor; + // uint8_t idModelRevMinor; + // uint8_t idModuleRevMajor; + // uint8_t idModuleRevMinor; + // uint16_t idDate; + // uint16_t idTime; + // }; + void getIdentification(struct VL6180Identification *temp); + + //Change the default address of the device to allow multiple + //sensors on the bus. Can use up to 127 sensors. New address + //is saved in non-volatile device memory. + uint8_t changeAddress(uint8_t old_address, uint8_t new_address); - /** Float cast is shorthand for read() */ - operator float(); - + int writeSingleRegister( uint16_t reg_address, uint8_t data ); + + private: - void writeI2C(int reg, char data); - char readI2C(int reg); - I2C _i2c; - int _res; - static const int _addr = 0x52; + //Store address given when the class is initialized. + //This value can be changed by the changeAddress() function + I2C i2c; + int VL6180_i2cAddress; + uint8_t VL6180_error_no; + + uint8_t VL6180_getRegister(uint16_t registerAddr); + uint16_t VL6180_getRegister16bit(uint16_t registerAddr); + + void VL6180_setRegister(uint16_t registerAddr, uint8_t value); + void VL6180_setRegister16bit(uint16_t registerAddr, uint16_t value); + + }; #endif \ No newline at end of file