@@ -251,6 +251,7 @@ uint8_t VL53L1X::getDistanceMode()
251
251
}
252
252
253
253
// Set a custom zone from the array of sensors. Minimum of 4x4, maximum of 16x16.
254
+ // lower left corner of the array is (0, 0) and upper right is (16, 16)
254
255
void VL53L1X::setUserRoi (UserRoi *roi)
255
256
{
256
257
uint8_t centerX = (roi->topLeftX + roi->bottomRightX + 1 ) / 2 ;
@@ -259,9 +260,9 @@ void VL53L1X::setUserRoi(UserRoi *roi)
259
260
uint8_t height = roi->topLeftY - roi->bottomRightY ;
260
261
261
262
// Check boundary conditions, if incorrect set to default values.
262
- if (width < 3 || width > 15 || height < 3 || height > 15 ){
263
+ if (width < 3 || height < 3 ){
263
264
setCenter ((uint8_t )8 , (uint8_t )8 );
264
- setZoneSize ((uint8_t )15 , (uint8_t )8 );
265
+ setZoneSize ((uint8_t )15 , (uint8_t )15 );
265
266
}
266
267
else {
267
268
setCenter (centerX, centerY);
@@ -272,21 +273,48 @@ void VL53L1X::setUserRoi(UserRoi *roi)
272
273
void VL53L1X::setCenter (uint8_t centerX, uint8_t centerY){
273
274
uint8_t centerValue;
274
275
275
- if (centerX > 7 ){
276
- centerValue = 128 + (centerY << 3 ) + (15 - centerX );
276
+ if (centerY > 7 ){
277
+ centerValue = 128 + (centerX << 3 ) + (15 - centerY );
277
278
}
278
279
else {
279
- centerValue = ((15 - centerY ) << 3 ) + centerX ;
280
+ centerValue = ((15 - centerX ) << 3 ) + centerY ;
280
281
}
281
282
282
283
writeRegister (VL53L1_ROI_CONFIG__USER_ROI_CENTRE_SPAD , centerValue);
283
284
}
284
285
285
286
void VL53L1X::setZoneSize (uint8_t width, uint8_t height){
286
- uint8_t dimensions = (height << 4 ) + width;
287
+ uint8_t dimensions = (height << 4 ) + width;
287
288
writeRegister (VL53L1_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE, dimensions);
288
289
}
289
290
291
+ UserRoi* VL53L1X::getUserRoi (){
292
+ UserRoi* roi = new UserRoi ();
293
+
294
+ uint8_t center = readRegister (VL53L1_ROI_CONFIG__USER_ROI_CENTRE_SPAD);
295
+ uint8_t row = 0 ;
296
+ uint8_t col = 0 ;
297
+ if (center > 127 ){
298
+ row = 8 + ((255 -center) & 0x07 );
299
+ col = (center - 128 ) >> 3 ;
300
+ } else {
301
+ row = center & 0x07 ;
302
+ col = (127 - center) >> 3 ;
303
+ }
304
+
305
+ uint8_t dimensions = readRegister (VL53L1_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE);
306
+ uint8_t height = dimensions >> 4 ;
307
+ uint8_t width = dimensions & 0x0F ;
308
+
309
+
310
+ roi->topLeftX = (2 * col - width) >> 1 ;
311
+ roi->topLeftY = (2 * row - height) >> 1 ;
312
+ roi->bottomRightX = (2 * col + width) >> 1 ;
313
+ roi->bottomRightY = (2 * row + height) >> 1 ;
314
+
315
+ return roi;
316
+ }
317
+
290
318
// The sensor returns a range status that needs to be re-mapped to one of 9 different statuses
291
319
// This does that.
292
320
uint8_t VL53L1X::getRangeStatus ()
0 commit comments