forked from platypush/platypush
Added plugin and backend for VL53L1X laser ranger/distance sensor
This commit is contained in:
parent
8462f474f7
commit
e60660b0e6
8 changed files with 115 additions and 0 deletions
|
@ -32,6 +32,7 @@ Backends
|
||||||
platypush/backend/scard.rst
|
platypush/backend/scard.rst
|
||||||
platypush/backend/sensor.accelerometer.rst
|
platypush/backend/sensor.accelerometer.rst
|
||||||
platypush/backend/sensor.bme280.rst
|
platypush/backend/sensor.bme280.rst
|
||||||
|
platypush/backend/sensor.distance.vl53l1x.rst
|
||||||
platypush/backend/sensor.envirophat.rst
|
platypush/backend/sensor.envirophat.rst
|
||||||
platypush/backend/sensor.ir.zeroborg.rst
|
platypush/backend/sensor.ir.zeroborg.rst
|
||||||
platypush/backend/sensor.leap.rst
|
platypush/backend/sensor.leap.rst
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
``platypush.backend.sensor.distance.vl53l1x``
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
.. automodule:: platypush.backend.sensor.distance.vl53l1x
|
||||||
|
:members:
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
``platypush.plugins.gpio.sensor.distance.vl53l1x``
|
||||||
|
==================================================
|
||||||
|
|
||||||
|
.. automodule:: platypush.plugins.gpio.sensor.distance.vl53l1x
|
||||||
|
:members:
|
||||||
|
|
|
@ -27,6 +27,7 @@ Plugins
|
||||||
platypush/plugins/gpio.sensor.accelerometer.rst
|
platypush/plugins/gpio.sensor.accelerometer.rst
|
||||||
platypush/plugins/gpio.sensor.bme280.rst
|
platypush/plugins/gpio.sensor.bme280.rst
|
||||||
platypush/plugins/gpio.sensor.distance.rst
|
platypush/plugins/gpio.sensor.distance.rst
|
||||||
|
platypush/plugins/gpio.sensor.distance.vl53l1x.rst
|
||||||
platypush/plugins/gpio.sensor.envirophat.rst
|
platypush/plugins/gpio.sensor.envirophat.rst
|
||||||
platypush/plugins/gpio.sensor.ltr559.rst
|
platypush/plugins/gpio.sensor.ltr559.rst
|
||||||
platypush/plugins/gpio.sensor.mcp3008.rst
|
platypush/plugins/gpio.sensor.mcp3008.rst
|
||||||
|
|
30
platypush/backend/sensor/distance/vl53l1x.py
Normal file
30
platypush/backend/sensor/distance/vl53l1x.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from platypush.backend.sensor import SensorBackend
|
||||||
|
|
||||||
|
|
||||||
|
class SensorDistanceVl53l1xBackend(SensorBackend):
|
||||||
|
"""
|
||||||
|
Backend to poll an `VL53L1x <https://www.st.com/en/imaging-and-photonics-solutions/vl53l1x.html>`_
|
||||||
|
laser ranger/distance sensor
|
||||||
|
|
||||||
|
Requires:
|
||||||
|
|
||||||
|
* ``smbus2`` (``pip install smbus2``)
|
||||||
|
* ``vl53l1x`` (``pip install vl53l1x``)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, short=True, medium=True, long=True, **kwargs):
|
||||||
|
"""
|
||||||
|
:param short: Enable short range measurement (default: True)
|
||||||
|
:param medium: Enable medium range measurement (default: True)
|
||||||
|
:param long: Enable long range measurement (default: True)
|
||||||
|
"""
|
||||||
|
enabled_sensors = {
|
||||||
|
'short': short,
|
||||||
|
'medium': medium,
|
||||||
|
'long': long,
|
||||||
|
}
|
||||||
|
|
||||||
|
super().__init__(plugin='gpio.sensor.distance.vl53l1x', enabled_sensors=enabled_sensors, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# vim:sw=4:ts=4:et:
|
67
platypush/plugins/gpio/sensor/distance/vl53l1x.py
Normal file
67
platypush/plugins/gpio/sensor/distance/vl53l1x.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
from platypush.plugins import action
|
||||||
|
from platypush.plugins.gpio.sensor import GpioSensorPlugin
|
||||||
|
|
||||||
|
|
||||||
|
class GpioSensorDistanceVl53l1xPlugin(GpioSensorPlugin):
|
||||||
|
"""
|
||||||
|
Plugin to interact with an `VL53L1x <https://www.st.com/en/imaging-and-photonics-solutions/vl53l1x.html>`_
|
||||||
|
laser ranger/distance sensor
|
||||||
|
|
||||||
|
Requires:
|
||||||
|
|
||||||
|
* ``smbus2`` (``pip install smbus2``)
|
||||||
|
* ``vl53l1x`` (``pip install vl53l1x``)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, i2c_bus=1, i2c_address=0x29, **kwargs):
|
||||||
|
"""
|
||||||
|
:param i2c_bus: I2C bus number (default: 1)
|
||||||
|
:param i2c_address: I2C address (default: 0x29)
|
||||||
|
"""
|
||||||
|
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self.i2c_bus = i2c_bus
|
||||||
|
self.i2c_address = i2c_address
|
||||||
|
self._device = None
|
||||||
|
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
def _get_device(self):
|
||||||
|
if self._device:
|
||||||
|
return self._device
|
||||||
|
|
||||||
|
import VL53L1X
|
||||||
|
self._device = VL53L1X(i2c_bus=self.i2c_bus, i2c_address=self.i2c_address)
|
||||||
|
return self._device
|
||||||
|
|
||||||
|
@action
|
||||||
|
def get_measurement(self, short=True, medium=True, long=True):
|
||||||
|
"""
|
||||||
|
:param short: Enable short range measurement (default: True)
|
||||||
|
:param medium: Enable medium range measurement (default: True)
|
||||||
|
:param long: Enable long range measurement (default: True)
|
||||||
|
|
||||||
|
:returns: dict. Example::
|
||||||
|
|
||||||
|
output = {
|
||||||
|
"short": 83, # Short range measurement in mm
|
||||||
|
"medium": 103, # Medium range measurement
|
||||||
|
"long": 43, # Long range measurement
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
device = self._get_device()
|
||||||
|
device.open()
|
||||||
|
ret = {}
|
||||||
|
|
||||||
|
for i, r in enumerate(['short', 'medium', 'long']):
|
||||||
|
if eval(r):
|
||||||
|
device.start_ranging(i+1)
|
||||||
|
ret[r] = device.get_distance()
|
||||||
|
device.stop_ranging()
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
# vim:sw=4:ts=4:et:
|
|
@ -159,3 +159,6 @@ pyScss
|
||||||
# Support for LTR559 light/proximity sensor
|
# Support for LTR559 light/proximity sensor
|
||||||
# ltr559
|
# ltr559
|
||||||
|
|
||||||
|
# Support for VL53L1X laser ranger/distance sensor
|
||||||
|
# smbus2
|
||||||
|
# vl53l1x
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -175,6 +175,7 @@ setup(
|
||||||
'Support for GPS': ['gps'],
|
'Support for GPS': ['gps'],
|
||||||
'Support for BME280 environment sensor': ['pimoroni-bme280'],
|
'Support for BME280 environment sensor': ['pimoroni-bme280'],
|
||||||
'Support for LTR559 light/proximity sensor': ['ltr559'],
|
'Support for LTR559 light/proximity sensor': ['ltr559'],
|
||||||
|
'Support for VL53L1X laser ranger/distance sensor': ['smbus2','vl53l1x'],
|
||||||
# 'Support for Leap Motion backend': ['git+ssh://git@github.com:BlackLight/leap-sdk-python3.git'],
|
# 'Support for Leap Motion backend': ['git+ssh://git@github.com:BlackLight/leap-sdk-python3.git'],
|
||||||
# 'Support for Flic buttons': ['git+https://@github.com/50ButtonsEach/fliclib-linux-hci.git']
|
# 'Support for Flic buttons': ['git+https://@github.com/50ButtonsEach/fliclib-linux-hci.git']
|
||||||
# 'Support for media subtitles': ['git+https://github.com/agonzalezro/python-opensubtitles#egg=python-opensubtitles']
|
# 'Support for media subtitles': ['git+https://github.com/agonzalezro/python-opensubtitles#egg=python-opensubtitles']
|
||||||
|
|
Loading…
Reference in a new issue