|
46 | 46 | _RANGE_CONFIG__VALID_PHASE_HIGH = const(0x0069)
|
47 | 47 | _SD_CONFIG__WOI_SD0 = const(0x0078)
|
48 | 48 | _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) |
49 | 51 | _SYSTEM__INTERRUPT_CLEAR = const(0x0086)
|
50 | 52 | _SYSTEM__MODE_START = const(0x0087)
|
51 | 53 | _VL53L1X_RESULT__RANGE_STATUS = const(0x0089)
|
@@ -295,6 +297,45 @@ def distance_mode(self, mode):
|
295 | 297 | raise ValueError("Unsupported mode.")
|
296 | 298 | self.timing_budget = self._timing_budget
|
297 | 299 |
|
| 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 | + |
298 | 339 | def _write_register(self, address, data, length=None):
|
299 | 340 | if length is None:
|
300 | 341 | length = len(data)
|
|
0 commit comments