Sub-issue of #44.
Problem
read() reads the result registers (0x0089, 17 bytes) directly without:
- Checking if ranging is active
- Polling the data ready flag before reading
- 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
Sub-issue of #44.
Problem
read()reads the result registers (0x0089, 17 bytes) directly without:If the user calls
reset()thenread(), stale/invalid data is returned. In continuous mode, not clearing the interrupt means subsequent reads may return the same stale result.Solution
start_ranging(): write 0x40 to SYSTEM__MODE_START (0x0087)stop_ranging(): write 0x00 to SYSTEM__MODE_START (0x0087)_is_data_ready(): read GPIO__TIO_HV_STATUS (0x0031) bit 0, compare with interrupt polarity_clear_interrupt(): write 0x01 to SYSTEM__INTERRUPT_CLEAR (0x0086)_ensure_data(): if ranging not active, start it; poll data readyread()to poll data ready and clear interrupt after readingconst.pyor inline indevice.pyReference
VL53L1X_CheckForDataReady(),VL53L1X_ClearInterrupt()_ensure_data()pattern (PR wsen-pads: Add pressure sensor driver. #3)