lis2mdl: Auto-trigger single conversion in idle mode.#73
Conversation
Observed behavior confirming the need for
|
525b973 to
663c1c0
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the LIS2MDL driver so that read methods automatically trigger a one-shot conversion when the device is in idle mode (after power_down()), aligning behavior with the repository’s “auto-trigger in power-down/idle” convention.
Changes:
- Add
LIS2MDL._ensure_data()to switch to single-conversion mode and wait fordata_ready()when the sensor is idle. - Call
_ensure_data()fromread_magnet()andread_temperature_raw()so higher-level APIs inherit the behavior. - Add new scenario tests for “read after power down” behavior in both mock and hardware modes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/lis2mdl/lis2mdl/device.py |
Adds _ensure_data() and hooks it into magnet/temperature reads to auto-trigger conversions in idle mode. |
tests/scenarios/lis2mdl.yaml |
Adds mock + hardware scenarios intended to validate “fresh reads after power down” behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🎉 This PR is included in version 0.0.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes #70
Summary
When the LIS2MDL is in idle mode (
power_down()called), reading magnetic field or temperature data now automatically triggers a single conversion and waits for data ready, instead of returning stale values._ensure_data()— checksis_idle(), sets mode to "single", pollsdata_ready()(up to 100ms)read_magnet()andread_temperature_raw()read_magnet_uT(),magnitude_uT(),read_temperature_c(),heading_flat_only(), etc.) benefit automaticallyFollows the same convention as WSEN-PADS, WSEN-HIDS, HTS221, and ISM330DL (#44).
Test plan
Mock tests (no hardware)
python3 -m pytest tests/ -k "lis2mdl and mock" -vHardware tests (STeaMi board connected)
python3 -m pytest tests/ --port /dev/ttyACM0 -k "lis2mdl and hardware" -s -v