From c3e206b422c8d0fc7bb5238d1869ded355b9a787 Mon Sep 17 00:00:00 2001 From: JohnFFlanagan Date: Thu, 2 Jan 2025 10:22:20 -0600 Subject: [PATCH 1/4] Update adafruit_vl53l1x.py Proposed changes --- adafruit_vl53l1x.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/adafruit_vl53l1x.py b/adafruit_vl53l1x.py index 9e6ebfd..ba22f8e 100644 --- a/adafruit_vl53l1x.py +++ b/adafruit_vl53l1x.py @@ -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 @@ -319,22 +318,22 @@ 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: From ee74252ee46e4aa7825576fe2ea21ca860f2b6ce Mon Sep 17 00:00:00 2001 From: JohnFFlanagan Date: Thu, 2 Jan 2025 12:51:32 -0600 Subject: [PATCH 2/4] Update adafruit_vl53l1x.py Change single to double quotes --- adafruit_vl53l1x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_vl53l1x.py b/adafruit_vl53l1x.py index ba22f8e..1f36b81 100644 --- a/adafruit_vl53l1x.py +++ b/adafruit_vl53l1x.py @@ -301,7 +301,7 @@ 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, 'little') & 0x0F) + 1 + x = (int.from_bytes(temp) & 0x0F) + 1 y = ((int.from_bytes(temp, 'little') & 0xF0) >> 4) + 1 return x, y From a7e6843a3b9dca3b086951e837cbdb596266d872 Mon Sep 17 00:00:00 2001 From: JohnFFlanagan Date: Thu, 2 Jan 2025 13:00:28 -0600 Subject: [PATCH 3/4] Update adafruit_vl53l1x.py Fixed last update that only fixed first issue. --- adafruit_vl53l1x.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_vl53l1x.py b/adafruit_vl53l1x.py index 1f36b81..31c168b 100644 --- a/adafruit_vl53l1x.py +++ b/adafruit_vl53l1x.py @@ -301,8 +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, 'little') & 0xF0) >> 4) + 1 + x = (int.from_bytes(temp, "little") & 0x0F) + 1 + y = ((int.from_bytes(temp, "little") & 0xF0) >> 4) + 1 return x, y @@ -318,18 +318,18 @@ def roi_xy(self, data): optical_center = 199 self._write_register( - _ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes(1,'little') + _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(1,'little'), + ((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, 'little') + return int.from_bytes(temp, "little") @roi_center.setter def roi_center(self, center): From 9efea710e660342b060813be3e0c314b4601ef3f Mon Sep 17 00:00:00 2001 From: JohnFFlanagan Date: Thu, 2 Jan 2025 13:14:55 -0600 Subject: [PATCH 4/4] More format issues After LOTS of phython issue got "black" to run. --- adafruit_vl53l1x.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adafruit_vl53l1x.py b/adafruit_vl53l1x.py index 31c168b..94e2e84 100644 --- a/adafruit_vl53l1x.py +++ b/adafruit_vl53l1x.py @@ -318,11 +318,11 @@ def roi_xy(self, data): optical_center = 199 self._write_register( - _ROI_CONFIG__USER_ROI_CENTRE_SPAD, optical_center.to_bytes(1,"little") + _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(1,"little"), + ((y - 1) << 4 | (x - 1)).to_bytes(1, "little"), ) @property @@ -333,7 +333,9 @@ def roi_center(self): @roi_center.setter def roi_center(self, center): - self._write_register(_ROI_CONFIG__USER_ROI_CENTRE_SPAD, center.to_bytes(1,'little')) + 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: