From 36f4efbca9561462ec821821cffb55a79eb4dfb7 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Tue, 13 Oct 2020 21:49:42 +0200 Subject: [PATCH] fix(bhi160): Allow to re-open the sensor from Python Closes #210 --- pycardium/modules/py/bhi160.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pycardium/modules/py/bhi160.py b/pycardium/modules/py/bhi160.py index 430508d1..6036e9a2 100644 --- a/pycardium/modules/py/bhi160.py +++ b/pycardium/modules/py/bhi160.py @@ -18,6 +18,11 @@ class BHI160: def enable_sensor(self): interrupt.disable_callback(self.interrupt_id) interrupt.set_callback(self.interrupt_id, self._interrupt) + + # If the sensor is already enabled, disable it first. + # The call is allowed to silently fail. + sys_bhi160.disable_sensor(self.sensor_id) + self.stream_id = sys_bhi160.enable_sensor( self.sensor_id, self.sample_buffer_len, self.sample_rate, self.dynamic_range ) -- GitLab