Skip to content

Commit

Permalink
Merge pull request #24 from caternuson/iss15_reset
Browse files Browse the repository at this point in the history
Tweak memory alloc and cleanup AND renable fresh_out_of_reset check
  • Loading branch information
caternuson authored Aug 25, 2021
2 parents 7bc5dd3 + 6378110 commit d246ce8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions Adafruit_VL6180X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
///! period between each measurement when in continuous mode
#define SYSRANGE__INTERMEASUREMENT_PERIOD 0x001b // P19 application notes

Adafruit_VL6180X::~Adafruit_VL6180X() {
if (i2c_dev)
delete i2c_dev;
}

/**************************************************************************/
/*!
@brief Instantiates a new VL6180X class
Expand All @@ -54,19 +59,22 @@ boolean Adafruit_VL6180X::begin(TwoWire *theWire) {
// only needed to support setAddress()
_i2c = theWire;

if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(_i2caddr, _i2c);
if (!i2c_dev->begin())
return false;

// check for expected model id
if (read8(VL6180X_REG_IDENTIFICATION_MODEL_ID) != 0xB4) {
return false;
}

// if (read8(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET) == 0x01) {
loadSettings();
//}

write8(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET, 0x00);
// fresh out of reset?
if (read8(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET) & 0x01) {
loadSettings();
write8(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET, 0x00);
}

return true;
}
Expand All @@ -85,7 +93,8 @@ boolean Adafruit_VL6180X::setAddress(uint8_t newAddr) {
write8(VL6180X_REG_SLAVE_DEVICE_ADDRESS, newAddr & 0x7F);
_i2caddr = newAddr;

delete i2c_dev;
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(_i2caddr, _i2c);

return i2c_dev->begin();
Expand Down
1 change: 1 addition & 0 deletions Adafruit_VL6180X.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
class Adafruit_VL6180X {
public:
Adafruit_VL6180X(uint8_t i2caddr = VL6180X_DEFAULT_I2C_ADDR);
~Adafruit_VL6180X();
boolean begin(TwoWire *theWire = &Wire);
boolean setAddress(uint8_t newAddr);
uint8_t getAddress(void);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit_VL6180X
version=1.3.0
version=1.3.1
author=Adafruit
maintainer=adafruit <[email protected]>
sentence=Sensor driver for VL6180X Time of Flight sensor
Expand Down

0 comments on commit d246ce8

Please sign in to comment.