Skip to content

ism330dl: Add two-point temperature calibration methods.#121

Merged
nedseb merged 3 commits intomainfrom
fix/ism330dl-temp-calibration
Mar 14, 2026
Merged

ism330dl: Add two-point temperature calibration methods.#121
nedseb merged 3 commits intomainfrom
fix/ism330dl-temp-calibration

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 14, 2026

Closes #107

Summary

Add temperature calibration methods to the ISM330DL driver, consistent with the harmonized interface from #103:

  • set_temp_offset(offset_c) — simple offset correction (gain=1.0)
  • calibrate_temperature(ref_low, measured_low, ref_high, measured_high) — two-point gain+offset calibration
  • _temp_gain and _temp_offset initialized in __init__
  • temperature_c() applies calibration: gain * factory + offset

Test plan

python3 -m pytest tests/ -k "ism330dl and mock" -v

3 new mock tests (24 total):

  • Temperature offset shifts reading
  • Temperature with two-point calibration
  • Calibration rejects equal measurements

Test results

python3 -m pytest tests/ -k "ism330dl and hardware" -v --port /dev/ttyACM0 -s

======================================================= test session starts ========================================================
platform linux -- Python 3.13.7, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/nedjar/sandbox/micropython-steami-lib
configfile: pytest.ini
plugins: typeguard-4.4.2
collected 199 items / 191 deselected / 8 selected                                                                                  

tests/test_scenarios.py::test_scenario[board_i2c_scan/ISM330DL WHO_AM_I (0x6B)/hardware] 0x6A
PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Verify WHO_AM_I register/hardware] 0x6A
PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Read WHO_AM_I via method/hardware] 0x6A
PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Status returns dictionary/hardware] {'accel_ready': True, 'temp_ready': True, 'gyro_ready': True}
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] 24.17
PASSED
tests/test_scenarios.py::test_scenario[ism330dl/Sensor readings feel correct/hardware]   Acceleration (g): [-0.397171, 0.23973, -0.862296] 
  Gyroscope (dps): [-0.04375, -3.21125, 0.00875] 
  Temperature: 24.27 °C
  Orientation: SCREEN_UP 
  [MANUAL] Les valeurs d'accélération, rotation, température et orientation sont-elles cohérentes ? [Entree=oui / Echap=non] 
PASSED

================================================ 8 passed, 191 deselected in 51.01s ================================================

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 a harmonized two-point temperature calibration interface to the ISM330DL MicroPython driver (per #103 / #107), and validates it via new mock scenario tests.

Changes:

  • Initialize temperature calibration state (_temp_gain, _temp_offset) in ISM330DL.__init__().
  • Apply calibration in temperature_c() and add set_temp_offset() + calibrate_temperature() APIs.
  • Add mock scenario coverage for offset calibration, two-point calibration, and invalid calibration inputs.

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 calibration state + public calibration methods; applies gain/offset to computed factory temperature.
tests/scenarios/ism330dl.yaml Adds mock scenario tests covering offset behavior, two-point calibration result, and ValueError on invalid delta.

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

@nedseb nedseb merged commit d505f38 into main Mar 14, 2026
4 checks passed
@nedseb nedseb deleted the fix/ism330dl-temp-calibration branch March 14, 2026 20:16
@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: Add two-point temperature calibration methods.

2 participants