From 6b051ef58bc96e6f60556dcbab194011f4918db0 Mon Sep 17 00:00:00 2001 From: ladyada Date: Thu, 5 Mar 2020 10:34:43 -0500 Subject: [PATCH] add high pass filter support --- adafruit_lsm6ds.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index 67de186..832e6af 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -73,6 +73,7 @@ _LSM6DS_CTRL3_C = const(0x12) _LSM6DS_CTRL_5_C = const(0x14) _LSM6DS_MASTER_CONFIG = const(0x14) +_LSM6DS_CTRL8_XL = const(0x17) _LSM6DS_CTRL9_XL = const(0x18) _LSM6DS_CTRL10_C = const(0x19) _LSM6DS_OUT_TEMP_L = const(0x20) @@ -157,6 +158,17 @@ class Rate(CV): ('RATE_1_6_HZ', 11, 1.6, None) )) +class AccelHPF(CV): + """Options for the accelerometer high pass filter""" + pass #pylint: disable=unnecessary-pass + +AccelHPF.add_values(( + ('SLOPE', 0, 0, None), + ('HPF_DIV100', 1, 0, None), + ('HPF_DIV9', 2, 0, None), + ('HPF_DIV400', 3, 0, None), +)) + class LSM6DS: #pylint: disable=too-many-instance-attributes @@ -220,6 +232,9 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes _ped_enable = RWBit(_LSM6DS_TAP_CFG, 6) _func_enable = RWBit(_LSM6DS_CTRL10_C, 2) + high_pass_filter_enabled = RWBit(_LSM6DS_CTRL8_XL, 2) + _pass_filter = RWBits(2, _LSM6DS_CTRL8_XL, 5) + CHIP_ID = None def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS): @@ -360,6 +375,18 @@ def pedometer_enable(self, enable): self._func_enable = enable self.pedometer_reset = enable + @property + def high_pass_filter(self): + """The high pass filter applied to accelerometer data""" + return self._pass_filter + + @high_pass_filter.setter + def high_pass_filter(self, value): + if not AccelHPF.is_valid(value): + raise AttributeError("range must be an `AccelHPF`") + self._pass_filter = value + + class LSM6DSOX(LSM6DS): #pylint: disable=too-many-instance-attributes """Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.