Skip to content

lis2mdl: Add temperature offset correction with calibration method.#98

Merged
nedseb merged 3 commits intomainfrom
fix/lis2mdl-temp-offset
Mar 14, 2026
Merged

lis2mdl: Add temperature offset correction with calibration method.#98
nedseb merged 3 commits intomainfrom
fix/lis2mdl-temp-offset

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 13, 2026

Closes #97

Summary

  • Add LIS2MDL_TEMP_SENSITIVITY (8 LSB/°C) and LIS2MDL_TEMP_OFFSET (25°C) constants in const.py
  • Apply offset correction in read_temperature_c(): offset + raw / sensitivity instead of raw / 8.0
  • Add set_temp_offset(offset) method for runtime calibration
  • Update mock test registers (TEMP_OUT=0 → 25°C with offset)
  • Tighten hardware temperature test range to [10, 45]°C

Context

The LIS2MDL datasheet specifies 8 LSB/°C sensitivity but does not guarantee the absolute temperature offset. Hardware tests showed ~5.75°C at room temperature (~22°C), confirming the need for an offset correction.

The default offset of 25°C is an empirical starting point. The set_temp_offset() method allows per-board calibration — we plan to refine the default after testing ~100 STeaMi boards.

Test plan

  • ruff check passes
  • pytest tests/ -k "lis2mdl and mock" -v — 6/6 passed
  • pytest tests/ -k mock -v — 44/44 passed (no regressions)
  • Hardware test: pytest tests/ --port /dev/ttyACM0 -s -k lis2mdl

@nedseb nedseb requested a review from Copilot March 13, 2026 16:37
@nedseb nedseb self-assigned this Mar 13, 2026
@nedseb nedseb added the bug Something isn't working label Mar 13, 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

Adds temperature offset correction and calibration support to the LIS2MDL driver so temperature readings can be adjusted for the datasheet’s unspecified absolute offset (issue #97).

Changes:

  • Introduces LIS2MDL_TEMP_SENSITIVITY and LIS2MDL_TEMP_OFFSET constants and applies offset + raw/sensitivity conversion.
  • Adds runtime calibration via set_temp_offset().
  • Updates LIS2MDL scenario mock temperature registers and tightens the hardware plausible-range check.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
lib/lis2mdl/lis2mdl/const.py Adds temperature conversion constants used by the driver.
lib/lis2mdl/lis2mdl/device.py Applies offset-based temperature conversion and adds a calibration setter.
tests/scenarios/lis2mdl.yaml Updates mock TEMP_OUT values and tightens hardware temperature range.

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

Comment thread lib/lis2mdl/lis2mdl/const.py Outdated
Comment thread lib/lis2mdl/lis2mdl/device.py Outdated
Comment thread lib/lis2mdl/lis2mdl/device.py Outdated
Comment thread tests/scenarios/lis2mdl.yaml
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@nedseb
Copy link
Copy Markdown
Contributor Author

nedseb commented Mar 14, 2026

Suggestions Copilot prises en compte dans le commit 9c7d83d :

  1. const() wrapper sur LIS2MDL_TEMP_SENSITIVITY et LIS2MDL_TEMP_OFFSET — déjà appliqué (commit 6aa75d0).
  2. Docstring read_temperature_c() — enrichie : mention du datasheet Table 4, offset empirique, référence au PR Zephyr #35912.
  3. set_temp_offset() — paramètre renommé offset_c, coercion float(), docstring avec Args.
  4. Test mock températureexpect_not_none remplacé par expect: 25.0 (valeur exacte vérifiable avec raw=0).

@nedseb nedseb merged commit 641163f into main Mar 14, 2026
3 checks passed
@nedseb nedseb deleted the fix/lis2mdl-temp-offset branch March 14, 2026 06:53
@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

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lis2mdl: Temperature reading missing offset correction.

2 participants