Skip to content

Commit 7a9789d

Browse files
authored
Merge pull request #28 from tekktrik/dev/fix-setting-delay
Add ValueError to start_range_continuous()
2 parents afcb59e + 374eaf9 commit 7a9789d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

adafruit_vl6180x.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,17 @@ def range_history_enabled(self) -> bool:
170170
def start_range_continuous(self, period: int = 100) -> None:
171171
"""Start continuous range mode
172172
173-
:param int period: Time delay between measurements, in milliseconds
173+
:param int period: Time delay between measurements, in milliseconds; the value you
174+
will be floored to the nearest 10 milliseconds (setting to 157 ms sets it to 150
175+
ms). Range is 10 - 2550 ms.
174176
"""
175177
# Set range between measurements
176-
period_reg: int = 0
177-
if period > 10:
178-
if period < 2250:
179-
period_reg = (period // 10) - 1
180-
else:
181-
period_reg = 254
178+
if not 10 <= period <= 2550:
179+
raise ValueError(
180+
"Delay must be in 10 millisecond increments between 10 and 2550 milliseconds"
181+
)
182+
183+
period_reg = (period // 10) - 1
182184
self._write_8(_VL6180X_REG_SYSRANGE_INTERMEASUREMENT_PERIOD, period_reg)
183185

184186
# Start continuous range measurement

0 commit comments

Comments
 (0)