Skip to content

Commit 0d083fd

Browse files
authored
Merge pull request #6 from cparata/master
Add begin and end APIs and update examples
2 parents 3bfdd40 + 733f4cb commit 0d083fd

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

examples/VL53L3CX_Sat_HelloWorld/VL53L3CX_Sat_HelloWorld.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#define LedPin LED_BUILTIN
6868

6969
// Components.
70-
VL53LX *sensor_vl53lx_sat;
70+
VL53LX sensor_vl53lx_sat(&DEV_I2C, A1);
7171

7272

7373
/* Setup ---------------------------------------------------------------------*/
@@ -84,17 +84,17 @@ void setup()
8484
// Initialize I2C bus.
8585
DEV_I2C.begin();
8686

87-
// Create VL53LX satellite component.
88-
sensor_vl53lx_sat = new VL53LX(&DEV_I2C, A1, A2);
87+
// Configure VL53LX satellite component.
88+
sensor_vl53lx_sat.begin();
8989

9090
// Switch off VL53LX satellite component.
91-
sensor_vl53lx_sat->VL53LX_Off();
91+
sensor_vl53lx_sat.VL53LX_Off();
9292

9393
//Initialize VL53LX satellite component.
94-
sensor_vl53lx_sat->InitSensor(0x12);
94+
sensor_vl53lx_sat.InitSensor(0x12);
9595

9696
// Start Measurements
97-
sensor_vl53lx_sat->VL53LX_StartMeasurement();
97+
sensor_vl53lx_sat.VL53LX_StartMeasurement();
9898
}
9999

100100
void loop()
@@ -108,15 +108,15 @@ void loop()
108108

109109
do
110110
{
111-
status = sensor_vl53lx_sat->VL53LX_GetMeasurementDataReady(&NewDataReady);
111+
status = sensor_vl53lx_sat.VL53LX_GetMeasurementDataReady(&NewDataReady);
112112
} while (!NewDataReady);
113113

114114
//Led on
115115
digitalWrite(LedPin, HIGH);
116116

117117
if((!status)&&(NewDataReady!=0))
118118
{
119-
status = sensor_vl53lx_sat->VL53LX_GetMultiRangingData(pMultiRangingData);
119+
status = sensor_vl53lx_sat.VL53LX_GetMultiRangingData(pMultiRangingData);
120120
no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
121121
snprintf(report, sizeof(report), "VL53LX Satellite: Count=%d, #Objs=%1d ", pMultiRangingData->StreamCount, no_of_object_found);
122122
SerialPort.print(report);
@@ -137,7 +137,7 @@ void loop()
137137
SerialPort.println("");
138138
if (status==0)
139139
{
140-
status = sensor_vl53lx_sat->VL53LX_ClearInterruptAndStartMeasurement();
140+
status = sensor_vl53lx_sat.VL53LX_ClearInterruptAndStartMeasurement();
141141
}
142142
}
143143

examples/VL53L3CX_Sat_HelloWorld_Interrupt/VL53L3CX_Sat_HelloWorld_Interrupt.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
#define interruptPin A2
7575

7676
// Components.
77-
VL53LX *sensor_vl53lx_sat;
77+
VL53LX sensor_vl53lx_sat(&DEV_I2C, A1);
7878

7979
volatile int interruptCount=0;
8080

@@ -98,20 +98,20 @@ void setup()
9898
// Initialize I2C bus.
9999
DEV_I2C.begin();
100100

101-
// Create VL53LX satellite component.
102-
sensor_vl53lx_sat = new VL53LX(&DEV_I2C, A1, A2);
101+
// Configure VL53LX satellite component.
102+
sensor_vl53lx_sat.begin();
103103

104104
// Switch off VL53LX satellite component.
105-
sensor_vl53lx_sat->VL53LX_Off();
105+
sensor_vl53lx_sat.VL53LX_Off();
106106

107107
// Initialize VL53LX satellite component.
108-
status = sensor_vl53lx_sat->InitSensor(0x12);
108+
status = sensor_vl53lx_sat.InitSensor(0x12);
109109
if(status)
110110
{
111111
SerialPort.println("Init sensor_vl53lx_sat failed...");
112112
}
113113

114-
sensor_vl53lx_sat->VL53LX_StartMeasurement();
114+
sensor_vl53lx_sat.VL53LX_StartMeasurement();
115115
}
116116

117117
void loop()
@@ -129,10 +129,10 @@ void loop()
129129
// Led blinking.
130130
digitalWrite(LedPin, HIGH);
131131

132-
status = sensor_vl53lx_sat->VL53LX_GetMeasurementDataReady(&NewDataReady);
132+
status = sensor_vl53lx_sat.VL53LX_GetMeasurementDataReady(&NewDataReady);
133133
if((!status)&&(NewDataReady!=0))
134134
{
135-
status = sensor_vl53lx_sat->VL53LX_GetMultiRangingData(pMultiRangingData);
135+
status = sensor_vl53lx_sat.VL53LX_GetMultiRangingData(pMultiRangingData);
136136
no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
137137
snprintf(report, sizeof(report), "Count=%d, #Objs=%1d ", pMultiRangingData->StreamCount, no_of_object_found);
138138
SerialPort.print(report);
@@ -153,7 +153,7 @@ void loop()
153153
SerialPort.println("");
154154
if (status==0)
155155
{
156-
status = sensor_vl53lx_sat->VL53LX_ClearInterruptAndStartMeasurement();
156+
status = sensor_vl53lx_sat.VL53LX_ClearInterruptAndStartMeasurement();
157157
}
158158
}
159159

keywords.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
#######################################
88

99
ComponentObject KEYWORD1
10-
LightSensor KEYWORD1
1110
RangeSensor KEYWORD1
1211
VL53L3CX KEYWORD1
1312

1413
#######################################
1514
# Methods and Functions (KEYWORD2)
1615
#######################################
16+
17+
begin KEYWORD2
18+
end KEYWORD2
1719
VL53LX_On KEYWORD2
1820
VL53LX_Off KEYWORD2
1921
InitSensor KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino VL53L3CX
2-
version=1.0.2
2+
version=2.0.0
33
author=STMicroelectronics
44
maintainer=stm32duino
55
sentence=Allows controlling the VL53L3CX (Time-of-Flight ranging sensor with multi target detection)

src/vl53lx_class.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,15 @@
9999
class VL53LX : public RangeSensor {
100100
public:
101101
/** Constructor
102-
* @param[in] &i2c device I2C to be used for communication
103-
* @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
104-
* @param[in] DevAddr device address, 0x52 by default
102+
* @param[in] i2c device I2C to be used for communication
103+
* @param[in] pin shutdown pin to be used as component GPIO0
105104
*/
106-
VL53LX(TwoWire *i2c, int pin, int pin_gpio1) : RangeSensor(), dev_i2c(i2c), gpio0(pin), gpio1Int(pin_gpio1)
105+
VL53LX(TwoWire *i2c, int pin) : RangeSensor(), dev_i2c(i2c), gpio0(pin)
107106
{
108-
MyDevice.I2cDevAddr = VL53LX_DEFAULT_DEVICE_ADDRESS ;
109-
MyDevice.I2cHandle = i2c;
110107
Dev = &MyDevice;
111-
if (gpio0 >= 0) {
112-
pinMode(gpio0, OUTPUT);
113-
}
108+
memset((void *)Dev, 0x0, sizeof(VL53LX_Dev_t));
109+
MyDevice.I2cHandle = i2c;
110+
MyDevice.I2cDevAddr = VL53LX_DEFAULT_DEVICE_ADDRESS ;
114111
}
115112

116113

@@ -120,6 +117,22 @@ class VL53LX : public RangeSensor {
120117
/* warning: VL53LX class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
121118
The warning should request to introduce a virtual destructor to make sure to delete the object */
122119

120+
virtual int begin()
121+
{
122+
if (gpio0 >= 0) {
123+
pinMode(gpio0, OUTPUT);
124+
}
125+
return 0;
126+
}
127+
128+
virtual int end()
129+
{
130+
if (gpio0 >= 0) {
131+
pinMode(gpio0, INPUT);
132+
}
133+
return 0;
134+
}
135+
123136
/*** Interface Methods ***/
124137
/*** High level API ***/
125138
/**
@@ -3529,7 +3542,6 @@ class VL53LX : public RangeSensor {
35293542
TwoWire *dev_i2c;
35303543
/* Digital out pin */
35313544
int gpio0;
3532-
int gpio1Int;
35333545
/* Device data */
35343546
VL53LX_Dev_t MyDevice;
35353547
VL53LX_DEV Dev;

src/vl53lx_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3479,7 +3479,7 @@ typedef int8_t VL53LX_Error;
34793479
#define VL53LX_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53LX_Error) - 22)
34803480
/*!< Thrown when run_xtalk_extraction fn has 0 successful samples
34813481
* when using the full array to sample the xtalk. In this case there is
3482-
* not enough information to generate new Xtalk parm info. The function
3482+
* not enough information to generate new Xtalk param info. The function
34833483
* will exit and leave the current xtalk parameters unaltered
34843484
*/
34853485
#define VL53LX_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53LX_Error) - 23)

0 commit comments

Comments
 (0)