Skip to content

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

@nedseb

Description

@nedseb

Sub-issue of #44.

Problem

read() reads the result registers (0x0089, 17 bytes) directly without:

  1. Checking if ranging is active
  2. Polling the data ready flag before reading
  3. Clearing the interrupt after reading

If the user calls reset() then read(), stale/invalid data is returned. In continuous mode, not clearing the interrupt means subsequent reads may return the same stale result.

Solution

  • Add start_ranging(): write 0x40 to SYSTEM__MODE_START (0x0087)
  • Add stop_ranging(): write 0x00 to SYSTEM__MODE_START (0x0087)
  • Add _is_data_ready(): read GPIO__TIO_HV_STATUS (0x0031) bit 0, compare with interrupt polarity
  • Add _clear_interrupt(): write 0x01 to SYSTEM__INTERRUPT_CLEAR (0x0086)
  • Add _ensure_data(): if ranging not active, start it; poll data ready
  • Update read() to poll data ready and clear interrupt after reading
  • Add necessary register constants to const.py or inline in device.py

Reference

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdriverConcerne un driver spécifiqueenhancementNew feature or requestreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions