Skip to content

Commit a5ebcca

Browse files
authored
Merge pull request #20 from TheIllusionist77/main
Added getter and setter functions for ROI
2 parents 4f88df7 + 6a71ae1 commit a5ebcca

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

adafruit_vl53l1x.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
_RANGE_CONFIG__VALID_PHASE_HIGH = const(0x0069)
4747
_SD_CONFIG__WOI_SD0 = const(0x0078)
4848
_SD_CONFIG__INITIAL_PHASE_SD0 = const(0x007A)
49+
_ROI_CONFIG__USER_ROI_CENTRE_SPAD = const(0x007F)
50+
_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE = const(0x0080)
4951
_SYSTEM__INTERRUPT_CLEAR = const(0x0086)
5052
_SYSTEM__MODE_START = const(0x0087)
5153
_VL53L1X_RESULT__RANGE_STATUS = const(0x0089)
@@ -295,6 +297,45 @@ def distance_mode(self, mode):
295297
raise ValueError("Unsupported mode.")
296298
self.timing_budget = self._timing_budget
297299

300+
@property
301+
def roi_xy(self):
302+
"""Returns the x and y coordinates of the sensor's region of interest"""
303+
temp = self._read_register(_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE)
304+
305+
x = (int.from_bytes(temp) & 0x0F) + 1
306+
y = ((int.from_bytes(temp) & 0xF0) >> 4) + 1
307+
308+
return x, y
309+
310+
@roi_xy.setter
311+
def roi_xy(self, data):
312+
x, y = data
313+
optical_center = 0
314+
315+
x = min(x, 16)
316+
y = min(y, 16)
317+
318+
if x > 10 or y > 10:
319+
optical_center = 199
320+
321+
self._write_register(
322+
_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes()
323+
)
324+
self._write_register(
325+
_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
326+
((y - 1) << 4 | (x - 1)).to_bytes(),
327+
)
328+
329+
@property
330+
def roi_center(self):
331+
"""Returns the center of the sensor's region of interest"""
332+
temp = self._read_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD)
333+
return int.from_bytes(temp)
334+
335+
@roi_center.setter
336+
def roi_center(self, center):
337+
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes())
338+
298339
def _write_register(self, address, data, length=None):
299340
if length is None:
300341
length = len(data)

0 commit comments

Comments
 (0)