@@ -36,7 +36,7 @@ def __init__(self, i2c_addr=I2C_ADDR_PRIMARY, i2c_device=None):
3636 self .set_temperature_oversample (OS_8X )
3737 self .set_filter (FILTER_SIZE_3 )
3838 self .set_gas_status (ENABLE_GAS_MEAS )
39-
39+ self . set_temp_offset ( 0 )
4040 self .get_sensor_data ()
4141
4242 def _get_calibration_data (self ):
@@ -56,6 +56,17 @@ def soft_reset(self):
5656 self ._set_regs (SOFT_RESET_ADDR , SOFT_RESET_CMD )
5757 time .sleep (RESET_PERIOD / 1000.0 )
5858
59+ def set_temp_offset (self , value ):
60+ """Set temperature offset in celsius
61+
62+ If set, the temperature t_fine will be increased by given value in celsius.
63+ :param value: Temperature offset in Celsius, eg. 4, -8, 1.25
64+ """
65+ if value == 0 :
66+ self .offset_temp_in_t_fine = 0
67+ else :
68+ self .offset_temp_in_t_fine = int (math .copysign ((((int (abs (value ) * 100 )) << 8 ) - 128 ) / 5 , value ))
69+
5970 def set_humidity_oversample (self , value ):
6071 """Set humidity oversampling
6172
@@ -293,7 +304,7 @@ def _calc_temperature(self, temperature_adc):
293304 var3 = ((var3 ) * (self .calibration_data .par_t3 << 4 )) >> 14
294305
295306 # Save teperature data for pressure calculations
296- self .calibration_data .t_fine = (var2 + var3 )
307+ self .calibration_data .t_fine = (var2 + var3 ) + self . offset_temp_in_t_fine
297308 calc_temp = (((self .calibration_data .t_fine * 5 ) + 128 ) >> 8 )
298309
299310 return calc_temp
0 commit comments