@@ -279,16 +279,12 @@ def _get_spad_info(self):
279
279
# Get reference SPAD count and type, returned as a 2-tuple of
280
280
# count and boolean is_aperture. Based on code from:
281
281
# 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 ])
286
284
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 ])
292
288
start = time .monotonic ()
293
289
while self ._read_u8 (0x83 ) == 0x00 :
294
290
if self .io_timeout_s > 0 and \
@@ -298,13 +294,11 @@ def _get_spad_info(self):
298
294
tmp = self ._read_u8 (0x92 )
299
295
count = tmp & 0x7F
300
296
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 ] )
303
299
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 ])
308
302
return (count , is_aperture )
309
303
310
304
def _perform_single_ref_calibration (self , vhv_init_byte ):
@@ -440,14 +434,10 @@ def range(self):
440
434
# Adapted from readRangeSingleMillimeters &
441
435
# readRangeContinuousMillimeters in pololu code at:
442
436
# 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 ])
451
441
start = time .monotonic ()
452
442
while (self ._read_u8 (_SYSRANGE_START ) & 0x01 ) > 0 :
453
443
if self .io_timeout_s > 0 and \
0 commit comments