Skip to content

Commit d1fcdcc

Browse files
authored
Merge pull request #6 from rlake/time_conversion
Fix time conversion in measurement_timing_budget
2 parents e397455 + 22ff34e commit d1fcdcc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

adafruit_vl53l0x.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ def _timeout_mclks_to_microseconds(timeout_period_mclks, vcsel_period_pclks):
140140
macro_period_ns = (((2304 * (vcsel_period_pclks) * 1655) + 500) // 1000)
141141
return ((timeout_period_mclks * macro_period_ns) + (macro_period_ns // 2)) // 1000
142142

143+
def _timeout_microseconds_to_mclks(timeout_period_us, vcsel_period_pclks):
144+
macro_period_ns = (((2304 * (vcsel_period_pclks) * 1655) + 500) // 1000)
145+
return ((timeout_period_us * 1000) + (macro_period_ns // 2)) // macro_period_ns
146+
143147
class VL53L0X:
144148
"""Driver for the VL53L0X distance sensor."""
145149
# Class-level buffer for reading and writing data with the sensor.
@@ -477,7 +481,7 @@ def measurement_timing_budget(self, budget_us):
477481
if used_budget_us > budget_us:
478482
raise ValueError('Requested timeout too big.')
479483
final_range_timeout_us = budget_us - used_budget_us
480-
final_range_timeout_mclks = _timeout_mclks_to_microseconds(
484+
final_range_timeout_mclks = _timeout_microseconds_to_mclks(
481485
final_range_timeout_us,
482486
final_range_vcsel_period_pclks)
483487
if pre_range:

0 commit comments

Comments
 (0)