Skip to content

Commit 74a7a7f

Browse files
authored
Merge pull request #6 from tannewt/remove_stop
Remove stop kwarg and use write_then_readinto.
2 parents 37bf4cd + 0c11b3d commit 74a7a7f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

adafruit_vl6180x.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,29 +266,23 @@ def _write_8(self, address, data):
266266
def _write_16(self, address, data):
267267
# Write a 16-bit big endian value to the specified 16-bit register
268268
# address.
269-
with self._device:
270-
self._device.write(bytes([(address >> 8) & 0xFF,
271-
address & 0xFF,
272-
(data >> 8) & 0xFF,
273-
data & 0xFF]))
269+
with self._device as i2c:
270+
i2c.write(bytes([(address >> 8) & 0xFF,
271+
address & 0xFF,
272+
(data >> 8) & 0xFF,
273+
data & 0xFF]))
274274

275275
def _read_8(self, address):
276276
# Read and return a byte from the specified 16-bit register address.
277-
with self._device:
278-
self._device.write(bytes([(address >> 8) & 0xFF,
279-
address & 0xFF]),
280-
stop=False)
277+
with self._device as i2c:
281278
result = bytearray(1)
282-
self._device.readinto(result)
279+
i2c.write_then_readinto(bytes([(address >> 8) & 0xFF, address & 0xFF]), result)
283280
return result[0]
284281

285282
def _read_16(self, address):
286283
# Read and return a 16-bit unsigned big endian value read from the
287284
# specified 16-bit register address.
288-
with self._device:
289-
self._device.write(bytes([(address >> 8) & 0xFF,
290-
address & 0xFF]),
291-
stop=False)
285+
with self._device as i2c:
292286
result = bytearray(2)
293-
self._device.readinto(result)
287+
i2c.write_then_readinto(bytes([(address >> 8) & 0xFF, address & 0xFF]), result)
294288
return (result[0] << 8) | result[1]

0 commit comments

Comments
 (0)