45
45
https://github.com/adafruit/circuitpython/releases
46
46
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
47
47
"""
48
- import atexit
49
48
import math
50
49
import time
51
50
@@ -321,7 +320,6 @@ def __init__(self, i2c, address=41, io_timeout_s=0):
321
320
self ._perform_single_ref_calibration (0x00 )
322
321
# "restore the previous Sequence Config"
323
322
self ._write_u8 (_SYSTEM_SEQUENCE_CONFIG , 0xE8 )
324
- atexit .register (self ._cleanup )
325
323
326
324
def _read_u8 (self , address ):
327
325
# Read an 8-bit unsigned value from the specified 8-bit address.
@@ -458,11 +456,6 @@ def _get_sequence_step_timeouts(self, pre_range):
458
456
pre_range_mclks ,
459
457
)
460
458
461
- def _cleanup (self ):
462
- #when exiting, don't forget to also turn off continuous mode
463
- if (self ._continuous_mode ):
464
- self .stopContinuous ()
465
-
466
459
@property
467
460
def signal_rate_limit (self ):
468
461
"""The signal rate limit in mega counts per second."""
@@ -537,17 +530,17 @@ def measurement_timing_budget(self, budget_us):
537
530
538
531
@property
539
532
def range (self ):
540
- """Perform a single (or continuous if `startContinuous ` called)
533
+ """Perform a single (or continuous if `start_continuous ` called)
541
534
reading of the range for an object in front of the sensor and
542
535
return the distance in millimeters.
543
536
"""
544
537
# Adapted from readRangeSingleMillimeters in pololu code at:
545
538
# https://github.com/pololu/vl53l0x-arduino/blob/master/VL53L0X.cpp
546
- if ( not self ._continuous_mode ) :
547
- self .doRangeMeasurement ()
548
- return self .readRange ()
539
+ if not self ._continuous_mode :
540
+ self .do_range_measurement ()
541
+ return self .read_range ()
549
542
550
- def doRangeMeasurement (self ):
543
+ def do_range_measurement (self ):
551
544
"""Perform a single reading of the range for an object in front of the
552
545
sensor, but without return the distance.
553
546
"""
@@ -572,11 +565,11 @@ def doRangeMeasurement(self):
572
565
):
573
566
raise RuntimeError ("Timeout waiting for VL53L0X!" )
574
567
575
- def readRange (self ):
568
+ def read_range (self ):
576
569
"""Return a range reading in millimeters.
577
570
578
571
Note: Avoid calling this directly. If you do single mode, you need
579
- to call doRangeMeasurement first. Or your program will stuck or
572
+ to call `do_range_measurement` first. Or your program will stuck or
580
573
timeout occurred.
581
574
"""
582
575
# Adapted from readRangeContinuousMillimeters in pololu code at:
@@ -596,16 +589,17 @@ def readRange(self):
596
589
597
590
@property
598
591
def continuous_mode (self ):
592
+ """Is the sensor currently in continuous mode?"""
599
593
return self ._continuous_mode
600
594
601
595
@continuous_mode .setter
602
596
def continuous_mode (self , enabled ):
603
- if ( enabled ) :
604
- self .startContinuous ()
597
+ if enabled :
598
+ self .start_continuous ()
605
599
else :
606
- self .stopContinuous ()
600
+ self .stop_continuous ()
607
601
608
- def startContinuous (self ):
602
+ def start_continuous (self ):
609
603
"""Perform a continuous reading of the range for an object in front of
610
604
the sensor.
611
605
"""
@@ -631,7 +625,7 @@ def startContinuous(self):
631
625
raise RuntimeError ("Timeout waiting for VL53L0X!" )
632
626
self ._continuous_mode = True
633
627
634
- def stopContinuous (self ):
628
+ def stop_continuous (self ):
635
629
"""Stop continuous readings.
636
630
"""
637
631
# Adapted from stopContinuous in pololu code at:
@@ -642,7 +636,7 @@ def stopContinuous(self):
642
636
(0x00 , 0x00 ),
643
637
(0x91 , 0x00 ),
644
638
(0x00 , 0x01 ),
645
- (0xFF , 0x00 )
639
+ (0xFF , 0x00 ),
646
640
):
647
641
self ._write_u8 (pair [0 ], pair [1 ])
648
642
self ._continuous_mode = False
0 commit comments