Skip to content

Commit

Permalink
Add Temperature Oversampling
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-eng committed Jan 31, 2025
1 parent 4e6ba64 commit 3199526
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion adafruit_mlx90393.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__( # pylint: disable=too-many-arguments
filt: int = FILTER_7,
oversampling: int = OSR_3,
temperature_compensation: bool = False,
temperature_oversampling: int = OSR_0,
offset: int = 0,
debug: bool = False,
) -> None:
Expand All @@ -226,6 +227,7 @@ def __init__( # pylint: disable=too-many-arguments
self._osr = oversampling
self._gain_current = gain
self._temperature_compensation = temperature_compensation
self._osr2 = temperature_oversampling
# Typical value according the application note
self._tref = 0xB668
self._off_x = self._off_y = self._off_z = offset
Expand All @@ -247,6 +249,7 @@ def __init__( # pylint: disable=too-many-arguments
# Set gain to the supplied level
self.gain = self._gain_current
self.temperature_compensation = self._temperature_compensation
self.temperature_oversampling = self._osr2

# Set offsets to supplied level
self.offset_x = self._off_x
Expand Down Expand Up @@ -387,7 +390,7 @@ def filter(self, level: int) -> None:

@property
def oversampling(self) -> int:
"""The oversampling level."""
"""The magnetic sensor oversampling level."""
return self._osr

@oversampling.setter
Expand All @@ -414,6 +417,21 @@ def temperature_compensation(self, temperature_compensation: bool) -> None:
self.write_reg(_CMD_REG_CONF2, reg)
self._temperature_compensation = temperature_compensation

@property
def temperature_oversampling(self) -> int:
"""The temperature sensor oversampling level."""
return self._osr2

@temperature_oversampling.setter
def temperature_oversampling(self, level: int) -> None:
if level not in range(4):
raise ValueError("Incorrect oversampling level.")
reg = self.read_reg(_CMD_REG_CONF3)
reg &= 0xE7FF
reg |= (level & 0x3) << 12
self.write_reg(_CMD_REG_CONF3, reg)
self._osr2 = level

@property
def offset_x(self) -> int:
"""The X axis offset."""
Expand Down

0 comments on commit 3199526

Please sign in to comment.