Added accelerometer sensor backend
This commit is contained in:
parent
692d33a071
commit
98a8874084
2 changed files with 28 additions and 2 deletions
22
platypush/backend/sensor/accelerometer.py
Normal file
22
platypush/backend/sensor/accelerometer.py
Normal 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:
|
||||
|
|
@ -47,10 +47,14 @@ class GpioSensorAccelerometerPlugin(GpioSensorPlugin):
|
|||
"""
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue