Skip to content

Commit 2088a89

Browse files
committed
Add begin(TwoWire &i2cPort) - requires VL53L1X::dev_i2c to be public
1 parent c4982b8 commit 2088a89

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun VL53L1X 4m Laser Distance Sensor
2-
version=1.2.11
2+
version=1.2.12
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the SparkFun Qwiic 4m Distance Sensor - VL53L1X

src/SparkFun_VL53L1X.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@
3333
#include <stdlib.h>
3434
#include "SparkFun_VL53L1X.h"
3535

36+
SFEVL53L1X::SFEVL53L1X()
37+
{
38+
_i2cPort = &Wire;
39+
_shutdownPin = -1;
40+
_interruptPin = -1;
41+
_device = new VL53L1X(&Wire, -1, -1);
42+
}
43+
SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort)
44+
{
45+
_i2cPort = &i2cPort;
46+
_shutdownPin = -1;
47+
_interruptPin = -1;
48+
_device = new VL53L1X(&i2cPort, -1, -1);
49+
}
50+
SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin)
51+
{
52+
_i2cPort = &i2cPort;
53+
_shutdownPin = shutdownPin;
54+
_interruptPin = -1;
55+
_device = new VL53L1X(&i2cPort, shutdownPin, -1);
56+
}
3657
SFEVL53L1X::SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin)
3758
{
3859
_i2cPort = &i2cPort;
@@ -54,6 +75,25 @@ bool SFEVL53L1X::begin()
5475
return _device->VL53L1X_SensorInit();
5576
}
5677

78+
bool SFEVL53L1X::begin(TwoWire &i2cPort)
79+
{
80+
_i2cPort = &i2cPort;
81+
_device->dev_i2c = &i2cPort;
82+
83+
if (checkID() == false)
84+
{
85+
Serial.println("Check ID failed...");
86+
return (VL53L1_ERROR_PLATFORM_SPECIFIC_START);
87+
}
88+
89+
bool result = _device->VL53L1X_SensorInit() == 0;
90+
91+
if (!result)
92+
Serial.println("Init failed...");
93+
94+
return result;
95+
}
96+
5797
/*Checks the ID of the device, returns true if ID is correct*/
5898

5999
bool SFEVL53L1X::checkID()

src/SparkFun_VL53L1X.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ struct DetectionConfig
5959
class SFEVL53L1X
6060
{
6161
public:
62-
SFEVL53L1X(TwoWire &i2cPort = Wire, int shutdownPin = -1, int interruptPin = -1); //Constructs our Distance sensor without an interrupt or shutdown pin
62+
//Constructs our Distance sensor
63+
SFEVL53L1X(); // Default to Wire. Set both pins to -1 (undefined).
64+
SFEVL53L1X(TwoWire &i2cPort); // Set both pins to -1 (undefined).
65+
SFEVL53L1X(TwoWire &i2cPort, int shutdownPin); // Set interrupt pin to -1 (undefined).
66+
SFEVL53L1X(TwoWire &i2cPort, int shutdownPin, int interruptPin);
6367
bool init(); //Deprecated version of begin
6468
bool begin(); //Initialization of sensor
69+
bool begin(TwoWire &i2cPort); //Initialization of sensor
6570
bool checkID(); //Check the ID of the sensor, returns true if ID is correct
6671
void sensorOn(); //Toggles shutdown pin to turn sensor on and off
6772
void sensorOff(); //Toggles shutdown pin to turn sensor on and off

src/st_src/vl53l1x_class.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,13 @@ class VL53L1X : public RangeSensor
553553

554554

555555

556-
protected:
556+
public:
557557

558558
/* IO Device */
559559
TwoWire *dev_i2c;
560+
561+
protected:
562+
560563
/* Digital out pin */
561564
int gpio0;
562565
int gpio1Int;

0 commit comments

Comments
 (0)