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: