Skip to content

Commit

Permalink
Remove stop kwarg and use write_then_readinto.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Aug 21, 2019
1 parent 37bf4cd commit 0c11b3d
Showing 1 changed file with 9 additions and 15 deletions.
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]

0 comments on commit 0c11b3d

Please sign in to comment.