From d6de1189e579193a7615a798c60b7c5c91558441 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 24 Sep 2019 00:13:02 +0200 Subject: [PATCH] Simplified motion sensor interface by removing unneeded absolute vector --- platypush/backend/sensor/motion/pwm3901.py | 18 ++-------------- .../plugins/gpio/sensor/motion/pwm3901.py | 21 ++++++------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/platypush/backend/sensor/motion/pwm3901.py b/platypush/backend/sensor/motion/pwm3901.py index 401f12979..6bb7c3290 100644 --- a/platypush/backend/sensor/motion/pwm3901.py +++ b/platypush/backend/sensor/motion/pwm3901.py @@ -13,26 +13,12 @@ class SensorMotionPwm3901Backend(SensorBackend): _default_poll_seconds = 0.01 - def __init__(self, absolute=True, relative=True, **kwargs): - """ - :param absolute: Enable absolute motion sensor events (default: true) - :param relative: Enable relative motion sensor events (default: true) - """ - - enabled_sensors = { - 'motion_rel_x': relative, - 'motion_rel_y': relative, - 'motion_rel_mod': relative, - 'motion_abs_x': absolute, - 'motion_abs_y': absolute, - 'motion_abs_mod': absolute, - } - + def __init__(self, **kwargs): if 'poll_seconds' not in kwargs: # noinspection PyTypeChecker kwargs['poll_seconds'] = self._default_poll_seconds - super().__init__(plugin='gpio.sensor.motion.pwm3901', enabled_sensors=enabled_sensors, **kwargs) + super().__init__(plugin='gpio.sensor.motion.pwm3901', **kwargs) # vim:sw=4:ts=4:et: diff --git a/platypush/plugins/gpio/sensor/motion/pwm3901.py b/platypush/plugins/gpio/sensor/motion/pwm3901.py index a38fdaef8..318585fab 100644 --- a/platypush/plugins/gpio/sensor/motion/pwm3901.py +++ b/platypush/plugins/gpio/sensor/motion/pwm3901.py @@ -45,7 +45,6 @@ class GpioSensorMotionPwm3901Plugin(GpioSensorPlugin): super().__init__(**kwargs) self.spi_port = spi_port self._sensor = None - (self.x, self.y) = (0, 0) try: if isinstance(rotation, int): @@ -82,28 +81,20 @@ class GpioSensorMotionPwm3901Plugin(GpioSensorPlugin): :returns: dict. Example:: output = { - "motion_rel_x": 0, # Detected relative motion vector X-coord - "motion_rel_y": 1, # Detected relative motion vector Y-coord - "motion_abs_x": 3, # Detected absolute motion vector X-coord - "motion_abs_y": 3, # Detected absolute motion vector Y-coord - "motion_rel_mod": 1, # Detected relative motion vector module - "motion_abs_mod": 5 # Detected absolute motion vector module + "motion_x": 3, # Detected motion vector X-coord + "motion_y": 4, # Detected motion vector Y-coord + "motion_mod": 5 # Detected motion vector module } """ sensor = self._get_sensor() x, y = sensor.get_motion() - self.x += x - self.y += y return { - 'motion_rel_x': x, - 'motion_rel_y': y, - 'motion_abs_x': self.x, - 'motion_abs_y': self.y, - 'motion_rel_mod': math.sqrt(x * x + y * y), - 'motion_abs_mod': math.sqrt(self.x * self.x + self.y * self.y), + 'motion_x': x, + 'motion_y': y, + 'motion_mod': math.sqrt(x * x + y * y), }