Skip to content

ism330dl: Auto-trigger conversion when reading after power down.#124

Merged
nedseb merged 3 commits intomainfrom
fix/ism330dl-auto-trigger
Mar 14, 2026
Merged

ism330dl: Auto-trigger conversion when reading after power down.#124
nedseb merged 3 commits intomainfrom
fix/ism330dl-auto-trigger

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 14, 2026

Closes #123

Summary

When the ISM330DL is in power-down mode (power_down() called), reading acceleration, gyroscope, or temperature data now automatically restores the previous ODR configuration and waits for fresh data, instead of returning stale values.

  • _is_power_down() — checks if both CTRL1_XL and CTRL2_G have ODR=0
  • _ensure_data() — restores saved ODR/scale and waits 100ms for data ready
  • _accel_odr / _gyro_odr — track the last non-zero ODR to enable restoration
  • Called in acceleration_raw(), gyroscope_raw(), temperature_raw()

Follows the same convention as WSEN-PADS, WSEN-HIDS, and HTS221 (#44).

Test plan

Mock tests (no hardware)

python3 -m pytest tests/ -k "ism330dl and mock" -v
tests/test_scenarios.py::test_scenario[ism330dl/Verify WHO_AM_I register/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Read WHO_AM_I via method/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Status returns all ready flags/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Acceleration raw returns tuple of 3 ints/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Acceleration g returns expected values/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Acceleration ms2 matches g times 9.80665/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Gyroscope raw returns tuple of 3 ints/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Gyroscope dps returns zeros when static/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Gyroscope rads consistent with dps/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature returns 25.0 from mock data/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature raw returns int/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature offset shifts reading/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature with two-point calibration/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Calibration rejects equal measurements/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Orientation detects SCREEN_DOWN/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Motion returns STABLE when static/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure accel writes correct register value/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure gyro writes correct register value/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure accel rejects invalid scale/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure accel rejects invalid ODR/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure gyro rejects invalid scale/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Configure gyro rejects invalid ODR/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Power down writes zero to CTRL registers/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Reset sets BDU and IF_INC in CTRL3_C/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Acceleration readable after power down/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Gyroscope readable after power down/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature readable after power down/mock] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Auto-trigger restores ODR after power down/mock] PASSED

28 passed

Hardware tests (STeaMi board connected)

python3 -m pytest tests/ --port /dev/ttyACM0 -k "ism330dl and hardware" -s -v
tests/test_scenarios.py::test_scenario[ism330dl/Verify WHO_AM_I register/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Read WHO_AM_I via method/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Status returns dictionary/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Acceleration magnitude near 1g/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Gyroscope values plausible at rest/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Temperature in plausible range/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Fresh acceleration after power down/hardware] PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Fresh temperature after power down/hardware] PASSED

8 passed, 2 skipped (board_i2c_scan uses legacy 0x6B, manual test requires interactive mode)

@nedseb nedseb requested a review from Copilot March 14, 2026 20:45
@nedseb nedseb self-assigned this Mar 14, 2026
@nedseb nedseb added the enhancement New feature or request label 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 auto-trigger conversion support to the ISM330DL driver when the sensor is in power-down mode. After power_down() is called, reading acceleration, gyroscope, or temperature data now automatically restores the previous ODR configuration and waits for fresh data instead of returning stale values.

Changes:

  • Added _is_power_down() and _ensure_data() methods plus _accel_odr/_gyro_odr tracking fields to auto-restore sensor configuration on read after power-down
  • Hooked _ensure_data() into acceleration_raw(), gyroscope_raw(), and temperature_raw()
  • Added 4 mock test scenarios verifying read-after-power-down behavior and ODR restoration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/ism330dl/ism330dl/device.py Adds ODR tracking, _is_power_down(), _ensure_data(), and hooks them into raw read methods
tests/scenarios/ism330dl.yaml Adds 4 mock test scenarios for auto-trigger behavior after power down

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

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 auto-trigger conversion support for the ISM330DL driver. When the sensor is in power-down mode, reading acceleration, gyroscope, or temperature data now automatically restores the previous ODR/scale configuration and waits for fresh data before returning values. This follows the established convention used in WSEN-PADS, WSEN-HIDS, and HTS221 drivers.

Changes:

  • Added _is_power_down() and _ensure_data() methods plus _accel_odr/_gyro_odr state tracking to enable auto-trigger on read after power down.
  • Hooked _ensure_data() into acceleration_raw(), gyroscope_raw(), and temperature_raw().
  • Added 8 new YAML test scenarios covering auto-trigger behavior in both mock and hardware modes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/ism330dl/ism330dl/device.py Added ODR tracking fields, _is_power_down(), _ensure_data(), and calls in raw reading methods.
tests/scenarios/ism330dl.yaml Added mock and hardware test scenarios for read-after-power-down behavior.

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

@nedseb nedseb merged commit 1492c3e into main Mar 14, 2026
7 checks passed
@nedseb nedseb deleted the fix/ism330dl-auto-trigger branch March 14, 2026 21:01
@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.

ism330dl: Ensure read methods auto-trigger conversion in power-down mode.

2 participants