Skip to content

Update read_reg() to use repeated start #38

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 1 commit into from
Mar 28, 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
9 changes: 3 additions & 6 deletions adafruit_mlx90393.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,12 @@ def read_reg(self, reg: int) -> int:

:param int reg: The register to read
"""
# Write 'value' to the specified register
# Read register
payload = bytes([_CMD_RR, reg << 2])
with self.i2c_device as i2c:
i2c.write(payload)

# Read the response (+1 to account for the mandatory status byte!)
data = bytearray(3)
with self.i2c_device as i2c:
i2c.readinto(data)
i2c.write_then_readinto(payload, data)

# Unpack data (status byte, big-endian 16-bit register value)
self._status_last, val = struct.unpack(">BH", data)
if self._debug:
Expand Down