Skip to content

Commit aaff860

Browse files
authored
Merge pull request #25 from apzerafa/main
enables ROI useage
2 parents 3f15840 + c1bcf4d commit aaff860

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

adafruit_vl53l1x.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ def roi_xy(self):
297297
"""Returns the x and y coordinates of the sensor's region of interest"""
298298
temp = self._read_register(_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE)
299299

300-
x = (int.from_bytes(temp) & 0x0F) + 1
301-
y = ((int.from_bytes(temp) & 0xF0) >> 4) + 1
300+
x = (int.from_bytes(temp, "big") & 0x0F) + 1
301+
y = ((int.from_bytes(temp, "big") & 0xF0) >> 4) + 1
302302

303303
return x, y
304304

@@ -313,21 +313,46 @@ def roi_xy(self, data):
313313
if x > 10 or y > 10:
314314
optical_center = 199
315315

316-
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes())
316+
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes(1, "big"))
317317
self._write_register(
318318
_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
319-
((y - 1) << 4 | (x - 1)).to_bytes(),
320-
) # noqa: E501
319+
((y - 1) << 4 | (x - 1)).to_bytes(1, "big"),
320+
)
321321

322322
@property
323323
def roi_center(self):
324-
"""Returns the center of the sensor's region of interest"""
324+
"""The center of the sensor's region of interest.
325+
To set the center, set the pad that is to the right and above the
326+
exact center of the region you'd like to measure as your opticalCenter.
327+
You must change the roi_xy value to somtheing smaller than 16x16
328+
in order to use any center value other than 199.
329+
330+
.. code-block::
331+
332+
128,136,144,152,160,168,176,184, 192,200,208,216,224,232,240,248
333+
129,137,145,153,161,169,177,185, 193,201,209,217,225,233,241,249
334+
130,138,146,154,162,170,178,186, 194,202,210,218,226,234,242,250
335+
131,139,147,155,163,171,179,187, 195,203,211,219,227,235,243,251
336+
132,140,148,156,164,172,180,188, 196,204,212,220,228,236,244,252
337+
133,141,149,157,165,173,181,189, 197,205,213,221,229,237,245,253
338+
134,142,150,158,166,174,182,190, 198,206,214,222,230,238,246,254
339+
135,143,151,159,167,175,183,191, 199,207,215,223,231,239,247,255
340+
341+
127,119,111,103, 95, 87, 79, 71, 63, 55, 47, 39, 31, 23, 15, 7
342+
126,118,110,102, 94, 86, 78, 70, 62, 54, 46, 38, 30, 22, 14, 6
343+
125,117,109,101, 93, 85, 77, 69, 61, 53, 45, 37, 29, 21, 13, 5
344+
124,116,108,100, 92, 84, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4
345+
123,115,107, 99, 91, 83, 75, 67, 59, 51, 43, 35, 27, 19, 11, 3
346+
122,114,106, 98, 90, 82, 74, 66, 58, 50, 42, 34, 26, 18, 10, 2
347+
121,113,105, 97, 89, 81, 73, 65, 57, 49, 41, 33, 25, 17, 9, 1
348+
120,112,104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0
349+
"""
325350
temp = self._read_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD)
326-
return int.from_bytes(temp)
351+
return int.from_bytes(temp, "big")
327352

328353
@roi_center.setter
329354
def roi_center(self, center):
330-
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes())
355+
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes(1, "big"))
331356

332357
def _write_register(self, address, data, length=None):
333358
if length is None:

0 commit comments

Comments
 (0)