Skip to content

Fix time conversion in measurement_timing_budget #6

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

Merged
merged 1 commit into from
Aug 13, 2018
Merged
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
6 changes: 5 additions & 1 deletion adafruit_vl53l0x.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def _timeout_mclks_to_microseconds(timeout_period_mclks, vcsel_period_pclks):
macro_period_ns = (((2304 * (vcsel_period_pclks) * 1655) + 500) // 1000)
return ((timeout_period_mclks * macro_period_ns) + (macro_period_ns // 2)) // 1000

def _timeout_microseconds_to_mclks(timeout_period_us, vcsel_period_pclks):
macro_period_ns = (((2304 * (vcsel_period_pclks) * 1655) + 500) // 1000)
return ((timeout_period_us * 1000) + (macro_period_ns // 2)) // macro_period_ns

class VL53L0X:
"""Driver for the VL53L0X distance sensor."""
# Class-level buffer for reading and writing data with the sensor.
Expand Down Expand Up @@ -477,7 +481,7 @@ def measurement_timing_budget(self, budget_us):
if used_budget_us > budget_us:
raise ValueError('Requested timeout too big.')
final_range_timeout_us = budget_us - used_budget_us
final_range_timeout_mclks = _timeout_mclks_to_microseconds(
final_range_timeout_mclks = _timeout_microseconds_to_mclks(
final_range_timeout_us,
final_range_vcsel_period_pclks)
if pre_range:
Expand Down