Skip to content

Add Temperature Oversampling #48

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does self.temperature_oversampling need to get set here? It seems like the getter/setter properties will override this immediately. Maybe we can remove it here inside of init.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just copying what all the other settings were doing.


# 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