Skip to content

vl53l1x: Check data ready and clear interrupt in read().#74

Merged
nedseb merged 2 commits intomainfrom
fix/vl53l1x-data-ready
Mar 14, 2026
Merged

vl53l1x: Check data ready and clear interrupt in read().#74
nedseb merged 2 commits intomainfrom
fix/vl53l1x-data-ready

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 13, 2026

Closes #71

Summary

The read() method now checks for data ready before reading and clears the interrupt after, ensuring fresh measurements instead of stale data.

  • start_ranging() / stop_ranging() — control ranging via SYSTEM__MODE_START (0x0087)
  • _is_data_ready() — checks GPIO__TIO_HV_STATUS (0x0031) bit 0 vs interrupt polarity
  • _clear_interrupt() — writes 0x01 to SYSTEM__INTERRUPT_CLEAR (0x0086)
  • _ensure_data() — starts ranging and polls data ready if no data available (up to 1s)
  • read() calls _ensure_data() before reading and _clear_interrupt() after

Follows the auto-trigger convention from #44.

Test plan

Mock tests (no hardware)

python3 -m pytest tests/ -k "vl53l1x and mock" -v
tests/test_scenarios.py::test_scenario[vl53l1x/Verify model ID register/mock] PASSED
tests/test_scenarios.py::test_scenario[vl53l1x/Read distance returns expected value/mock] PASSED
tests/test_scenarios.py::test_scenario[vl53l1x/Data ready check works/mock] PASSED
tests/test_scenarios.py::test_scenario[vl53l1x/Read clears interrupt/mock] PASSED
tests/test_scenarios.py::test_scenario[vl53l1x/Distance after stop and restart/mock] PASSED

5 passed

Hardware tests (STeaMi board connected)

python3 -m pytest tests/ --port /dev/ttyACM0 -k "vl53l1x and hardware" -s -v
tests/test_scenarios.py::test_scenario[vl53l1x/Verify model ID register/hardware] PASSED
tests/test_scenarios.py::test_scenario[vl53l1x/Distance in plausible range/hardware] PASSED

2 passed, 2 skipped

@nedseb nedseb changed the title vl53l1x: Check data ready and clear interrupt in read(). [WIP] vl53l1x: Check data ready and clear interrupt in read(). Mar 13, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 13, 2026
@nedseb nedseb force-pushed the fix/vl53l1x-data-ready branch from 2237105 to 157fed0 Compare March 14, 2026 21:12
@nedseb nedseb marked this pull request as ready for review March 14, 2026 21:13
@nedseb nedseb requested a review from Copilot March 14, 2026 21:15
@nedseb nedseb assigned nedseb and unassigned Charly-sketch Mar 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds data-ready checking and interrupt clearing to the VL53L1X time-of-flight sensor's read() method, ensuring fresh measurements instead of stale data. It follows the auto-trigger convention established in issue #44.

Changes:

  • Added start_ranging(), stop_ranging(), _is_data_ready(), _clear_interrupt(), and _ensure_data() methods to the VL53L1X driver
  • Modified read() to call _ensure_data() before reading and _clear_interrupt() after, while removing commented-out dead code
  • Added mock test scenarios for data-ready checking, interrupt clearing, and stop/restart behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/vl53l1x/vl53l1x/device.py Added ranging control, data-ready polling, interrupt clearing, and integrated them into read()
tests/scenarios/vl53l1x.yaml Added mock registers for new functionality and three new test scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/vl53l1x/vl53l1x/device.py
@nedseb nedseb changed the title [WIP] vl53l1x: Check data ready and clear interrupt in read(). vl53l1x: Check data ready and clear interrupt in read(). Mar 14, 2026
@nedseb nedseb merged commit 19b8744 into main Mar 14, 2026
3 checks passed
@nedseb nedseb deleted the fix/vl53l1x-data-ready branch March 14, 2026 21:52
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vl53l1x: Check data ready and clear interrupt in read().

3 participants