Skip to content

Commit ce2f0e4

Browse files
GrahldgGrahldg
authored andcommitted
Custom ROI
Added checks to verify custom zone does not exceed boundries, added documentation.
1 parent 00144f0 commit ce2f0e4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/SparkFun_VL53L1X_Arduino_Library.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,18 @@ uint8_t VL53L1X::getDistanceMode()
251251
}
252252

253253
//Set a custom zone from the array of sensors. Minimum of 4x4, maximum of 16x16.
254+
//Custom zone must be centered
254255
void VL53L1X::setUserRoi(UserRoi *roi)
255256
{
256257
uint8_t centerX = (roi->topLeftX + roi->bottomRightX + 1) / 2;
257258
uint8_t centerY = (roi->topLeftY + roi->bottomRightY + 1) / 2;
258259
uint8_t width = roi->bottomRightX - roi->topLeftX;
259260
uint8_t height = roi->topLeftY - roi->bottomRightY;
260261

261-
if (width < 3 || height < 3){
262-
return;
262+
//Check boundary conditions, if incorrect set to default values.
263+
if (width < 3 || width > 15 || height < 3 || height > 15){
264+
setCenter((uint8_t)8, (uint8_t)8);
265+
setZoneSize((uint8_t)15, (uint8_t)8);
263266
}
264267
else{
265268
setCenter(centerX, centerY);

0 commit comments

Comments
 (0)