Skip to content

Commit 0b7525a

Browse files
Update adafruit_vl53l1x.py
1 parent 4f88df7 commit 0b7525a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

adafruit_vl53l1x.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from adafruit_bus_device import i2c_device
3232
from micropython import const
3333

34-
__version__ = "0.0.0+auto.0"
34+
__version__ = "1.1.14"
3535
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VL53L1X.git"
3636

3737
_VL53L1X_I2C_SLAVE_DEVICE_ADDRESS = const(0x0001)
@@ -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)
@@ -294,7 +296,35 @@ def distance_mode(self, mode):
294296
else:
295297
raise ValueError("Unsupported mode.")
296298
self.timing_budget = self._timing_budget
299+
300+
def set_roi(self, x, y):
301+
optical_center = 0
297302

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+
298328
def _write_register(self, address, data, length=None):
299329
if length is None:
300330
length = len(data)

0 commit comments

Comments
 (0)