lis2mdl: Add temperature offset correction with calibration method.#98
Merged
lis2mdl: Add temperature offset correction with calibration method.#98
Conversation
Contributor
There was a problem hiding this comment.
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_SENSITIVITYandLIS2MDL_TEMP_OFFSETconstants and appliesoffset + raw/sensitivityconversion. - 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Mar 14, 2026
Contributor
Author
|
Suggestions Copilot prises en compte dans le commit 9c7d83d :
|
This was referenced Mar 14, 2026
|
🎉 This PR is included in version 0.0.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #97
Summary
LIS2MDL_TEMP_SENSITIVITY(8 LSB/°C) andLIS2MDL_TEMP_OFFSET(25°C) constants inconst.pyread_temperature_c():offset + raw / sensitivityinstead ofraw / 8.0set_temp_offset(offset)method for runtime calibrationContext
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 checkpassespytest tests/ -k "lis2mdl and mock" -v— 6/6 passedpytest tests/ -k mock -v— 44/44 passed (no regressions)pytest tests/ --port /dev/ttyACM0 -s -k lis2mdl