@@ -211,14 +211,18 @@ def self_test(self) -> None:
211
211
raise RuntimeError ("Self test failed" )
212
212
213
213
def _read_data (self ) -> None :
214
- """Reads the temp/hum/co2 from the sensor and caches it"""
214
+ """Reads the temp/hum/co2 from the sensor and caches it.
215
+ Equations used for calculation:
216
+ CO2 = word[0]
217
+ T = -45 + 175 * (word[1] / (2**16 - 1))
218
+ RH = 100 * (word[2] / (2**16 - 1))"""
215
219
self ._send_command (_SCD4X_READMEASUREMENT , cmd_delay = 0.001 )
216
220
self ._read_reply (self ._buffer , 9 )
217
221
self ._co2 = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
218
222
temp = (self ._buffer [3 ] << 8 ) | self ._buffer [4 ]
219
- self ._temperature = - 45 + 175 * (temp / ( 2 ** 16 - 1 ) )
223
+ self ._temperature = - 45 + 175 * (temp / 65535 )
220
224
humi = (self ._buffer [6 ] << 8 ) | self ._buffer [7 ]
221
- self ._relative_humidity = 100 * (humi / ( 2 ** 16 - 1 ) )
225
+ self ._relative_humidity = 100 * (humi / 65535 )
222
226
223
227
@property
224
228
def data_ready (self ) -> bool :
@@ -285,7 +289,9 @@ def set_ambient_pressure(self, ambient_pressure: int) -> None:
285
289
def temperature_offset (self ) -> float :
286
290
"""Specifies the offset to be added to the reported measurements to account for a bias in
287
291
the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a
288
- maximum value of 374 C
292
+ maximum value of 374 C.
293
+ Equation used for calculation:
294
+ T_offset = word[0] * (175 / (2**16 - 1))
289
295
290
296
.. note::
291
297
This value will NOT be saved and will be reset on boot unless saved with
@@ -295,15 +301,17 @@ def temperature_offset(self) -> float:
295
301
self ._send_command (_SCD4X_GETTEMPOFFSET , cmd_delay = 0.001 )
296
302
self ._read_reply (self ._buffer , 3 )
297
303
temp = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
298
- return 175.0 * temp / 2 ** 16
304
+ return temp * 175.0 / 65535
299
305
300
306
@temperature_offset .setter
301
307
def temperature_offset (self , offset : Union [int , float ]) -> None :
308
+ """Equation used for calculation:
309
+ word[0] = T_offset * ((2**16 -1) / 175)"""
302
310
if offset > 374 :
303
311
raise AttributeError (
304
312
"Offset value must be less than or equal to 374 degrees Celsius"
305
313
)
306
- temp = int (offset * 2 ** 16 / 175 )
314
+ temp = int (offset * 65535 / 175 )
307
315
self ._set_command_value (_SCD4X_SETTEMPOFFSET , temp )
308
316
309
317
@property
0 commit comments