Skip to content

Commit 832c0b0

Browse files
committed
Add destructor. Correct begin overload
1 parent 2a4660a commit 832c0b0

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/SparkFun_VL53L1X.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin)
4747
_interruptPin = interruptPin;
4848
_device = new VL53L1X(&i2cPort, shutdownPin, interruptPin);
4949
}
50+
SFEVL53L1X::~SFEVL53L1X()
51+
{
52+
delete (VL53L1X *)_device;
53+
}
5054

5155
bool SFEVL53L1X::init()
5256
{
@@ -66,18 +70,7 @@ bool SFEVL53L1X::begin(TwoWire &i2cPort)
6670
_i2cPort = &i2cPort;
6771
_device->dev_i2c = &i2cPort;
6872

69-
if (checkID() == false)
70-
{
71-
Serial.println("Check ID failed...");
72-
return (VL53L1_ERROR_PLATFORM_SPECIFIC_START);
73-
}
74-
75-
bool result = _device->VL53L1X_SensorInit() == 0;
76-
77-
if (!result)
78-
Serial.println("Init failed...");
79-
80-
return result;
73+
return begin();
8174
}
8275

8376
/*Checks the ID of the device, returns true if ID is correct*/

src/SparkFun_VL53L1X.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SFEVL53L1X
6262
//Constructs our Distance sensor
6363
SFEVL53L1X(); // Default to Wire. Set both pins to -1 (undefined).
6464
SFEVL53L1X(TwoWire &i2cPort, int shutdownPin = -1, int interruptPin = -1);
65+
~SFEVL53L1X();
6566
bool init(); //Deprecated version of begin
6667
bool begin(); //Initialization of sensor
6768
bool begin(TwoWire &i2cPort); //Initialization of sensor

0 commit comments

Comments
 (0)