Skip to content

Subtract demominator by one #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions adafruit_scd4x.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,14 @@ def _read_data(self) -> None:
"""Reads the temp/hum/co2 from the sensor and caches it"""
self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001)
self._read_reply(self._buffer, 9)
# CO2 = word[0]
self._co2 = (self._buffer[0] << 8) | self._buffer[1]
temp = (self._buffer[3] << 8) | self._buffer[4]
self._temperature = -45 + 175 * (temp / 2**16)
# T = -45 + 175 * (word[1] / 2**16 - 1)
self._temperature = -45 + 175 * (temp / 65535)
humi = (self._buffer[6] << 8) | self._buffer[7]
self._relative_humidity = 100 * (humi / 2**16)
# RH = 100 * (word[2] / (2**16 - 1))
self._relative_humidity = 100 * (humi / 65535)

@property
def data_ready(self) -> bool:
Expand Down Expand Up @@ -285,7 +288,7 @@ def set_ambient_pressure(self, ambient_pressure: int) -> None:
def temperature_offset(self) -> float:
"""Specifies the offset to be added to the reported measurements to account for a bias in
the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a
maximum value of 374 C
maximum value of 374 C.

.. note::
This value will NOT be saved and will be reset on boot unless saved with
Expand All @@ -295,15 +298,15 @@ def temperature_offset(self) -> float:
self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001)
self._read_reply(self._buffer, 3)
temp = (self._buffer[0] << 8) | self._buffer[1]
return 175.0 * temp / 2**16
return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1))

@temperature_offset.setter
def temperature_offset(self, offset: Union[int, float]) -> None:
if offset > 374:
raise AttributeError(
"Offset value must be less than or equal to 374 degrees Celsius"
)
temp = int(offset * 2**16 / 175)
temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175)
self._set_command_value(_SCD4X_SETTEMPOFFSET, temp)

@property
Expand Down