Skip to content

Remove stop kwarg and use write_then_readinto. #6

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
24 changes: 9 additions & 15 deletions adafruit_vl6180x.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,29 +266,23 @@ def _write_8(self, address, data):
def _write_16(self, address, data):
# Write a 16-bit big endian value to the specified 16-bit register
# address.
with self._device:
self._device.write(bytes([(address >> 8) & 0xFF,
address & 0xFF,
(data >> 8) & 0xFF,
data & 0xFF]))
with self._device as i2c:
i2c.write(bytes([(address >> 8) & 0xFF,
address & 0xFF,
(data >> 8) & 0xFF,
data & 0xFF]))

def _read_8(self, address):
# Read and return a byte from the specified 16-bit register address.
with self._device:
self._device.write(bytes([(address >> 8) & 0xFF,
address & 0xFF]),
stop=False)
with self._device as i2c:
result = bytearray(1)
self._device.readinto(result)
i2c.write_then_readinto(bytes([(address >> 8) & 0xFF, address & 0xFF]), result)
return result[0]

def _read_16(self, address):
# Read and return a 16-bit unsigned big endian value read from the
# specified 16-bit register address.
with self._device:
self._device.write(bytes([(address >> 8) & 0xFF,
address & 0xFF]),
stop=False)
with self._device as i2c:
result = bytearray(2)
self._device.readinto(result)
i2c.write_then_readinto(bytes([(address >> 8) & 0xFF, address & 0xFF]), result)
return (result[0] << 8) | result[1]