From 0084513688e8e6cbcc19e98a9a1fd6713eae4430 Mon Sep 17 00:00:00 2001 From: katzenparadoxon <katzenparadoxon@malbolge.net> Date: Tue, 27 Aug 2019 21:02:14 +0000 Subject: [PATCH] feat(bhi160.py): Add function to disable all sensors --- pycardium/modules/bhi160-sys.c | 13 +++++++++++++ pycardium/modules/py/bhi160.py | 9 +++++++++ pycardium/modules/qstrdefs.h | 1 + 3 files changed, 23 insertions(+) diff --git a/pycardium/modules/bhi160-sys.c b/pycardium/modules/bhi160-sys.c index db0a5c9a..7320885c 100644 --- a/pycardium/modules/bhi160-sys.c +++ b/pycardium/modules/bhi160-sys.c @@ -66,6 +66,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( mp_bhi160_disable_sensor_obj, mp_bhi160_disable_sensor ); +STATIC mp_obj_t mp_bhi160_disable_all_sensors() +{ + epic_bhi160_disable_all_sensors(); + + return mp_const_none; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_0( + mp_bhi160_disable_all_sensors_obj, mp_bhi160_disable_all_sensors +); + STATIC const mp_rom_map_elem_t bhi160_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_bhi160) }, { MP_ROM_QSTR(MP_QSTR_enable_sensor), @@ -74,6 +85,8 @@ STATIC const mp_rom_map_elem_t bhi160_module_globals_table[] = { MP_ROM_PTR(&mp_bhi160_read_sensor_obj) }, { MP_ROM_QSTR(MP_QSTR_disable_sensor), MP_ROM_PTR(&mp_bhi160_disable_sensor_obj) }, + { MP_ROM_QSTR(MP_QSTR_disable_all_sensors), + MP_ROM_PTR(&mp_bhi160_disable_all_sensors_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bhi160_module_globals, bhi160_module_globals_table); diff --git a/pycardium/modules/py/bhi160.py b/pycardium/modules/py/bhi160.py index f95874e5..5d28e1e6 100644 --- a/pycardium/modules/py/bhi160.py +++ b/pycardium/modules/py/bhi160.py @@ -5,6 +5,15 @@ import ucollections DataVector = ucollections.namedtuple("DataVector", ["x", "y", "z", "status"]) +def disable_all_sensors(): + """ + Disable all sensor also if they are already deactivated. + + :returns: None + """ + sys_bhi160.disable_all_sensors() + + class BHI160: def enable_sensor(self): interrupt.disable_callback(self.interrupt_id) diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index c5813602..75c8876e 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -67,6 +67,7 @@ Q(RTC_ALARM) Q(sys_bhi160) Q(enable_sensor) Q(disable_sensor) +Q(disable_all_sensors) Q(read_sensor) Q(x) Q(y) -- GitLab