@@ -59,6 +59,8 @@ def __init__(
5959 self ._buffer_1 = bytearray (1 )
6060
6161 self ._calibration = {}
62+ self ._temp_gain = 1.0
63+ self ._temp_offset = 0.0
6264
6365 if check_device :
6466 self .check_device ()
@@ -257,7 +259,36 @@ def _convert_temperature(self, t_raw):
257259 if delta_out == 0 :
258260 raise WSENHIDSError ("Invalid temperature calibration data" )
259261
260- return ((t1_degC - t0_degC ) * (t_raw - t0_out ) / delta_out ) + t0_degC
262+ factory = ((t1_degC - t0_degC ) * (t_raw - t0_out ) / delta_out ) + t0_degC
263+ return self ._temp_gain * factory + self ._temp_offset
264+
265+ # -------------------------------------------------------------------------
266+ # Calibration
267+ # -------------------------------------------------------------------------
268+
269+ def set_temp_offset (self , offset_c ):
270+ """Set a temperature offset in °C (gain remains 1.0).
271+
272+ Args:
273+ offset_c: offset value in degrees Celsius.
274+ """
275+ self ._temp_gain = 1.0
276+ self ._temp_offset = float (offset_c )
277+
278+ def calibrate_temperature (self , ref_low , measured_low , ref_high , measured_high ):
279+ """Two-point calibration from reference measurements.
280+
281+ Computes gain and offset so that the sensor reading is adjusted
282+ to match reference values at two temperature points.
283+
284+ Args:
285+ ref_low: reference temperature at the low point (°C).
286+ measured_low: sensor reading at the low point (°C).
287+ ref_high: reference temperature at the high point (°C).
288+ measured_high: sensor reading at the high point (°C).
289+ """
290+ self ._temp_gain = float (ref_high - ref_low ) / float (measured_high - measured_low )
291+ self ._temp_offset = float (ref_low ) - self ._temp_gain * float (measured_low )
261292
262293 # -------------------------------------------------------------------------
263294 # Public measurement API
0 commit comments