From 0c11b3d29ad59b8269dcbbe3e0845094522b2a17 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 20 Aug 2019 21:45:33 -0700 Subject: [PATCH] Remove stop kwarg and use write_then_readinto. See https://github.com/adafruit/circuitpython/issues/2082 for details. --- adafruit_vl6180x.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/adafruit_vl6180x.py b/adafruit_vl6180x.py index cc94cca..282e243 100644 --- a/adafruit_vl6180x.py +++ b/adafruit_vl6180x.py @@ -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]