Skip to content

Remove stop kwarg and use write_then_readinto. #18

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
Aug 23, 2019
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
12 changes: 6 additions & 6 deletions adafruit_mcp9808.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ def __init__(self, i2c_bus, address=0x18):
self.buf = bytearray(3)
self.buf[0] = 0x06
with self.i2c_device as i2c:
i2c.write(self.buf, end=1, stop=False)
i2c.readinto(self.buf, start=1)
i2c.write_then_readinto(self.buf, self.buf,
out_end=1, in_start=1)

ok = self.buf[2] == 0x54 and self.buf[1] == 0

# Check device id.
self.buf[0] = 0x07
with self.i2c_device as i2c:
i2c.write(self.buf, end=1, stop=False)
i2c.readinto(self.buf, start=1)
i2c.write_then_readinto(self.buf, self.buf,
out_end=1, in_start=1)

if not ok or self.buf[1] != 0x04:
raise ValueError("Unable to find MCP9808 at i2c address " + str(hex(address)))
Expand All @@ -94,8 +94,8 @@ def temperature(self):
"""Temperature in celsius. Read-only."""
self.buf[0] = 0x05
with self.i2c_device as i2c:
i2c.write(self.buf, end=1, stop=False)
i2c.readinto(self.buf, start=1)
i2c.write_then_readinto(self.buf, self.buf,
out_end=1, in_start=1)

# Clear flags from the value
self.buf[1] = self.buf[1] & 0x1f
Expand Down