Skip to content

Commit b3a1601

Browse files
committed
simplify continuous manager, add license
1 parent e100ce8 commit b3a1601

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

adafruit_vl53l0x.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -589,25 +589,21 @@ def read_range(self):
589589

590590
@property
591591
def is_continuous_mode(self):
592-
"""Is the sensor currently in continuous mode?
593-
"""
592+
"""Is the sensor currently in continuous mode?"""
594593
return self._continuous_mode
595594

596595
def continuous_mode(self):
597-
"""Create a new context manager to manage the continuous mode
598-
"""
599-
class continuous_manager:
600-
def __init__(self, driver):
601-
self.driver = driver
596+
"""Activate the continuous mode manager"""
597+
return self
602598

603-
def __enter__(self):
604-
self.driver.start_continuous()
605-
return self.driver
599+
def __enter__(self):
600+
"""For continuous mode manager, called when used on `with` keyword"""
601+
self.start_continuous()
602+
return self
606603

607-
def __exit__(self, exc_type, exc_value, tb):
608-
self.driver.stop_continuous()
609-
610-
return continuous_manager(self)
604+
def __exit__(self, exc_type, exc_value, traceback):
605+
"""For continuous mode manager, called at the end of `with` scope"""
606+
self.stop_continuous()
611607

612608
def start_continuous(self):
613609
"""Perform a continuous reading of the range for an object in front of
@@ -636,8 +632,7 @@ def start_continuous(self):
636632
self._continuous_mode = True
637633

638634
def stop_continuous(self):
639-
"""Stop continuous readings.
640-
"""
635+
"""Stop continuous readings."""
641636
# Adapted from stopContinuous in pololu code at:
642637
# https://github.com/pololu/vl53l0x-arduino/blob/master/VL53L0X.cpp
643638
for pair in (

examples/vl53l0x_multiple_sensors_continuous.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 Smankusors for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
14
"""
25
Example of how to use the adafruit_vl53l0x library to change the assigned address of
36
multiple VL53L0X sensors on the same I2C bus. This example only focuses on 2 VL53L0X
@@ -84,7 +87,7 @@ def detect_range(count=5):
8487

8588

8689
def stop_continuous():
87-
""" this is not required, if you use XSHUT to reset the sensor.
90+
"""this is not required, if you use XSHUT to reset the sensor.
8891
unless if you want to save some energy
8992
"""
9093
for sensor in vl53:

examples/vl53l0x_simplecontinuous.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 Smankusors for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
14
# Simple demo of the VL53L0X distance sensor with continuous mode.
25
# Will print the sensed range/distance as fast as possible.
36
import time

0 commit comments

Comments
 (0)