Skip to content

Update adafruit_vl53l1x.py #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions adafruit_vl53l1x.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ def distance_mode(self, mode):
def roi_xy(self):
"""Returns the x and y coordinates of the sensor's region of interest"""
temp = self._read_register(_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE)

x = (int.from_bytes(temp) & 0x0F) + 1
y = ((int.from_bytes(temp) & 0xF0) >> 4) + 1
x = (int.from_bytes(temp, "little") & 0x0F) + 1
y = ((int.from_bytes(temp, "little") & 0xF0) >> 4) + 1

return x, y

Expand All @@ -319,22 +318,24 @@ def roi_xy(self, data):
optical_center = 199

self._write_register(
_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes()
_ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes(1, "little")
)
self._write_register(
_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
((y - 1) << 4 | (x - 1)).to_bytes(),
((y - 1) << 4 | (x - 1)).to_bytes(1, "little"),
)

@property
def roi_center(self):
"""Returns the center of the sensor's region of interest"""
temp = self._read_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD)
return int.from_bytes(temp)
return int.from_bytes(temp, "little")

@roi_center.setter
def roi_center(self, center):
self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes())
self._write_register(
_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes(1, "little")
)

def _write_register(self, address, data, length=None):
if length is None:
Expand Down
Loading