Skip to content

Commit a76bcfc

Browse files
committed
more calls -> iter
1 parent 8f70183 commit a76bcfc

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

adafruit_vl53l0x.py

+13-23
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,12 @@ def _get_spad_info(self):
279279
# Get reference SPAD count and type, returned as a 2-tuple of
280280
# count and boolean is_aperture. Based on code from:
281281
# https://github.com/pololu/vl53l0x-arduino/blob/master/VL53L0X.cpp
282-
self._write_u8(0x80, 0x01)
283-
self._write_u8(0xFF, 0x01)
284-
self._write_u8(0x00, 0x00)
285-
self._write_u8(0xFF, 0x06)
282+
for pair in ((0x80, 0x01), (0xFF, 0x01), (0x00, 0x00), (0xFF, 0x06)):
283+
self._write_u8(pair[0], pair[1])
286284
self._write_u8(0x83, self._read_u8(0x83) | 0x04)
287-
self._write_u8(0xFF, 0x07)
288-
self._write_u8(0x81, 0x01)
289-
self._write_u8(0x80, 0x01)
290-
self._write_u8(0x94, 0x6b)
291-
self._write_u8(0x83, 0x00)
285+
for pair in ((0xFF, 0x07), (0x81, 0x01), (0x80, 0x01),
286+
(0x94, 0x6b), (0x83, 0x00)):
287+
self._write_u8(pair[0], pair[1])
292288
start = time.monotonic()
293289
while self._read_u8(0x83) == 0x00:
294290
if self.io_timeout_s > 0 and \
@@ -298,13 +294,11 @@ def _get_spad_info(self):
298294
tmp = self._read_u8(0x92)
299295
count = tmp & 0x7F
300296
is_aperture = ((tmp >> 7) & 0x01) == 1
301-
self._write_u8(0x81, 0x00)
302-
self._write_u8(0xFF, 0x06)
297+
for pair in ((0x81, 0x00), (0xFF, 0x06)):
298+
self._write_u8(pair[0], pair[1])
303299
self._write_u8(0x83, self._read_u8(0x83) & ~0x04)
304-
self._write_u8(0xFF, 0x01)
305-
self._write_u8(0x00, 0x01)
306-
self._write_u8(0xFF, 0x00)
307-
self._write_u8(0x80, 0x00)
300+
for pair in ((0xFF, 0x01), (0x00, 0x01), (0xFF, 0x00), (0x80, 0x00)):
301+
self._write_u8(pair[0], pair[1])
308302
return (count, is_aperture)
309303

310304
def _perform_single_ref_calibration(self, vhv_init_byte):
@@ -440,14 +434,10 @@ def range(self):
440434
# Adapted from readRangeSingleMillimeters &
441435
# readRangeContinuousMillimeters in pololu code at:
442436
# https://github.com/pololu/vl53l0x-arduino/blob/master/VL53L0X.cpp
443-
self._write_u8(0x80, 0x01)
444-
self._write_u8(0xFF, 0x01)
445-
self._write_u8(0x00, 0x00)
446-
self._write_u8(0x91, self._stop_variable)
447-
self._write_u8(0x00, 0x01)
448-
self._write_u8(0xFF, 0x00)
449-
self._write_u8(0x80, 0x00)
450-
self._write_u8(_SYSRANGE_START, 0x01)
437+
for pair in ((0x80, 0x01), (0xFF, 0x01), (0x00, 0x00),
438+
(0x91, self._stop_variable), (0x00, 0x01), (0xFF, 0x00),
439+
(0x80, 0x00), (_SYSRANGE_START, 0x01)):
440+
self._write_u8(pair[0], pair[1])
451441
start = time.monotonic()
452442
while (self._read_u8(_SYSRANGE_START) & 0x01) > 0:
453443
if self.io_timeout_s > 0 and \

0 commit comments

Comments
 (0)