From 98a8874084ec2969e32cc36d66918627d9ec30f2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 6 Sep 2018 02:31:01 +0200 Subject: [PATCH] Added accelerometer sensor backend --- platypush/backend/sensor/accelerometer.py | 22 +++++++++++++++++++ .../gpio/sensor/accelerometer/__init__.py | 8 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 platypush/backend/sensor/accelerometer.py diff --git a/platypush/backend/sensor/accelerometer.py b/platypush/backend/sensor/accelerometer.py new file mode 100644 index 000000000..ee9a05922 --- /dev/null +++ b/platypush/backend/sensor/accelerometer.py @@ -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: + diff --git a/platypush/plugins/gpio/sensor/accelerometer/__init__.py b/platypush/plugins/gpio/sensor/accelerometer/__init__.py index 6f3c7ee22..11c592dd0 100644 --- a/platypush/plugins/gpio/sensor/accelerometer/__init__.py +++ b/platypush/plugins/gpio/sensor/accelerometer/__init__.py @@ -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: