Skip to content

Commit

Permalink
Merge pull request #26 from amitrao17/set_offset_and_read_ID
Browse files Browse the repository at this point in the history
add capability to set offset and read ID registers
  • Loading branch information
ladyada authored Feb 14, 2022
2 parents 9f75a6d + 9dfab6f commit 47519ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Adafruit_VL6180X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,36 @@ float Adafruit_VL6180X::readLux(uint8_t gain) {
return lux;
}

/**************************************************************************/
/*!
@brief Set the offset
@param offset Offset setting
*/
/**************************************************************************/

void Adafruit_VL6180X::setOffset(uint8_t offset) {
// write the offset
write8(VL6180X_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET, offset);
}

/**************************************************************************/
/*!
@brief Get the 7 bytes of id
@param id_ptr Pointer to array of id bytes
*/
/**************************************************************************/

void Adafruit_VL6180X::getID(uint8_t *id_ptr) {

id_ptr[0] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 0);
id_ptr[1] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 1);
id_ptr[2] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 2);
id_ptr[3] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 3);
id_ptr[4] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 4);
id_ptr[6] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 6);
id_ptr[7] = read8(VL6180X_REG_IDENTIFICATION_MODEL_ID + 7);
}

/**************************************************************************/
/*!
@brief I2C low level interfacing
Expand Down
5 changes: 5 additions & 0 deletions Adafruit_VL6180X.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#define VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET 0x016
///! Trigger Ranging
#define VL6180X_REG_SYSRANGE_START 0x018
///! Part to part range offset
#define VL6180X_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x024
///! Trigger Lux Reading
#define VL6180X_REG_SYSALS_START 0x038
///! Lux reading gain
Expand Down Expand Up @@ -95,6 +97,9 @@ class Adafruit_VL6180X {
void stopRangeContinuous(void);
// readRangeResult and isRangeComplete apply here is well

void setOffset(uint8_t offset);
void getID(uint8_t *id_ptr);

private:
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
void loadSettings(void);
Expand Down

0 comments on commit 47519ae

Please sign in to comment.