Skip to content

drivers: Harmonize two-point temperature calibration across all sensors. #103

@nedseb

Description

@nedseb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorNettoyage/harmonisation sans changement fonctionnel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions