Skip to content

Commit 4cb6c8b

Browse files
committed
Add ID check to begin(). Fix typo in device ID.
* Add checkID to begin to make sure the device is what we expect it is before an init. * This required PR #36 fix (thanks @rneurink!) * It looks like there was a typo in the device ID. All the units I have are 0xEACC, whereas the original code was 0xEEAC. Any idea where 0xEEAC came from? I think we're safe, I just worry a bit that there's a doc with a typo out there (not surprising with this sensor).
1 parent 1ea3ea6 commit 4cb6c8b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/SparkFun_VL53L1X.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ bool SFEVL53L1X::init()
4242

4343
bool SFEVL53L1X::begin()
4444
{
45+
if (checkID() == false)
46+
return (VL53L1_ERROR_PLATFORM_SPECIFIC_START);
47+
4548
return _device->VL53L1X_SensorInit();
4649
}
4750

@@ -51,32 +54,31 @@ bool SFEVL53L1X::checkID()
5154
{
5255
uint16_t sensorId;
5356
_device->VL53L1X_GetSensorId(&sensorId);
54-
if (sensorId == 0xEEAC)
57+
if (sensorId == 0xEACC)
5558
return true;
5659
return false;
5760
}
5861

59-
6062
/*Turns the sensor on if the Shutdown pin is connected*/
6163

6264
void SFEVL53L1X::sensorOn()
6365
{
64-
if(_shutdownPin >= 0)
65-
{
66-
digitalWrite(_shutdownPin, HIGH);
67-
}
68-
delay(10);
66+
if (_shutdownPin >= 0)
67+
{
68+
digitalWrite(_shutdownPin, HIGH);
69+
}
70+
delay(10);
6971
}
7072

7173
/*Turns the sensor off if the Shutdown pin is connected*/
7274

7375
void SFEVL53L1X::sensorOff()
7476
{
75-
if(_shutdownPin >= 0)
76-
{
77-
digitalWrite(_shutdownPin, LOW);
78-
}
79-
delay(10);
77+
if (_shutdownPin >= 0)
78+
{
79+
digitalWrite(_shutdownPin, LOW);
80+
}
81+
delay(10);
8082
}
8183

8284
/*Gets the software version number of the current library installed.*/
@@ -118,7 +120,7 @@ void SFEVL53L1X::setInterruptPolarityLow()
118120
* This function gets the interrupt polarity\n
119121
* 1=active high (default), 0=active low
120122
*/
121-
123+
122124
uint8_t SFEVL53L1X::getInterruptPolarity()
123125
{
124126
uint8_t tmp;
@@ -145,7 +147,7 @@ bool SFEVL53L1X::checkForDataReady()
145147

146148
void SFEVL53L1X::setTimingBudgetInMs(uint16_t timingBudget)
147149
{
148-
_device->VL53L1X_SetTimingBudgetInMs(timingBudget);
150+
_device->VL53L1X_SetTimingBudgetInMs(timingBudget);
149151
}
150152

151153
uint16_t SFEVL53L1X::getTimingBudgetInMs()

0 commit comments

Comments
 (0)