|
31 | 31 | from adafruit_bus_device import i2c_device
|
32 | 32 | from micropython import const
|
33 | 33 |
|
34 |
| -__version__ = "0.0.0+auto.0" |
| 34 | +__version__ = "1.1.14" |
35 | 35 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VL53L1X.git"
|
36 | 36 |
|
37 | 37 | _VL53L1X_I2C_SLAVE_DEVICE_ADDRESS = const(0x0001)
|
|
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)
|
@@ -294,7 +296,35 @@ def distance_mode(self, mode):
|
294 | 296 | else:
|
295 | 297 | raise ValueError("Unsupported mode.")
|
296 | 298 | self.timing_budget = self._timing_budget
|
| 299 | + |
| 300 | + def set_roi(self, x, y): |
| 301 | + optical_center = 0 |
297 | 302 |
|
| 303 | + if x > 16: |
| 304 | + x = 16 |
| 305 | + if y > 16: |
| 306 | + y = 16 |
| 307 | + if x > 10 or y > 10: |
| 308 | + optical_center = 199 |
| 309 | + |
| 310 | + self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes()); |
| 311 | + self._write_register(_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE, ((y - 1) << 4 | (x - 1)).to_bytes()) |
| 312 | + |
| 313 | + def get_roi(self): |
| 314 | + temp = self._read_register(_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE); |
| 315 | + |
| 316 | + x = (int.from_bytes(temp) & 0x0F) + 1 |
| 317 | + y = ((int.from_bytes(temp) & 0xF0) >> 4) + 1 |
| 318 | + |
| 319 | + return x, y |
| 320 | + |
| 321 | + def set_roi_center(self, center): |
| 322 | + self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes()) |
| 323 | + |
| 324 | + def get_roi_center(self): |
| 325 | + temp = self._read_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD) |
| 326 | + return int.from_bytes(temp) |
| 327 | + |
298 | 328 | def _write_register(self, address, data, length=None):
|
299 | 329 | if length is None:
|
300 | 330 | length = len(data)
|
|
0 commit comments