Skip to content

Commit 6766971

Browse files
committed
Add ValueError to start_range_continuous()
Refactors `start_range_continuous()` and also adds throwing ValueError if out of range.
1 parent 9da9424 commit 6766971

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

adafruit_vl6180x.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,16 @@ 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 will be floored
174+
to the nearest 10 milliseconds (setting to 157 ms sets it to 150 ms). Range is 10 - 2550 ms.
174175
"""
175176
# 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
177+
if not 10 <= period <= 2550:
178+
raise ValueError(
179+
"Delay must be in 10 millisecond increments between 10 and 2550 milliseconds"
180+
)
181+
182+
period_reg = (period // 10) - 1
182183
self._write_8(_VL6180X_REG_SYSRANGE_INTERMEASUREMENT_PERIOD, period_reg)
183184

184185
# Start continuous range measurement

0 commit comments

Comments
 (0)