Added accelerometer sensor backend

This commit is contained in:
Fabio Manganiello 2018-09-06 02:31:01 +02:00
parent 692d33a071
commit 98a8874084
2 changed files with 28 additions and 2 deletions

View file

@ -0,0 +1,22 @@
from platypush.backend.sensor import SensorBackend
from platypush.context import get_plugin
class SensorAccelerometerBackend(SensorBackend):
"""
Backend to poll position information from an accelerometer sensor.
Requires:
* ``Adafruit_Python_GPIO`` (``pip install Adafruit_Python_GPIO``)
* The :mod:`platypush.plugins.gpio.sensor.accelerometer` plugin configured
"""
def get_measurement(self):
""" get_measurement implementation """
plugin = get_plugin('gpio.sensor.accelerometer')
return plugin.get_data().output
# vim:sw=4:ts=4:et:

View file

@ -47,10 +47,14 @@ class GpioSensorAccelerometerPlugin(GpioSensorPlugin):
""" """
Extends :func:`.GpioSensorPlugin.get_measurement` Extends :func:`.GpioSensorPlugin.get_measurement`
:returns: The sensor's current position as a list with the three components (x,y,z) in degrees, each between -90 and 90 :returns: The sensor's current position as a dictionary with the three components (x,y,z) in degrees, each between -90 and 90
""" """
return [self.sensor.getX()*100, self.sensor.getY()*100, self.sensor.getZ()*100] return {
'x': self.sensor.getX()*100,
'y': self.sensor.getY()*100,
'z': self.sensor.getZ()*100
}
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: