Context
The multidriver temperature comparison test (PR #100) revealed discrepancies between sensors on the same board. Some were due to bugs (WSEN-HIDS AUTO_INCREMENT, fixed in #109), others to missing calibration (LIS2MDL empirical offset, fixed in PR #98).
To allow per-board fine-tuning during manufacturing or at runtime, all temperature-capable drivers should expose a uniform two-point calibration interface.
Proposed interface
Every driver with a temperature reading should implement:
def set_temp_offset(self, offset_c):
"""Set a temperature offset in °C (gain remains 1.0)."""
self._temp_offset = float(offset_c)
self._temp_gain = 1.0
def calibrate_temperature(self, ref_low, measured_low, ref_high, measured_high):
"""Two-point calibration: compute gain and offset from reference values.
Args:
ref_low: reference temperature at the low point (°C).
measured_low: sensor reading at the low point (°C).
ref_high: reference temperature at the high point (°C).
measured_high: sensor reading at the high point (°C).
"""
self._temp_gain = (ref_high - ref_low) / (measured_high - measured_low)
self._temp_offset = ref_low - self._temp_gain * measured_low
The temperature() method then applies:
return self._temp_gain * raw_or_factory_value + self._temp_offset
Default values: gain=1.0, offset=0.0 (identity) for sensors with factory calibration,
gain=1.0, offset=25.0 for LIS2MDL (no factory zero point).
Sensors concerned
| Sensor |
Issue |
Factory calibration |
Default offset |
Status |
| LIS2MDL |
#97 |
None (raw LSB) |
25.0°C |
✅ Done (PR #98, updated with two-point) |
| WSEN-HIDS |
#105 |
Yes (T0/T1 registers) |
0.0°C |
✅ Done |
| HTS221 |
#104 |
Yes (T0/T1 registers) |
0.0°C |
✅ Done |
| WSEN-PADS |
#106 |
Implicit |
0.0°C |
✅ Done |
| ISM330DL |
#107 |
None specified |
25.0°C |
✅ Done |
| BME280 |
#108 |
Yes (trimming) |
0.0°C |
Tracked separately (blocked by #9) |
Acceptance criteria
Resolution
All existing drivers now implement the harmonized set_temp_offset() / calibrate_temperature() interface. The BME280 calibration is tracked in #108 and will be implemented when the BME280 driver (#9) is completed.
Related
Context
The multidriver temperature comparison test (PR #100) revealed discrepancies between sensors on the same board. Some were due to bugs (WSEN-HIDS AUTO_INCREMENT, fixed in #109), others to missing calibration (LIS2MDL empirical offset, fixed in PR #98).
To allow per-board fine-tuning during manufacturing or at runtime, all temperature-capable drivers should expose a uniform two-point calibration interface.
Proposed interface
Every driver with a temperature reading should implement:
The
temperature()method then applies:Default values:
gain=1.0, offset=0.0(identity) for sensors with factory calibration,gain=1.0, offset=25.0for LIS2MDL (no factory zero point).Sensors concerned
Acceptance criteria
Resolution
All existing drivers now implement the harmonized
set_temp_offset()/calibrate_temperature()interface. The BME280 calibration is tracked in #108 and will be implemented when the BME280 driver (#9) is completed.Related